|
@ -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()); }); |
|
|
|
|
|
} |