diff --git a/src/iflytop/components/zcanreceiver/zcanhost.cpp b/src/iflytop/components/zcanreceiver/zcanhost.cpp index c976209..94266c0 100644 --- a/src/iflytop/components/zcanreceiver/zcanhost.cpp +++ b/src/iflytop/components/zcanreceiver/zcanhost.cpp @@ -75,20 +75,6 @@ void ZCanHost::initialize(string can_if_name, int baudrate, bool enablLoopback) logger->error("hpp272_read_c1000 fail"); return false; } - // int16_t hydrogen_peroxide_volume; // ppm 0x0100 - // int16_t h2o_h2o2_rs; // %RS * 100 - // int16_t temperature1; // °C * 100 - // int16_t relative_humidity; // %RH * 100 - // int16_t absolute_hydrogen_peroxide; // mg/m3 - // int16_t h2o_h2o2dew_point_temperature; // °C * 100 - // int16_t reserved1; // - // int16_t water_volume; // ppm - // int16_t water_vapor_pressure; // hpa - // int16_t absolute_humidity; // g/m3 - // int16_t water_vapor_saturation_pressure_h2o; // hpa - // int16_t temperature2; // °C * 100 - // int16_t h2o2_vapor_pressure; // hpa - // int16_t water_vapor_saturation_pressure_h2o_h2o2; // hpa logger->info("hpp272_read_c1000 {}:", id); logger->info(" hydrogen_peroxide_volume :{}", v.hydrogen_peroxide_volume); logger->info(" h2o_h2o2_rs :{}", v.h2o_h2o2_rs); @@ -218,7 +204,7 @@ bool ZCanHost::execcmd(string cmd, string& retval) { /** * @brief 0-1000 Command support */ -bool ZCanHost::ping(int board_id) { +int32_t ZCanHost::ping(int board_id) { shared_ptr cmd = make_shared(); cmd->cmdid = 0; cmd->subcmdid = 0; @@ -226,14 +212,14 @@ bool ZCanHost::ping(int board_id) { cmd->len = 1; auto rx = m_zcanReceiverHost->sendcmdblock(cmd, 100); if (rx == nullptr) { - return false; + return err::zecode(err::knoack); } if (rx->packetType == kpt_error_ack) { logger->error("ping error ack,{}", *zuint16p(&rx->data[0])); - return false; + return err::zecode(err::kfail); } - return rx != nullptr; + return 0; } int32_t ZCanHost::readio(int id, bool& value) { @@ -292,7 +278,7 @@ int32_t ZCanHost::readadc(int id, int& value) { } // 1004 -bool ZCanHost::pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm) { +int32_t ZCanHost::pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm) { shared_ptr cmd = make_shared(); cmd->cmdid = 1004; cmd->subcmdid = 0; @@ -301,12 +287,15 @@ bool ZCanHost::pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm) { *zint16p(&cmd->data[4]) = rpm; cmd->len = 6; auto rx = m_zcanReceiverHost->sendcmdblock(cmd, 100); + if (rx == nullptr) { + return err::zecode(err::knoack); + } if (rx->packetType == kpt_error_ack) { logger->error("pumpctrl_c1004 error ack,{}", *zuint16p(&rx->data[0])); - return false; + return err::zecode(err::kfail); } - return rx != nullptr; + return 0; } /** @@ -318,7 +307,7 @@ bool ZCanHost::pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm) { * @param b * @param w */ -bool ZCanHost::warning_light_ctrl_c1002(uint8_t sensorid, uint8_t r, uint8_t g, uint8_t b, uint8_t w) { +int32_t ZCanHost::warning_light_ctrl_c1002(uint8_t sensorid, uint8_t r, uint8_t g, uint8_t b, uint8_t w) { shared_ptr cmd = make_shared(); cmd->cmdid = 1002; cmd->subcmdid = 0; @@ -331,12 +320,16 @@ bool ZCanHost::warning_light_ctrl_c1002(uint8_t sensorid, uint8_t r, uint8_t g, auto rx = m_zcanReceiverHost->sendcmdblock(cmd, 100); + if (!rx) { + return err::zecode(err::knoack); + } + if (rx->packetType == kpt_error_ack) { logger->error("warning_light_ctrl_c1002 error ack,{}", *zuint16p(&rx->data[0])); - return false; + return err::zecode(err::kfail); } - return rx != nullptr; + return 0; } /** @@ -346,7 +339,7 @@ bool ZCanHost::warning_light_ctrl_c1002(uint8_t sensorid, uint8_t r, uint8_t g, * @param value */ -bool ZCanHost::huacheng_pressure_sensor_read_c1005(int sensorid, huacheng_pressure_sensor_read_c1005_t& value) { +int32_t ZCanHost::huacheng_pressure_sensor_read_c1005(int sensorid, huacheng_pressure_sensor_read_c1005_t& value) { /** * @brief */ @@ -358,15 +351,18 @@ bool ZCanHost::huacheng_pressure_sensor_read_c1005(int sensorid, huacheng_pressu cmd->len = 2; auto rx = m_zcanReceiverHost->sendcmdblock(cmd, 100); + if (!rx) { + return err::zecode(err::knoack); + } if (rx->packetType == kpt_error_ack) { logger->error("huacheng_pressure_sensor_read_c1005 error ack"); - return false; + return err::zecode(err::kfail); } if (rx->len != 10) { logger->warn("huacheng_pressure_sensor_read_c1005 rx len error:{}", rx->len); - return false; + return err::zecode(err::kfail); } value.precision = rx->data[2]; @@ -375,28 +371,31 @@ bool ZCanHost::huacheng_pressure_sensor_read_c1005(int sensorid, huacheng_pressu value.zero = *(int16_t*)(&rx->data[6]); value.full = *(int16_t*)(&rx->data[8]); - return rx != nullptr; + return 0; } -bool ZCanHost::hpp272_read_c1000(int sensorid, hpp272_data_t& value) { +int32_t ZCanHost::hpp272_read_c1000(int sensorid, hpp272_data_t& value) { shared_ptr cmd = make_shared(); cmd->cmdid = 1000; cmd->subcmdid = 0; cmd->data[0] = sensorid; cmd->len = 2; - auto rx = m_zcanReceiverHost->sendcmdblock(cmd, 100); + auto rx = m_zcanReceiverHost->sendcmdblock(cmd, 300); + if (!rx) { + logger->error("hpp272_read_c1000 timeout"); + return err::zecode(err::knoack); + } if (rx->packetType == kpt_error_ack) { logger->error("hpp272_read_c1000 error ack"); - return false; + return err::zecode(err::kfail); } if (rx->len != sizeof(hpp272_data_t) + 2) { logger->warn("hpp272_read_c1000 rx len error:{}!=", rx->len, sizeof(hpp272_data_t) + 2); - return false; + return err::zecode(err::kfail); } - memcpy(&value, &rx->data[2], sizeof(hpp272_data_t)); - return rx != nullptr; + return 0; } diff --git a/src/iflytop/components/zcanreceiver/zcanhost.hpp b/src/iflytop/components/zcanreceiver/zcanhost.hpp index 628652b..fe75cb6 100644 --- a/src/iflytop/components/zcanreceiver/zcanhost.hpp +++ b/src/iflytop/components/zcanreceiver/zcanhost.hpp @@ -31,7 +31,7 @@ class ZCanHost { /** * @brief 0-1000 Command support */ - bool ping(int board_id); + int32_t ping(int board_id); int32_t readio(int id, bool& value); int32_t writeio(int id, bool value); @@ -40,11 +40,11 @@ class ZCanHost { // 读取M211887(维萨拉)传感器信息 typedef struct { - int16_t hydrogen_peroxide_volume; // ppm 0x0100 - int16_t h2o_h2o2_rs; // %RS * 100 - int16_t temperature1; // °C * 100 - int16_t relative_humidity; // %RH * 100 - int16_t absolute_hydrogen_peroxide; // mg/m3 + int16_t hydrogen_peroxide_volume; // ppm 0x0100 过氧化氢浓度 + int16_t h2o_h2o2_rs; // %RS * 100 0x0101 过氧化氢相对饱和度 + int16_t temperature1; // °C * 100 0x0102 温度 + int16_t relative_humidity; // %RH * 100 0x0103 相对湿度 + int16_t absolute_hydrogen_peroxide; // mg/m3 0x0104 int16_t h2o_h2o2dew_point_temperature; // °C * 100 int16_t reserved1; // int16_t water_volume; // ppm @@ -56,7 +56,7 @@ class ZCanHost { int16_t water_vapor_saturation_pressure_h2o_h2o2; // hpa } hpp272_data_t; - bool hpp272_read_c1000(int sensorid, hpp272_data_t& value); + int32_t hpp272_read_c1000(int sensorid, hpp272_data_t& value); /** * @brief 报警三色指示灯控制 @@ -67,9 +67,9 @@ class ZCanHost { * @param b * @param w */ - bool warning_light_ctrl_c1002(uint8_t sensorid, uint8_t r, uint8_t g, uint8_t b, uint8_t w); + int32_t warning_light_ctrl_c1002(uint8_t sensorid, uint8_t r, uint8_t g, uint8_t b, uint8_t w); // 1004 - bool pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm); + int32_t pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm); /** * @brief 读取华成压力传感器数值 @@ -84,7 +84,7 @@ class ZCanHost { uint16_t zero; // 零点 uint16_t full; // 满量程 } huacheng_pressure_sensor_read_c1005_t; - bool huacheng_pressure_sensor_read_c1005(int sensorid, huacheng_pressure_sensor_read_c1005_t& value); + int32_t huacheng_pressure_sensor_read_c1005(int sensorid, huacheng_pressure_sensor_read_c1005_t& value); }; } // namespace iflytop \ No newline at end of file diff --git a/src/iflytop/core/error/error_code.cpp b/src/iflytop/core/error/error_code.cpp index 0ac7298..2945cb5 100644 --- a/src/iflytop/core/error/error_code.cpp +++ b/src/iflytop/core/error/error_code.cpp @@ -21,6 +21,7 @@ static vector ecode_desc_set = { {kce, kovertime, "overtime"}, {kce, kfail, "fail"}, {kce, knoack, "noack"}, + {kce, kerrorack, "errorack"}, {kce, kdevice_offline, "kdevice_offline"}, {kce, kparse_json_err, "kparse_json_err"}, {kce, kcatch_exception, "kcatch_exception"}, diff --git a/src/iflytop/core/error/error_code.hpp b/src/iflytop/core/error/error_code.hpp index b38b37a..2f3a16c 100644 --- a/src/iflytop/core/error/error_code.hpp +++ b/src/iflytop/core/error/error_code.hpp @@ -20,6 +20,7 @@ typedef enum { kovertime = 1, kfail, knoack, + kerrorack, kdevice_offline, kparse_json_err, kcatch_exception,