From 636ee51ce8a18e139e2662226ce5a23a26f2d615 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sat, 11 Nov 2023 15:39:52 +0800 Subject: [PATCH] init --- components/zcancmder/basic.cpp | 19 +++++++++++++++++-- components/zcancmder/basic.hpp | 6 +++--- components/zcancmder/zcan_board_module.cpp | 5 ++++- components/zcancmder/zcanreceiver_master.cpp | 3 ++- os/zthread.hpp | 2 +- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/components/zcancmder/basic.cpp b/components/zcancmder/basic.cpp index 6c006c6..49e6084 100644 --- a/components/zcancmder/basic.cpp +++ b/components/zcancmder/basic.cpp @@ -1,5 +1,8 @@ #include "basic.hpp" +#include +#include + using namespace iflytop; using namespace std; uint16_t CanPacketRxBuffer::get_packetindex() { @@ -23,9 +26,21 @@ uint8_t *CanPacketRxBuffer::get_data() { zcr_cmd_header_t *cmdheader = (zcr_cmd_header_t *)rxdata; return cmdheader->data; } -uint16_t CanPacketRxBuffer::get_datalen() { - return rxdataSize - sizeof(zcr_cmd_header_t); +uint16_t CanPacketRxBuffer::get_datalen() { return rxdataSize - sizeof(zcr_cmd_header_t); } +void CanPacketRxBuffer::clear() { + id = 0; + memset(&m_canPacket, 0, sizeof(m_canPacket) * sizeof(m_canPacket[0])); + m_canPacketNum = 0; + m_npacket = 0; + memset(rxdata, 0, sizeof(rxdata)); + rxdataSize = 0; + + dataIsReady = false; + isOnReceive = false; + isUsed = false; + lostpacket = false; } + bool CanPacketRxBuffer::iscmd(int32_t id) { zcr_cmd_header_t *cmdheader = (zcr_cmd_header_t *)rxdata; uint16_t maincmdid = ((uint32_t)id >> 8) & 0xFFFF; diff --git a/components/zcancmder/basic.hpp b/components/zcancmder/basic.hpp index 3838f51..c9c7dd9 100644 --- a/components/zcancmder/basic.hpp +++ b/components/zcancmder/basic.hpp @@ -14,11 +14,10 @@ typedef enum { kpacketTail = 2, } packet_type_t; -class CANPacket { - public: +typedef struct { CAN_RxHeaderTypeDef pHeader; uint8_t aData[8]; /*8byte table*/ -}; +} CANPacket; }; // namespace zcr using namespace zcr; @@ -44,6 +43,7 @@ class CanPacketRxBuffer { uint8_t get_packetType(); uint8_t *get_data(); uint16_t get_datalen(); + void clear(); zcr_cmd_header_t *get_cmdheader(); diff --git a/components/zcancmder/zcan_board_module.cpp b/components/zcancmder/zcan_board_module.cpp index 86a6fc5..9777e50 100644 --- a/components/zcancmder/zcan_board_module.cpp +++ b/components/zcancmder/zcan_board_module.cpp @@ -24,7 +24,10 @@ void ZCanBoardModule::initialize(int32_t moduleId, hardware_config_t *hcfg) { m_output_num++; } } -int32_t ZCanBoardModule::getid(int32_t *id) { *id = module_id; }; +int32_t ZCanBoardModule::getid(int32_t *id) { + *id = module_id; + return 0; +}; int32_t ZCanBoardModule::module_readio(int32_t *io) { *io = readinput(); return 0; diff --git a/components/zcancmder/zcanreceiver_master.cpp b/components/zcancmder/zcanreceiver_master.cpp index 5adb12b..6e83895 100644 --- a/components/zcancmder/zcanreceiver_master.cpp +++ b/components/zcancmder/zcanreceiver_master.cpp @@ -374,7 +374,8 @@ bool ZCanCommnaderMaster::getRxMessage(CAN_RxHeaderTypeDef *pHeader, uint8_t aDa return false; } void ZCanCommnaderMaster::initCanPacketRxBuffer(CanPacketRxBuffer *buf, uint16_t id) { - memset(buf, 0, sizeof(CanPacketRxBuffer)); + if (buf == nullptr) return; + buf->clear(); buf->id = id; } diff --git a/os/zthread.hpp b/os/zthread.hpp index 9c3941c..351ba19 100644 --- a/os/zthread.hpp +++ b/os/zthread.hpp @@ -13,7 +13,7 @@ class ZThread { } status_t; const char* m_name; - size_t m_stacksize; + uint32_t m_stacksize; osPriority m_uxPriority; status_t m_status = kidle;