From f9ae27f4fe53b579089c07d00fa1f2f9156578d0 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Thu, 12 Sep 2024 14:53:18 +0800 Subject: [PATCH] append --- .../canchannel/com/zscanprotocol_com.cpp | 22 ++++++++++++++++------ .../canchannel/com/zscanprotocol_com.hpp | 20 +++++++++++++------- appsrc/service/hardware/device_io_ctrl_service.cpp | 12 ++++-------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp b/appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp index 152f073..2e85d35 100644 --- a/appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp +++ b/appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp @@ -3,6 +3,7 @@ #include #include "app_protocols/appexception/appexception.hpp" +#include "iflytop/core/basic/zbin.hpp" using namespace iflytop; using namespace zscanprotocol; @@ -12,6 +13,9 @@ using namespace transmit_disfection_protocol; void ZSCanProtocolCom::initialize(const char *canname, int baudrate, bool enableLoopBack) { // m_channel = make_shared(); + m_wq.reset(new WorkQueue("ZSCanProtocolCom")); + m_wq->startWork(); + m_channel->initialize(canname, baudrate, enableLoopBack); m_channel->regFrameCB([this](shared_ptr canframe) { // @@ -26,11 +30,11 @@ void ZSCanProtocolCom::initialize(const char *canname, int baudrate, bool enable zcanid_t *canid = (zcanid_t *)&canframe->id; - uint8_t from = canid->from; - uint8_t to = canid->to; - uint8_t nframe = (canid->frameNumAndFrameId & 0xf0) >> 4; - uint8_t frameId = canid->frameNumAndFrameId & 0x0f; - CanPacketRxBuffer *rxbuf = nullptr; + uint8_t from = canid->from; + uint8_t to = canid->to; + uint8_t nframe = (canid->frameNumAndFrameId & 0xf0) >> 4; + uint8_t frameId = canid->frameNumAndFrameId & 0x0f; + CanPacketBuffer *rxbuf = nullptr; logger->debug("from:{} to:{} frameNum:{} ", canid->from, canid->to, canid->frameNumAndFrameId); @@ -118,12 +122,13 @@ void ZSCanProtocolCom::processRxPacket(int32_t from, int32_t to, uint8_t *data, if (on_rx_raw) on_rx_raw((packet_type_t)frame->ptype, from, to, (uint8_t *)frame, len); } else if (frame->ptype == kreport) { if (on_rx_raw) on_rx_raw((packet_type_t)frame->ptype, from, to, (uint8_t *)frame, len); + callOnReport(from, (uint8_t *)frame, len); } else { logger->error("unknow packet type %d", frame->ptype); } } -CanPacketRxBuffer *ZSCanProtocolCom::findRxBuff(int deviceId) { +CanPacketBuffer *ZSCanProtocolCom::findRxBuff(int deviceId) { for (uint32_t i = 0; i < ZARRAY_SIZE(m_rxbuf); i++) { if (m_rxbuf[i].id == deviceId) { return &m_rxbuf[i]; @@ -260,3 +265,8 @@ shared_ptr ZSCanProtocolCom::callcmd5(int32_t to, int32_t cmdid, int32_ void ZSCanProtocolCom::sendraw(int32_t from, int32_t to, uint8_t *data, size_t len) { sendframe(from, to, data, len); } string ZSCanProtocolCom::ecode2str(int ecode) { return AppEcodeInfoMgr::ins().getEcodeInfo(ecode); } + +void ZSCanProtocolCom::callOnReport(uint8_t from, uint8_t *hex, uint32_t hexlen) { + shared_ptr hexbin = make_shared(hex, hexlen); + m_wq->enQueue([this, from, hexbin]() { onReport(from, (uint8_t *)hexbin->data(), hexbin->size()); }); +} diff --git a/appsrc/appcomponents/canchannel/com/zscanprotocol_com.hpp b/appsrc/appcomponents/canchannel/com/zscanprotocol_com.hpp index c405d83..fa9dbfc 100644 --- a/appsrc/appcomponents/canchannel/com/zscanprotocol_com.hpp +++ b/appsrc/appcomponents/canchannel/com/zscanprotocol_com.hpp @@ -14,6 +14,7 @@ // #include "app_protocols/zscanprotocol/zscanprotocol.h" +#include "iflytop/core/components/jobs/work_queue.hpp" #include "iflytop/core/core.hpp" #include "socket_can.hpp" @@ -44,7 +45,7 @@ class Receipt { uint8_t *getByte() { return (uint8_t *)getPacket()->params; } }; -class CanPacketRxBuffer { +class CanPacketBuffer { public: int32_t id = 0; uint8_t from = 0; @@ -67,13 +68,13 @@ class ZSCanProtocolCom { mutex lock_; - unique_ptr m_thread; + unique_ptr m_thread; + unique_ptr m_wq; RxReceiptContext m_rxReceiptContext; mutex m_rxReceiptContext_lock; - mutex m_lock; - + mutex m_lock; /******************************************************************************* * TX CONTEXT * @@ -83,7 +84,7 @@ class ZSCanProtocolCom { int32_t m_rxsize = 0; uint8_t m_txindex = 0; - CanPacketRxBuffer m_rxbuf[255]; + CanPacketBuffer m_rxbuf[255]; on_raw_data_t on_rx_raw; @@ -92,6 +93,9 @@ class ZSCanProtocolCom { size_t m_receipt_len = 0; public: + nod::signal onReport; + + public: ZSCanProtocolCom() {} public: @@ -113,9 +117,11 @@ class ZSCanProtocolCom { void sendsubframe(int32_t from, int32_t to, int npacket, int packetIndex, uint8_t *packet, size_t len); void processRxPacket(int32_t from, int32_t to, uint8_t *data, size_t len); + void callOnReport(uint8_t from, uint8_t *hex, uint32_t hexlen); + private: - CanPacketRxBuffer *findRxBuff(int deviceId); - string ecode2str(int ecode); + CanPacketBuffer *findRxBuff(int deviceId); + string ecode2str(int ecode); shared_ptr base_callcmd(int32_t to, int32_t cmdid, uint8_t *param, int32_t paramLen, int32_t overtime); }; diff --git a/appsrc/service/hardware/device_io_ctrl_service.cpp b/appsrc/service/hardware/device_io_ctrl_service.cpp index fb39f7f..91b8a78 100644 --- a/appsrc/service/hardware/device_io_ctrl_service.cpp +++ b/appsrc/service/hardware/device_io_ctrl_service.cpp @@ -83,12 +83,8 @@ void DeviceIoControlService::initialize() { // fn_clear_reset_flag TransmitDisinfectionCanMaster::ins()->initialize(m_config->get_canIF().c_str(), m_config->get_canBitrate(), false); - TransmitDisinfectionCanMaster::ins()->getCanProtocolCom()->regOnRawData( // - [this](packet_type_t type, uint8_t from, uint8_t to, uint8_t *hex, uint32_t hexlen) { - if (type == kreport) { - processReportMsg(from, hex, hexlen); - } - }); + TransmitDisinfectionCanMaster::ins()->getCanProtocolCom()->onReport.connect( // + [this](uint8_t from, uint8_t *hex, uint32_t hexlen) { processReportMsg(from, hex, hexlen); }); // REGFNV2(DeviceIoControlService, test); /** @@ -152,10 +148,10 @@ int DeviceIoControlService::forceStopDeviceWithoutExc() { int DeviceIoControlService::processHeartReportMsg(uint8_t from, report_heatpacket_data_t *report) { logger->info(" REPORT [Heat ][FROM:{}] HeatIndex:{:x} ToardType:{} flag:{}", from, report->heartIndex, BoardTypeId2Str(report->boardType), report->flag); -#define CHECK_BOARD_IS_REBOOT(boardid, ecode) \ +#define CHECK_BOARD_IS_REBOOT(boardid, ecode) \ { \ static bool firstReport = true; \ - if (report->flag != 0 && from == boardid) { \ + if (report->flag != 0 && from == boardid) { \ if (firstReport) { \ CAN_MASTER->clearResetFlag(boardid); \ firstReport = false; \