From d3c111f03e712ea8c5642a8ffed9b8819d199624 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sat, 3 Feb 2024 16:08:14 +0800 Subject: [PATCH] fix protocol parser bug --- components/zcancmder/zcanreceiver.cpp | 1 + .../zcancmder_module/zcan_basic_order_module.cpp | 75 ---------------------- .../zcancmder_module/zcan_basic_order_module.hpp | 54 ---------------- components/zcancmder_module/zcan_eeprom_module.cpp | 33 ---------- components/zcancmder_module/zcan_eeprom_module.hpp | 21 ------ .../zcancmder_module/zcan_fan_ctrl_module.cpp | 74 --------------------- .../zcancmder_module/zcan_fan_ctrl_module.hpp | 56 ---------------- .../zcan_mini_servo_ctrl_module.cpp | 5 -- .../zcan_mini_servo_ctrl_module.hpp | 6 -- components/zprotocols/zcancmder_v2 | 2 +- 10 files changed, 2 insertions(+), 325 deletions(-) delete mode 100644 components/zcancmder_module/zcan_basic_order_module.cpp delete mode 100644 components/zcancmder_module/zcan_basic_order_module.hpp delete mode 100644 components/zcancmder_module/zcan_eeprom_module.cpp delete mode 100644 components/zcancmder_module/zcan_eeprom_module.hpp delete mode 100644 components/zcancmder_module/zcan_fan_ctrl_module.cpp delete mode 100644 components/zcancmder_module/zcan_fan_ctrl_module.hpp delete mode 100644 components/zcancmder_module/zcan_mini_servo_ctrl_module.cpp delete mode 100644 components/zcancmder_module/zcan_mini_servo_ctrl_module.hpp diff --git a/components/zcancmder/zcanreceiver.cpp b/components/zcancmder/zcanreceiver.cpp index 299d0dd..f86d834 100644 --- a/components/zcancmder/zcanreceiver.cpp +++ b/components/zcancmder/zcanreceiver.cpp @@ -348,6 +348,7 @@ void ZCanCmder::loop() { dataoff += rxbuf->m_canPacket[i].dlc; } rxbuf->rxdataSize = dataoff; + // ZLOGI(TAG,"rx packet"); for (auto &var : m_listenerList) { if (var) var->onRceivePacket(rxbuf->get_cmdheader(), rxbuf->get_params(), rxbuf->get_params_len()); diff --git a/components/zcancmder_module/zcan_basic_order_module.cpp b/components/zcancmder_module/zcan_basic_order_module.cpp deleted file mode 100644 index 4057165..0000000 --- a/components/zcancmder_module/zcan_basic_order_module.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "zcan_basic_order_module.hpp" - -#include -#include -#ifdef HAL_CAN_MODULE_ENABLED - -using namespace iflytop; -using namespace zcr; -#if 0 -void ZCanBasicOrderModule::initialize(ZCanCmder* zcanReceiver) { - zcanReceiver->registerListener(this); - m_zcanReceiver = zcanReceiver; -} -#if 0 -void ZCanBasicOrderModule::reg_read_io(readfn_t fn) { m_readfn = fn; } -void ZCanBasicOrderModule::reg_set_io(writefn_t fn) { m_writefn = fn; } -void ZCanBasicOrderModule::reg_read_adc(readadcval_t fn) { m_readadcval = fn; } -#endif -void ZCanBasicOrderModule::reg_read_io(uint8_t id, readfn_t fn) { m_inputCtlMap[id] = fn; } -void ZCanBasicOrderModule::reg_set_io(uint8_t id, writefn_t fn) { m_outCtlMap[id] = fn; } -void ZCanBasicOrderModule::reg_read_adc(uint8_t id, readadcval_t fn) { m_readAdcValMap[id] = fn; } - -void ZCanBasicOrderModule::onRceivePacket(CanPacketRxBuffer* rxbuf) { - if (rxbuf->iscmd(kcmd_ping)) { - kcmd_ping_cmd_t* pingcmd = rxbuf->get_param_as(); - kcmd_ping_ack_t* ack = (kcmd_ping_ack_t*)txbuff; - - if (pingcmd->boardid == m_zcanReceiver->getDeviceId()) { - ack->boardid = pingcmd->boardid; - m_zcanReceiver->sendAck(rxbuf->get_cmdheader(), txbuff, sizeof(kcmd_ping_ack_t)); - return; - } - } else if (rxbuf->iscmd(kcmd_read_io)) { - kcmd_read_io_cmd_t* cmd = rxbuf->get_param_as(); - kcmd_read_io_ack_t* ack = (kcmd_read_io_ack_t*)txbuff; - bool val = false; - - if (m_inputCtlMap.find(cmd->ioid) != m_inputCtlMap.end()) { - val = m_inputCtlMap[cmd->ioid](); - ack->ioid = cmd->ioid; - ack->val = val; - m_zcanReceiver->sendAck(rxbuf->get_cmdheader(), txbuff, sizeof(kcmd_read_io_ack_t)); - } - - } else if (rxbuf->iscmd(kcmd_set_io)) { - kcmd_set_io_cmd_t* cmd = rxbuf->get_param_as(); - kcmd_set_io_ack_t ack; - bool val = cmd->val; - - if (m_outCtlMap.find(cmd->ioid) != m_outCtlMap.end()) { - m_outCtlMap[cmd->ioid](val); - ack.ioid = cmd->ioid; - ack.val = val; - m_zcanReceiver->sendAck(rxbuf->get_cmdheader(), (uint8_t*)&ack, sizeof(ack)); - return; - } - - } else if (rxbuf->iscmd(kcmd_readadc_raw)) { - kcmd_readadc_raw_cmd_t* cmd = rxbuf->get_param_as(); - kcmd_readadc_raw_ack_t ack; - int32_t val = 0; - if (m_readAdcValMap.find(cmd->sensorid) != m_readAdcValMap.end()) { - val = m_readAdcValMap[cmd->sensorid](); - ack.sensorid = cmd->sensorid; - ack.val = val; - m_zcanReceiver->sendAck(rxbuf->get_cmdheader(), (uint8_t*)&ack, sizeof(ack)); - return; - } - } -} - -void ZCanBasicOrderModule::loop() {} - -#endif -#endif \ No newline at end of file diff --git a/components/zcancmder_module/zcan_basic_order_module.hpp b/components/zcancmder_module/zcan_basic_order_module.hpp deleted file mode 100644 index 71dd8e1..0000000 --- a/components/zcancmder_module/zcan_basic_order_module.hpp +++ /dev/null @@ -1,54 +0,0 @@ -// -// Created by zwsd -// - -#pragma once -// -#include "sdk/os/zos.hpp" -#include "sdk\components\zcancmder\zcanreceiver.hpp" -#ifdef HAL_CAN_MODULE_ENABLED -#include - -namespace iflytop { -using namespace std; -#if 0 -class ZCanBasicOrderModule : public ZCanCmderListener { - public: - private: - ZCanCmder* m_zcanReceiver; - - typedef function readfn_t; - typedef function writefn_t; - typedef function readadcval_t; - - // readfn_t m_readfn; - // writefn_t m_writefn; - // readadcval_t m_readadcval; - - uint8_t txbuff[32]; - - map m_inputCtlMap; - map m_outCtlMap; - map m_readAdcValMap; - - public: - ZCanBasicOrderModule(/* args */) {} - ~ZCanBasicOrderModule() {} - - public: - void initialize(ZCanCmder* zcanReceiver); - - void reg_read_io(uint8_t id, readfn_t fn); - void reg_set_io(uint8_t id, writefn_t fn); - void reg_read_adc(uint8_t id, readadcval_t fn); - - public: - virtual void onRceivePacket(CanPacketRxBuffer* rxbuf); - - private: - void loop(); -}; -#endif -} // namespace iflytop - -#endif \ No newline at end of file diff --git a/components/zcancmder_module/zcan_eeprom_module.cpp b/components/zcancmder_module/zcan_eeprom_module.cpp deleted file mode 100644 index ed58466..0000000 --- a/components/zcancmder_module/zcan_eeprom_module.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "zcan_eeprom_module.hpp" -using namespace iflytop; - -#define TAG "ZCanEepromModule" -#if 0 -void ZCanEepromModule::initialize(ZCanCmder* cancmder, int id, I_EEPROMModule* module) { - m_cancmder = cancmder; - m_id = id; - m_module = module; - m_lock.init(); - cancmder->registerListener(this); -} -void ZCanEepromModule::onRceivePacket(CanPacketRxBuffer* rxcmd) { // - - PROCESS_PACKET(kcmd_eeprom_start_monitor_status, m_id) { - errorcode = m_module->start_monitor_status([this, cmdheader](I_EEPROMModule::eeprom_status_t& status) { // - auto* report = (kcmd_eeprom_start_monitor_status_report_t*)m_txbuf; - static_assert(sizeof(*report) < sizeof(m_txbuf), "report size too large"); - - ZLOGI(TAG, "kcmd_eeprom_start_monitor_status exec_status:%d", status); - report->status = status; - m_cancmder->sendStatusReport(cmdheader, (uint8_t*)report, sizeof(*report)); - }); - }; - END_PP(); - - PROCESS_PACKET(kcmd_eeprom_stop_monitor_status, m_id) { errorcode = m_module->stop_monitor_status(); }; - END_PP(); - - PROCESS_PACKET(kcmd_eeprom_read_block, m_id) { errorcode = m_module->read(cmd->sector_index, cmd->sector_size, ack->ack); }; - END_PP(); -} -#endif diff --git a/components/zcancmder_module/zcan_eeprom_module.hpp b/components/zcancmder_module/zcan_eeprom_module.hpp deleted file mode 100644 index 9afe630..0000000 --- a/components/zcancmder_module/zcan_eeprom_module.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -// #include "sdk/components/zprotocols/zcancmder/api/i_step_motor_ctrl_module.hpp" -#include "sdk/components/zprotocols/zcancmder/api/i_eeprom.hpp" -#include "sdk\components\zcancmder\zcanreceiver.hpp" -namespace iflytop { - -#if 0 -class ZCanEepromModule : public ZCanCmderListener { - ZCanCmder* m_cancmder = nullptr; - int m_id = 0; - I_EEPROMModule* m_module; - - uint8_t m_txbuf[300] = {0}; - zmutex m_lock; - - public: - void initialize(ZCanCmder* cancmder, int id, I_EEPROMModule* module); - virtual void onRceivePacket(CanPacketRxBuffer* rxcmd); -}; -#endif -} // namespace iflytop diff --git a/components/zcancmder_module/zcan_fan_ctrl_module.cpp b/components/zcancmder_module/zcan_fan_ctrl_module.cpp deleted file mode 100644 index fd7ba31..0000000 --- a/components/zcancmder_module/zcan_fan_ctrl_module.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "zcan_fan_ctrl_module.hpp" -using namespace iflytop; -using namespace std; -#if 1 -#define TAG "ZcanFanCtrlModule" -void ZcanFanCtrlModule::initialize(int32_t id, ZIPWMFanCtrlModule* fanmodule, int32_t default_speed) { - m_id = id; - m_fanmodule = fanmodule; - ZASSERT(m_fanmodule != nullptr); - - OSDefaultSchduler::getInstance()->regPeriodJob( - [this](OSDefaultSchduler::Context& context) { // - if (m_isworking && m_com_reg.module_errorcode == 0) { - if (m_fanmodule->isError()) { - ZLOGE(TAG, "detect fan error,stop fan"); - m_com_reg.module_errorcode = err::khwardware_error; - m_fanmodule->clearError(); - module_stop(); - } - } - }, - 10); -} - -int32_t ZcanFanCtrlModule::getid(int32_t* id) { - *id = m_id; - return 0; -} -int32_t ZcanFanCtrlModule::module_get_status(int32_t* status) { - if (m_com_reg.module_errorcode != 0) { - *status = 2; - } else if (m_isworking) { - *status = 1; - } else { - *status = 0; - } - return 0; -} -int32_t ZcanFanCtrlModule::set_fan_default_speed(int32_t default_speed) { - m_default_speed = default_speed; - if (m_isworking) m_fanmodule->setFanSpeed(default_speed); - return 0; -} - -int32_t ZcanFanCtrlModule::module_xxx_reg(int32_t param_id, bool read, int32_t& val) { - switch (param_id) { - MODULE_COMMON_PROCESS_REG_CB(); - PROCESS_REG(kreg_fan0_ctrl_speed_level, REG_GET(m_default_speed), set_fan_default_speed(val)); - break; - default: - return err::kmodule_not_find_config_index; - } - return err::kmodule_not_find_config_index; -} - -int32_t ZcanFanCtrlModule::module_stop() { - m_isworking = false; - m_fanmodule->stop(); - return 0; -} -int32_t ZcanFanCtrlModule::module_start() { - module_clear_error(); - - if (m_default_speed == 0) { - module_stop(); - } - - m_isworking = true; - m_fanmodule->setFanSpeed(m_default_speed); - return 0; -} - -int32_t ZcanFanCtrlModule::do_action(int32_t actioncode) { return 0; } -#endif \ No newline at end of file diff --git a/components/zcancmder_module/zcan_fan_ctrl_module.hpp b/components/zcancmder_module/zcan_fan_ctrl_module.hpp deleted file mode 100644 index 4d26381..0000000 --- a/components/zcancmder_module/zcan_fan_ctrl_module.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#pragma once -/** - * @file tmp117.hpp - * @author zhaohe (h_zhaohe@163.com) - * @brief - * @version 0.1 - * @date 2023-04-14 - * - * @copyright Copyright (c) 2023 - * - * - * 1. 参考:https://github.com/rkiyak/TMP117.git - * 2. 同级目录有芯片的datasheet。 - */ -#include - -#include "sdk/os/zos.hpp" -// -#include "sdk\components\api\zi_pwm_fan_ctrl_module.hpp" -#include "sdk\components\zprotocols\zcancmder_v2\api\api.hpp" - -namespace iflytop { -/** - * @brief - * 水冷温度控制模块 - */ - -class ZcanFanCtrlModule : public ZIModule { - ENABLE_MODULE(ZcanFanCtrlModule, kfan_ctrl_module, 1); - - public: - ZIPWMFanCtrlModule* m_fanmodule = nullptr; - int32_t m_id = 0; - - bool m_isworking = false; - - int32_t m_default_speed = 50; - - public: - ZcanFanCtrlModule(){}; - virtual ~ZcanFanCtrlModule(){}; - - void initialize(int32_t id, ZIPWMFanCtrlModule* fanmodule, int32_t default_speed); - - virtual int32_t getid(int32_t* id) override; - virtual int32_t module_get_status(int32_t* status) override; - virtual int32_t module_start() override; - virtual int32_t module_stop() override; - virtual int32_t module_xxx_reg(int32_t param_id, bool read, int32_t& val) override; - - public: - virtual int32_t set_fan_default_speed(int32_t default_speed); - virtual int32_t do_action(int32_t actioncode) override; -}; - -} // namespace iflytop diff --git a/components/zcancmder_module/zcan_mini_servo_ctrl_module.cpp b/components/zcancmder_module/zcan_mini_servo_ctrl_module.cpp deleted file mode 100644 index dce2fb2..0000000 --- a/components/zcancmder_module/zcan_mini_servo_ctrl_module.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "zcan_mini_servo_ctrl_module.hpp" -using namespace iflytop; -#if 0 - -#endif \ No newline at end of file diff --git a/components/zcancmder_module/zcan_mini_servo_ctrl_module.hpp b/components/zcancmder_module/zcan_mini_servo_ctrl_module.hpp deleted file mode 100644 index 8e675b6..0000000 --- a/components/zcancmder_module/zcan_mini_servo_ctrl_module.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once -#include "sdk/components/zprotocols/zcancmder/api/i_mini_servo_module.hpp" -#include "sdk\components\zcancmder\zcanreceiver.hpp" -namespace iflytop { - -} // namespace iflytop diff --git a/components/zprotocols/zcancmder_v2 b/components/zprotocols/zcancmder_v2 index 7201808..a7f08c4 160000 --- a/components/zprotocols/zcancmder_v2 +++ b/components/zprotocols/zcancmder_v2 @@ -1 +1 @@ -Subproject commit 7201808ad36b90b7036e397875ebdef9820f0047 +Subproject commit a7f08c437c511fee6176ebd704ae24464d23917f