|
|
@ -4,8 +4,9 @@ using namespace iflytop; |
|
|
|
using namespace core; |
|
|
|
using namespace zcr; |
|
|
|
|
|
|
|
#define zint16p(x) ((int16_t*)(x))
|
|
|
|
#define zint32p(x) ((int32_t*)(x))
|
|
|
|
#define zint16p(x) ((int16_t*)(x))
|
|
|
|
#define zuint16p(x) ((uint16_t*)(x))
|
|
|
|
#define zint32p(x) ((int32_t*)(x))
|
|
|
|
|
|
|
|
#define CHECK_ARGC_NUM(x) \
|
|
|
|
if (argc != (x + 1)) { \ |
|
|
@ -65,6 +66,87 @@ void ZCanHost::initialize(string can_if_name, int baudrate, bool enablLoopback) |
|
|
|
retval = fmt::format("ACK:{}", v); |
|
|
|
return true; |
|
|
|
}; |
|
|
|
|
|
|
|
m_cmdMap["hpp272_read_c1000"] = [this](int argc, char** argv, string& retval) { |
|
|
|
CHECK_ARGC_NUM(1); |
|
|
|
uint8_t id = atoi(argv[1]); |
|
|
|
hpp272_data_t v = {0}; |
|
|
|
if (hpp272_read_c1000(id, v) != 0) { |
|
|
|
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); |
|
|
|
logger->info(" temperature1 :{}", v.temperature1); |
|
|
|
logger->info(" relative_humidity :{}", v.relative_humidity); |
|
|
|
logger->info(" absolute_hydrogen_peroxide :{}", v.absolute_hydrogen_peroxide); |
|
|
|
logger->info(" h2o_h2o2dew_point_temperature :{}", v.h2o_h2o2dew_point_temperature); |
|
|
|
logger->info(" reserved1 :{}", v.reserved1); |
|
|
|
logger->info(" water_volume :{}", v.water_volume); |
|
|
|
logger->info(" water_vapor_pressure :{}", v.water_vapor_pressure); |
|
|
|
logger->info(" absolute_humidity :{}", v.absolute_humidity); |
|
|
|
logger->info(" water_vapor_saturation_pressure_h2o :{}", v.water_vapor_saturation_pressure_h2o); |
|
|
|
logger->info(" temperature2 :{}", v.temperature2); |
|
|
|
logger->info(" h2o2_vapor_pressure :{}", v.h2o2_vapor_pressure); |
|
|
|
logger->info(" water_vapor_saturation_pressure_h2o_h2o2 :{}", v.water_vapor_saturation_pressure_h2o_h2o2); |
|
|
|
|
|
|
|
// retval = fmt::format("ACK:{}", v);
|
|
|
|
return true; |
|
|
|
}; |
|
|
|
|
|
|
|
m_cmdMap["warning_light_ctrl_c1002"] = [this](int argc, char** argv, string& retval) { |
|
|
|
CHECK_ARGC_NUM(5); |
|
|
|
uint8_t id = atoi(argv[1]); |
|
|
|
uint8_t r = atoi(argv[2]); |
|
|
|
uint8_t g = atoi(argv[3]); |
|
|
|
uint8_t b = atoi(argv[4]); |
|
|
|
uint8_t w = atoi(argv[5]); |
|
|
|
|
|
|
|
if (warning_light_ctrl_c1002(id, r, g, b, w) != 0) { |
|
|
|
logger->error("warning_light_ctrl_c1002 fail"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
}; |
|
|
|
// huacheng_pressure_sensor_read_c1005
|
|
|
|
m_cmdMap["huacheng_pressure_sensor_read_c1005"] = [this](int argc, char** argv, string& retval) { |
|
|
|
CHECK_ARGC_NUM(1); |
|
|
|
uint8_t id = atoi(argv[1]); |
|
|
|
huacheng_pressure_sensor_read_c1005_t v; |
|
|
|
if (huacheng_pressure_sensor_read_c1005(id, v) != 0) { |
|
|
|
logger->error("huacheng_pressure_sensor_read_c1005 fail"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
// 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; // 满量程
|
|
|
|
logger->info("huacheng_pressure_sensor_read_c1005 {}:", id); |
|
|
|
logger->info(" precision :{}", v.precision); |
|
|
|
logger->info(" unit :{}", v.unit); |
|
|
|
logger->info(" value :{}", v.value); |
|
|
|
logger->info(" zero :{}", v.zero); |
|
|
|
logger->info(" full :{}", v.full); |
|
|
|
// retval = fmt::format("ACK:{}", v);
|
|
|
|
return true; |
|
|
|
}; |
|
|
|
|
|
|
|
m_cmdMap["sleep_ms"] = [this](int argc, char** argv, string& retval) { |
|
|
|
CHECK_ARGC_NUM(1); |
|
|
|
int32_t ms = atoi(argv[1]); |
|
|
@ -143,6 +225,14 @@ bool ZCanHost::ping(int board_id) { |
|
|
|
cmd->data[0] = board_id; |
|
|
|
cmd->len = 1; |
|
|
|
auto rx = m_zcanReceiverHost->sendcmdblock(cmd, 100); |
|
|
|
if (rx == nullptr) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (rx->packetType == kpt_error_ack) { |
|
|
|
logger->error("ping error ack,{}", *zuint16p(&rx->data[0])); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return rx != nullptr; |
|
|
|
} |
|
|
|
|
|
|
@ -156,6 +246,11 @@ int32_t ZCanHost::readio(int id, bool& value) { |
|
|
|
if (rx == nullptr) { |
|
|
|
return err::zecode(err::knoack); |
|
|
|
} |
|
|
|
if (rx->packetType == kpt_error_ack) { |
|
|
|
logger->error("readio error ack,{}", *zuint16p(&rx->data[0])); |
|
|
|
return err::zecode(err::knoack); |
|
|
|
} |
|
|
|
|
|
|
|
value = rx->data[1]; |
|
|
|
return 0; |
|
|
|
} |
|
|
@ -170,6 +265,11 @@ int32_t ZCanHost::writeio(int id, bool value) { |
|
|
|
if (rx == nullptr) { |
|
|
|
return err::zecode(err::knoack); |
|
|
|
} |
|
|
|
if (rx->packetType == kpt_error_ack) { |
|
|
|
logger->error("writeio error ack,{}", *zuint16p(&rx->data[0])); |
|
|
|
return err::zecode(err::knoack); |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
int32_t ZCanHost::readadc(int id, int& value) { |
|
|
@ -182,6 +282,11 @@ int32_t ZCanHost::readadc(int id, int& value) { |
|
|
|
if (rx == nullptr) { |
|
|
|
return err::zecode(err::knoack); |
|
|
|
} |
|
|
|
|
|
|
|
if (rx->packetType == kpt_error_ack) { |
|
|
|
logger->error("readadc error ack,{}", *zuint16p(&rx->data[0])); |
|
|
|
return err::zecode(err::knoack); |
|
|
|
} |
|
|
|
value = *(int32_t*)(&rx->data[2]); |
|
|
|
return 0; |
|
|
|
} |
|
|
@ -196,6 +301,11 @@ 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->packetType == kpt_error_ack) { |
|
|
|
logger->error("pumpctrl_c1004 error ack,{}", *zuint16p(&rx->data[0])); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return rx != nullptr; |
|
|
|
} |
|
|
|
|
|
|
@ -208,7 +318,26 @@ 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) { return false; } |
|
|
|
bool ZCanHost::warning_light_ctrl_c1002(uint8_t sensorid, uint8_t r, uint8_t g, uint8_t b, uint8_t w) { |
|
|
|
shared_ptr<ZCanReceiverCMD> cmd = make_shared<ZCanReceiverCMD>(); |
|
|
|
cmd->cmdid = 1002; |
|
|
|
cmd->subcmdid = 0; |
|
|
|
cmd->data[0] = sensorid; |
|
|
|
cmd->data[2] = r; |
|
|
|
cmd->data[3] = g; |
|
|
|
cmd->data[4] = b; |
|
|
|
cmd->data[5] = w; |
|
|
|
cmd->len = 6; |
|
|
|
|
|
|
|
auto rx = m_zcanReceiverHost->sendcmdblock(cmd, 100); |
|
|
|
|
|
|
|
if (rx->packetType == kpt_error_ack) { |
|
|
|
logger->error("warning_light_ctrl_c1002 error ack,{}", *zuint16p(&rx->data[0])); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return rx != nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 读取华成压力传感器数值 |
|
|
@ -217,4 +346,57 @@ 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) { return false; } |
|
|
|
bool ZCanHost::huacheng_pressure_sensor_read_c1005(int sensorid, huacheng_pressure_sensor_read_c1005_t& value) { |
|
|
|
/**
|
|
|
|
* @brief |
|
|
|
*/ |
|
|
|
|
|
|
|
shared_ptr<ZCanReceiverCMD> cmd = make_shared<ZCanReceiverCMD>(); |
|
|
|
cmd->cmdid = 1005; |
|
|
|
cmd->subcmdid = 0; |
|
|
|
cmd->data[0] = sensorid; |
|
|
|
cmd->len = 2; |
|
|
|
|
|
|
|
auto rx = m_zcanReceiverHost->sendcmdblock(cmd, 100); |
|
|
|
|
|
|
|
if (rx->packetType == kpt_error_ack) { |
|
|
|
logger->error("huacheng_pressure_sensor_read_c1005 error ack"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (rx->len != 10) { |
|
|
|
logger->warn("huacheng_pressure_sensor_read_c1005 rx len error:{}", rx->len); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
value.precision = rx->data[2]; |
|
|
|
value.unit = rx->data[3]; |
|
|
|
value.value = *(int16_t*)(&rx->data[4]); |
|
|
|
value.zero = *(int16_t*)(&rx->data[6]); |
|
|
|
value.full = *(int16_t*)(&rx->data[8]); |
|
|
|
|
|
|
|
return rx != nullptr; |
|
|
|
} |
|
|
|
|
|
|
|
bool ZCanHost::hpp272_read_c1000(int sensorid, hpp272_data_t& value) { |
|
|
|
shared_ptr<ZCanReceiverCMD> cmd = make_shared<ZCanReceiverCMD>(); |
|
|
|
cmd->cmdid = 1000; |
|
|
|
cmd->subcmdid = 0; |
|
|
|
cmd->data[0] = sensorid; |
|
|
|
cmd->len = 2; |
|
|
|
|
|
|
|
auto rx = m_zcanReceiverHost->sendcmdblock(cmd, 100); |
|
|
|
|
|
|
|
if (rx->packetType == kpt_error_ack) { |
|
|
|
logger->error("hpp272_read_c1000 error ack"); |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
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; |
|
|
|
} |
|
|
|
|
|
|
|
memcpy(&value, &rx->data[2], sizeof(hpp272_data_t)); |
|
|
|
return rx != nullptr; |
|
|
|
} |