From 157291cecc151c5bb8f6e9ce51c635314d57b5cf Mon Sep 17 00:00:00 2001 From: wangbo Date: Tue, 5 Aug 2025 00:45:17 +0000 Subject: [PATCH] =?UTF-8?q?FIX=20=E5=8D=87=E7=BA=A7=E7=AC=A6=E5=90=88?= =?UTF-8?q?=E8=A6=81=E6=B1=82=E7=9A=84slot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/include/main.h | 2 +- app/include/pd_csg.h | 7 +- app/include/pd_modbus.h | 4 - app/include/pd_upgrade.h | 1 + app/lib/a_process/main.c | 2 +- app/lib/a_process/pd_csg.c | 378 +++++++++++++++++++++------------ app/lib/a_process/pd_modbus.c | 30 +-- app/lib/a_process/pd_upgrade.c | 11 +- 8 files changed, 278 insertions(+), 157 deletions(-) diff --git a/app/include/main.h b/app/include/main.h index 1a000b4..8d15964 100755 --- a/app/include/main.h +++ b/app/include/main.h @@ -59,7 +59,7 @@ typedef enum _REBOOT_MSG REBOOT_LOCAL_ARM_UPGRADE, REBOOT_REMOTE_SERVER_IP_CHANGE, REBOOT_REMOTE_IP_CHANGE, - REBOOT_REMOTE_HOST_NAME_CHANGE, + REBOOT_REMOTE_DEVINFO_CHANGE, REBOOT_REMOTE_RESET, REBOOT_UPGRADE_ALL, REBOOT_SYSTEM_RESET, diff --git a/app/include/pd_csg.h b/app/include/pd_csg.h index a853516..d255822 100755 --- a/app/include/pd_csg.h +++ b/app/include/pd_csg.h @@ -69,13 +69,7 @@ #define CSG_SEND_TIMEOUT (2) #define CSG_SEND_ERR_CNT (3) #define CSG_FILE_FIFO_PATH_LEN 256 - -//#define MAX_FILES (128) -//#define MAX_PATH_LEN (256) -//#define THRESHOLD_MS 10 // 时间差阈值 -//#define CSG_SEND_TIMEOUT (2) -//#define CSG_SEND_ERR_CNT (3) #define CSG_FILE_NAME_LEN (128) #define DAU_INSERT 1 @@ -510,6 +504,7 @@ extern void csg_upgrade_result_send(int32_t rv, char *buf); extern void _print_sockaddr_in(const struct sockaddr_in *addr); extern command_handler _csg_get_table_handle(command_entry *ptable, command_type cmd); extern void _csg_send_data(uint8_t cmd_type, uint8_t cmd, char *pkt, int32_t len, uint8_t); +extern int32_t _csg_update_slot(uint8_t type); #endif #endif /************************ (C) COPYRIGHT LandPower ***** END OF FILE ****************/ diff --git a/app/include/pd_modbus.h b/app/include/pd_modbus.h index ccaef8b..c1df86b 100755 --- a/app/include/pd_modbus.h +++ b/app/include/pd_modbus.h @@ -31,10 +31,6 @@ typedef struct { uint8_t unit_id; uint8_t status; - uint8_t is_insert; - uint8_t is_connect; - uint8_t type_m; - uint8_t type_s; uint32_t current; uint16_t alarm; } card_t; diff --git a/app/include/pd_upgrade.h b/app/include/pd_upgrade.h index 8175c35..d4e1090 100755 --- a/app/include/pd_upgrade.h +++ b/app/include/pd_upgrade.h @@ -91,6 +91,7 @@ typedef struct uint8_t upg_type; // 升级类型 PD_UPG_TYPE_xxx pd_upg_head_t head; // 报文头信息 void (*upgrade_result)(int32_t rv, char *msg); // 升级结果回调函数 + int32_t (*upgrade_slot)(uint8_t); char msg[128]; // 返回结果字符串 } pd_upg_ctrl_t; diff --git a/app/lib/a_process/main.c b/app/lib/a_process/main.c index a3746bd..76c968a 100755 --- a/app/lib/a_process/main.c +++ b/app/lib/a_process/main.c @@ -81,7 +81,7 @@ static reboot_msg_t _reboot_msg[] = {REBOOT_LOCAL_ARM_UPGRADE, "Reboot by debug tool softwave upgrade."}, {REBOOT_REMOTE_SERVER_IP_CHANGE, "Reboot by remote has changed server."}, {REBOOT_REMOTE_IP_CHANGE, "Reboot by remote has changed device ip."}, - {REBOOT_REMOTE_HOST_NAME_CHANGE, "Reboot by remote has changed device id."}, + {REBOOT_REMOTE_DEVINFO_CHANGE, "Reboot by remote has changed device info."}, {REBOOT_REMOTE_RESET, "Reboot by remote reset."}, {REBOOT_UPGRADE_ALL, "Reboot by softwave upgrade."}, {REBOOT_SYSTEM_RESET, "Reboot by command."}, diff --git a/app/lib/a_process/pd_csg.c b/app/lib/a_process/pd_csg.c index ae1b888..a47a722 100755 --- a/app/lib/a_process/pd_csg.c +++ b/app/lib/a_process/pd_csg.c @@ -382,7 +382,6 @@ void _csg_add_dau_recv(char *pkt) slot--; log_out(LOG_CSG, LOG_LVL_WARN, "_csg_add_dau_recv slot = %d\n", slot); daus[slot].state.is_insert = TRUE; - modbus.card[slot].is_insert = TRUE; } void _csg_remove_dau_recv(char *pkt) @@ -398,8 +397,7 @@ void _csg_remove_dau_recv(char *pkt) slot--; log_out(LOG_CSG, LOG_LVL_WARN, "_csg_remove_dau_recv slot = %d\n", slot); daus[slot].state.is_insert = FALSE; - modbus.card[slot].is_insert = FALSE; - modbus.card[slot].is_connect = FALSE; + daus[slot].state.is_connect = FALSE; } @@ -420,23 +418,36 @@ int32_t _csg_reboot_recv(char *pkt) { csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; int *data = NULL; - uint8_t slot = head->slot - 1; + uint8_t slot = head->slot; if (slot > PD_SLOTS_MAX) { DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot); return E_BAD_PARAM; } - data = XMALLOC(MTYPE_CSG, sizeof(int)); - if (!data) - { - DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n"); - return E_MEM; + if (0 != slot) + { + data = XMALLOC(MTYPE_CSG, sizeof(int)); + if (!data) + { + DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n"); + return E_MEM; + } + + if (_csg_msg_send_dau(slot - 1, DAU_SEND_RESET, data) != E_NONE) + { + XFREE(MTYPE_CSG, data); + } } - - if (_csg_msg_send_dau(slot, DAU_SEND_RESET, data) != E_NONE) + else { - XFREE(MTYPE_CSG, data); + csg_ack_t ack = {0}; + + ack.result = TRUE; + memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(csg_ack_t)); + _csg_send_data(CSG_REPLY, head->cmd, pkt, sizeof(csg_ack_t), slot); + + reboot_system(LOG_CSG, REBOOT_REMOTE_RESET); } return E_NONE; } @@ -449,24 +460,61 @@ int32_t _csg_dev_info_set_recv(char *pkt) csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; csg_dev_info_t *param = (csg_dev_info_t*)(pkt + sizeof(csg_pkt_head_t)); csg_dev_info_t *data = NULL; - uint8_t slot = head->slot - 1; + uint8_t slot = head->slot; if (slot > PD_SLOTS_MAX) { DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot); return E_BAD_PARAM; } - data = XMALLOC(MTYPE_CSG, sizeof(csg_dev_info_t)); - if (!data) - { - DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n"); - return E_MEM; + if (0 != slot) + { + data = XMALLOC(MTYPE_CSG, sizeof(csg_dev_info_t)); + if (!data) + { + DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n"); + return E_MEM; + } + + memcpy(data, param, sizeof(csg_dev_info_t)); + if (_csg_msg_send_dau(slot - 1, DAU_SEND_INFO_SET, data) != E_NONE) + { + XFREE(MTYPE_CSG, data); + } } - - memcpy(data, param, sizeof(csg_dev_info_t)); - if (_csg_msg_send_dau(slot, DAU_SEND_INFO_SET, data) != E_NONE) + else { - XFREE(MTYPE_CSG, data); + csg_dev_info_t *pinfo = (csg_dev_info_t *)(pkt + sizeof(csg_pkt_head_t)); + bool change_ip = FALSE; + uint8_t mac[MAC_ADDR_LEN] = {0}; + + device_info.dev_id = pinfo->dev_id; + device_info.mask = pinfo->mask; + device_info.gw = pinfo->gw; + snprintf((char*)device_info.hostname, FILE_NAME_LEN, "%s", pinfo->hostname); + if (device_info.ip != pinfo->ip) + { + device_info.ip = pinfo->ip; + change_ip = TRUE; + } + memcpy(device_info.mac, pinfo->mac, MAC_ADDR_LEN); + csg.server_ip = pinfo->server_ipv4; + csg.server_port = pinfo->server_port; + + csg_ack_t ack = {0}; + ack.result = TRUE; + memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(csg_ack_t)); + _csg_send_data(CSG_REPLY, head->cmd, pkt, sizeof(csg_ack_t), slot); + + vtysh_config_save(); + if (change_ip) + { + mac_generate_from_ip(device_info.ip, mac); + memcpy(device_info.mac, mac, MAC_ADDR_LEN); + vtysh_eth0_save(); + } + vtysh_device_save(); + reboot_system(LOG_CSG, REBOOT_REMOTE_DEVINFO_CHANGE); } return E_NONE; } @@ -476,23 +524,49 @@ int32_t _csg_dev_info_get_recv(char *pkt) { csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; int *data = NULL; - uint8_t slot = head->slot - 1; + uint8_t slot = head->slot; if (slot > PD_SLOTS_MAX) { DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot); return E_BAD_PARAM; } - data = XMALLOC(MTYPE_CSG, sizeof(int)); - if (!data) - { - DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n"); - return E_MEM; + if (0 != slot) + { + data = XMALLOC(MTYPE_CSG, sizeof(int)); + if (!data) + { + DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n"); + return E_MEM; + } + + if (_csg_msg_send_dau(slot - 1, DAU_SEND_INFO_GET, data) != E_NONE) + { + XFREE(MTYPE_CSG, data); + } } - - if (_csg_msg_send_dau(slot, DAU_SEND_INFO_GET, data) != E_NONE) + else { - XFREE(MTYPE_CSG, data); + csg_dev_info_t *pinfo = (csg_dev_info_t *)(pkt + sizeof(csg_pkt_head_t)); + + pinfo->type_m = device_info.type_m; + pinfo->type_s = device_info.type_s; + pinfo->dev_id = device_info.dev_id; + strcpy(pinfo->hostname, device_info.hostname); + pinfo->factory_date = device_info.factory_date; + pinfo->deployment_date = device_info.deployment_date; + strncpy((char *)pinfo->app_compile_time, host.compile, 31); + strncpy((char *)pinfo->app_version, host.version, 31); + //strncpy((char *)pinfo->hardware_version, host.hardversion, 31); + //strncpy((char *)pinfo->FPGA_version, host.FPGAversion, 31); + pinfo->ip = device_info.ip; + pinfo->mask = device_info.mask; + pinfo->gw = device_info.gw; + memcpy(pinfo->mac, device_info.mac, sizeof(pinfo->mac)); + pinfo->server_port = csg.server_port; + pinfo->server_ipv4 = csg.server_ip; + + _csg_send_data(CSG_REPLY, head->cmd, pkt, sizeof(csg_dev_info_t), slot); } return E_NONE; } @@ -503,24 +577,50 @@ int32_t _csg_config_set_recv(char *pkt) csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; csg_config_global_t *param = (csg_config_global_t*)(pkt + sizeof(csg_pkt_head_t)); csg_config_global_t *data = NULL; - uint8_t slot = head->slot - 1; + uint8_t slot = head->slot; if (slot > PD_SLOTS_MAX) { DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot); return E_BAD_PARAM; } - data = XMALLOC(MTYPE_CSG, sizeof(csg_config_global_t)); - if (!data) - { - DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n"); - return E_MEM; + if (0 != slot) + { + data = XMALLOC(MTYPE_CSG, sizeof(csg_config_global_t)); + if (!data) + { + DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n"); + return E_MEM; + } + + memcpy(data, param, sizeof(csg_config_global_t)); + if (_csg_msg_send_dau(slot - 1, DAU_SEND_CFG_SET, data) != E_NONE) + { + XFREE(MTYPE_CSG, data); + } } - - memcpy(data, param, sizeof(csg_config_global_t)); - if (_csg_msg_send_dau(slot, DAU_SEND_CFG_SET, data) != E_NONE) + else { - XFREE(MTYPE_CSG, data); + csg_config_global_t *pnet = (csg_config_global_t *)(pkt + sizeof(csg_pkt_head_t)); + + pd_config.config.power_frequency = pnet->power_frequency; + pd_config.config.trend_period = pnet->trend_period * 60; + pd_config.config.sync_mode = pnet->sync_mode; + pd_config.config.heartbeat_period = pnet->heartbeat_period; + pd_config.config.pps_mode = pnet->pps_mode; + pd_config.config.protocol_type = pnet->protocol_type; + pd_config.config.event_storage = pnet->event_storage; + pd_config.config.trend_storage = pnet->trend_storage; + csg.trend_file.files_max = pd_config.config.trend_storage; + csg.event_file.files_max = pd_config.config.event_storage; + + vtysh_config_save(); + + csg_ack_t ack = {0}; + ack.result = TRUE; + memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(csg_ack_t)); + + _csg_send_data(CSG_PRV_REPLY, head->cmd, pkt, sizeof(csg_ack_t), slot); } return E_NONE; } @@ -537,16 +637,34 @@ int32_t _csg_config_get_recv(char *pkt) return E_BAD_PARAM; } - data = XMALLOC(MTYPE_CSG, sizeof(int)); - if (!data) - { - DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n"); - return E_MEM; + if (0 != slot) + { + data = XMALLOC(MTYPE_CSG, sizeof(int)); + if (!data) + { + DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n"); + return E_MEM; + } + + if (_csg_msg_send_dau(slot, DAU_SEND_CFG_GET, data) != E_NONE) + { + XFREE(MTYPE_CSG, data); + } } - - if (_csg_msg_send_dau(slot, DAU_SEND_CFG_GET, data) != E_NONE) + else { - XFREE(MTYPE_CSG, data); + csg_config_global_t *config = (csg_config_global_t *)(pkt + sizeof(csg_pkt_head_t)); + + config->power_frequency = pd_config.config.power_frequency; + config->sync_mode = pd_config.config.sync_mode; + config->heartbeat_period = pd_config.config.heartbeat_period; + config->pps_mode = pd_config.config.pps_mode; + config->protocol_type = pd_config.config.protocol_type; + config->trend_period = pd_config.config.trend_period / 60; + config->trend_storage = pd_config.config.trend_storage; + config->event_storage = pd_config.config.event_storage; + + _csg_send_data(CSG_PRV_REPLY, head->cmd, pkt, sizeof(csg_config_global_t), slot); } return E_NONE; } @@ -557,8 +675,8 @@ int32_t _csg_port_config_set_recv(char *pkt) csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; csg_config_port_t *param = (csg_config_port_t*)(pkt + sizeof(csg_pkt_head_t)); csg_config_port_t *data = NULL; - uint8_t slot = head->slot - 1; - if (slot > PD_SLOTS_MAX) + uint8_t slot = head->slot; + if (slot > PD_SLOTS_MAX && slot != 0) { DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot); return E_BAD_PARAM; @@ -573,7 +691,7 @@ int32_t _csg_port_config_set_recv(char *pkt) } memcpy(data, param, sizeof(csg_config_port_t)); - if (_csg_msg_send_dau(slot, DAU_SEND_PORT_SET, data) != E_NONE) + if (_csg_msg_send_dau(slot - 1, DAU_SEND_PORT_SET, data) != E_NONE) { XFREE(MTYPE_CSG, data); } @@ -586,8 +704,8 @@ int32_t _csg_port_config_get_recv(char *pkt) csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; uint8_t *param = (uint8_t *)(pkt + sizeof(csg_pkt_head_t)); uint8_t *data = NULL; - uint8_t slot = head->slot - 1; - if (slot > PD_SLOTS_MAX) + uint8_t slot = head->slot; + if (slot > PD_SLOTS_MAX && slot != 0) { DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot); return E_BAD_PARAM; @@ -601,7 +719,7 @@ int32_t _csg_port_config_get_recv(char *pkt) } *data = *param; - if (_csg_msg_send_dau(slot, DAU_SEND_PORT_GET, data) != E_NONE) + if (_csg_msg_send_dau(slot - 1, DAU_SEND_PORT_GET, data) != E_NONE) { XFREE(MTYPE_CSG, data); } @@ -614,8 +732,8 @@ int32_t _csg_real_image_recv(char *pkt) csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; csg_real_image_get_t *param = (csg_real_image_get_t*)(pkt + sizeof(csg_pkt_head_t)); csg_real_image_get_t *data = NULL; - uint8_t slot = head->slot - 1; - if (slot > PD_SLOTS_MAX) + uint8_t slot = head->slot; + if (slot > PD_SLOTS_MAX && slot != 0) { DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot); return E_BAD_PARAM; @@ -629,7 +747,7 @@ int32_t _csg_real_image_recv(char *pkt) } memcpy(data, param, sizeof(csg_real_image_get_t)); - if (_csg_msg_send_dau(slot, DAU_SEND_PRPS_GET, data) != E_NONE) + if (_csg_msg_send_dau(slot - 1, DAU_SEND_PRPS_GET, data) != E_NONE) { XFREE(MTYPE_CSG, data); } @@ -675,6 +793,45 @@ int32_t _csg_event_get_recv(char *pkt) } return E_NONE; } + +int32_t _csg_update_slot(uint8_t type) +{ + csg_upate_msg_t *data = NULL; + dau_t *dau = NULL; + + for (int slot = 0; slot < PD_SLOTS_MAX; slot++) + { + dau = &daus[slot]; + if (dau->info.type_m == 0x03 && (dau->info.type_s == 0x01 + || dau->info.type_s == 0x02 + || dau->info.type_s == 0x03)) + { + data = XMALLOC(MTYPE_CSG, sizeof(csg_upate_msg_t)); + if (!data) + { + DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n"); + return E_ERROR; + } + + data->type = type; + + char buff[64] = {0}; + if (getcwd(buff, sizeof(buff)) == NULL) + { + XFREE(MTYPE_CSG, data); + DBG(DBG_M_PD_CSG_ERR, "getcwd error!\n"); + return E_ERROR; + } + snprintf(data->name, 128, "%s/%s", buff, PD_UPG_SOFTWARE); + + if (_csg_msg_send_dau(slot, DAU_SEND_UPDATE, data) != E_NONE) + { + XFREE(MTYPE_CSG, data); + } + } + } + return ENABLE_NODE; +} /* 升级文件接收 */ int32_t _csg_upgrade_recv(char *pkt) @@ -687,16 +844,8 @@ int32_t _csg_upgrade_recv(char *pkt) upgrade_ack_t ack = {0}; int32_t size = 0; int32_t len_wr = 0; - int32_t rv = E_NONE; uint32_t offset = 0; - - uint8_t slot = head->slot - 1; - if (slot > PD_SLOTS_MAX) - { - DBG(DBG_M_PD_CSG, "slot:%d error\r\n", head->slot); - return E_BAD_PARAM; - } - + /* 首保处理, 打开文件描述符, 初始化变量 */ if (head_msg->index == 0) { @@ -739,51 +888,15 @@ int32_t _csg_upgrade_recv(char *pkt) close(fd); fd = -1; DBG(DBG_M_PD_CSG, "Receive upgrade file end.\n"); - csg_upate_msg_t *data; - - data = XMALLOC(MTYPE_CSG, sizeof(csg_upate_msg_t)); - if (!data) - { - DBG(DBG_M_PD_CSG_ERR, "XMALLOC ERROR!\r\n"); - rv = E_ERROR; - goto UP_ERR; - } - - data->type = head_msg->type; - - char buff[64] = {0}; - if (getcwd(buff, sizeof(buff)) == NULL) - { - DBG(DBG_M_PD_CSG_ERR, "getcwd error!\n"); - rv = E_ERROR; - goto UP_ERR; - } - - snprintf(data->name, 128, "%s/%s", buff, PD_UPG_SOFTWARE); - - if (_csg_msg_send_dau(slot, DAU_SEND_UPDATE, data) != E_NONE) - { - XFREE(MTYPE_CSG, data); - } + pd_upg_start(PD_UPG_FROM_CSG, head_msg->type); } -UP_ERR: - ack.index = head_msg->index; - ack.result = TRUE; - - DBG(DBG_M_PD_CSG_ERR," send ack\n"); - - /* 发送应答 */ - memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(csg_ack_t)); - _csg_send_data(CSG_REPLY, head->cmd, pkt, sizeof(ack), 0); + ack.index = head_msg->index; + ack.result = TRUE; - /* 如果升级线程开启失败返回错误信息. */ - if (rv != E_NONE) - { - printf("Upgrade start failed.\n"); - csg_upgrade_result_send(0, "Upgrade start failed."); - } - + /* 发送应答 */ + memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(csg_ack_t)); + _csg_send_data(CSG_REPLY, head->cmd, pkt, sizeof(ack), 0); return E_NONE; } @@ -818,7 +931,7 @@ int32_t _csg_recv_process(char *pkt, uint32_t len) return E_ERROR; } - if (3 == typem && 4 == types) + if (DEVICE_M_TYPE == typem && 4 == types) { _csgiron_recv_process(head->slot - 1, pkt, len); return E_NONE; @@ -2105,11 +2218,12 @@ void _csg_report_modbus() { if (0 == modbus.card[i].status) continue; - if (modbus.card[i].is_connect == TRUE - && modbus.card[i].is_insert == TRUE - && modbus.card[i].type_m == DEVICE_M_TYPE) + + if (daus[i].state.is_connect == TRUE + && daus[i].state.is_insert == TRUE + && daus[i].info.type_m == DEVICE_M_TYPE) { - switch (modbus.card[i].type_s) + switch (daus[i].info.type_s) { case DEVICE_IR_TYPE: iron.current = modbus.card[i].current; @@ -2135,6 +2249,7 @@ void *_csg_heartbeat_handle(void *arg) time_t t_connect = 0; time_t t_heartbeat = 0; int count = 0; + dau_t *dau = NULL; /* 等待初始化完成 */ while(!is_system_init) @@ -2174,28 +2289,31 @@ void *_csg_heartbeat_handle(void *arg) } } - for (int i = 0; i < PD_SLOTS_MAX; i++) + for (int slot = 0; slot < PD_SLOTS_MAX; slot++) { - if (daus[i].state.is_connect == TRUE - && daus[i].state.is_insert != TRUE) - { - _csg_send_add_dau(i, &daus[i].info); - } - else if (modbus.card[i].is_connect == TRUE - && modbus.card[i].is_insert != TRUE) + dau = &daus[slot]; + if (dau->state.is_connect == TRUE + && dau->state.is_insert != TRUE) { - csg_contact_t info = {0}; - info.type_m = modbus.card[i].type_m; - info.type_s = modbus.card[i].type_s; - _csg_send_add_dau(i, &info); + if (dau->info.type_m == 0x03 && dau->info.type_m == 0x04) + { + csg_contact_t info = {0}; + info.type_m = dau->info.type_m; + info.type_s = dau->info.type_s; + _csg_send_add_dau(slot, &info); + } + else + { + _csg_send_add_dau(slot, &dau->info); + } } - if (modbus.card[i].status == 0) + if (modbus.card[slot].status == 0) { - if (modbus.card[i].is_connect == TRUE - && modbus.card[i].is_insert == TRUE) + if (dau->state.is_connect == TRUE + && dau->state.is_insert == TRUE) { - _csg_send_del_dau(i, NULL); + _csg_send_del_dau(slot, NULL); } } } diff --git a/app/lib/a_process/pd_modbus.c b/app/lib/a_process/pd_modbus.c index 47337bc..fb738f1 100755 --- a/app/lib/a_process/pd_modbus.c +++ b/app/lib/a_process/pd_modbus.c @@ -11,19 +11,19 @@ #include "hwgpio.h" #include "serial.h" #include "pd_modbus.h" +#include "pd_dau.h" /* Private variables ---------------------------------------------------------*/ modbus_t modbus; void _modbus_show(void) { - card_t *pcard = modbus.card; - printh("ID ST IN CO M S\r\n"); + card_t *pcard = NULL; + printh("ID ST \r\n"); for (int slot = 0; slot < PD_SLOTS_MAX; slot++) { - printh("%-02d %-02d %-02d %-02d %d %d\r\n", pcard->unit_id, pcard->status, - pcard->is_insert, pcard->is_connect, pcard->type_m, pcard->type_s); - pcard++; + pcard = &modbus.card[slot]; + printh("%-02d %-02d \r\n", pcard->unit_id, pcard->status); } } @@ -200,6 +200,7 @@ void _modbus_read_slot_stat(card_t *pcard) void *_modbus_send_handle() { card_t *pcard = NULL; + dau_t *dau = NULL; while (1) { #if 0 @@ -216,18 +217,20 @@ void *_modbus_send_handle() } } #else - pcard = modbus.card; - _modbus_read_slot_stat(pcard); + _modbus_read_slot_stat(modbus.card); for (int slot = 0; slot < PD_SLOTS_MAX; slot++) { + pcard = &modbus.card[slot]; + dau = &daus[slot]; if (pcard->status) { - _modbus_get_device_type(pcard->unit_id, &pcard->type_m, &pcard->type_s); + _modbus_get_device_type(pcard->unit_id, &dau->info.type_m, &dau->info.type_s); - if (DEVICE_IR_TYPE == pcard->type_s && DEVICE_M_TYPE == pcard->type_m) + if (DEVICE_IR_TYPE == dau->info.type_s && DEVICE_M_TYPE == dau->info.type_m) { - pcard->is_connect = TRUE; + dau->state.beat_cnt = 0; + dau->state.is_connect = TRUE; _modbus_get_current(pcard->unit_id, MODBUS_IR_CURRENT_ADDR, MODBUS_IR_CURRENT_LEN, &pcard->current); //DBG(DBG_M_PD_MODBUS, "current:%d\n", pcard->current); @@ -236,15 +239,14 @@ void *_modbus_send_handle() MODBUS_IR_ALARM_ADDR, MODBUS_IR_ALARM_LEN, &pcard->alarm); //DBG(DBG_M_PD_MODBUS, "alarm:%d\n", pcard->alarm); } - else if (DEVICE_DC_TYPE == pcard->type_s && DEVICE_M_TYPE == pcard->type_m) + else if (DEVICE_DC_TYPE == dau->info.type_s && DEVICE_M_TYPE == dau->info.type_m) { - pcard->is_connect = TRUE; + dau->state.beat_cnt = 0; + dau->state.is_connect = TRUE; _modbus_get_current(pcard->unit_id, MODBUS_DC_CURRENT_ADDR, MODBUS_DC_CURRENT_LEN, &pcard->current); } } - - pcard++; } #endif diff --git a/app/lib/a_process/pd_upgrade.c b/app/lib/a_process/pd_upgrade.c index c24a516..2c548f7 100755 --- a/app/lib/a_process/pd_upgrade.c +++ b/app/lib/a_process/pd_upgrade.c @@ -59,7 +59,7 @@ /* Private define ------------------------------------------------------------*/ #define PD_UPG_READ_SIZE (1024*1024) -#define PD_UPG_HARDWARE_VERSON "GIS7.0" +#define PD_UPG_HARDWARE_VERSON "GIS-cmu" #define PD_UPG_DAU_FILE "/lib/firmware/system_wrapper.bin" /* Private macro -------------------------------------------------------------*/ @@ -314,6 +314,10 @@ int32_t _pd_upg_hardware_check(void) DBG(DBG_M_PD_UPGRADE, "Hardware version(%s) not match\n", pd_upg_ctrl.head.hard_ver); return E_ERROR; } + else + { + pd_upg_ctrl.upgrade_slot = _csg_update_slot; + } return E_NONE; } @@ -432,6 +436,11 @@ void *_pd_upg_handle(void *parm) break; } + if (pd_upg_ctrl.upgrade_slot) + { + pd_upg_ctrl.upgrade_slot(pd_upg_ctrl.upg_type); + } + /* 升级系统 */ rv = _pd_upg_upgrade(); if (rv != E_NONE)