From b488bfeb9b17566156f0d421fce2c21dfdb0ea21 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Wed, 15 May 2024 18:42:01 +0800 Subject: [PATCH] update --- src/iflytop/components/zcanreceiver/zcanhost.hpp | 2 ++ src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp | 8 ++------ src/iflytop/components/zcanreceiver/zcanreceiverhost.hpp | 4 ++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/iflytop/components/zcanreceiver/zcanhost.hpp b/src/iflytop/components/zcanreceiver/zcanhost.hpp index ff3faec..cf44b0b 100644 --- a/src/iflytop/components/zcanreceiver/zcanhost.hpp +++ b/src/iflytop/components/zcanreceiver/zcanhost.hpp @@ -47,6 +47,8 @@ class ZCanHost { int16_t m_pumpc1004_speed_cache[255]; public: + shared_ptr getZCanReceiverHost() { return m_zcanReceiverHost; } + void initialize(string can_if_name, int baudrate, bool enablLoopback); bool execcmd(string cmd, string& retval); diff --git a/src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp b/src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp index ca473da..359fec0 100644 --- a/src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp +++ b/src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp @@ -20,6 +20,7 @@ void ZCanReceiverHost::initialize(string can_if_name, int baudrate, bool enablLo resetSocketCan(); } void ZCanReceiverHost::registerListener(onpacket_t onpacket) { m_onpacket = onpacket; } +void ZCanReceiverHost::registerReportMsgListener(onreport_t onpacket) { m_onReportPacket = onpacket; } shared_ptr ZCanReceiverHost::sendcmdblock(shared_ptr cmd, int overtime_ms) { // lock_guard lock(m_txblocklock); @@ -140,14 +141,9 @@ void ZCanReceiverHost::processOnePacket(CanPacketRxBuffer *rxbuf, uint8_t *packe 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); + if (m_onReportPacket) m_onReportPacket(packet, len); } } - /** - * @brief 处理其他类型的消息 - */ } void ZCanReceiverHost::processRx(shared_ptr frame) { diff --git a/src/iflytop/components/zcanreceiver/zcanreceiverhost.hpp b/src/iflytop/components/zcanreceiver/zcanreceiverhost.hpp index 3c215dc..706b463 100644 --- a/src/iflytop/components/zcanreceiver/zcanreceiverhost.hpp +++ b/src/iflytop/components/zcanreceiver/zcanreceiverhost.hpp @@ -52,11 +52,14 @@ class ZCanReceiverHost { typedef function onpacket_t; + typedef function onreport_t; + public: uint8_t m_sendbuf[1000]; CanPacketRxBuffer m_canPacketRxBuffer[255]; onpacket_t m_onpacket; uint8_t m_deviceId = 1; + onreport_t m_onReportPacket; uint16_t m_index = 1; @@ -75,6 +78,7 @@ class ZCanReceiverHost { void initialize(string can_if_name, int baudrate, bool enablLoopback); void registerListener(onpacket_t onpacket); + void registerReportMsgListener(onreport_t onpacket); shared_ptr sendcmdblock(shared_ptr cmd, int overtime_ms);