diff --git a/iflytop_canbus_protocol.cpp b/iflytop_canbus_protocol.cpp new file mode 100644 index 0000000..7be7a88 --- /dev/null +++ b/iflytop_canbus_protocol.cpp @@ -0,0 +1,356 @@ +#pragma once +#include + +#define PROTOCOL_VERSION 1 +#define HEART_PACKET_PERIOD_MS (5 * 1000) + +extern "C" { +#pragma pack(1) + +/** + * @brief 消息格式 12bit from,1bit emergency + * H L + * [1] [4bit] [8bit] [8bit] [4bit/4bit] + * , from to frameNum/frameId + */ + +typedef struct { + uint8_t frameNumAndFrameId; + uint8_t to; + uint8_t from; + uint8_t pad; +} zcanid_t; + +typedef struct { + uint8_t ptype; + uint8_t index; + uint16_t function_id; + uint8_t params[]; +} zcanbus_packet_t; + +#pragma pack() + +typedef enum { + kcmd, + kreceipt, + kerror_receipt, + kreport, +} packet_type_t; + +typedef enum { + kMainBoard = 0, // 主机 + kBoardType_LiquidCtrl = 1, // 液路板 + kBoardType_PowerControl = 2, // 电源板 + kBoardType_PowerControlMiniBoard = 3, // 电源控制Mini板,用于拉杆箱箱消毒机 + kBoardType_ExtBallValveCtrl = 4, // 外部球阀控制板 + kBoardType_H2O2Sensor = 5, // H2O2传感器板 +} BoardType_t; + +static inline const char *BoardTypeToString(uint32_t type) { + switch (type) { + case kMainBoard: + return "MainBoard"; + case kBoardType_LiquidCtrl: + return "LiquidCtrl"; + case kBoardType_PowerControl: + return "PowerControl"; + case kBoardType_PowerControlMiniBoard: + return "PowerControlMiniBoard"; + case kBoardType_ExtBallValveCtrl: + return "ExtBallValveCtrl"; + case kBoardType_H2O2Sensor: + return "H2O2Sensor"; + default: + return "unkown"; + } +} + +typedef enum { + klarge_space_disinfection_machine = 1, // 大空间消毒机 + ksmall_space_disinfection_machine = 2, // 小空间消毒机 + kpipe_disinfection_machine = 3, // 管道式消毒机 + kdraw_bar_disinfection_box = 4, // 手持拉杆箱消毒机 +} ProjectID_t; + +static inline const char *ProjectIDToString(uint32_t id) { + switch (id) { + case klarge_space_disinfection_machine: + return "large_space_disinfection_machine"; + case ksmall_space_disinfection_machine: + return "small_space_disinfection_machine"; + case kpipe_disinfection_machine: + return "pipe_disinfection_machine"; + case kdraw_bar_disinfection_box: + return "draw_bar_disinfection_box"; + default: + return "unkown"; + } +} + +typedef enum { + kerr_noerror = 0, + kerr_overtime = 1, + + // 驱动器错误 + kerr_motorReset = 100, + kerr_motorUnkownError = 101, + + kerr_AirBlowerError = 200, // 空压机异常 + kerr_HeaterError = 201, // 加热片异常 + kerr_BlowerError = 202, // 鼓风机异常 + kerr_ProportionalValveError = 203, // 气密性测试专用空压机异常 + +} ErrorCode_t; + +static inline const char *ErrorCodeToString(uint32_t code) { + switch (code) { + case kerr_noerror: + return "no error"; + case kerr_motorReset: + return "motor reset"; + case kerr_motorUnkownError: + return "motor unkown error"; + case kerr_AirBlowerError: + return "air blower error"; + case kerr_HeaterError: + return "heater error"; + case kerr_BlowerError: + return "blower error"; + case kerr_ProportionalValveError: + return "proportional valve error"; + default: + return "unkown error"; + } +} + +typedef enum { + + /*********************************************************************************************************************** + * 板子基本操作 * + ***********************************************************************************************************************/ + kcmd_read_board_info = 1, // cmd:no, ack:read_board_info_ack_t + kcmd_force_report = 2, // cmd:no, ack:read_board_info_ack_t + kcmd_read_sysinfo = 3, // cmd:no, ack:read_board_info_ack_t + kcmd_read_taskinfo = 4, // cmd:taskoff, ack:read_board_info_ack_t + kreport_heatpacket = 50, // cmd:no ack:no report:heatpacket_t + kreport_exception_error = 51, // report:error_code,subid + + /*********************************************************************************************************************** + * 蠕动泵控制 * + ***********************************************************************************************************************/ + /** + * 旋转(id,速度) + * 停止 + * + * 设置TMC参数 + * 读取TMC参数 + * 设置ihold,irun,idelay + * + */ + kcmd_pump_rotate = 100, // cmd: rpm + kcmd_pump_stop = 101, // cmd: rpm + kcmd_pump_set_subic_reg = 102, // cmd: add,val + kcmd_pump_get_subic_reg = 103, // cmd: add,ack:val + kcmd_pump_set_irun_ihold = 104, // cmd: irun,ihold,idelay + + /*********************************************************************************************************************** + * 报警指示灯控制 * + ***********************************************************************************************************************/ + kcmd_triple_warning_light_ctl = 200, // cmd: r,g,b,warning + + /*********************************************************************************************************************** + * 压力传感器读取 * + ***********************************************************************************************************************/ + kreport_pressure_data = 300, // report:subid pressure(0.1pa) + + /*********************************************************************************************************************** + * H2O2传感器数值上报 * + ***********************************************************************************************************************/ + kreport_h2o2_data = 400, // report:subid h2o2_sensor_data + + /*********************************************************************************************************************** + * 加热片控制 * + ***********************************************************************************************************************/ + /** + * @brief 加热片控制 + * 打开/关闭 + * 安全继电器控制 + * 是否支持读取温度 + * + * 电流上报 + * 温度上报 + */ + kcmd_heater_ctrl = 500, // cmd: power(0-100) + kcmd_heater_ctrl_safe_valve = 501, // cmd: valve_state + kreport_heater_temperature_data = 550, // report:temperature(0.01) + kreport_heater_electric_current = 551, // report:electric_current(ma) + + /*********************************************************************************************************************** + * 风机控制 * + ***********************************************************************************************************************/ + /** + * @brief 风机控制 + * 打开/关闭 + * 安全继电器控制 + * 电流上报 + */ + + kcmd_blower_ctrl = 600, // cmd: power(0-100) + kcmd_blower_ctrl_safe_valve = 601, // cmd: valve_state + kreport_blower_electric_current = 651, // report:electric_current(ma) + + /*********************************************************************************************************************** + * 空压机控制 * + ***********************************************************************************************************************/ + /** + * @brief 空压机 airCompressor + * 打开/关闭 + * 安全继电器控制 + * 电流上报 + * 调整风速 + */ + + kcmd_airCompressor_ctrl = 700, // cmd: power(0-100) + kcmd_airCompressor_ctrl_safe_valve = 701, // cmd: valve_state + kreport_airCompressor_electric_current = 751, // report:electric_current(ma) + + /*********************************************************************************************************************** + * 气密性测试专用空压机 * + ***********************************************************************************************************************/ + /** + * @brief air Tightness Test AirCompressor + * 打开/关闭 + * 电流上报 + * + * + */ + + kcmd_ATTAirCompressor_ctrl = 800, // cmd: power(0-100) + kcmd_ATTAirCompressor_ctrl_safe_valve = 801, // cmd: valve_state + + /*********************************************************************************************************************** + * 电磁阀控制 * + ***********************************************************************************************************************/ + + /** + * @brief 电磁阀控制 + * 打开/关闭 + */ + kcmd_electromagnetic_valve_ctrl = 900, // cmd: valve_state + + /*********************************************************************************************************************** + * 球阀控制 * + ***********************************************************************************************************************/ + + /** + * @brief 电磁阀控制 + * 打开/关闭 + */ + kcmd_ball_valve_ctrl = 1000, // cmd: valve_state + + /*********************************************************************************************************************** + * 比例阀控制 * + ***********************************************************************************************************************/ + + /** + * @brief 比例阀控制 + * 打开/关闭 + * 比例阀当前比例上报 + */ + + kcmd_proportional_valve_ctrl = 1100, // cmd: subid valve_state(0->100) + kreport_proportional_valve_value = 1150, // cmd: subid valve_state(0->100) + + /*********************************************************************************************************************** + * 水浸传感器状态上报 * + ***********************************************************************************************************************/ + + kreport_evaporation_bin_water_sensor = 1200, // report:state //蒸发仓水浸 + kreport_device_bottom_water_sensor = 1201, // report:state //设备底部水浸 + +} cmd_t; + +#pragma pack(1) + +/*********************************************************************************************************************** + * ACK * + ***********************************************************************************************************************/ +typedef struct { + uint16_t boardType; + uint16_t projectId; + uint16_t protcol_version; + uint16_t software_version; + uint16_t hardware_version; +} ack_read_board_info_data_t; + +typedef struct { + uint8_t taskName[8]; + uint16_t stackRemindSize; + uint16_t priority; + uint8_t state; +} ask_task_info; + +typedef struct { + uint16_t total_heap_size; + uint16_t free_heap_size; + uint16_t taskNum; + uint16_t sysHasRun; +} ack_sysinfo_t; + +/*********************************************************************************************************************** + * Report * + ***********************************************************************************************************************/ + +typedef struct { + uint16_t boardType; +} report_heatpacket_data_t; + +typedef struct { + uint16_t subid; + uint32_t ecode; +} report_exeception_data_t; + +typedef struct { + uint16_t subid; + uint32_t pressure; +} report_pressure_data_t; + +typedef struct { + uint16_t subid; + uint16_t h2o2; // ppm + uint16_t humid; // %RH * 100 + uint16_t temp; // °C * 100 + uint16_t saturation; // %RS * 100 +} report_h2o2_data_t; + +typedef struct { + uint16_t temperature; // 0.01 +} report_heater_temperature_data_t; + +typedef struct { + uint16_t electric_current; // ma +} report_heater_electric_current_data_t; + +typedef struct { + uint16_t electric_current; // ma +} report_blower_electric_current_data_t; + +typedef struct { + uint16_t electric_current; // ma +} report_airCompressor_electric_current_data_t; + +typedef struct { + uint16_t subid; // 0->100 + uint16_t valve_state; // 0->100 +} report_proportional_valve_value_data_t; + +typedef struct { + uint16_t state; +} report_evaporation_bin_water_sensor_data_t; + +typedef struct { + uint16_t state; +} report_device_bottom_water_sensor_data_t; + +#pragma pack() +} diff --git a/iflytop_canbus_protocol.hpp b/iflytop_canbus_protocol.hpp index 541b959..668c196 100644 --- a/iflytop_canbus_protocol.hpp +++ b/iflytop_canbus_protocol.hpp @@ -46,6 +46,25 @@ typedef enum { kBoardType_H2O2Sensor = 5, // H2O2传感器板 } BoardType_t; +static inline const char *BoardTypeToString(uint32_t type) { + switch (type) { + case kMainBoard: + return "MainBoard"; + case kBoardType_LiquidCtrl: + return "LiquidCtrl"; + case kBoardType_PowerControl: + return "PowerControl"; + case kBoardType_PowerControlMiniBoard: + return "PowerControlMiniBoard"; + case kBoardType_ExtBallValveCtrl: + return "ExtBallValveCtrl"; + case kBoardType_H2O2Sensor: + return "H2O2Sensor"; + default: + return "unkown"; + } +} + typedef enum { klarge_space_disinfection_machine = 1, // 大空间消毒机 ksmall_space_disinfection_machine = 2, // 小空间消毒机 @@ -53,6 +72,21 @@ typedef enum { kdraw_bar_disinfection_box = 4, // 手持拉杆箱消毒机 } ProjectID_t; +static inline const char *ProjectIDToString(uint32_t id) { + switch (id) { + case klarge_space_disinfection_machine: + return "large_space_disinfection_machine"; + case ksmall_space_disinfection_machine: + return "small_space_disinfection_machine"; + case kpipe_disinfection_machine: + return "pipe_disinfection_machine"; + case kdraw_bar_disinfection_box: + return "draw_bar_disinfection_box"; + default: + return "unkown"; + } +} + typedef enum { kerr_noerror = 0, kerr_overtime = 1, @@ -88,16 +122,15 @@ static inline const char *ErrorCodeToString(uint32_t code) { return "unkown error"; } } - typedef enum { /*********************************************************************************************************************** * 板子基本操作 * ***********************************************************************************************************************/ - kcmd_read_board_info = 1, // cmd:no, ack:read_board_info_ack_t - kcmd_force_report = 2, // cmd:no, ack:read_board_info_ack_t - kcmd_read_sysinfo = 3, // cmd:no, ack:read_board_info_ack_t - kcmd_read_taskinfo = 4, // cmd:taskoff, ack:read_board_info_ack_t + kcmd_read_board_info = 1, // cmd:no, ack:ack_read_board_info_data_t + kcmd_force_report = 2, // cmd:no, ack:none + kcmd_read_sysinfo = 3, // cmd:no, ack:ack_sysinfo_t + kcmd_read_taskinfo = 4, // cmd:taskoff, ack:ask_taskinfo_t kreport_heatpacket = 50, // cmd:no ack:no report:heatpacket_t kreport_exception_error = 51, // report:error_code,subid @@ -254,7 +287,7 @@ typedef struct { uint16_t stackRemindSize; uint16_t priority; uint8_t state; -} ask_task_info; +} ask_taskinfo_t; typedef struct { uint16_t total_heap_size;