From 0035acd2d227a103291b128fdcda9cf3f9531662 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Wed, 15 May 2024 17:14:42 +0800 Subject: [PATCH] update --- src/iflytop/components/zcanreceiver/cmd.hpp | 34 +++------------------- .../components/zcanreceiver/zcanreceiverhost.cpp | 28 +++++++++++------- 2 files changed, 21 insertions(+), 41 deletions(-) diff --git a/src/iflytop/components/zcanreceiver/cmd.hpp b/src/iflytop/components/zcanreceiver/cmd.hpp index eeb96b0..6c3a74e 100644 --- a/src/iflytop/components/zcanreceiver/cmd.hpp +++ b/src/iflytop/components/zcanreceiver/cmd.hpp @@ -1,45 +1,19 @@ #pragma once #include +#include #include #include #include #include +#include #include #include #include -#include -#include + +#include "transmit_disinfection_protocol_v1/transmit_disinfection_protocol_v1.hpp" namespace iflytop { namespace zcr { -typedef struct { - uint16_t packetindex; - uint16_t cmdid; - uint8_t subcmdid; - uint8_t packetType; - uint8_t data[]; -} Cmdheader_t; - -typedef enum { - kpt_cmd = 0, - kpt_ack = 1, - kpt_error_ack = 2, - kpt_status_report = 3, -} PacketType_t; - -typedef enum { - kcmd_ping = 0, - kcmd_read_io = 1, - kcmd_set_io = 2, - - kcmd_m211887_operation = 1000, // 维萨拉压力传感器 - kcmd_read_presure_sensor = 1001, - kcmd_triple_warning_light_ctl = 1002, - kcmd_high_power_electrical_ctl = 1003, - kcmd_peristaltic_pump_ctl = 1004, - kcmd_read_huacheng_pressure_sensor = 1005, -} CmdID_t; - } // namespace zcr } // namespace iflytop diff --git a/src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp b/src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp index b3b0ebd..ca473da 100644 --- a/src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp +++ b/src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp @@ -23,7 +23,7 @@ void ZCanReceiverHost::registerListener(onpacket_t onpacket) { m_onpacket = onpa shared_ptr ZCanReceiverHost::sendcmdblock(shared_ptr cmd, int overtime_ms) { // lock_guard lock(m_txblocklock); - //加这个延时是因为,曾经出现一个BUG,当发送一条指令成功后,立马下发第二条指令,第二条指令会发送失败,原因未知 + // 加这个延时是因为,曾经出现一个BUG,当发送一条指令成功后,立马下发第二条指令,第二条指令会发送失败,原因未知 usleep(10 * 1000); m_index++; @@ -58,22 +58,22 @@ shared_ptr ZCanReceiverHost::sendcmdblock(shared_ptrwarn("sendcmdblock(index {},cmd {},subcmd {}) fail,timeout", cmd->packetindex, cmd->cmdid, cmd->subcmdid); return nullptr; } - usleep(10*1000); + usleep(10 * 1000); return m_txContext.rx; } void ZCanReceiverHost::sendcmd(uint16_t packetindex, uint16_t cmdid, uint8_t subcmdid, uint8_t *data, size_t len) { - Cmdheader_t *header = (Cmdheader_t *)m_sendbuf; - header->packetindex = packetindex; - header->cmdid = cmdid; - header->subcmdid = subcmdid; - header->packetType = 0x00; + transmit_disinfection_protocol_header_t *header = (transmit_disinfection_protocol_header_t *)m_sendbuf; + header->packetindex = packetindex; + header->cmdid = cmdid; + header->subcmdid = subcmdid; + header->packetType = 0x00; memcpy(header->data, data, len); // printf("sendcmd(%d:%d:%d) ", packetindex, cmdid, subcmdid); // for (size_t i = 0; i < len; i++) { // printf("%02x ", data[i]); // } - sendPacket(m_sendbuf, sizeof(Cmdheader_t) + len); + sendPacket(m_sendbuf, sizeof(transmit_disinfection_protocol_header_t) + len); } void ZCanReceiverHost::sendPacket(uint8_t *packet, size_t len) { /** @@ -114,7 +114,7 @@ bool ZCanReceiverHost::sendPacketSub(int npacket, int packetIndex, uint8_t *pack void ZCanReceiverHost::processOnePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len) { // - Cmdheader_t *header = (Cmdheader_t *)packet; + transmit_disinfection_protocol_header_t *header = (transmit_disinfection_protocol_header_t *)packet; // uint8_t from = rxbuf->id; shared_ptr rx = make_shared(); @@ -122,14 +122,14 @@ void ZCanReceiverHost::processOnePacket(CanPacketRxBuffer *rxbuf, uint8_t *packe rx->cmdid = header->cmdid; rx->subcmdid = header->subcmdid; rx->packetType = header->packetType; - rx->len = len - sizeof(Cmdheader_t); + rx->len = len - sizeof(transmit_disinfection_protocol_header_t); memcpy(rx->data, header->data, rx->len); /** * @brief 匹配下发的命令 */ // logger->info("processOnePacket(index {}, packetType {} ,cmd {},subcmd {}),rx(index {})", header->packetindex, header->packetType, header->cmdid, - // header->subcmdid, rx->packetindex); + // header->subcmdid, rx->packetindex); if (header->packetType == kpt_ack || header->packetType == kpt_error_ack) { if (header->packetindex == m_txContext.txcmdcache->packetindex) { lock_guard lock(m_txContextLock); @@ -138,6 +138,12 @@ void ZCanReceiverHost::processOnePacket(CanPacketRxBuffer *rxbuf, uint8_t *packe m_txContext.isReady = true; } return; + } else if (header->packetType == kpt_status_report) { + if (header->cmdid == kreport_h2o2_sensor_data) { + report_h2o2_data_t *h2o2data = (report_h2o2_data_t *)rx->data; + logger->info("[h2o2 sensor] id:{} e:{} h2o2:{} temp:{} humid:{} saturation:{}", // + h2o2data->sensorid, h2o2data->sensor_error, h2o2data->h2o2, h2o2data->temp, h2o2data->humid, h2o2data->saturation); + } } /** * @brief 处理其他类型的消息