|
@ -2,30 +2,12 @@ |
|
|
|
|
|
|
|
|
#include "base/device_info.hpp"
|
|
|
#include "base/device_info.hpp"
|
|
|
#include "base/hardware.hpp"
|
|
|
#include "base/hardware.hpp"
|
|
|
#include "report_flag_mgr.hpp"
|
|
|
|
|
|
|
|
|
#include "function_impl/afunction_impl.hpp"
|
|
|
#include "zsdk/modbus/modbus_block_host.hpp"
|
|
|
#include "zsdk/modbus/modbus_block_host.hpp"
|
|
|
#include "zsdk/zcanreceiver/zcanreceiver.hpp"
|
|
|
|
|
|
|
|
|
#include "zsdk/zcanreceiver_old/zcanreceiver.hpp"
|
|
|
|
|
|
#include "basic/report_flag_mgr.hpp"
|
|
|
#define TAG "PROTO"
|
|
|
#define TAG "PROTO"
|
|
|
using namespace iflytop; |
|
|
using namespace iflytop; |
|
|
/***********************************************************************************************************************
|
|
|
|
|
|
* FUNCTION_LIST * |
|
|
|
|
|
***********************************************************************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
#define CHECK_PARAM_LEN(_paramNum, expectNum) \
|
|
|
|
|
|
if (_paramNum != expectNum) { \ |
|
|
|
|
|
zcanbus_send_errorack(packet, kerr_invalid_param_num); \ |
|
|
|
|
|
return true; \ |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define CHECK_MOTOR_INDEX(_subindex) \
|
|
|
|
|
|
if (_subindex > Hardware::ins().motorNum()) { \ |
|
|
|
|
|
zcanbus_send_errorack(packet, kerr_invalid_param); \ |
|
|
|
|
|
return true; \ |
|
|
|
|
|
} |
|
|
|
|
|
#define GET_PARAM(buff, off) ((((int32_t*)(buff))[off]))
|
|
|
|
|
|
|
|
|
|
|
|
#define ZCLEAR_BIT(val, bit) (val &= ~(1 << bit))
|
|
|
|
|
|
#define ZSET_BIT(val, bit) (val |= (1 << bit))
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************************************************************
|
|
|
/***********************************************************************************************************************
|
|
|
* VAR_LIST * |
|
|
* VAR_LIST * |
|
@ -33,208 +15,70 @@ using namespace iflytop; |
|
|
|
|
|
|
|
|
static osTimerId PacketReportTimerId; |
|
|
static osTimerId PacketReportTimerId; |
|
|
static osThreadId PacketRxThreadId; |
|
|
static osThreadId PacketRxThreadId; |
|
|
|
|
|
static osThreadId DeviceStateMonitorThreadId; |
|
|
|
|
|
|
|
|
static osTimerId PressureSensorDataReportTimerId; // 压力传感器数值上报
|
|
|
static osTimerId PressureSensorDataReportTimerId; // 压力传感器数值上报
|
|
|
static uint32_t m_pressureSensorDataReportPeriodMs = 3000; |
|
|
static uint32_t m_pressureSensorDataReportPeriodMs = 3000; |
|
|
|
|
|
|
|
|
static osTimerId MotorMonitorTimerId; // 压力传感器数值上报
|
|
|
|
|
|
|
|
|
|
|
|
static uint8_t m_dflag; |
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************************************************************
|
|
|
/***********************************************************************************************************************
|
|
|
* FUNCTION_IMPL * |
|
|
|
|
|
|
|
|
* SCHEDULER * |
|
|
***********************************************************************************************************************/ |
|
|
***********************************************************************************************************************/ |
|
|
|
|
|
|
|
|
static bool basic_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { |
|
|
|
|
|
zcanbus_packet_t* packet = (zcanbus_packet_t*)rawpacket; |
|
|
|
|
|
int32_t paramLen = (len - sizeof(zcanbus_packet_t)) / 4; |
|
|
|
|
|
|
|
|
|
|
|
// 读板子信息
|
|
|
|
|
|
if (packet->function_id == kcmd_read_board_info) { |
|
|
|
|
|
static ack_read_board_info_data_t ack; |
|
|
|
|
|
ack.boardType = deviceInfo_getBoardType(); |
|
|
|
|
|
ack.projectId = deviceInfo_getProjectId(); |
|
|
|
|
|
ack.protcol_version = deviceInfo_getProtocolVersion(); |
|
|
|
|
|
ack.software_version = deviceInfo_getSoftwareVersion(); |
|
|
|
|
|
ack.hardware_version = deviceInfo_getHardwareVersion(); |
|
|
|
|
|
|
|
|
|
|
|
zcanbus_send_ack(packet, (uint8_t*)&ack, sizeof(ack)); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 读系统信息
|
|
|
|
|
|
else if (packet->function_id == kcmd_read_sysinfo) { |
|
|
|
|
|
static ack_sysinfo_t ack; |
|
|
|
|
|
ack.free_heap_size = SysMgr::ins()->osGetMinimumEverFreeHeapSize(); |
|
|
|
|
|
ack.total_heap_size = SysMgr::ins()->osGetTotalHeapSize(); |
|
|
|
|
|
ack.taskNum = SysMgr::ins()->getTaskNum(); |
|
|
|
|
|
ack.sysHasRun = SysMgr::ins()->osGetSysRunTime() / 1000; |
|
|
|
|
|
zcanbus_send_ack(packet, (uint8_t*)&ack, sizeof(ack)); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 读任务信息
|
|
|
|
|
|
else if (packet->function_id == kcmd_read_taskinfo) { |
|
|
|
|
|
static ask_taskinfo_t ack; |
|
|
|
|
|
int32_t taskoff = GET_PARAM(packet->params, 0); |
|
|
|
|
|
osThreadId taskId = SysMgr::ins()->osGetId(taskoff); |
|
|
|
|
|
SysMgr::ins()->osTaskName(taskId, (char*)ack.taskName, sizeof(ack.taskName)); |
|
|
|
|
|
SysMgr::ins()->osTaskStackRemainingSize(taskId, &ack.stackRemindSize); |
|
|
|
|
|
SysMgr::ins()->osTaskPriority(taskId, &ack.priority); |
|
|
|
|
|
SysMgr::ins()->osTaskGetState(taskId, (char*)&ack.state); |
|
|
|
|
|
|
|
|
|
|
|
zcanbus_send_ack(packet, (uint8_t*)&ack, sizeof(ack)); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
// 心跳 ping pong
|
|
|
|
|
|
else if (packet->function_id == kcmd_heart_ping) { |
|
|
|
|
|
static report_heatpacket_data_t heatpacket; |
|
|
|
|
|
heatpacket.boardType = deviceInfo_getBoardType(); |
|
|
|
|
|
heatpacket.heartIndex = GET_PARAM(packet->params, 0); |
|
|
|
|
|
heatpacket.flag = m_dflag; |
|
|
|
|
|
zcanbus_send_report(kreport_heatpacket_pong, (uint8_t*)&heatpacket, sizeof(heatpacket), 30); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
else if (packet->function_id == kcmd_clear_reset_flag) { |
|
|
|
|
|
ZCLEAR_BIT(m_dflag, 0); |
|
|
|
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
static void onPacketRxThreadStart(void const* argument) { |
|
|
|
|
|
while (true) { |
|
|
|
|
|
ZCanReceiver::ins()->loop(); |
|
|
|
|
|
osDelay(1); |
|
|
} |
|
|
} |
|
|
// 触发一次强制上报事件
|
|
|
|
|
|
if (packet->function_id == kcmd_force_report) { |
|
|
|
|
|
ForceReportFlagMgr::ins()->trigger(); |
|
|
|
|
|
if (from != 0xff) zcanbus_send_ack(packet, NULL, 0); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
static void onDeviceStateMonitorThreadStart(void const* argument) { |
|
|
|
|
|
while (true) { |
|
|
|
|
|
osDelay(1000); |
|
|
} |
|
|
} |
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static bool heater_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { |
|
|
|
|
|
zcanbus_packet_t* packet = (zcanbus_packet_t*)rawpacket; |
|
|
|
|
|
int32_t paramNum = (len - sizeof(zcanbus_packet_t)) / 4; |
|
|
|
|
|
// 加热棒
|
|
|
|
|
|
if (packet->function_id == kcmd_heater_ctrl) { |
|
|
|
|
|
CHECK_PARAM_LEN(paramNum, 1); |
|
|
|
|
|
Hardware::ins().heater_ctrl(GET_PARAM(packet->params, 0)); |
|
|
|
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
static uint8_t txdatabuf[1024] = {0}; |
|
|
|
|
|
static void zcanbus_on_rx(CanPacketRxBuffer* rxbuf, uint8_t* packet, size_t len) { //
|
|
|
|
|
|
auto* cmdheader = (transmit_disinfection_protocol_header_t*)packet; |
|
|
|
|
|
|
|
|
|
|
|
if (cmdheader->cmdid == kcmd_dbdb_heater_ctrl) { |
|
|
|
|
|
int32_t val = *(int32_t*)(cmdheader->data); |
|
|
|
|
|
Hardware::ins().heater_ctrl(val); |
|
|
|
|
|
ZCanReceiver::ins()->sendAck(cmdheader, NULL, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
else if (packet->function_id == kcmd_heater_ctrl_safe_valve) { |
|
|
|
|
|
CHECK_PARAM_LEN(paramNum, 1); |
|
|
|
|
|
Hardware::ins().heater_ctrl_safe_valve(GET_PARAM(packet->params, 0)); |
|
|
|
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
else if (cmdheader->cmdid == kcmd_dbdb_heater_ctrl_safe_valve) { |
|
|
|
|
|
int32_t val = *(int32_t*)(cmdheader->data); |
|
|
|
|
|
Hardware::ins().heater_ctrl_safe_valve(val); |
|
|
|
|
|
ZCanReceiver::ins()->sendAck(cmdheader, NULL, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
else if (packet->function_id == kcmd_heater_read_electric_current) { |
|
|
|
|
|
|
|
|
else if (cmdheader->cmdid == kcmd_dbdb_heater_read_electric_current) { |
|
|
int32_t current = Hardware::ins().heater_read_electric_current(); |
|
|
int32_t current = Hardware::ins().heater_read_electric_current(); |
|
|
zcanbus_send_ack(packet, (uint8_t*)¤t, sizeof(current)); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
ZCanReceiver::ins()->sendAck(cmdheader, (uint8_t*)¤t, sizeof(current)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
else if (packet->function_id == kcmd_heater_read_temperature_data) { |
|
|
|
|
|
|
|
|
else if (cmdheader->cmdid == kcmd_dbdb_heater_read_temperature_data) { |
|
|
int32_t temp = Hardware::ins().heater_read_temperature_data(); |
|
|
int32_t temp = Hardware::ins().heater_read_temperature_data(); |
|
|
zcanbus_send_ack(packet, (uint8_t*)&temp, sizeof(temp)); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
ZCanReceiver::ins()->sendAck(cmdheader, (uint8_t*)&temp, sizeof(temp)); |
|
|
} |
|
|
} |
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static bool h2o2_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { |
|
|
|
|
|
zcanbus_packet_t* packet = (zcanbus_packet_t*)rawpacket; |
|
|
|
|
|
int32_t paramNum = (len - sizeof(zcanbus_packet_t)) / 4; |
|
|
|
|
|
// H2O2
|
|
|
|
|
|
if (packet->function_id == kcmd_h2o2_sensor_read_calibration_date) { |
|
|
|
|
|
CHECK_PARAM_LEN(paramNum, 1); |
|
|
|
|
|
int32_t subic = GET_PARAM(packet->params, 0); |
|
|
|
|
|
int32_t data[3]; |
|
|
|
|
|
Hardware::ins().h2o2_sensor_read_calibration_date(&data[0], &data[1], &data[2]); |
|
|
|
|
|
zcanbus_send_ack(packet, (uint8_t*)&data, sizeof(data)); |
|
|
|
|
|
return true; |
|
|
|
|
|
} else if (packet->function_id == kcmd_h2o2_sensor_read_sub_ic_errorcode) { |
|
|
|
|
|
int32_t ecode = Hardware::ins().h2o2_sensor_read_sub_ic_errorcode(); |
|
|
|
|
|
zcanbus_send_ack(packet, (uint8_t*)&ecode, sizeof(ecode)); |
|
|
|
|
|
return true; |
|
|
|
|
|
} else if (packet->function_id == kcmd_h2o2_sensor_read_sub_ic_reg) { |
|
|
|
|
|
CHECK_PARAM_LEN(paramNum, 3); |
|
|
|
|
|
int32_t subic = GET_PARAM(packet->params, 0); |
|
|
|
|
|
int32_t addr = GET_PARAM(packet->params, 1); |
|
|
|
|
|
int32_t regNum = GET_PARAM(packet->params, 2); |
|
|
|
|
|
if (regNum > 10) regNum = 10; // 最多读10个寄存器
|
|
|
|
|
|
static uint16_t data[10]; |
|
|
|
|
|
memset(data, 0, sizeof(data)); |
|
|
|
|
|
|
|
|
|
|
|
Hardware::ins().h2o2_sensor_read_sub_ic_reg(addr, data, regNum); |
|
|
|
|
|
zcanbus_send_ack(packet, (uint8_t*)&data, regNum * 2); |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static bool others_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { |
|
|
|
|
|
zcanbus_packet_t* packet = (zcanbus_packet_t*)rawpacket; |
|
|
|
|
|
int32_t paramNum = (len - sizeof(zcanbus_packet_t)) / 4; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if 1
|
|
|
// MINI鼓风机
|
|
|
// MINI鼓风机
|
|
|
if (packet->function_id == kcmd_mini_pwm_blower_ctrl) { |
|
|
|
|
|
CHECK_PARAM_LEN(paramNum, 1); |
|
|
|
|
|
Hardware::ins().mini_pwm_blower_ctrl(GET_PARAM(packet->params, 0)); |
|
|
|
|
|
zcanbus_send_ack(packet, NULL, 0); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cmdheader->cmdid == kcmd_dbdb_mini_pwm_blower_ctrl) { |
|
|
|
|
|
int32_t val = *(int32_t*)(cmdheader->data); |
|
|
|
|
|
Hardware::ins().mini_pwm_blower_ctrl(val); |
|
|
|
|
|
ZCanReceiver::ins()->sendAck(cmdheader, NULL, 0); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
else if (packet->function_id == kcmd_mini_pwm_blower_read_fbcount) { |
|
|
|
|
|
|
|
|
else if (cmdheader->cmdid == kcmd_dbdb_mini_pwm_blower_read_fbcount) { |
|
|
int32_t fbcount = Hardware::ins().mini_pwm_blower_read_fbcount(); |
|
|
int32_t fbcount = Hardware::ins().mini_pwm_blower_read_fbcount(); |
|
|
zcanbus_send_ack(packet, (uint8_t*)&fbcount, sizeof(fbcount)); |
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
|
ZCanReceiver::ins()->sendAck(cmdheader, (uint8_t*)&fbcount, sizeof(fbcount)); |
|
|
} |
|
|
} |
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************************************************************
|
|
|
|
|
|
* SCHEDULER * |
|
|
|
|
|
***********************************************************************************************************************/ |
|
|
|
|
|
static void onPacketRxThreadStart(void const* argument) { |
|
|
|
|
|
while (true) { |
|
|
|
|
|
zcanbus_schedule(); |
|
|
|
|
|
osDelay(1); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
static void onPacketReportTimer(void const* argument) { |
|
|
|
|
|
static report_h2o2_data_t data; |
|
|
|
|
|
memset(&data, 0, sizeof(data)); |
|
|
|
|
|
Hardware::ins().h2o2_sensor_data(&data); |
|
|
|
|
|
zcanbus_send_report(kreport_h2o2_sensor_data, (uint8_t*)&data, sizeof(data), 30); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void zcanbus_on_rx(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { //
|
|
|
|
|
|
zcanbus_packet_t* packet = (zcanbus_packet_t*)rawpacket; |
|
|
|
|
|
ZLOGI(TAG, "process packet from %d to %d, function_id %d, len %d", from, to, packet->function_id, len); |
|
|
|
|
|
|
|
|
|
|
|
if (basic_func_impl(from, to, rawpacket, len)) { |
|
|
|
|
|
} else if (heater_func_impl(from, to, rawpacket, len)) { |
|
|
|
|
|
} else if (h2o2_func_impl(from, to, rawpacket, len)) { |
|
|
|
|
|
} else if (others_func_impl(from, to, rawpacket, len)) { |
|
|
|
|
|
} else { |
|
|
|
|
|
zcanbus_send_errorack(packet, kerr_function_not_support); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ZLOGI(TAG, "process end"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void zcanbus_on_connected(bool connected) { |
|
|
|
|
|
if (connected) { |
|
|
|
|
|
ZLOGI(TAG, "connected to host"); |
|
|
|
|
|
} else { |
|
|
|
|
|
ZLOGI(TAG, "disconnected from host"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// if (cmdheader->cmdid == kcmd_ping && cmdheader->data[0] == DEVICE_ID) {
|
|
|
|
|
|
// ZCanReceiver::ins()->sendAck(cmdheader, NULL, 0);
|
|
|
|
|
|
// }
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/***********************************************************************************************************************
|
|
|
/***********************************************************************************************************************
|
|
@ -244,17 +88,16 @@ static void zcanbus_on_connected(bool connected) { |
|
|
void protocol_impl_service_init() { //
|
|
|
void protocol_impl_service_init() { //
|
|
|
Hardware::ins().init(); |
|
|
Hardware::ins().init(); |
|
|
ForceReportFlagMgr::ins()->init(); |
|
|
ForceReportFlagMgr::ins()->init(); |
|
|
m_dflag = 0x00; |
|
|
|
|
|
ZSET_BIT(m_dflag, 0); |
|
|
|
|
|
|
|
|
|
|
|
zcanbus_init(deviceInfo_getBoardId()); |
|
|
|
|
|
zcanbus_reglistener(zcanbus_on_rx); |
|
|
|
|
|
zcanbus_reg_on_connected_listener(zcanbus_on_connected); |
|
|
|
|
|
|
|
|
ZCanReceiver::CFG* cfg = ZCanReceiver::ins()->createCFG(deviceInfo_getBoardId()); |
|
|
|
|
|
ZCanReceiver::ins()->init(cfg); |
|
|
|
|
|
ZCanReceiver::ins()->registerListener(zcanbus_on_rx); |
|
|
|
|
|
|
|
|
osTimerDef(PacketReportTimer, onPacketReportTimer); |
|
|
|
|
|
PacketReportTimerId = osTimerCreate(osTimer(PacketReportTimer), osTimerPeriodic, NULL); |
|
|
|
|
|
osTimerStart(PacketReportTimerId, 5000); |
|
|
|
|
|
|
|
|
{ h2o2_fn_impl_init(); } |
|
|
|
|
|
|
|
|
osThreadDef(PacketRxThread, onPacketRxThreadStart, osPriorityNormal, 0, 1024); |
|
|
osThreadDef(PacketRxThread, onPacketRxThreadStart, osPriorityNormal, 0, 1024); |
|
|
PacketRxThreadId = osThreadCreate(osThread(PacketRxThread), NULL); |
|
|
PacketRxThreadId = osThreadCreate(osThread(PacketRxThread), NULL); |
|
|
|
|
|
|
|
|
|
|
|
osThreadDef(DeviceStateMonitorThread, onDeviceStateMonitorThreadStart, osPriorityNormal, 0, 1024); |
|
|
|
|
|
DeviceStateMonitorThreadId = osThreadCreate(osThread(DeviceStateMonitorThread), NULL); |
|
|
} |
|
|
} |