diff --git a/iflytop_canbus_protocol b/iflytop_canbus_protocol index efbd4c3..bd49987 160000 --- a/iflytop_canbus_protocol +++ b/iflytop_canbus_protocol @@ -1 +1 @@ -Subproject commit efbd4c31b82554530300d3104c0e14f2b5e7f581 +Subproject commit bd49987090f3666d4d68713f0ba4ca4d31cc3a5f diff --git a/usrc/main.cpp b/usrc/main.cpp index 6cfbb4d..8d0eb8b 100644 --- a/usrc/main.cpp +++ b/usrc/main.cpp @@ -3,6 +3,7 @@ #include "base/config_service.hpp" #include "base/device_info.hpp" +#include "iwdg.h" #include "protocol_impl/protocol_impl_service.hpp" #include "zsdk/zcanreceiver/zcanreceiver.hpp" #include "zsdk/zsdk.hpp" diff --git a/usrc/protocol_impl/protocol_impl_service.cpp b/usrc/protocol_impl/protocol_impl_service.cpp index 1b1efa1..c7b0e0f 100644 --- a/usrc/protocol_impl/protocol_impl_service.cpp +++ b/usrc/protocol_impl/protocol_impl_service.cpp @@ -14,13 +14,13 @@ using namespace iflytop; #define CHECK_PARAM_LEN(_paramNum, expectNum) \ if (_paramNum != expectNum) { \ zcanbus_send_errorack(packet, kerr_invalid_param_num); \ - return; \ + return true; \ } #define CHECK_MOTOR_INDEX(_subindex) \ if (_subindex > Hardware::ins().motorNum()) { \ zcanbus_send_errorack(packet, kerr_invalid_param); \ - return; \ + return true; \ } #define GET_PARAM(buff, off) ((((int32_t*)(buff))[off])) @@ -41,13 +41,11 @@ static osTimerId MotorMonitorTimerId; // 压力传感器数值上报 static uint8_t m_dflag; - - /*********************************************************************************************************************** * FUNCTION_IMPL * ***********************************************************************************************************************/ -static void basic_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { +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; @@ -61,6 +59,7 @@ static void basic_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t ack.hardware_version = deviceInfo_getHardwareVersion(); zcanbus_send_ack(packet, (uint8_t*)&ack, sizeof(ack)); + return true; } // 读系统信息 @@ -71,6 +70,8 @@ static void basic_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t ack.taskNum = SysMgr::ins()->getTaskNum(); ack.sysHasRun = SysMgr::ins()->osGetSysRunTime() / 1000; zcanbus_send_ack(packet, (uint8_t*)&ack, sizeof(ack)); + return true; + } // 读任务信息 @@ -84,6 +85,8 @@ static void basic_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t 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) { @@ -92,73 +95,72 @@ static void basic_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t 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; } // 触发一次强制上报事件 if (packet->function_id == kcmd_force_report) { ForceReportFlagMgr::ins()->trigger(); if (from != 0xff) zcanbus_send_ack(packet, NULL, 0); + return true; } + return false; } -static void others_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t len) { +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; - - // 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); - } - - else if (packet->function_id == kcmd_mini_pwm_blower_read_fbcount) { - int32_t fbcount = Hardware::ins().mini_pwm_blower_read_fbcount(); - zcanbus_send_ack(packet, (uint8_t*)&fbcount, sizeof(fbcount)); - } - // 加热棒 - else if (packet->function_id == kcmd_heater_ctrl) { + 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; } 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 (packet->function_id == kcmd_heater_read_electric_current) { int32_t current = Hardware::ins().heater_read_electric_current(); zcanbus_send_ack(packet, (uint8_t*)¤t, sizeof(current)); + return true; } else if (packet->function_id == kcmd_heater_read_temperature_data) { int32_t temp = Hardware::ins().heater_read_temperature_data(); zcanbus_send_ack(packet, (uint8_t*)&temp, sizeof(temp)); + return true; } + 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 - else if (packet->function_id == kcmd_h2o2_sensor_read_calibration_date) { + 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)); - } - - else if (packet->function_id == kcmd_h2o2_sensor_read_sub_ic_errorcode) { + 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)); - } - - else if (packet->function_id == kcmd_h2o2_sensor_read_sub_ic_reg) { + 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); @@ -169,8 +171,31 @@ static void others_func_impl(uint8_t from, uint8_t to, uint8_t* rawpacket, size_ 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; + + // 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; + } + + else if (packet->function_id == kcmd_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; + } + + return false; } /*********************************************************************************************************************** @@ -193,10 +218,13 @@ static void zcanbus_on_rx(uint8_t from, uint8_t to, uint8_t* rawpacket, size_t l 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); - others_func_impl(from, to, rawpacket, 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"); } diff --git a/zsdk b/zsdk index f03f863..d2e04bf 160000 --- a/zsdk +++ b/zsdk @@ -1 +1 @@ -Subproject commit f03f8639e81f3e7e5cbe9fd563503f46e46ddf84 +Subproject commit d2e04bf8ba4c394816866555f3cda296bd664b16