From 12dc851e462b47cf6a7ea9a454f04065ad94d9f7 Mon Sep 17 00:00:00 2001 From: wangbo Date: Mon, 11 Aug 2025 02:08:37 +0000 Subject: [PATCH] =?UTF-8?q?FIX=201.=E5=A2=9E=E5=8A=A0=E9=93=81=E8=8A=AF?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=88=86=E6=94=AF;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/include/pd_csgiron.h | 8 +++++- app/lib/a_process/pd_csg.c | 3 ++- app/lib/a_process/pd_csgiron.c | 48 ++++++++++++++++++++++++++++++---- app/lib/a_process/pd_main.c | 2 ++ app/lib/a_process/pd_modbus.c | 22 ++++------------ 5 files changed, 59 insertions(+), 24 deletions(-) diff --git a/app/include/pd_csgiron.h b/app/include/pd_csgiron.h index dbf893a..621badf 100755 --- a/app/include/pd_csgiron.h +++ b/app/include/pd_csgiron.h @@ -9,10 +9,16 @@ typedef int32_t (*csgiron_recv_fun_cb)(uint8_t, char*, uint16_t); typedef struct { + uint8_t vport; // slot 1~8 + uint8_t reserved[1]; uint16_t report_period; - uint8_t reserved[2]; } iron_config_t; +typedef struct { + uint8_t vport; // slot编号 1~8 + uint8_t result; // 应答结果. 0:成功 1:失败 + uint8_t reserved[2]; // 保留 +}iron_ack_t; extern int32_t _csgiron_recv_process(uint8_t slot, char *pkt, uint16_t len); #endif diff --git a/app/lib/a_process/pd_csg.c b/app/lib/a_process/pd_csg.c index a47a722..0496a3f 100755 --- a/app/lib/a_process/pd_csg.c +++ b/app/lib/a_process/pd_csg.c @@ -931,7 +931,8 @@ int32_t _csg_recv_process(char *pkt, uint32_t len) return E_ERROR; } - if (DEVICE_M_TYPE == typem && 4 == types) + if (DEVICE_M_TYPE == typem && DEVICE_IR_TYPE == types + && CSG_C_ADD_DAU != head->cmd) { _csgiron_recv_process(head->slot - 1, pkt, len); return E_NONE; diff --git a/app/lib/a_process/pd_csgiron.c b/app/lib/a_process/pd_csgiron.c index 5a84848..efcbe1f 100755 --- a/app/lib/a_process/pd_csgiron.c +++ b/app/lib/a_process/pd_csgiron.c @@ -32,19 +32,41 @@ int32_t _csgiron_config_port_get(uint8_t slot, char* pkt, uint16_t len) { csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; iron_config_t *pdata = (iron_config_t*)(pkt + sizeof(csg_pkt_head_t)); + pdata->vport = slot + 1; pdata->report_period = pd_config.config_slot[slot].report_period; - _csg_send_data(CSG_REPLY, head->cmd, pkt, sizeof(iron_config_t), slot + 1); + _csg_send_data(CSG_PRV_REPLY, head->cmd, pkt, sizeof(iron_config_t), slot + 1); return E_NONE; } int32_t _csgiron_config_port_set(uint8_t slot, char* pkt, uint16_t len) { + csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; iron_config_t *pdata = (iron_config_t*)(pkt + sizeof(csg_pkt_head_t)); pd_config.config_slot[slot].report_period = pdata->report_period; + + vtysh_config_save(); + + iron_ack_t ack = {0}; + ack.vport = slot + 1; + ack.result = TRUE; + memcpy(pkt + sizeof(csg_pkt_head_t), (char *)&ack, sizeof(iron_ack_t)); + _csg_send_data(CSG_PRV_REPLY, head->cmd, pkt, sizeof(iron_ack_t), slot + 1); + return E_NONE; +} + +int32_t _csgiron_modbus_reply(uint8_t slot, char* pkt, uint16_t len) +{ + //csg_pkt_head_t *head = (csg_pkt_head_t*)pkt; + //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 + 1); return E_NONE; } + /* 命令映射表 */ static csgiron_recv_fun_cb _csgiron_command[] = { @@ -59,18 +81,34 @@ static csgiron_recv_fun_cb _csgiron_prv_command[] = NULL, // CSG_PRV_CONFIG_GLOBAL_GET _csgiron_config_port_set, // CSG_PRV_CONFIG_PORT_SET _csgiron_config_port_get, // CSG_PRV_CONFIG_PORT_GET + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, + NULL, // CSG_PRV_MODBUS + NULL }; int32_t _csgiron_recv_process(uint8_t slot, char *pkt, uint16_t len) { dau_pkt_head_t *head = (dau_pkt_head_t*)pkt; - if (CSG_REQUEST == head->cmd) + if (CSG_REQUEST == head->cmd_type) { - _csgiron_command[head->cmd](slot, pkt, len); + if (_csgiron_command[head->cmd]) + { + _csgiron_command[head->cmd](slot, pkt, len); + } } - else if (CSG_PRV_REQUEST == head->cmd) + else if (CSG_PRV_REQUEST == head->cmd_type) { - _csgiron_prv_command[head->cmd](slot, pkt, len); + if (_csgiron_prv_command[head->cmd]) + { + _csgiron_prv_command[head->cmd](slot, pkt, len); + } } return E_NONE; } diff --git a/app/lib/a_process/pd_main.c b/app/lib/a_process/pd_main.c index 6492e36..fa9cc0b 100755 --- a/app/lib/a_process/pd_main.c +++ b/app/lib/a_process/pd_main.c @@ -728,6 +728,8 @@ int32_t _pd_main_init(void) cmd_install_element(CONFIG_NODE, &pd_protocol_type_cmd); cmd_install_element(CONFIG_NODE, &pd_slot_terminal_cmd); + + cmd_install_element(PORT_NODE, &pd_slot_terminal_cmd); cmd_install_element(COMMON_NODE, &show_pd_cmd); diff --git a/app/lib/a_process/pd_modbus.c b/app/lib/a_process/pd_modbus.c index fb738f1..8ad91cd 100755 --- a/app/lib/a_process/pd_modbus.c +++ b/app/lib/a_process/pd_modbus.c @@ -203,20 +203,6 @@ void *_modbus_send_handle() dau_t *dau = NULL; while (1) { -#if 0 - for (int unit = 1; unit <= 6; unit++) - { - if (_modbus_tcp_transaction(0, unit, MODBUS_ADDR_CURRENT, MODBUS_CURRENT_LEN) > 0) - { - - } - - if (_modbus_tcp_transaction(0, unit, MODBUS_ADDR_CURRENT, MODBUS_CURRENT_LEN) > 0) - { - - } - } -#else _modbus_read_slot_stat(modbus.card); for (int slot = 0; slot < PD_SLOTS_MAX; slot++) @@ -225,12 +211,14 @@ void *_modbus_send_handle() dau = &daus[slot]; if (pcard->status) { - _modbus_get_device_type(pcard->unit_id, &dau->info.type_m, &dau->info.type_s); + _modbus_get_device_type(pcard->unit_id, &dau->info.type_m, &dau->info.type_s); + //DBG(DBG_M_PD_MODBUS, "typem:%d types:%d\n", dau->info.type_m, dau->info.type_s); if (DEVICE_IR_TYPE == dau->info.type_s && DEVICE_M_TYPE == dau->info.type_m) { dau->state.beat_cnt = 0; dau->state.is_connect = TRUE; + sleep(1); _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); @@ -243,13 +231,13 @@ void *_modbus_send_handle() { dau->state.beat_cnt = 0; dau->state.is_connect = TRUE; + sleep(1); _modbus_get_current(pcard->unit_id, MODBUS_DC_CURRENT_ADDR, MODBUS_DC_CURRENT_LEN, &pcard->current); + //DBG(DBG_M_PD_MODBUS, "current:%d\n", pcard->current); } } } - -#endif sleep(5); }