diff --git a/app/include/pd_csg.h b/app/include/pd_csg.h index 4d281c9..20a4a41 100755 --- a/app/include/pd_csg.h +++ b/app/include/pd_csg.h @@ -45,6 +45,14 @@ /* Define --------------------------------------------------------------------*/ +#define CSG_FIFO_CMD "CSG_FIFO_CMD" +#define CSG_FIFO_PRPS "CSG_FIFO_PRPS" +#define CSG_FIFO_EVENT "CSG_FIFO_EVENT" +#define CSG_FIFO_TREND "CSG_FIFO_TREND" +#define CSG_CMD_FIFO_NUM (16) +#define CSG_PRPS_FIFO_NUM (8) +#define CSG_EVENT_FIFO_NUM (4) +#define CSG_TREND_FIFO_NUM (2) #define CSG_HEAD_LEN (32) #define CSG_TOTLE_LEN (26) #define CSG_PKT_LEN (1300) @@ -125,8 +133,12 @@ typedef struct { /* . */ typedef struct { - int skfd; // 后台通讯使用的 socket. - uint32_t pkt_index; // 报文索引. + int skfd; // 后台通讯使用的 socket. + uint32_t pkt_index; // 报文索引. + int32_t fifo_cmd_id; // 普通命令fifo + int32_t fifo_prps_id; // 实时图谱 fifo + int32_t fifo_event_id; // 事件 fifo + int32_t fifo_trend_id; // 趋势 fifo char buf_send[1500]; char buf_recv[1500]; char event_booster_buf[1500]; @@ -348,13 +360,27 @@ typedef struct } csg_contact_t; typedef struct -{ - uint32_t dev_id; - uint8_t slot; - uint8_t status; - uint8_t reserved[2]; - uint8_t port[8]; - uint8_t port_type[8]; +{ + uint8_t type_m; // 主设备号 + uint8_t type_s; // 次设备号 + uint8_t slot; // 槽位号 + uint8_t status; // 1:插入 0:拔出 + uint32_t dev_id; // 设备ID + char hostname[FILE_NAME_LEN]; // 设备名 128byte + uint32_t factory_date; // 出厂日期. + uint32_t deployment_date; // 部署日期. + uint8_t app_version[DEV_VERSION_STR_LEN]; // 软件版本 + uint8_t app_compile_time[DEV_VERSION_STR_LEN]; // 软件编译时间 + uint8_t hardware_version[DEV_VERSION_STR_LEN]; // 硬件版本 + uint8_t FPGA_version[DEV_VERSION_STR_LEN]; // fpga版本 + uint32_t ip; // 本机 IP. + uint32_t mask; // 本机 MASK. + uint32_t gw; // 本机网关 + uint8_t mac[MAC_ADDR_LEN]; // MAC地址. + uint16_t server_port; // 服务器端口号. + uint32_t server_ipv4; // 服务器 IP. + uint8_t port[PD_PORT_SUM]; + uint8_t port_type[PD_PORT_SUM]; } csg_add_dau_t; typedef struct diff --git a/app/include/pd_main.h b/app/include/pd_main.h index 054b22a..9db5f4b 100755 --- a/app/include/pd_main.h +++ b/app/include/pd_main.h @@ -81,6 +81,7 @@ typedef enum PD_SEND_TYPE_TREND, PD_SEND_TYPE_EVENT, PD_SEND_TYPE_POINT, + PD_SEND_TYPE_CMD, PD_SEND_TYPE_COUNT } PD_SEND_TYPE_E; diff --git a/app/lib/a_process/pd_csg.c b/app/lib/a_process/pd_csg.c index e9c8a88..d1b8d85 100755 --- a/app/lib/a_process/pd_csg.c +++ b/app/lib/a_process/pd_csg.c @@ -138,6 +138,26 @@ void _csg_server_set(int32_t ip, uint16_t port) csg.server.sin_port = htons(csg.server_port); } } + +/* 封装数据并写fifo */ +int32_t _csg_msg_send(uint32_t type, void *data) +{ + pd_csg_msg_t msg; + + /* 封装消息. */ + msg.type = type; + msg.data = data; + + /* 发送消息 */ + if (fifo_write(csg.fifo_cmd_id, (void*)(&msg), sizeof(pd_csg_msg_t)) != sizeof(pd_csg_msg_t)) + { + DBG(DBG_M_FIFO, "SSG write ERROR! type=%d\r\n", msg.type); + return E_ERROR; + } + + return E_NONE; +} + /* 校验收到包的包头, 长度, 校验码. */ int32_t _csg_pkt_check(char *pkt) @@ -207,8 +227,6 @@ int32_t _csg_connect_send(void) { char *pkt = csg.buf_send; csg_contact_t *pinfo = (csg_contact_t *)(pkt + sizeof(csg_pkt_head_t)); - uint8_t unit = 0; - uint8_t port = 0; pinfo->type_m = device_info.type_m; pinfo->type_s = device_info.type_s; @@ -228,21 +246,7 @@ int32_t _csg_connect_send(void) pinfo->server_ipv4 = csg.server_ip; memset(pinfo->port, 0, sizeof(pinfo->port)); - memset(pinfo->port, 0, sizeof(pinfo->port_type)); - for(unit = 0; unit < PD_DAU_SUM; unit++) - { - //if (!dau_is_valid(dau[unit])) - { - continue; - } - - //for(port = 0; port < dau[unit]->port_num; port++) - { - pinfo->port[port] = pd_config.config_port[unit][port].vport; - pinfo->port_type[port] = pd_config.config_port[unit][port].port_type;; - } - } - + memset(pinfo->port_type, 0, sizeof(pinfo->port_type)); _csg_send_data(CSG_REPLY, CSG_C_CONTACT, pkt, sizeof(csg_contact_t)); return E_NONE; @@ -308,19 +312,52 @@ void _csg_connect_recv(void) void _csg_add_dau_recv(char *pkt) { csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; - //int slot = head->slot; + int slot = head->slot; + if (slot < 0 || slot >= PD_SLOTS_MAX) + { + DBG(DBG_M_PD_CSG_ERR, "Add DAU %d error!\r\n", slot); + return; + } - printf("_csg_add_dau_recv slot = %d\n", head->slot); + printf("_csg_add_dau_recv slot = %d\n", slot); head->dev_id = head->sdev_id; head->cmd_type = CSG_REQUEST; head->cmd = CSG_C_CONTACT; head->len = CSG_HEAD_LEN + 4; - //(uint32_t *)(pkt + CSG_HEAD_LEN) = time(NULL); uint32_t *timestamp = (uint32_t *)(pkt + CSG_HEAD_LEN); *timestamp = time(NULL); + daus[slot].state.is_insert = TRUE; //_dau_response(slot, pkt, head->len); - //_dau_response(slot, pkt, head->len); +} + +void _csg_add_dau_send(int slot, int status) +{ + char *pkt = csg.buf_send; + csg_add_dau_t *pinfo = (csg_add_dau_t *)(pkt + sizeof(csg_pkt_head_t)); + dau_contact_t *pdau = &daus[slot].info; + pinfo->type_m = pdau->type_m; + pinfo->type_s = pdau->type_s; + pinfo->slot = slot; + pinfo->status = status; + pinfo->dev_id = pdau->dev_id; + strncpy(pinfo->hostname, pdau->hostname, sizeof(pinfo->hostname)-1); + pinfo->factory_date = pdau->factory_date; + pinfo->deployment_date = pdau->deployment_date; + strncpy((char *)pinfo->app_version, (char *)pdau->app_version, sizeof(pinfo->app_version)-1); + strncpy((char *)pinfo->app_compile_time, (char *)pdau->app_compile_time, sizeof(pinfo->app_compile_time)-1); + strncpy((char *)pinfo->hardware_version, (char *)pdau->hardware_version, sizeof(pinfo->hardware_version)-1); + strncpy((char *)pinfo->FPGA_version, (char *)pdau->FPGA_version, sizeof(pinfo->FPGA_version)-1); + pinfo->ip = pdau->ip; + pinfo->mask = pdau->mask; + pinfo->gw = pdau->gw; + memcpy(pinfo->mac, pdau->mac, sizeof(pinfo->mac)); + pinfo->server_port = pdau->server_port; + pinfo->server_ipv4 = pdau->server_ipv4; + memcpy(pinfo->port, pdau->port, sizeof(pinfo->port)); + memcpy(pinfo->port_type, pdau->port_type, sizeof(pinfo->port_type)); + + _csg_send_data(CSG_REPLY, CSG_C_ADD_DAU, pkt, sizeof(csg_add_dau_t)); } /* 解析心跳报文. */ @@ -572,6 +609,26 @@ int32_t _csg_port_config_get_recv(char *pkt) return E_NONE; } + +/* 解析HUF实时图谱召唤报文. */ +int32_t _csg_real_image_recv(char *pkt) +{ + csg_real_image_get_t *pdata = (csg_real_image_get_t*)(pkt + sizeof(csg_pkt_head_t)); + void *data = NULL; + + DBG(DBG_M_PD_CSG, "vport=%d \r\n", pdata->vport); + DBG(DBG_M_PD_CSG, "is_concern=%d\r\n", pdata->is_concern); + DBG(DBG_M_PD_CSG, "denoise_correlation=%d\r\n", pdata->denoise_correlation); + DBG(DBG_M_PD_CSG, "denoise_type=%d\r\n", pdata->denoise_type); + DBG(DBG_M_PD_CSG, "denoise_manual=%d\r\n", pdata->denoise_manual); + DBG(DBG_M_PD_CSG, "filter_cfg=%d\r\n", pdata->filter); + + data = XMALLOC(MTYPE_CSG, sizeof(csg_real_image_get_t)); + memcpy(data, pdata, sizeof(csg_real_image_get_t)); + _csg_msg_send(PD_SEND_TYPE_CMD, data); + return E_NONE; +} + /* 升级文件接收 */ int32_t _csg_upgrade_recv(char *pkt) @@ -718,6 +775,7 @@ int32_t _csg_recv_process(char *pkt, uint32_t len) _csg_port_config_get_recv(pkt); break; case CSG_PRV_CONFIG_REAL_WAVE: + _csg_real_image_recv(pkt); break; case CSG_PRV_TREND: break; @@ -817,6 +875,17 @@ void *_csg_heartbeat_handle(void *arg) _csg_disconnect_set(__FUNCTION__); } } + + for (int i = 0; i < PD_SLOTS_MAX; i++) + { + printf("dau[%d]:is_connect=%d is_insert=%d\n", i, daus[i].state.is_connect, + daus[i].state.is_insert); + if (daus[i].state.is_connect == TRUE + && daus[i].state.is_insert != TRUE) + { + _csg_add_dau_send(i + 1, 1); + } + } } return NULL; @@ -903,6 +972,34 @@ int32_t csg_handle_init_after(void) /* 保存数据. */ csg.skfd = fd; } + + csg.fifo_cmd_id = fifo_create(CSG_FIFO_CMD, CSG_CMD_FIFO_NUM); + if (csg.fifo_cmd_id < 0) + { + log_err(LOG_CSG, "Open fifo " CSG_FIFO_CMD " error!"); + return E_ERROR; + } + + csg.fifo_prps_id = fifo_create(CSG_FIFO_PRPS, CSG_PRPS_FIFO_NUM); + if (csg.fifo_prps_id < 0) + { + log_err(LOG_CSG, "Open fifo " CSG_FIFO_PRPS " error!"); + return E_ERROR; + } + + csg.fifo_event_id = fifo_create(CSG_FIFO_EVENT, CSG_EVENT_FIFO_NUM); + if (csg.fifo_event_id < 0) + { + log_err(LOG_CSG, "Open fifo " CSG_FIFO_EVENT " error!"); + return E_ERROR; + } + + csg.fifo_trend_id = fifo_create(CSG_FIFO_TREND, CSG_TREND_FIFO_NUM); + if (csg.fifo_trend_id < 0) + { + log_err(LOG_CSG, "Open fifo " CSG_FIFO_TREND " error!"); + return E_ERROR; + } param.arg = NULL; param.log_module = LOG_CSG;