diff --git a/components/zcan_module/zcan_high_power_electrical_ctl_module.cpp b/components/zcan_module/zcan_high_power_electrical_ctl_module.cpp index 0e15d99..e69de29 100644 --- a/components/zcan_module/zcan_high_power_electrical_ctl_module.cpp +++ b/components/zcan_module/zcan_high_power_electrical_ctl_module.cpp @@ -1,105 +0,0 @@ -#include "zcan_high_power_electrical_ctl_module.hpp" - -#include -#include -#ifdef HAL_CAN_MODULE_ENABLED - -using namespace iflytop; -using namespace zcr; -#define TAG "ZCanHighPowerElectricalCtlModule" - -void ZCanHighPowerElectricalCtlModule::initialize(ZCanReceiver* zcanReceiver) { - zcanReceiver->registerListener(this); - m_zcanReceiver = zcanReceiver; -} - -void ZCanHighPowerElectricalCtlModule::pushElectricAppliance(int id, setswitchfn_t m_set_safe_switch, setswitchfn_t m_set_power_switch, - getcurrentfn_t m_get_current) { - ZASSERT(m_set_safe_switch != NULL); - ZASSERT(m_set_power_switch != NULL); - ZASSERT(m_get_current != NULL); - - ElectricAppliance* appliance = new ElectricAppliance(); - ZASSERT(appliance != NULL); - appliance->id = id; - appliance->m_set_safe_switch = m_set_safe_switch; - appliance->m_set_power_switch = m_set_power_switch; - appliance->m_get_current = m_get_current; - m_electricAppliances.push_back(appliance); -} -ZCanHighPowerElectricalCtlModule::ElectricAppliance* ZCanHighPowerElectricalCtlModule::find(int id) { - for (auto it = m_electricAppliances.begin(); it != m_electricAppliances.end(); it++) { - if ((*it)->id == id) { - return *it; - } - } - return NULL; -} - -void ZCanHighPowerElectricalCtlModule::onRceivePacket(CanPacketRxBuffer* rxbuf, uint8_t* packet, size_t len) { // - // - - Cmdheader_t* cmdheader = (Cmdheader_t*)packet; - if (cmdheader->cmdid == kcmd_high_power_electrical_ctl && cmdheader->subcmdid == 0) { - /** - * @brief 通断控制(0) - * cmd : b0:id b1:switchstatus - * ack : b0:boardid b1:switchstatus - * ack_datalen : 2 - */ - uint8_t id = cmdheader->data[0]; - bool swicthval = cmdheader->data[1]; - ElectricAppliance* appliance = find(id); - if (appliance) { - appliance->m_set_power_switch(swicthval); - - uint8_t txbuff[2] = {id, swicthval}; - m_zcanReceiver->sendAck(cmdheader, txbuff, 2); - - ZLOGI(TAG, "set power switch %d %d", id, swicthval); - - return; - } - } - - if (cmdheader->cmdid == kcmd_high_power_electrical_ctl && cmdheader->subcmdid == 1) { - /** - * @brief 设置安全继电器通断 - * cmd : b0:id b1:switchstatus - * ack : b0:boardid b1:switchstatus - * ack_datalen : 2 - */ - uint8_t id = cmdheader->data[0]; - bool swicthval = cmdheader->data[1]; - ElectricAppliance* appliance = find(id); - if (appliance) { - appliance->m_set_power_switch(swicthval); - - uint8_t txbuff[2] = {id, swicthval}; - m_zcanReceiver->sendAck(cmdheader, txbuff, 2); - - ZLOGI(TAG, "set safe switch %d %d", id, swicthval); - return; - } - } - - if (cmdheader->cmdid == kcmd_high_power_electrical_ctl && cmdheader->subcmdid == 3) { - /** - * @brief 读取电流 - * cmd : b0:id - * ack : b0:boardid b2-5 current - * ack_datalen : 2 - */ - uint8_t id = cmdheader->data[0]; - ElectricAppliance* appliance = find(id); - if (appliance) { - uint8_t txbuff[2 + 4] = {0}; - txbuff[0] = id; - *(int32_t*)(&txbuff[2]) = appliance->m_get_current(); - m_zcanReceiver->sendAck(cmdheader, txbuff, sizeof(txbuff)); - return; - } - } -} - -#endif \ No newline at end of file diff --git a/components/zcan_module/zcan_high_power_electrical_ctl_module.hpp b/components/zcan_module/zcan_high_power_electrical_ctl_module.hpp index 018c030..e69de29 100644 --- a/components/zcan_module/zcan_high_power_electrical_ctl_module.hpp +++ b/components/zcan_module/zcan_high_power_electrical_ctl_module.hpp @@ -1,47 +0,0 @@ -// -// Created by zwsd -// - -#pragma once -#include "sdk/hal/zhal.hpp" -// -#include "../zcanreceiver/zcanreceiver.hpp" -#ifdef HAL_CAN_MODULE_ENABLED -namespace iflytop { - -class ZCanHighPowerElectricalCtlModule : public ZCanRceiverListener { - public: - typedef function setswitchfn_t; - typedef function getcurrentfn_t; // 读取工作电流 ma - - class ElectricAppliance { - public: - int id; - setswitchfn_t m_set_safe_switch; - setswitchfn_t m_set_power_switch; - getcurrentfn_t m_get_current; // 0.1A - }; - - private: - ZCanReceiver* m_zcanReceiver; - - list m_electricAppliances; - - public: - ZCanHighPowerElectricalCtlModule(/* args */) {} - ~ZCanHighPowerElectricalCtlModule() {} - - public: - void initialize(ZCanReceiver* zcanReceiver); - void pushElectricAppliance(int id, setswitchfn_t m_set_safe_switch, setswitchfn_t m_set_power_switch, getcurrentfn_t m_get_current); - - public: - virtual void onRceivePacket(CanPacketRxBuffer* rxbuf, uint8_t* packet, size_t len); - ElectricAppliance* find(int id); - - private: - void loop(); -}; -} // namespace iflytop - -#endif \ No newline at end of file diff --git a/components/zcanreceiver/cmd.hpp b/components/zcanreceiver/cmd.hpp index ebcc5d9..4224f10 100644 --- a/components/zcanreceiver/cmd.hpp +++ b/components/zcanreceiver/cmd.hpp @@ -28,7 +28,6 @@ typedef enum { kcmd_m211887_operation = 1000, // 维萨拉压力传感器 kcmd_read_presure_sensor = 1001, kcmd_triple_warning_light_ctl = 1002, - kcmd_high_power_electrical_ctl = 1003, kcmd_peristaltic_pump_ctl = 1004, kcmd_read_huacheng_pressure_sensor = 1005, kcmd_set_proportional_valve = 1006, // 设置比例阀 {4:valveId,4:valveValue} @@ -50,6 +49,12 @@ typedef enum { #define IS_CMD(cmdheader, cmd, subcmd) ((cmdheader->cmdid == cmd) && (cmdheader->subcmdid == subcmd)) #define CMD_GET_PARAM(cmdheader, index) (((int32_t*)cmdheader->data)[index]) +#define PROCESS_CMD(cmd, _subcmdid, id) \ + if ((cmdheader->cmdid == (uint16_t)cmd) && (cmdheader->subcmdid == _subcmdid) && cmdheader->data[0] == id) { \ + matching = true; \ + } \ + if ((cmdheader->cmdid == (uint16_t)cmd) && (cmdheader->subcmdid == _subcmdid) && cmdheader->data[0] == id) + /** * @brief */