3 changed files with 6 additions and 153 deletions
-
105components/zcan_module/zcan_high_power_electrical_ctl_module.cpp
-
47components/zcan_module/zcan_high_power_electrical_ctl_module.hpp
-
7components/zcanreceiver/cmd.hpp
@ -1,105 +0,0 @@ |
|||
#include "zcan_high_power_electrical_ctl_module.hpp"
|
|||
|
|||
#include <stdio.h>
|
|||
#include <string.h>
|
|||
#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
|
@ -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<void(bool)> setswitchfn_t; |
|||
typedef function<int32_t()> 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<ElectricAppliance*> 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
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue