From 94a846162c5f38a2631421586f235fd39bba21d3 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Tue, 15 Aug 2023 23:12:29 +0800 Subject: [PATCH] update --- src/iflytop/components/zcanreceiver/zcanhost.cpp | 55 +++++++++++++++++++----- src/iflytop/components/zcanreceiver/zcanhost.hpp | 11 ++--- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/src/iflytop/components/zcanreceiver/zcanhost.cpp b/src/iflytop/components/zcanreceiver/zcanhost.cpp index 94266c0..e596f83 100644 --- a/src/iflytop/components/zcanreceiver/zcanhost.cpp +++ b/src/iflytop/components/zcanreceiver/zcanhost.cpp @@ -8,11 +8,11 @@ using namespace zcr; #define zuint16p(x) ((uint16_t*)(x)) #define zint32p(x) ((int32_t*)(x)) -#define CHECK_ARGC_NUM(x) \ - if (argc != (x + 1)) { \ - logger->error("do {},argc error", argv[0]); \ - retval = "argc num error"; \ - return false; \ +#define CHECK_ARGC_NUM(x) \ + if (argc != (x + 1)) { \ + logger->error("do {},argc error {}!={}", argv[0], argc, x + 1); \ + retval = "argc num error"; \ + return false; \ } void ZCanHost::initialize(string can_if_name, int baudrate, bool enablLoopback) { @@ -20,11 +20,24 @@ void ZCanHost::initialize(string can_if_name, int baudrate, bool enablLoopback) m_zcanReceiverHost->initialize(can_if_name, baudrate, enablLoopback); m_cmdMap["pumpctrl_c1004"] = [this](int argc, char** argv, string& retval) { - CHECK_ARGC_NUM(4); - uint8_t id = atoi(argv[1]); - int16_t acc = atoi(argv[2]); - int16_t rpm = atoi(argv[3]); - return pumpctrl_c1004(id, acc, rpm) != 0; + // CHECK_ARGC_NUM(3); + + if (argc == 4) { + uint8_t id = atoi(argv[1]); + int16_t acc = atoi(argv[2]); + int16_t rpm = atoi(argv[3]); + return pumpctrl_c1004(id, acc, rpm) != 0; + } else if (argc == 6) { + uint8_t id = atoi(argv[1]); + int16_t acc = atoi(argv[2]); + int16_t rpm = atoi(argv[3]); + int8_t idlepower = atoi(argv[4]); + int8_t power = atoi(argv[5]); + return pumpctrl_c1004(id, acc, rpm, idlepower, power) != 0; + } + logger->error("do {},argc error {}!={},{}", argv[0], argc, 4, 6); + retval = "argc num error"; + return false; }; // ZCanHost::readio(int id, bool& value) @@ -298,6 +311,28 @@ int32_t ZCanHost::pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm) { return 0; } +int32_t ZCanHost::pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm, int8_t idlepower, int8_t power) { + shared_ptr cmd = make_shared(); + cmd->cmdid = 1004; + cmd->subcmdid = 1; + cmd->data[0] = sensorid; + *zint16p(&cmd->data[2]) = acc; + *zint16p(&cmd->data[4]) = rpm; + cmd->data[6] = idlepower; + cmd->data[7] = power; + cmd->len = 8; + 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 err::zecode(err::kfail); + } + + return 0; +} + /** * @brief 报警三色指示灯控制 * diff --git a/src/iflytop/components/zcanreceiver/zcanhost.hpp b/src/iflytop/components/zcanreceiver/zcanhost.hpp index fe75cb6..2d6ac10 100644 --- a/src/iflytop/components/zcanreceiver/zcanhost.hpp +++ b/src/iflytop/components/zcanreceiver/zcanhost.hpp @@ -70,6 +70,7 @@ class ZCanHost { int32_t warning_light_ctrl_c1002(uint8_t sensorid, uint8_t r, uint8_t g, uint8_t b, uint8_t w); // 1004 int32_t pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm); + int32_t pumpctrl_c1004(int sensorid, int16_t acc, int16_t rpm, int8_t idlepower, int8_t power); /** * @brief 读取华成压力传感器数值 @@ -78,11 +79,11 @@ class ZCanHost { * @param value */ typedef struct { - uint8_t precision; // 0,1,2,3 - uint8_t unit; // 0-Mpa ,1-Kpa ,2-Pa ,3-Bar ,4-Mbar ,5-kg/cm2 ,6-psi ,7-mh2o ,8-mmh2o - uint16_t value; // value, realvalue = value / 10^precision unit - uint16_t zero; // 零点 - uint16_t full; // 满量程 + uint8_t precision; // 0,1,2,3 + uint8_t unit; // 0-Mpa ,1-Kpa ,2-Pa ,3-Bar ,4-Mbar ,5-kg/cm2 ,6-psi ,7-mh2o ,8-mmh2o + int16_t value; // value, realvalue = value / 10^precision unit + int16_t zero; // 零点 + int16_t full; // 满量程 } huacheng_pressure_sensor_read_c1005_t; int32_t huacheng_pressure_sensor_read_c1005(int sensorid, huacheng_pressure_sensor_read_c1005_t& value); };