28 changed files with 1289 additions and 1031 deletions
-
2.project
-
2iflytop_canbus_protocol
-
10large_space_disinfection__liquid_ctrl_board Debug.launch
-
0large_space_disinfection__liquid_ctrl_board.cfg
-
4large_space_disinfection__liquid_ctrl_board.ioc
-
0large_space_disinfection__liquid_ctrl_board.launch
-
4usrc/base/device_info.cpp
-
32usrc/base/hardware.cpp
-
44usrc/base/hardware.hpp
-
47usrc/project_configs.h
-
4usrc/protocol_impl/basic/fn_mgr.cpp
-
35usrc/protocol_impl/basic/fn_mgr.hpp
-
0usrc/protocol_impl/basic/report_flag_mgr.cpp
-
0usrc/protocol_impl/basic/report_flag_mgr.hpp
-
61usrc/protocol_impl/function_impl/afunction_impl.hpp
-
91usrc/protocol_impl/function_impl/basic_fn.cpp
-
72usrc/protocol_impl/function_impl/pressure_fn_impl.cpp
-
209usrc/protocol_impl/function_impl/pump_fn_impl.cpp
-
18usrc/protocol_impl/function_impl/triple_warning_light_ctl.cpp
-
64usrc/protocol_impl/function_impl/water_sensor_report_fn_impl.cpp
-
456usrc/protocol_impl/protocol_impl_service.cpp
-
1usrc/protocol_impl/protocol_impl_service.hpp
@ -1 +1 @@ |
|||
Subproject commit 0e47768d3761fa4926957ad385416dc9410861bc |
|||
Subproject commit eb739c10f2971294ee3a12e845e9bfb4cb40f32d |
@ -0,0 +1,4 @@ |
|||
#include "fn_mgr.hpp"
|
|||
|
|||
void fn_map_reg(uint16_t function_id, protocol_impl_func_t funtion) {} |
|||
bool fn_map_process(uint16_t function_id, uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { return true; } |
@ -0,0 +1,35 @@ |
|||
#include <stddef.h>
|
|||
#include <stdio.h>
|
|||
|
|||
#include "base/config_service.hpp"
|
|||
#include "zsdk/zsdk.hpp"
|
|||
|
|||
/***********************************************************************************************************************
|
|||
* MARCO * |
|||
***********************************************************************************************************************/ |
|||
|
|||
#define CHECK_PARAM_LEN(_paramNum, expectNum) \
|
|||
if (_paramNum != expectNum) { \ |
|||
zcanbus_send_errorack(packet, kerr_invalid_param_num); \ |
|||
return; \ |
|||
} |
|||
|
|||
#define CHECK_MOTOR_INDEX(_subindex) \
|
|||
if (_subindex > Hardware::ins().motorNum()) { \ |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); \ |
|||
return; \ |
|||
} |
|||
#define GET_PARAM(buff, off) ((((int32_t*)(buff))[off]))
|
|||
#define PRAAM_LEN() ((len - sizeof(zcanbus_packet_t)) / 4)
|
|||
|
|||
#define CLEAR_BIT(val, bit) (val &= ~(1 << bit))
|
|||
#define SET_BIT(val, bit) (val |= (1 << bit))
|
|||
|
|||
/***********************************************************************************************************************
|
|||
* FUNC * |
|||
***********************************************************************************************************************/ |
|||
|
|||
typedef void(protocol_impl_func_t)(uint8_t from, uint8_t to, zcanbus_packet_t* rawpacket, size_t len); |
|||
|
|||
void fn_map_reg(uint16_t function_id, protocol_impl_func_t funtion); |
|||
bool fn_map_process(uint16_t function_id, uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len); |
@ -0,0 +1,61 @@ |
|||
#pragma ocne
|
|||
#include <stddef.h>
|
|||
#include <stdio.h>
|
|||
|
|||
#include "../basic/fn_mgr.hpp"
|
|||
#include "../basic/report_flag_mgr.hpp"
|
|||
//
|
|||
#include "base/device_info.hpp"
|
|||
#include "base/hardware.hpp"
|
|||
#include "zsdk/modbus/modbus_block_host.hpp"
|
|||
#include "zsdk/zcanreceiver/zcanreceiver.hpp"
|
|||
|
|||
/***********************************************************************************************************************
|
|||
* basic_fn * |
|||
***********************************************************************************************************************/ |
|||
|
|||
void fn_cmd_read_board_info(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
void fn_cmd_read_sysinfo(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
void fn_cmd_read_taskinfo(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
void fn_cmd_heart_ping(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
void fn_cmd_clear_reset_flag(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
|
|||
void basic_fn_init(); |
|||
|
|||
/***********************************************************************************************************************
|
|||
* pump_fn * |
|||
***********************************************************************************************************************/ |
|||
|
|||
void fn_cmd_pump_rotate(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
void fn_cmd_pump_stop(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
void fn_cmd_pump_set_ihold_irun_idelay(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
void fn_cmd_pump_set_acc(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
void fn_cmd_pump_set_subic_reg(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
void fn_cmd_pump_get_subic_reg(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
void fn_cmd_pump_ping(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
|
|||
void pump_fn_init(); |
|||
void pump_fn_report_tmr_start(); |
|||
|
|||
/***********************************************************************************************************************
|
|||
* pressure_fn_impl * |
|||
***********************************************************************************************************************/ |
|||
void fn_cmd_pressure_sensor_bus_read_data(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
void fn_cmd_pressure_sensor_bus_set_report_period_ms(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
|
|||
void pressure_fn_impl_init(); |
|||
|
|||
/***********************************************************************************************************************
|
|||
* triple_warning_light_fn_impl * |
|||
***********************************************************************************************************************/ |
|||
void fn_cmd_triple_warning_light_ctl(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
|
|||
/***********************************************************************************************************************
|
|||
* water_sensor_report_fn_impl * |
|||
***********************************************************************************************************************/ |
|||
void fn_cmd_evaporation_bin_water_sensor_read_state(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
void fn_cmd_device_bottom_water_sensor_read_state(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
|
|||
void water_sensor_report_fn_impl_init(); |
|||
void water_sensor_report_fn_impl_start_tmr(); |
|||
void water_sensor_report_fn_impl_force_report(); |
@ -0,0 +1,91 @@ |
|||
|
|||
#include "afunction_impl.hpp"
|
|||
using namespace iflytop; |
|||
|
|||
static uint8_t m_boardflag; // 0: 重启标志
|
|||
|
|||
/**
|
|||
* @brief 读取板子信息 |
|||
* |
|||
* @param from |
|||
* @param to |
|||
* @param packet |
|||
* @param len |
|||
*/ |
|||
void fn_cmd_read_board_info(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
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)); |
|||
} |
|||
/**
|
|||
* @brief 读取系统信息 |
|||
* |
|||
* @param from |
|||
* @param to |
|||
* @param packet |
|||
* @param len |
|||
*/ |
|||
void fn_cmd_read_sysinfo(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
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)); |
|||
} |
|||
/**
|
|||
* @brief 读取线程信息 |
|||
* |
|||
* @param from |
|||
* @param to |
|||
* @param packet |
|||
* @param len |
|||
*/ |
|||
void fn_cmd_read_taskinfo(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
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)); |
|||
} |
|||
/**
|
|||
* @brief PING |
|||
* |
|||
* @param from |
|||
* @param to |
|||
* @param packet |
|||
* @param len |
|||
*/ |
|||
void fn_cmd_heart_ping(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
static report_heatpacket_data_t heatpacket; |
|||
heatpacket.boardType = deviceInfo_getBoardType(); |
|||
heatpacket.heartIndex = GET_PARAM(packet->params, 0); |
|||
heatpacket.flag = m_boardflag; |
|||
zcanbus_send_report(kreport_heatpacket_pong, (uint8_t*)&heatpacket, sizeof(heatpacket), 30); |
|||
} |
|||
/**
|
|||
* @brief 清除板子复位标志位 |
|||
* |
|||
* @param from |
|||
* @param to |
|||
* @param packet |
|||
* @param len |
|||
*/ |
|||
void fn_cmd_clear_reset_flag(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
CLEAR_BIT(m_boardflag, 0); |
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
|
|||
void basic_fn_init() { |
|||
m_boardflag = 0x00; |
|||
SET_BIT(m_boardflag, 0); |
|||
} |
@ -0,0 +1,72 @@ |
|||
|
|||
#include "afunction_impl.hpp"
|
|||
using namespace iflytop; |
|||
|
|||
#define TAG "PRESSURE_FN"
|
|||
|
|||
static osTimerId PressureSensorDataReportTimerId; // 压力传感器数值上报
|
|||
static uint32_t m_pressureSensorDataReportPeriodMs = 3000; |
|||
|
|||
static void onPressureSensorDataReportTimer(void const* argument) { |
|||
// 压力传感器数据上报
|
|||
static uint8_t reportcache[100]; |
|||
static report_pressure_data_t* report = (report_pressure_data_t*)reportcache; |
|||
|
|||
int sensorNum = 0; |
|||
|
|||
for (size_t i = 0; i < PXX_PRESSURE_SENSOR_NUM; i++) { |
|||
int16_t val = 0; |
|||
bool suc = Hardware::ins().pressureSensorBus()->readData(i, &val); |
|||
|
|||
if (suc) { |
|||
report->data[sensorNum].subid = i; |
|||
report->data[sensorNum].pressureVal = val; |
|||
sensorNum++; |
|||
} |
|||
} |
|||
|
|||
report->sensorDataNum = sensorNum; |
|||
zcanbus_send_report(kreport_pressure_data, (uint8_t*)report, //
|
|||
sizeof(report_pressure_data_t) + sensorNum * sizeof(report->data[0]), 10); |
|||
} |
|||
|
|||
|
|||
void fn_cmd_pressure_sensor_bus_read_data(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 1); |
|||
int32_t index = GET_PARAM(packet->params, 0); |
|||
|
|||
int16_t val = 0; |
|||
int32_t reportVal = 0; |
|||
bool suc = Hardware::ins().pressureSensorBus()->readData(index, &val); |
|||
|
|||
reportVal = val; |
|||
|
|||
if (suc) { |
|||
zcanbus_send_ack(packet, (uint8_t*)&reportVal, sizeof(reportVal)); |
|||
} else { |
|||
zcanbus_send_errorack(packet, kerr_subdevice_offline); |
|||
} |
|||
} |
|||
void fn_cmd_pressure_sensor_bus_set_report_period_ms(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 1); |
|||
int32_t period = GET_PARAM(packet->params, 0); |
|||
|
|||
ZLOGI(TAG, "set pressure sensor data report period %d ms", period); |
|||
|
|||
if (period != 0) { |
|||
if (period < 200) period = 200; |
|||
osTimerStop(PressureSensorDataReportTimerId); |
|||
osTimerStart(PressureSensorDataReportTimerId, period); |
|||
m_pressureSensorDataReportPeriodMs = period; |
|||
} else { |
|||
osTimerStop(PressureSensorDataReportTimerId); |
|||
} |
|||
|
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
|
|||
void pressure_fn_impl_init() { |
|||
osTimerDef(PressureSensorDataReportTimer, onPressureSensorDataReportTimer); |
|||
PressureSensorDataReportTimerId = osTimerCreate(osTimer(PressureSensorDataReportTimer), osTimerPeriodic, NULL); |
|||
// osTimerStart(PressureSensorDataReportTimerId, m_pressureSensorDataReportPeriodMs);
|
|||
} |
@ -0,0 +1,209 @@ |
|||
|
|||
#include "afunction_impl.hpp"
|
|||
using namespace iflytop; |
|||
|
|||
#define TAG "PUMP_FN"
|
|||
|
|||
static osTimerId MotorMonitorTimerId; // 压力传感器数值上报
|
|||
static bool motorErrorFlagCache[10]; // 电机异常状态上报标志位
|
|||
static zmutex motorErrorFlagCacheLock; |
|||
|
|||
static bool motorErrorFlag_get(int subindex) { |
|||
bool ret; |
|||
{ |
|||
zlock_guard guard(motorErrorFlagCacheLock); |
|||
ret = motorErrorFlagCache[subindex]; |
|||
} |
|||
return ret; |
|||
} |
|||
|
|||
static void motorErrorFlag_set(int subindex, bool val) { |
|||
{ |
|||
zlock_guard guard(motorErrorFlagCacheLock); |
|||
motorErrorFlagCache[subindex] = val; |
|||
} |
|||
} |
|||
|
|||
void fn_cmd_pump_rotate(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 2); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
int32_t velocity = GET_PARAM(packet->params, 1); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
|
|||
Hardware::ins().motor(subindex)->enableIC(false); |
|||
Hardware::ins().motor(subindex)->enableIC(true); |
|||
Hardware::ins().motor(subindex)->rotate(velocity); |
|||
|
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
motorErrorFlag_set(subindex, false); |
|||
} |
|||
void fn_cmd_pump_stop(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 1); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
|
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
|
|||
Hardware::ins().motor(subindex)->stop(); |
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
void fn_cmd_pump_set_ihold_irun_idelay(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 4); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
int32_t ihold = GET_PARAM(packet->params, 1); |
|||
int32_t irun = GET_PARAM(packet->params, 2); |
|||
int32_t idelay = GET_PARAM(packet->params, 3); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
|
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
|
|||
Hardware::ins().motor(subindex)->setIHOLD_IRUN(ihold, irun, idelay); |
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
void fn_cmd_pump_set_acc(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 2); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
int32_t acc = GET_PARAM(packet->params, 1); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
|
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
|
|||
Hardware::ins().motor(subindex)->setAcceleration(acc); |
|||
Hardware::ins().motor(subindex)->setDeceleration(acc); |
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
void fn_cmd_pump_set_subic_reg(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 3); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
int32_t regadd = GET_PARAM(packet->params, 1); |
|||
int32_t regval = GET_PARAM(packet->params, 2); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
|
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
|
|||
Hardware::ins().motor(subindex)->writeInt(regadd, regval); |
|||
} |
|||
void fn_cmd_pump_get_subic_reg(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 3); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
int32_t regadd = GET_PARAM(packet->params, 1); |
|||
int32_t regval = GET_PARAM(packet->params, 2); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
|
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
|
|||
Hardware::ins().motor(subindex)->writeInt(regadd, regval); |
|||
} |
|||
void fn_cmd_pump_ping(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 1); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
|
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
|
|||
static void onMotorMonitorTimer(void const* argument) { |
|||
// 电机异常检查
|
|||
|
|||
report_exeception_data_t data; |
|||
for (size_t i = 0; i < Hardware::ins().motorNum(); i++) { |
|||
bool estate = motorErrorFlag_get(i); |
|||
|
|||
if (!Hardware::ins().motor(i)->ping()) { |
|||
data.subid = i; |
|||
data.ecode = kerr_motor_subdevice_offline; |
|||
|
|||
if (!estate) { |
|||
motorErrorFlag_set(i, true); |
|||
ZLOGE(TAG, "motor %d offline error", i); |
|||
zcanbus_send_emergency_report(kreport_exception_error, (uint8_t*)&data, sizeof(data), 100); |
|||
} |
|||
} else { |
|||
auto gstate = Hardware::ins().motor(i)->getGState(); |
|||
bool flag = gstate.reset || gstate.drv_err || gstate.uv_cp; |
|||
if (!flag && estate) { |
|||
motorErrorFlag_set(i, false); |
|||
} else if (flag && !estate) { |
|||
ZLOGE(TAG, "motor %d error, reset %d, drv_err %d, uv_cp %d", i, gstate.reset, gstate.drv_err, gstate.uv_cp); |
|||
if (gstate.reset) { |
|||
data.ecode = kerr_motor_reset_error; |
|||
} else if (gstate.uv_cp) { |
|||
data.ecode = kerr_motor_undervoltage_error; |
|||
} else if (gstate.drv_err) { |
|||
data.ecode = kerr_motor_driver_error; |
|||
} else { |
|||
data.ecode = kerr_motor_unkown_error; |
|||
} |
|||
data.subid = i; |
|||
motorErrorFlag_set(i, true); |
|||
zcanbus_send_emergency_report(kreport_exception_error, (uint8_t*)&data, sizeof(data), 100); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
void pump_fn_init() { motorErrorFlagCacheLock.init(); } |
|||
|
|||
void pump_fn_report_tmr_start() { |
|||
osTimerDef(MotorMonitorTimer, onMotorMonitorTimer); |
|||
MotorMonitorTimerId = osTimerCreate(osTimer(MotorMonitorTimer), osTimerPeriodic, NULL); |
|||
osTimerStart(MotorMonitorTimerId, 1000); |
|||
} |
@ -0,0 +1,18 @@ |
|||
#include "afunction_impl.hpp"
|
|||
using namespace iflytop; |
|||
|
|||
#define TAG "TRIPLE_WARNING_LIGHT"
|
|||
|
|||
// kcmd_triple_warning_light_ctl
|
|||
|
|||
void fn_cmd_triple_warning_light_ctl(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 4); |
|||
|
|||
int32_t r = GET_PARAM(packet->params, 0); |
|||
int32_t g = GET_PARAM(packet->params, 1); |
|||
int32_t b = GET_PARAM(packet->params, 2); |
|||
int32_t warning = GET_PARAM(packet->params, 3); |
|||
|
|||
Hardware::ins().setRGB(r, g, b, warning); |
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
@ -0,0 +1,64 @@ |
|||
|
|||
#include "afunction_impl.hpp"
|
|||
using namespace iflytop; |
|||
|
|||
#define TAG "WATER_SENSOR_REPORT_FN"
|
|||
|
|||
static osTimerId WaterSensorReportTimerId; //
|
|||
static bool m_force_report = false; |
|||
|
|||
static void onWaterSensorReportTimer(void const* argument) { |
|||
// 水浸传感器数据上报
|
|||
static uint8_t reportcache[50]; |
|||
static report_water_sensor_state_t* report = (report_water_sensor_state_t*)reportcache; |
|||
|
|||
static bool state = true; |
|||
|
|||
int16_t val = 0; |
|||
static bool evaporation_bin_water_sensor_state; |
|||
{ |
|||
bool state = Hardware::ins().m_evaporation_bin_water_sensor.read(); |
|||
if (m_force_report || state != evaporation_bin_water_sensor_state) { |
|||
evaporation_bin_water_sensor_state = state; |
|||
ZLOGI(TAG, "evaporation_bin_water_sensor state %d", state); |
|||
report->state = val; |
|||
zcanbus_send_report(kreport_evaporation_bin_water_sensor, (uint8_t*)report, sizeof(report_water_sensor_state_t), 10); |
|||
} |
|||
} |
|||
|
|||
static bool device_bottom_water_sensor_state; |
|||
{ |
|||
bool state = Hardware::ins().m_device_bottom_water_sensor.read(); |
|||
if (m_force_report || state != device_bottom_water_sensor_state) { |
|||
device_bottom_water_sensor_state = state; |
|||
ZLOGI(TAG, "device_bottom_water_sensor state %d", state); |
|||
report->state = val; |
|||
zcanbus_send_report(kreport_device_bottom_water_sensor, (uint8_t*)report, sizeof(report_water_sensor_state_t), 10); |
|||
} |
|||
} |
|||
|
|||
m_force_report = false; |
|||
} |
|||
|
|||
void fn_cmd_evaporation_bin_water_sensor_read_state(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 0); |
|||
|
|||
int32_t val = Hardware::ins().m_evaporation_bin_water_sensor.read(); |
|||
zcanbus_send_ack(packet, (uint8_t*)&val, sizeof(val)); |
|||
} |
|||
|
|||
void fn_cmd_device_bottom_water_sensor_read_state(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len) { |
|||
CHECK_PARAM_LEN(PRAAM_LEN(), 0); |
|||
|
|||
int32_t val = Hardware::ins().m_device_bottom_water_sensor.read(); |
|||
zcanbus_send_ack(packet, (uint8_t*)&val, sizeof(val)); |
|||
} |
|||
|
|||
void water_sensor_report_fn_impl_init() { |
|||
osTimerDef(WaterSensorReportTimer, onWaterSensorReportTimer); |
|||
WaterSensorReportTimerId = osTimerCreate(osTimer(WaterSensorReportTimer), osTimerPeriodic, NULL); |
|||
} |
|||
|
|||
void water_sensor_report_fn_impl_start_tmr() { osTimerStart(WaterSensorReportTimerId, 20); } |
|||
|
|||
void water_sensor_report_fn_impl_force_report() { m_force_report = true; } |
@ -1,453 +1,95 @@ |
|||
#include "protocol_impl_service.hpp"
|
|||
|
|||
#include "base/device_info.hpp"
|
|||
#include "base/hardware.hpp"
|
|||
#include "report_flag_mgr.hpp"
|
|||
#include "zsdk/modbus/modbus_block_host.hpp"
|
|||
#include "zsdk/zcanreceiver/zcanreceiver.hpp"
|
|||
#include "function_impl/afunction_impl.hpp"
|
|||
|
|||
#define TAG "PROTO"
|
|||
using namespace iflytop; |
|||
/***********************************************************************************************************************
|
|||
* FUNCTION_LIST * |
|||
***********************************************************************************************************************/ |
|||
|
|||
#define CHECK_PARAM_LEN(_paramNum, expectNum) \
|
|||
if (_paramNum != expectNum) { \ |
|||
zcanbus_send_errorack(packet, kerr_invalid_param_num); \ |
|||
return; \ |
|||
} |
|||
|
|||
#define CHECK_MOTOR_INDEX(_subindex) \
|
|||
if (_subindex > Hardware::ins().motorNum()) { \ |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); \ |
|||
return; \ |
|||
} |
|||
#define GET_PARAM(buff, off) ((((int32_t*)(buff))[off]))
|
|||
|
|||
#define CLEAR_BIT(val, bit) (val &= ~(1 << bit))
|
|||
#define SET_BIT(val, bit) (val |= (1 << bit))
|
|||
|
|||
/***********************************************************************************************************************
|
|||
* VAR_LIST * |
|||
***********************************************************************************************************************/ |
|||
|
|||
static osTimerId HeartReportTimerId; |
|||
static osThreadId PacketRxThreadId; |
|||
|
|||
static osTimerId PressureSensorDataReportTimerId; // 压力传感器数值上报
|
|||
static uint32_t m_pressureSensorDataReportPeriodMs = 3000; |
|||
|
|||
static osTimerId MotorMonitorTimerId; // 压力传感器数值上报
|
|||
static bool motorErrorFlagCache[10]; // 电机异常状态上报标志位
|
|||
static zmutex motorErrorFlagCacheLock; |
|||
static uint8_t m_dflag; |
|||
|
|||
static bool motorErrorFlag_get(int subindex) { |
|||
bool ret; |
|||
{ |
|||
zlock_guard guard(motorErrorFlagCacheLock); |
|||
ret = motorErrorFlagCache[subindex]; |
|||
} |
|||
return ret; |
|||
} |
|||
|
|||
static void motorErrorFlag_set(int subindex, bool val) { |
|||
{ |
|||
zlock_guard guard(motorErrorFlagCacheLock); |
|||
motorErrorFlagCache[subindex] = val; |
|||
} |
|||
} |
|||
|
|||
/***********************************************************************************************************************
|
|||
* FUNCTION_IMPL * |
|||
***********************************************************************************************************************/ |
|||
|
|||
static void 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)); |
|||
} |
|||
|
|||
// 读系统信息
|
|||
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)); |
|||
} |
|||
|
|||
// 读任务信息
|
|||
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)); |
|||
} |
|||
// 心跳 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); |
|||
} |
|||
|
|||
else if (packet->function_id == kcmd_clear_reset_flag) { |
|||
CLEAR_BIT(m_dflag, 0); |
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
// 触发一次强制上报事件
|
|||
if (packet->function_id == kcmd_force_report) { |
|||
ForceReportFlagMgr::ins()->trigger(); |
|||
if (from != 0xff) zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
} |
|||
|
|||
static void pump_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_pump_rotate) { |
|||
CHECK_PARAM_LEN(paramNum, 2); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
int32_t velocity = GET_PARAM(packet->params, 1); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
|
|||
Hardware::ins().motor(subindex)->enableIC(false); |
|||
Hardware::ins().motor(subindex)->enableIC(true); |
|||
Hardware::ins().motor(subindex)->rotate(velocity); |
|||
|
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
motorErrorFlag_set(subindex, false); |
|||
} |
|||
|
|||
// 泵机停止
|
|||
else if (packet->function_id == kcmd_pump_stop) { |
|||
CHECK_PARAM_LEN(paramNum, 1); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
|
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
|
|||
Hardware::ins().motor(subindex)->stop(); |
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
|
|||
// 设置电流/保持电流/IDELAY
|
|||
else if (packet->function_id == kcmd_pump_set_ihold_irun_idelay) { |
|||
CHECK_PARAM_LEN(paramNum, 4); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
int32_t ihold = GET_PARAM(packet->params, 1); |
|||
int32_t irun = GET_PARAM(packet->params, 2); |
|||
int32_t idelay = GET_PARAM(packet->params, 3); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
|
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
|
|||
Hardware::ins().motor(subindex)->setIHOLD_IRUN(ihold, irun, idelay); |
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
// 设置加速度
|
|||
else if (packet->function_id == kcmd_pump_set_acc) { |
|||
CHECK_PARAM_LEN(paramNum, 2); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
int32_t acc = GET_PARAM(packet->params, 1); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
|
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
|
|||
Hardware::ins().motor(subindex)->setAcceleration(acc); |
|||
Hardware::ins().motor(subindex)->setDeceleration(acc); |
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
|
|||
} |
|||
|
|||
// 设置5130寄存器
|
|||
else if (packet->function_id == kcmd_pump_set_subic_reg) { |
|||
CHECK_PARAM_LEN(paramNum, 3); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
int32_t regadd = GET_PARAM(packet->params, 1); |
|||
int32_t regval = GET_PARAM(packet->params, 2); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
|
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
|
|||
Hardware::ins().motor(subindex)->writeInt(regadd, regval); |
|||
} |
|||
|
|||
// 读取5130寄存器
|
|||
else if (packet->function_id == kcmd_pump_get_subic_reg) { |
|||
CHECK_PARAM_LEN(paramNum, 2); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
int32_t regadd = GET_PARAM(packet->params, 1); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
|
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
|
|||
int32_t regval = Hardware::ins().motor(subindex)->readInt(regadd); |
|||
zcanbus_send_ack(packet, (uint8_t*)®val, sizeof(regval)); |
|||
} |
|||
|
|||
// ping
|
|||
else if (packet->function_id == kcmd_pump_get_subic_reg) { |
|||
CHECK_PARAM_LEN(paramNum, 1); |
|||
|
|||
int32_t subindex = GET_PARAM(packet->params, 0); |
|||
|
|||
if (subindex >= Hardware::ins().motorNum()) { |
|||
zcanbus_send_errorack(packet, kerr_invalid_param); |
|||
return; |
|||
} |
|||
|
|||
if (!Hardware::ins().motor(subindex)->ping()) { |
|||
zcanbus_send_errorack(packet, kerr_motor_subdevice_offline); |
|||
return; |
|||
} |
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
} |
|||
|
|||
static void 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; |
|||
|
|||
// m_atta_mini_air_compressor_ctrl
|
|||
|
|||
// 喷液MINI真空泵
|
|||
if (packet->function_id == kcmd_sl_mini_ac_ctrl) { |
|||
CHECK_PARAM_LEN(paramNum, 1); |
|||
Hardware::ins().sl_mini_ac_ctrl()->write(GET_PARAM(packet->params, 0)); |
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
// 气密性测试MINI真空泵
|
|||
else if (packet->function_id == kcmd_atta_mini_air_compressor_ctrl) { |
|||
CHECK_PARAM_LEN(paramNum, 1); |
|||
Hardware::ins().atta_mini_air_compressor_ctrl()->write(GET_PARAM(packet->params, 0)); |
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
|
|||
// 压力传感器数据上报
|
|||
else if (packet->function_id == kcmd_pressure_sensor_bus_read_data) { |
|||
CHECK_PARAM_LEN(paramNum, 1); |
|||
int32_t index = GET_PARAM(packet->params, 0); |
|||
|
|||
int16_t val = 0; |
|||
int32_t reportVal = 0; |
|||
bool suc = Hardware::ins().pressureSensorBus()->readData(index, &val); |
|||
|
|||
reportVal = val; |
|||
|
|||
if (suc) { |
|||
zcanbus_send_ack(packet, (uint8_t*)&reportVal, sizeof(reportVal)); |
|||
} else { |
|||
zcanbus_send_errorack(packet, kerr_subdevice_offline); |
|||
} |
|||
} |
|||
#if 0
|
|||
// 压力传感器数据上报
|
|||
else if (packet->function_id == kcmd_pressure_sensor_bus_set_report_period_ms) { |
|||
CHECK_PARAM_LEN(paramNum, 1); |
|||
int32_t period = GET_PARAM(packet->params, 0); |
|||
|
|||
ZLOGI(TAG, "set pressure sensor data report period %d ms", period); |
|||
|
|||
if (period != 0) { |
|||
if (period < 200) period = 200; |
|||
osTimerStop(PressureSensorDataReportTimerId); |
|||
osTimerStart(PressureSensorDataReportTimerId, period); |
|||
m_pressureSensorDataReportPeriodMs = period; |
|||
} else { |
|||
osTimerStop(PressureSensorDataReportTimerId); |
|||
} |
|||
|
|||
zcanbus_send_ack(packet, NULL, 0); |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
/***********************************************************************************************************************
|
|||
* SCHEDULER * |
|||
***********************************************************************************************************************/ |
|||
static void onPacketRxThreadStart(void const* argument) { |
|||
while (true) { |
|||
zcanbus_schedule(); |
|||
osDelay(1); |
|||
} |
|||
} |
|||
|
|||
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); |
|||
|
|||
basic_func_impl(from, to, rawpacket, len); |
|||
pump_func_impl(from, to, rawpacket, len); |
|||
others_func_impl(from, to, rawpacket, len); |
|||
|
|||
bool processed = fn_map_process(packet->function_id, from, to, rawpacket, len); |
|||
if (!processed) { |
|||
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"); |
|||
water_sensor_report_fn_impl_force_report(); |
|||
} else { |
|||
ZLOGI(TAG, "disconnected from host"); |
|||
} |
|||
} |
|||
#if 0
|
|||
static void onPressureSensorDataReportTimer(void const* argument) { |
|||
// 压力传感器数据上报
|
|||
static uint8_t reportcache[100]; |
|||
static report_pressure_data_t* report = (report_pressure_data_t*)reportcache; |
|||
|
|||
int sensorNum = 0; |
|||
void fn_cmd_triple_warning_light_ctl(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
|
|||
for (size_t i = 0; i < PXX_PRESSURE_SENSOR_NUM; i++) { |
|||
int16_t val = 0; |
|||
bool suc = Hardware::ins().pressureSensorBus()->readData(i, &val); |
|||
|
|||
if (suc) { |
|||
report->data[sensorNum].subid = i; |
|||
report->data[sensorNum].pressureVal = val; |
|||
sensorNum++; |
|||
} |
|||
} |
|||
|
|||
report->sensorDataNum = sensorNum; |
|||
zcanbus_send_report(kreport_pressure_data, (uint8_t*)report, //
|
|||
sizeof(report_pressure_data_t) + sensorNum * sizeof(report->data[0]), 10); |
|||
} |
|||
#endif
|
|||
|
|||
static void onMotorMonitorTimer(void const* argument) { |
|||
// 电机异常检查
|
|||
|
|||
report_exeception_data_t data; |
|||
for (size_t i = 0; i < Hardware::ins().motorNum(); i++) { |
|||
bool estate = motorErrorFlag_get(i); |
|||
|
|||
if (!Hardware::ins().motor(i)->ping()) { |
|||
data.subid = i; |
|||
data.ecode = kerr_motor_subdevice_offline; |
|||
|
|||
if (!estate) { |
|||
motorErrorFlag_set(i, true); |
|||
ZLOGE(TAG, "motor %d offline error", i); |
|||
zcanbus_send_emergency_report(kreport_exception_error, (uint8_t*)&data, sizeof(data), 100); |
|||
} |
|||
} else { |
|||
auto gstate = Hardware::ins().motor(i)->getGState(); |
|||
bool flag = gstate.reset || gstate.drv_err || gstate.uv_cp; |
|||
if (!flag && estate) { |
|||
motorErrorFlag_set(i, false); |
|||
} else if (flag && !estate) { |
|||
ZLOGE(TAG, "motor %d error, reset %d, drv_err %d, uv_cp %d", i, gstate.reset, gstate.drv_err, gstate.uv_cp); |
|||
if (gstate.reset) { |
|||
data.ecode = kerr_motor_reset_error; |
|||
} else if (gstate.uv_cp) { |
|||
data.ecode = kerr_motor_undervoltage_error; |
|||
} else if (gstate.drv_err) { |
|||
data.ecode = kerr_motor_driver_error; |
|||
} else { |
|||
data.ecode = kerr_motor_unkown_error; |
|||
} |
|||
data.subid = i; |
|||
motorErrorFlag_set(i, true); |
|||
zcanbus_send_emergency_report(kreport_exception_error, (uint8_t*)&data, sizeof(data), 100); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
void fn_cmd_evaporation_bin_water_sensor_read_state(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
void fn_cmd_device_bottom_water_sensor_read_state(uint8_t from, uint8_t to, zcanbus_packet_t* packet, size_t len); |
|||
|
|||
/***********************************************************************************************************************
|
|||
* EXT * |
|||
***********************************************************************************************************************/ |
|||
void water_sensor_report_fn_impl_init(); |
|||
void water_sensor_report_fn_impl_start_tmr(); |
|||
void water_sensor_report_fn_impl_force_report(); |
|||
|
|||
void protocol_impl_service_init() { //
|
|||
Hardware::ins().init(); |
|||
ForceReportFlagMgr::ins()->init(); |
|||
motorErrorFlagCacheLock.init(); |
|||
m_dflag = 0x00; |
|||
SET_BIT(m_dflag, 0); |
|||
|
|||
zcanbus_init(deviceInfo_getBoardId()); |
|||
zcanbus_reglistener(zcanbus_on_rx); |
|||
zcanbus_reg_on_connected_listener(zcanbus_on_connected); |
|||
|
|||
#if 0
|
|||
osTimerDef(PressureSensorDataReportTimer, onPressureSensorDataReportTimer); |
|||
PressureSensorDataReportTimerId = osTimerCreate(osTimer(PressureSensorDataReportTimer), osTimerPeriodic, NULL); |
|||
osTimerStart(PressureSensorDataReportTimerId, m_pressureSensorDataReportPeriodMs); |
|||
#endif
|
|||
{ |
|||
basic_fn_init(); |
|||
fn_map_reg(kcmd_read_board_info, fn_cmd_read_board_info); |
|||
fn_map_reg(kcmd_read_sysinfo, fn_cmd_read_sysinfo); |
|||
fn_map_reg(kcmd_read_taskinfo, fn_cmd_read_taskinfo); |
|||
fn_map_reg(kcmd_heart_ping, fn_cmd_heart_ping); |
|||
fn_map_reg(kcmd_clear_reset_flag, fn_cmd_clear_reset_flag); |
|||
} |
|||
|
|||
{ |
|||
water_sensor_report_fn_impl_init(); |
|||
fn_map_reg(kcmd_evaporation_bin_water_sensor_read_state, fn_cmd_evaporation_bin_water_sensor_read_state); |
|||
fn_map_reg(kcmd_device_bottom_water_sensor_read_state, fn_cmd_device_bottom_water_sensor_read_state); |
|||
water_sensor_report_fn_impl_start_tmr(); |
|||
} |
|||
|
|||
osTimerDef(MotorMonitorTimer, onMotorMonitorTimer); |
|||
MotorMonitorTimerId = osTimerCreate(osTimer(MotorMonitorTimer), osTimerPeriodic, NULL); |
|||
osTimerStart(MotorMonitorTimerId, 1000); |
|||
{ |
|||
pump_fn_init(); |
|||
pump_fn_report_tmr_start(); |
|||
|
|||
fn_map_reg(kcmd_pump_rotate, fn_cmd_pump_rotate); |
|||
fn_map_reg(kcmd_pump_stop, fn_cmd_pump_stop); |
|||
fn_map_reg(kcmd_pump_set_ihold_irun_idelay, fn_cmd_pump_set_ihold_irun_idelay); |
|||
fn_map_reg(kcmd_pump_set_acc, fn_cmd_pump_set_acc); |
|||
fn_map_reg(kcmd_pump_set_subic_reg, fn_cmd_pump_set_subic_reg); |
|||
fn_map_reg(kcmd_pump_get_subic_reg, fn_cmd_pump_get_subic_reg); |
|||
fn_map_reg(kcmd_pump_ping, fn_cmd_pump_ping); |
|||
} |
|||
|
|||
{ fn_map_reg(kcmd_triple_warning_light_ctl, fn_cmd_triple_warning_light_ctl); } |
|||
|
|||
{ |
|||
pressure_fn_impl_init(); |
|||
fn_map_reg(kcmd_pressure_sensor_bus_read_data, fn_cmd_pressure_sensor_bus_read_data); |
|||
fn_map_reg(kcmd_pressure_sensor_bus_set_report_period_ms, fn_cmd_pressure_sensor_bus_set_report_period_ms); |
|||
} |
|||
|
|||
osThreadDef(PacketRxThread, onPacketRxThreadStart, osPriorityNormal, 0, 1024); |
|||
PacketRxThreadId = osThreadCreate(osThread(PacketRxThread), NULL); |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue