Browse Source

append

storage-in-realtime
zhaohe 11 months ago
parent
commit
f9ae27f4fe
  1. 22
      appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp
  2. 20
      appsrc/appcomponents/canchannel/com/zscanprotocol_com.hpp
  3. 12
      appsrc/service/hardware/device_io_ctrl_service.cpp

22
appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp

@ -3,6 +3,7 @@
#include <stdarg.h> #include <stdarg.h>
#include "app_protocols/appexception/appexception.hpp" #include "app_protocols/appexception/appexception.hpp"
#include "iflytop/core/basic/zbin.hpp"
using namespace iflytop; using namespace iflytop;
using namespace zscanprotocol; using namespace zscanprotocol;
@ -12,6 +13,9 @@ using namespace transmit_disfection_protocol;
void ZSCanProtocolCom::initialize(const char *canname, int baudrate, bool enableLoopBack) { // void ZSCanProtocolCom::initialize(const char *canname, int baudrate, bool enableLoopBack) { //
m_channel = make_shared<SocketCan>(); m_channel = make_shared<SocketCan>();
m_wq.reset(new WorkQueue("ZSCanProtocolCom"));
m_wq->startWork();
m_channel->initialize(canname, baudrate, enableLoopBack); m_channel->initialize(canname, baudrate, enableLoopBack);
m_channel->regFrameCB([this](shared_ptr<SocketCanFrame> canframe) { // m_channel->regFrameCB([this](shared_ptr<SocketCanFrame> canframe) { //
@ -26,11 +30,11 @@ void ZSCanProtocolCom::initialize(const char *canname, int baudrate, bool enable
zcanid_t *canid = (zcanid_t *)&canframe->id; 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); 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); if (on_rx_raw) on_rx_raw((packet_type_t)frame->ptype, from, to, (uint8_t *)frame, len);
} else if (frame->ptype == kreport) { } else if (frame->ptype == kreport) {
if (on_rx_raw) on_rx_raw((packet_type_t)frame->ptype, from, to, (uint8_t *)frame, len); 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 { } else {
logger->error("unknow packet type %d", frame->ptype); 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++) { for (uint32_t i = 0; i < ZARRAY_SIZE(m_rxbuf); i++) {
if (m_rxbuf[i].id == deviceId) { if (m_rxbuf[i].id == deviceId) {
return &m_rxbuf[i]; return &m_rxbuf[i];
@ -260,3 +265,8 @@ shared_ptr<Receipt> 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); } 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); } string ZSCanProtocolCom::ecode2str(int ecode) { return AppEcodeInfoMgr::ins().getEcodeInfo(ecode); }
void ZSCanProtocolCom::callOnReport(uint8_t from, uint8_t *hex, uint32_t hexlen) {
shared_ptr<ZBin> hexbin = make_shared<ZBin>(hex, hexlen);
m_wq->enQueue([this, from, hexbin]() { onReport(from, (uint8_t *)hexbin->data(), hexbin->size()); });
}

20
appsrc/appcomponents/canchannel/com/zscanprotocol_com.hpp

@ -14,6 +14,7 @@
// //
#include "app_protocols/zscanprotocol/zscanprotocol.h" #include "app_protocols/zscanprotocol/zscanprotocol.h"
#include "iflytop/core/components/jobs/work_queue.hpp"
#include "iflytop/core/core.hpp" #include "iflytop/core/core.hpp"
#include "socket_can.hpp" #include "socket_can.hpp"
@ -44,7 +45,7 @@ class Receipt {
uint8_t *getByte() { return (uint8_t *)getPacket()->params; } uint8_t *getByte() { return (uint8_t *)getPacket()->params; }
}; };
class CanPacketRxBuffer {
class CanPacketBuffer {
public: public:
int32_t id = 0; int32_t id = 0;
uint8_t from = 0; uint8_t from = 0;
@ -67,13 +68,13 @@ class ZSCanProtocolCom {
mutex lock_; mutex lock_;
unique_ptr<thread> m_thread;
unique_ptr<thread> m_thread;
unique_ptr<WorkQueue> m_wq;
RxReceiptContext m_rxReceiptContext; RxReceiptContext m_rxReceiptContext;
mutex m_rxReceiptContext_lock; mutex m_rxReceiptContext_lock;
mutex m_lock;
mutex m_lock;
/******************************************************************************* /*******************************************************************************
* TX CONTEXT * * TX CONTEXT *
@ -83,7 +84,7 @@ class ZSCanProtocolCom {
int32_t m_rxsize = 0; int32_t m_rxsize = 0;
uint8_t m_txindex = 0; uint8_t m_txindex = 0;
CanPacketRxBuffer m_rxbuf[255];
CanPacketBuffer m_rxbuf[255];
on_raw_data_t on_rx_raw; on_raw_data_t on_rx_raw;
@ -92,6 +93,9 @@ class ZSCanProtocolCom {
size_t m_receipt_len = 0; size_t m_receipt_len = 0;
public: public:
nod::signal<void(uint8_t from, uint8_t *hex, uint32_t hexlen)> onReport;
public:
ZSCanProtocolCom() {} ZSCanProtocolCom() {}
public: 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 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 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: private:
CanPacketRxBuffer *findRxBuff(int deviceId);
string ecode2str(int ecode);
CanPacketBuffer *findRxBuff(int deviceId);
string ecode2str(int ecode);
shared_ptr<Receipt> base_callcmd(int32_t to, int32_t cmdid, uint8_t *param, int32_t paramLen, int32_t overtime); shared_ptr<Receipt> base_callcmd(int32_t to, int32_t cmdid, uint8_t *param, int32_t paramLen, int32_t overtime);
}; };

12
appsrc/service/hardware/device_io_ctrl_service.cpp

@ -83,12 +83,8 @@ void DeviceIoControlService::initialize() {
// fn_clear_reset_flag // fn_clear_reset_flag
TransmitDisinfectionCanMaster::ins()->initialize(m_config->get_canIF().c_str(), m_config->get_canBitrate(), false); 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); // REGFNV2(DeviceIoControlService, test);
/** /**
@ -152,10 +148,10 @@ int DeviceIoControlService::forceStopDeviceWithoutExc() {
int DeviceIoControlService::processHeartReportMsg(uint8_t from, report_heatpacket_data_t *report) { 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); 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; \ static bool firstReport = true; \
if (report->flag != 0 && from == boardid) { \
if (report->flag != 0 && from == boardid) { \
if (firstReport) { \ if (firstReport) { \
CAN_MASTER->clearResetFlag(boardid); \ CAN_MASTER->clearResetFlag(boardid); \
firstReport = false; \ firstReport = false; \

Loading…
Cancel
Save