diff --git a/src/iflytop/components/zcanreceiver/zcanhost.cpp b/src/iflytop/components/zcanreceiver/zcanhost.cpp index c09d952..4c05ea8 100644 --- a/src/iflytop/components/zcanreceiver/zcanhost.cpp +++ b/src/iflytop/components/zcanreceiver/zcanhost.cpp @@ -461,6 +461,7 @@ int32_t ZCanHost::hpp272_read_c1000(int sensorid, hpp272_data_t& value) { return 0; } + int32_t ZCanHost::call(int32_t cmdid, int32_t* val0, int32_t nval, int32_t* ack, int32_t* acknum) { shared_ptr cmd = make_shared(); cmd->cmdid = cmdid; diff --git a/src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp b/src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp index 359fec0..8cbfc3d 100644 --- a/src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp +++ b/src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp @@ -23,6 +23,21 @@ void ZCanReceiverHost::registerListener(onpacket_t onpacket) { m_onpacket = onpa void ZCanReceiverHost::registerReportMsgListener(onreport_t onpacket) { m_onReportPacket = onpacket; } shared_ptr ZCanReceiverHost::sendcmdblock(shared_ptr cmd, int overtime_ms) { // + + /** + * @brief 指令发送失败后,重试3次 + */ + for (int i = 0; i < 3; i++) { + auto rx = _sendcmdblock(cmd, overtime_ms); + if (rx) { + return rx; + } + } + + return nullptr; +} + +shared_ptr ZCanReceiverHost::_sendcmdblock(shared_ptr cmd, int overtime_ms) { // lock_guard lock(m_txblocklock); // 加这个延时是因为,曾经出现一个BUG,当发送一条指令成功后,立马下发第二条指令,第二条指令会发送失败,原因未知 usleep(10 * 1000); diff --git a/src/iflytop/components/zcanreceiver/zcanreceiverhost.hpp b/src/iflytop/components/zcanreceiver/zcanreceiverhost.hpp index 706b463..c619b16 100644 --- a/src/iflytop/components/zcanreceiver/zcanreceiverhost.hpp +++ b/src/iflytop/components/zcanreceiver/zcanreceiverhost.hpp @@ -83,6 +83,8 @@ class ZCanReceiverHost { shared_ptr sendcmdblock(shared_ptr cmd, int overtime_ms); private: + shared_ptr _sendcmdblock(shared_ptr cmd, int overtime_ms); + void processRx(shared_ptr frame); void processOnePacket(CanPacketRxBuffer *rxbuf, uint8_t *packet, size_t len); void resetSocketCan();