From 3cd88d85f20ebc1f0cb337ab10d9023ad7531df3 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Wed, 22 May 2024 17:18:05 +0800 Subject: [PATCH] =?UTF-8?q?zcanhost=E6=B7=BB=E5=8A=A0=E9=87=8D=E5=8F=91?= =?UTF-8?q?=E6=9C=BA=E5=88=B6,=E8=A7=A3=E5=86=B3zcan=E5=B0=8F=E6=A6=82?= =?UTF-8?q?=E7=8E=87=E6=8C=87=E4=BB=A4=E4=B8=8B=E5=8F=91=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/iflytop/components/zcanreceiver/zcanhost.cpp | 1 + src/iflytop/components/zcanreceiver/zcanreceiverhost.cpp | 15 +++++++++++++++ src/iflytop/components/zcanreceiver/zcanreceiverhost.hpp | 2 ++ 3 files changed, 18 insertions(+) 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();