From 5541a190189721a15221b165ee533240e7a3a5e4 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sat, 17 Aug 2024 18:39:16 +0800 Subject: [PATCH] update --- README.md | 8 +++++--- .../canchannel/com/zscanprotocol_com.cpp | 23 +++++++++++++++++++--- .../canchannel/com/zscanprotocol_com.hpp | 2 ++ doc/硬件测试指令.md | 0 4 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 doc/硬件测试指令.md diff --git a/README.md b/README.md index 470112b..af75aa6 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,11 @@ TODO: 1. 整理大空间,小空间,管道式的单片机代码,满足多设备编码规范。(按照真实的设备情况编写代码)OK -2. 整理大空间,小空间,管道式的ID路由代码。 -3. 填充硬件测试页面。 -4. 指令重发代码功能。 +2. 整理大空间,小空间,管道式的ID路由代码。OK +3. 填充硬件测试页面。OK +4. 指令重发代码功能。OK +5. 硬件测试 OK + 6. 所有后台程序添加异常检查,当异常发生过,则设置全局标志位(硬件异常)。此时后台程序相应的线程将不再继续工作。(直到设备重启) 7. 所有后台程序(有前端启动的),则是检查全局标志位,如果触发错误,则报错。 8. 添加消毒日志打印程序 diff --git a/appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp b/appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp index 178e6b6..482e27f 100644 --- a/appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp +++ b/appsrc/appcomponents/canchannel/com/zscanprotocol_com.cpp @@ -9,7 +9,6 @@ using namespace zscanprotocol; #define TAG "ZScanProtocolCom" - void ZSCanProtocolCom::initialize(const char *canname, int baudrate, bool enableLoopBack) { // m_channel = make_shared(); m_channel->initialize(canname, baudrate, enableLoopBack); @@ -73,7 +72,7 @@ void ZSCanProtocolCom::sendframe(int32_t from, int32_t to, uint8_t *frame, size_ int npacket = len / 8 + (len % 8 == 0 ? 0 : 1); if (npacket > 255) { - THROW_APP_EXCEPTION(err::kerr_invalid_param, "param error: packet too long"); + THROW_APP_EXCEPTION(err::kerr_invalid_param, "param error: packet too long"); } int finalpacketlen = len % 8 == 0 ? 8 : len % 8; @@ -140,7 +139,7 @@ CanPacketRxBuffer *ZSCanProtocolCom::findRxBuff(int deviceId) { return nullptr; } -shared_ptr ZSCanProtocolCom::callcmd(int32_t to, int32_t cmdid, uint8_t *param, int32_t paramLen, int32_t overtime) { +shared_ptr ZSCanProtocolCom::base_callcmd(int32_t to, int32_t cmdid, uint8_t *param, int32_t paramLen, int32_t overtime) { m_txindex++; if (m_txindex < 200) m_txindex = 200; @@ -193,6 +192,24 @@ shared_ptr ZSCanProtocolCom::callcmd(int32_t to, int32_t cmdid, uint8_t receipt->receiptLen = m_receipt_len; return receipt; } + +shared_ptr ZSCanProtocolCom::callcmd(int32_t to, int32_t cmdid, uint8_t *param, int32_t paramLen, int32_t overtime) { + shared_ptr receipt; + + for (size_t i = 0; i <= 3; i++) { + try { + if (i != 0) logger->warn("callcmd overtime, retry %d", i); + receipt = base_callcmd(to, cmdid, param, paramLen, overtime); + } catch (const appexception &e) { + if (e.ecode() == err::kerr_overtime) { + continue; + } + throw; + } + } + if(receipt == nullptr) THROW_APP_EXCEPTION(err::kerr_overtime, "overtime"); + return receipt; +} shared_ptr ZSCanProtocolCom::callcmd0(int32_t to, int32_t cmdid, int32_t overtime) { return callcmd(to, cmdid, nullptr, 0, overtime); } shared_ptr ZSCanProtocolCom::callcmd1(int32_t device_id, int32_t cmdid, int32_t param0, int32_t overtime) { int32_t param[4]; diff --git a/appsrc/appcomponents/canchannel/com/zscanprotocol_com.hpp b/appsrc/appcomponents/canchannel/com/zscanprotocol_com.hpp index 6246bee..72bac29 100644 --- a/appsrc/appcomponents/canchannel/com/zscanprotocol_com.hpp +++ b/appsrc/appcomponents/canchannel/com/zscanprotocol_com.hpp @@ -113,6 +113,8 @@ class ZSCanProtocolCom { private: CanPacketRxBuffer *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); }; } // namespace zscanprotocol diff --git a/doc/硬件测试指令.md b/doc/硬件测试指令.md new file mode 100644 index 0000000..e69de29