From e22ab54f93b7a1a2f96027152d9a12c2a154938e Mon Sep 17 00:00:00 2001 From: zhaohe Date: Fri, 23 Aug 2024 21:35:44 +0800 Subject: [PATCH] update --- README.md | 7 +++- app_protocols/zscanprotocol | 2 +- .../preportional_valve/preportional_valve_ctrl.cpp | 28 ++++++-------- usrc/module/blower_controller.hpp | 2 +- usrc/module/proportional_valve_ctrl.cpp | 44 ++++++++++++++++++++++ usrc/module/proportional_valve_ctrl.hpp | 43 +++------------------ usrc/project_configs.h | 2 +- 7 files changed, 69 insertions(+), 59 deletions(-) create mode 100644 usrc/module/proportional_valve_ctrl.cpp diff --git a/README.md b/README.md index 457402a..124012a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,12 @@ ``` ``` - V103:增加比例阀超时判定阈值 + V103:增加比例阀超时判定 + + V104: + 1. 添加子设备超时错误码 + 2. 主控直接下发指令控制子设备时候,增加超时判定,超时后返回子设备超时错误码。 + 3. 上位机指令超时时间建议设置成500ms ``` diff --git a/app_protocols/zscanprotocol b/app_protocols/zscanprotocol index d11d41c..8a3aeaf 160000 --- a/app_protocols/zscanprotocol +++ b/app_protocols/zscanprotocol @@ -1 +1 @@ -Subproject commit d11d41c1062568f629d5ec2bc6435319b7ea83e3 +Subproject commit 8a3aeaf8883a3c7d01594e0399fbe96bf8b9cf72 diff --git a/ucomponents/preportional_valve/preportional_valve_ctrl.cpp b/ucomponents/preportional_valve/preportional_valve_ctrl.cpp index 60007f9..6c0421e 100644 --- a/ucomponents/preportional_valve/preportional_valve_ctrl.cpp +++ b/ucomponents/preportional_valve/preportional_valve_ctrl.cpp @@ -7,26 +7,20 @@ using namespace zscanprotocol; #define WORK_STATE_REG 0x0000 #define CTRL_STATE_REG 0x0001 #define POS_STATE_REG 0x0013 -#define OVERTIME 1000 +#define OVERTIME 100 #define TAG "PreportionalValveCtrl" void PreportionalValveCtrl::initialize(UART_HandleTypeDef* huart) { m_modbusBlockHost.initialize(huart); } int32_t PreportionalValveCtrl::writeReg06(uint8_t slaveAddr, uint16_t regAddr, uint16_t regVal) { - // 重发三次 - for (size_t i = 0; i < 5; i++) { - int32_t err = m_modbusBlockHost.writeReg06(slaveAddr, regAddr, regVal, OVERTIME); - if (err == 0) return 0; - } - return err::kerr_subdevice_offline; + int32_t err = m_modbusBlockHost.writeReg06(slaveAddr, regAddr, regVal, OVERTIME); + if (err == 0) return 0; + return err::kerr_subdevice_overtime; } int32_t PreportionalValveCtrl::readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal) { - // 重发三次 - for (size_t i = 0; i < 5; i++) { - int32_t err = m_modbusBlockHost.readReg03(slaveAddr, regAddr, regVal, OVERTIME); - if (err == 0) return 0; - } - return err::kerr_subdevice_offline; + int32_t err = m_modbusBlockHost.readReg03(slaveAddr, regAddr, regVal, OVERTIME); + if (err == 0) return 0; + return err::kerr_subdevice_overtime; } int32_t PreportionalValveCtrl::setValvePos(int32_t valueid, int32_t pos) { // @@ -35,7 +29,7 @@ int32_t PreportionalValveCtrl::setValvePos(int32_t valueid, int32_t pos) { // return err::kerr_invalid_param; } ret = writeReg06(valueid, CTRL_STATE_REG, pos); - if (!ret) return err::kerr_subdevice_offline; + if (!ret) return err::kerr_subdevice_overtime; m_last_set_valve_ticket = HAL_GetTick(); m_targetpos[valueid] = pos; @@ -50,7 +44,7 @@ int32_t PreportionalValveCtrl::getValvePos(int32_t valueid, int32_t* pos) { uint16_t pos16 = 0; ret = readReg03(valueid, POS_STATE_REG, &pos16); - if (!ret) return err::kerr_subdevice_offline; + if (!ret) return err::kerr_subdevice_overtime; *pos = pos16; return 0; @@ -63,7 +57,7 @@ int32_t PreportionalValveCtrl::getValveOrderPos(int32_t valueid, int32_t* pos) { uint16_t pos16 = 0; ret = readReg03(valueid, CTRL_STATE_REG, &pos16); - if (!ret) return err::kerr_subdevice_offline; + if (!ret) return err::kerr_subdevice_overtime; *pos = pos16; return 0; @@ -101,7 +95,7 @@ int32_t PreportionalValveCtrl::getValveWorkState(int32_t valueid, int32_t* state uint16_t state16 = 0; ret = readReg03(valueid, WORK_STATE_REG, &state16); - if (!ret) return err::kerr_subdevice_offline; + if (!ret) return err::kerr_subdevice_overtime; *state = state16; return 0; } \ No newline at end of file diff --git a/usrc/module/blower_controller.hpp b/usrc/module/blower_controller.hpp index 16e20b8..4d47921 100644 --- a/usrc/module/blower_controller.hpp +++ b/usrc/module/blower_controller.hpp @@ -116,7 +116,7 @@ class BlowerController { zcanbus_send_ack(cxt->packet, NULL, 0); isopen = GET_PARAM(0) > 0 ? true : false; } else { - zcanbus_send_errorack(cxt->packet, err::kerr_overtime); + zcanbus_send_errorack(cxt->packet, err::kerr_subdevice_overtime); } } else if (m_blowerType == kMiniPwmBlower) { diff --git a/usrc/module/proportional_valve_ctrl.cpp b/usrc/module/proportional_valve_ctrl.cpp new file mode 100644 index 0000000..4cde46d --- /dev/null +++ b/usrc/module/proportional_valve_ctrl.cpp @@ -0,0 +1,44 @@ +#include "proportional_valve_ctrl.hpp" + +using namespace iflytop; +using namespace transmit_disfection_protocol; + +void ProportionalValveCtrl::initialize(UART_HandleTypeDef* huart) { + valve.initialize(huart); + m_isInitialized = true; + + BIND_FN(ProportionalValveCtrl, this, fn_proportional_set_valve); + BIND_FN(ProportionalValveCtrl, this, fn_proportional_read_pos); + BIND_FN(ProportionalValveCtrl, this, fn_proportional_is_busy); +} + +bool ProportionalValveCtrl::isInitialized() { return m_isInitialized; } + +void ProportionalValveCtrl::fn_proportional_set_valve(ProcessContext* cxt) { + int32_t err = valve.setValvePos(GET_PARAM(0), GET_PARAM(1)); + if (err) { + zcanbus_send_errorack(cxt->packet, err); + } else { + zcanbus_send_ack(cxt->packet, NULL, 0); + } +} + +void ProportionalValveCtrl::fn_proportional_read_pos(ProcessContext* cxt) { + int32_t pos = 0; + int32_t err = valve.getValvePos(GET_PARAM(0), &pos); + if (err) { + zcanbus_send_errorack(cxt->packet, err); + } else { + zcanbus_send_ack(cxt->packet, (uint8_t*)&pos, sizeof(pos)); + } +} + +void ProportionalValveCtrl::fn_proportional_is_busy(ProcessContext* cxt) { + int32_t busy = 0; + int32_t err = valve.isBusy(GET_PARAM(0), &busy); + if (err) { + zcanbus_send_errorack(cxt->packet, err); + } else { + zcanbus_send_ack(cxt->packet, (uint8_t*)&busy, sizeof(busy)); + } +} diff --git a/usrc/module/proportional_valve_ctrl.hpp b/usrc/module/proportional_valve_ctrl.hpp index a41d6c4..1d7e91f 100644 --- a/usrc/module/proportional_valve_ctrl.hpp +++ b/usrc/module/proportional_valve_ctrl.hpp @@ -9,46 +9,13 @@ class ProportionalValveCtrl { bool m_isInitialized = false; public: - void initialize(UART_HandleTypeDef* huart) { - valve.initialize(huart); - m_isInitialized = true; - - BIND_FN(ProportionalValveCtrl, this, fn_proportional_set_valve); - BIND_FN(ProportionalValveCtrl, this, fn_proportional_read_pos); - BIND_FN(ProportionalValveCtrl, this, fn_proportional_is_busy); - } - - bool isInitialized() { return m_isInitialized; } + void initialize(UART_HandleTypeDef* huart); + bool isInitialized(); private: - void fn_proportional_set_valve(ProcessContext* cxt) { - int32_t err = valve.setValvePos(GET_PARAM(0), GET_PARAM(1)); - if (err) { - zcanbus_send_errorack(cxt->packet, err); - } else { - zcanbus_send_ack(cxt->packet, NULL, 0); - } - } - - void fn_proportional_read_pos(ProcessContext* cxt) { - int32_t pos = 0; - int32_t err = valve.getValvePos(GET_PARAM(0), &pos); - if (err) { - zcanbus_send_errorack(cxt->packet, err); - } else { - zcanbus_send_ack(cxt->packet, (uint8_t*)&pos, sizeof(pos)); - } - } - - void fn_proportional_is_busy(ProcessContext* cxt) { - int32_t busy = 0; - int32_t err = valve.isBusy(GET_PARAM(0), &busy); - if (err) { - zcanbus_send_errorack(cxt->packet, err); - } else { - zcanbus_send_ack(cxt->packet, (uint8_t*)&busy, sizeof(busy)); - } - } + void fn_proportional_set_valve(ProcessContext* cxt); + void fn_proportional_read_pos(ProcessContext* cxt); + void fn_proportional_is_busy(ProcessContext* cxt); private: }; diff --git a/usrc/project_configs.h b/usrc/project_configs.h index c547d2d..62acc6d 100644 --- a/usrc/project_configs.h +++ b/usrc/project_configs.h @@ -15,7 +15,7 @@ * @brief 基础配置 * */ -#define SOFTWARE_VERSION 103 // 软件版本 +#define SOFTWARE_VERSION 104 // 软件版本 #define HARDWARE_VERSION 1 // 硬件版本 #define PROJECT "transmit_disinfection_micro_re" // 工程名称 #define SN_HEADER "SN" // SN号前缀