From 46658ddf81dbfebd9fb37c18c77d16c16022015b Mon Sep 17 00:00:00 2001 From: zhaohe Date: Sun, 2 Jun 2024 17:49:12 +0800 Subject: [PATCH] recode --- api/api.hpp | 21 +---- api/apibasic/basic.hpp | 14 +++ api/apibasic/cmdid.hpp | 157 ++++++++++++++++++++++++++++++ api/apibasic/errorcode.cpp | 87 +++++++++++++++++ api/apibasic/errorcode.hpp | 110 +++++++++++++++++++++ api/apibasic/module_type_index.hpp | 17 ++++ api/apibasic/packet_interface.hpp | 31 ++++++ api/apibasic/protocol_constant.hpp | 1 + api/apibasic/reg_index.hpp | 189 +++++++++++++++++++++++++++++++++++++ api/errorcode.cpp | 87 ----------------- api/errorcode.hpp | 110 --------------------- api/i_zcanreceiver.hpp | 26 ----- api/module_type_index.hpp | 17 ---- api/packet_interface.hpp | 32 ------- api/protocol_constant.hpp | 1 - api/reg_index.hpp | 189 ------------------------------------- api/reg_index_table.cpp | 24 ----- api/reg_index_table.hpp | 13 --- api/zi_a8000_optical_module.hpp | 3 +- api/zi_adc_capture.hpp | 15 --- api/zi_board_module.hpp | 22 ----- api/zi_code_scaner.hpp | 18 ---- api/zi_event_bus.hpp | 5 +- api/zi_module.hpp | 4 +- api/zi_motor.hpp | 4 +- api/zi_pipette_ctrl_module.hpp | 3 +- api/zi_xymotor.hpp | 3 +- cmdid.hpp | 156 ------------------------------ i_zcanreceiver.hpp | 25 +++++ protocol.hpp | 8 ++ protocol_event_bus_sender.cpp | 2 +- protocol_event_bus_sender.hpp | 3 +- reg_index_table.cpp | 24 +++++ reg_index_table.hpp | 13 +++ 34 files changed, 697 insertions(+), 737 deletions(-) create mode 100644 api/apibasic/basic.hpp create mode 100644 api/apibasic/cmdid.hpp create mode 100644 api/apibasic/errorcode.cpp create mode 100644 api/apibasic/errorcode.hpp create mode 100644 api/apibasic/module_type_index.hpp create mode 100644 api/apibasic/packet_interface.hpp create mode 100644 api/apibasic/protocol_constant.hpp create mode 100644 api/apibasic/reg_index.hpp delete mode 100644 api/errorcode.cpp delete mode 100644 api/errorcode.hpp delete mode 100644 api/i_zcanreceiver.hpp delete mode 100644 api/module_type_index.hpp delete mode 100644 api/packet_interface.hpp delete mode 100644 api/protocol_constant.hpp delete mode 100644 api/reg_index.hpp delete mode 100644 api/reg_index_table.cpp delete mode 100644 api/reg_index_table.hpp delete mode 100644 api/zi_adc_capture.hpp delete mode 100644 api/zi_board_module.hpp delete mode 100644 api/zi_code_scaner.hpp delete mode 100644 cmdid.hpp create mode 100644 i_zcanreceiver.hpp create mode 100644 protocol.hpp create mode 100644 reg_index_table.cpp create mode 100644 reg_index_table.hpp diff --git a/api/api.hpp b/api/api.hpp index 337c876..e45eef8 100644 --- a/api/api.hpp +++ b/api/api.hpp @@ -1,6 +1,7 @@ #pragma once +#include "apibasic/basic.hpp" // -#include "errorcode.hpp" + // #include "zi_module.hpp" // @@ -8,24 +9,8 @@ // #include "zi_xymotor.hpp" // -#include "packet_interface.hpp" -// -#include "i_zcanreceiver.hpp" - - -// -#include "protocol_constant.hpp" -// -#include "reg_index.hpp" -// -#include "zi_code_scaner.hpp" -// #include "zi_event_bus.hpp" // #include "zi_a8000_optical_module.hpp" // -#include "zi_board_module.hpp" - -// -#include "zi_pipette_ctrl_module.hpp" -#include "reg_index_table.hpp" \ No newline at end of file +#include "zi_pipette_ctrl_module.hpp" \ No newline at end of file diff --git a/api/apibasic/basic.hpp b/api/apibasic/basic.hpp new file mode 100644 index 0000000..395c1d5 --- /dev/null +++ b/api/apibasic/basic.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "cmdid.hpp" +// +#include "errorcode.hpp" +// +#include "packet_interface.hpp" +// +#include "module_type_index.hpp" +// +#include "protocol_constant.hpp" +// +#include "reg_index.hpp" +// diff --git a/api/apibasic/cmdid.hpp b/api/apibasic/cmdid.hpp new file mode 100644 index 0000000..6018ee6 --- /dev/null +++ b/api/apibasic/cmdid.hpp @@ -0,0 +1,157 @@ +#pragma once + +#define CMDID(cmdid, cmdSubId) ((cmdid << 8) + cmdSubId) + +namespace iflytop { +namespace zcr { +typedef enum { +#if 0 + + virtual int32_t board_reset() = 0; +#endif + + kboard_reset = CMDID(0, 0), // para:{}, ack:{} + + kevent_bus_reg_change_report = CMDID(0, 100), // para:{}, ack:{} +#if 0 + virtual int32_t module_get_state(int32_t state_id, int32_t *state_value) { return err::koperation_not_support; } + virtual int32_t module_read_raw(int32_t startadd, int32_t *data, int32_t *len) { return err::koperation_not_support; } + virtual int32_t module_enable(int32_t enable) { return err::koperation_not_support; } + virtual int32_t module_start() { return err::koperation_not_support; } +#endif + kmodule_ping = CMDID(1, 0), // para:{}, ack:{} + kmodule_stop = CMDID(1, 1), // para:{}, ack:{} + kmodule_break = CMDID(1, 2), // para:{}, ack:{} + kmodule_get_last_exec_status = CMDID(1, 3), // para:{}, ack:{4} + kmodule_get_status = CMDID(1, 4), // para:{}, ack:{4} + kmodule_set_reg = CMDID(1, 5), // para:{4,4}, ack:{} + kmodule_get_reg = CMDID(1, 6), // para:{4}, ack:{4}I + kmodule_readio = CMDID(1, 7), // para:{}, ack:{4} + kmodule_writeio = CMDID(1, 8), // para:{4}, ack:{} + kmodule_read_adc = CMDID(1, 9), // para:{4}, ack:{4} + kmodule_get_error = CMDID(1, 10), // para:{}, ack:{1} + kmodule_clear_error = CMDID(1, 11), // para:{}, ack:{} + kmodule_set_inited_flag = CMDID(1, 12), // para:{4}, ack:{} + kmodule_get_inited_flag = CMDID(1, 13), // para:{}, ack:{4} + kmodule_factory_reset = CMDID(1, 14), // para:{}, ack:{} + kmodule_flush_cfg = CMDID(1, 15), // para:{}, ack:{} + kmodule_active_cfg = CMDID(1, 16), // para:{}, ack:{} + kmodule_read_raw = CMDID(1, 19), // para:{4,4}, ack:{4} + kmodule_enable = CMDID(1, 20), // para:{4}, ack:{} + kmodule_start = CMDID(1, 21), // para:{4}, ack:{} + +#if 0 + virtual int32_t motor_enable(int32_t enable) { return err::koperation_not_support; } + virtual int32_t motor_rotate(int32_t direction, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; } + virtual int32_t motor_move_by(int32_t distance, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; } + virtual int32_t motor_move_to(int32_t position, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; } + + virtual int32_t motor_rotate_acctime(int32_t direction, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; } + virtual int32_t motor_move_by_acctime(int32_t distance, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; } + virtual int32_t motor_move_to_acctime(int32_t position, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; } + + virtual int32_t motor_rotate_with_torque(int32_t direction, int32_t torque) { return err::koperation_not_support; } + virtual int32_t motor_move_to_torque(int32_t pos, int32_t torque, int32_t overtime) { return err::koperation_not_support; } + + virtual int32_t motor_move_to_zero_forward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; } + virtual int32_t motor_move_to_zero_backward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; } + + virtual int32_t motor_move_to_zero_forward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; } + virtual int32_t motor_move_to_zero_backward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; } + + virtual int32_t motor_read_pos(int32_t* pos) { return err::koperation_not_support; } + virtual int32_t motor_set_current_pos_by_change_shift(int32_t pos) { return err::koperation_not_support; } // 一般用于舵机 + + virtual int32_t motor_easy_rotate(int32_t direction) { return err::koperation_not_support; }; + virtual int32_t motor_easy_move_by(int32_t distance) { return err::koperation_not_support; }; + virtual int32_t motor_easy_move_to(int32_t position) { return err::koperation_not_support; }; + virtual int32_t motor_easy_move_to_zero(int32_t direction) { return err::koperation_not_support; }; + virtual int32_t motor_easy_move_to_io(int32_t ioindex, int32_t direction) { return err::koperation_not_support; }; + +#endif + + kmotor_enable = CMDID(2, 1), // para:{1}, ack:{} + kmotor_rotate = CMDID(2, 2), // para:{1,4}, ack:{} + kmotor_move_by = CMDID(2, 3), // para:{4,4}, ack:{} + kmotor_move_to = CMDID(2, 4), // para:{4,4}, ack:{} + kmotor_rotate_acctime = CMDID(2, 5), // para:{4,4}, ack:{} + kmotor_move_by_acctime = CMDID(2, 6), // para:{4,4}, ack:{} + kmotor_move_to_acctime = CMDID(2, 7), // para:{4,4}, ack:{} + kmotor_rotate_with_torque = CMDID(2, 8), // para:{4,4}, ack:{} + kmotor_move_to_zero_forward = CMDID(2, 9), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime + kmotor_move_to_zero_backward = CMDID(2, 10), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime + kmotor_read_pos = CMDID(2, 11), // para:{}, ack:{4} + kmotor_set_current_pos_by_change_shift = CMDID(2, 12), // para:{4}, ack:{} + kmotor_motor_move_to_zero_forward_and_calculated_shift = CMDID(2, 13), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime + kmotor_motor_move_to_zero_backward_and_calculated_shift = CMDID(2, 14), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime + kmotor_move_to_torque = CMDID(2, 15), // para:{4,4,4}, ack:{} + kmotor_calculated_pos_by_move_to_zero = CMDID(2, 16), // para:{}, ack:{} + + kmotor_easy_rotate = CMDID(2, 17), // para:{4}, ack:{} + kmotor_easy_move_by = CMDID(2, 18), // para:{4}, ack:{} + kmotor_easy_move_to = CMDID(2, 19), // para:{4}, ack:{} + kmotor_easy_move_to_zero = CMDID(2, 20), // para:{1}, ack:{} + kmotor_easy_set_current_pos = CMDID(2, 21), // para:{4}, ack:{} + kmotor_easy_move_to_io = CMDID(2, 22), // para:{4,4}, ack:{} + +#if 0 + virtual ~ZIXYMotor() {} + virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; } + virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; } + virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; } + virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; } + virtual int32_t xymotor_move_to_zero_and_calculated_shift() { return err::koperation_not_support; } + virtual int32_t xymotor_read_pos(int32_t *x, int32_t *y) { return err::koperation_not_support; } + virtual int32_t xymotor_calculated_pos_by_move_to_zero() { return err::koperation_not_support; } +#endif + kxymotor_enable = CMDID(3, 1), // para:{1}, ack:{} + kxymotor_move_by = CMDID(3, 2), // para:{4,4,4}, ack:{} + kxymotor_move_to = CMDID(3, 3), // para:{4,4,4}, ack:{} + kxymotor_move_to_zero = CMDID(3, 4), // para:{}, ack:{} + kxymotor_move_to_zero_and_calculated_shift = CMDID(3, 5), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime + kxymotor_read_pos = CMDID(3, 6), // para:{}, ack:{4,4} + kxymotor_calculated_pos_by_move_to_zero = CMDID(3, 7), // para:{}, ack:{} + +#if 0 + virtual int32_t code_scaner_start_scan() { return err::koperation_not_support; } + virtual int32_t code_scaner_stop_scan() { return err::koperation_not_support; } + virtual int32_t code_scaner_read_scaner_result(int32_t startadd, uint8_t *data, int32_t *len) { return err::koperation_not_support; } +#endif + + kcode_scaner_start_scan = CMDID(4, 1), // para:{}, ack:{} + kcode_scaner_stop_scan = CMDID(4, 2), // para:{}, ack:{} + kcode_scaner_read_scaner_result = CMDID(4, 3), // para:{4,4}, ack:{4} + +#if 0 + virtual int32_t pipette_ctrl_init_device() { return err::koperation_not_support; }; + virtual int32_t pipette_ctrl_put_tip() { return err::koperation_not_support; }; + virtual int32_t pipette_ctrl_move_to_ul(int32_t ul) { return err::koperation_not_support; }; +#endif + + kpipette_ctrl_init_device = CMDID(5, 1), // para:{}, ack:{} + kpipette_ctrl_put_tip = CMDID(5, 2), // para:{}, ack:{} + kpipette_ctrl_move_to_ul = CMDID(5, 3), // para:{4}, ack:{} + +#if 0 + virtual int32_t a8000_optical_module_power_ctrl(int32_t state) = 0; + virtual int32_t a8000_optical_open_laser(int32_t type) = 0; + virtual int32_t a8000_optical_close_laser(int32_t type) = 0; + virtual int32_t a8000_optical_set_laster_gain(int32_t type, int32_t gain) = 0; + virtual int32_t a8000_optical_set_scan_amp_gain(int32_t type, int32_t gain) = 0; + virtual int32_t a8000_optical_read_scanner_adc_val(int32_t type, int32_t* adcval) = 0; + virtual int32_t a8000_optical_read_laster_adc_val(int32_t type, int32_t* adcval) = 0; + virtual int32_t a8000_optical_scan_current_point_amp_adc_val(int32_t type, int32_t lastergain, int32_t ampgain, int32_t* laster_fb_val, int32_t* adcval) = 0; +#endif + ka8000_optical_module_power_ctrl = CMDID(6, 0), // para:{4}, ack:{} + ka8000_optical_open_laser = CMDID(6, 1), // para:{4}, ack:{} + ka8000_optical_close_laser = CMDID(6, 2), // para:{4}, ack:{} + ka8000_optical_set_laster_gain = CMDID(6, 3), // para:{4,4}, ack:{} + ka8000_optical_set_scan_amp_gain = CMDID(6, 4), // para:{4,4}, ack:{} + ka8000_optical_read_scanner_adc_val = CMDID(6, 5), // para:{4}, ack:{4} + ka8000_optical_read_laster_adc_val = CMDID(6, 6), // para:{4}, ack:{4} + ka8000_optical_scan_current_point_amp_adc_val = CMDID(6, 7), // para:{4,4,4,4}, ack:{4,4} + +} cmdid_t; + +} // namespace zcr +} // namespace iflytop \ No newline at end of file diff --git a/api/apibasic/errorcode.cpp b/api/apibasic/errorcode.cpp new file mode 100644 index 0000000..09b11ce --- /dev/null +++ b/api/apibasic/errorcode.cpp @@ -0,0 +1,87 @@ +#include "errorcode.hpp" + +#define ERR2STR(code) \ + case code: \ + return #code; + +namespace iflytop { +namespace err { +const char* error2str(int32_t code) { + switch (code) { + ERR2STR(ksucc); + ERR2STR(kfail); + ERR2STR(kparam_out_of_range); + ERR2STR(koperation_not_support); + ERR2STR(kdevice_is_busy); + ERR2STR(kdevice_is_offline); + ERR2STR(kovertime); + ERR2STR(knoack); + ERR2STR(kerrorack); + ERR2STR(kdevice_offline); + ERR2STR(kparse_json_err); + ERR2STR(ksubdevice_overtime); + ERR2STR(kbuffer_not_enough); + ERR2STR(kcmd_not_found); + ERR2STR(kcmd_param_num_error); + ERR2STR(kcheckcode_is_error); + ERR2STR(kcatch_exception); + ERR2STR(khwardware_error_fan_error); + ERR2STR(ksys_error); + ERR2STR(ksys_create_file_error); + ERR2STR(ksys_create_dir_error); + ERR2STR(ksys_open_file_error); + ERR2STR(ksys_open_dir_error); + ERR2STR(ksys_read_file_error); + ERR2STR(ksys_write_file_error); + ERR2STR(ksys_close_file_error); + ERR2STR(ksys_close_dir_error); + ERR2STR(ksys_delete_file_error); + ERR2STR(ksys_delete_dir_error); + ERR2STR(ksys_copy_file_error); + ERR2STR(kmodule_not_inited); + ERR2STR(kmodule_not_found); + ERR2STR(kmodule_opeation_break_by_user); + ERR2STR(kmodule_error); + ERR2STR(kmodule_not_find_config_index); + ERR2STR(kmodule_not_find_state_index); + ERR2STR(kmotor_not_found_zero_point); + ERR2STR(kmotor_did_not_go_zero); + ERR2STR(kmotor_over_temperature); + ERR2STR(kmotor_over_voltage); + ERR2STR(kxymotor_not_found_x_zero_point); + ERR2STR(kxymotor_not_found_y_zero_point); + ERR2STR(kxymotor_x_find_zero_edge_fail); + ERR2STR(kxymotor_y_find_zero_edge_fail); + ERR2STR(kSMTP2_NoError); + ERR2STR(kSMTP2_InitFail); + ERR2STR(kSMTP2_InvalidCmd); + ERR2STR(kSMTP2_InvalidArg); + ERR2STR(kSMTP2_PressureSensorError); + ERR2STR(kSMTP2_OverPressure); + ERR2STR(kSMTP2_LLDError); + ERR2STR(kSMTP2_DeviceNotInit); + ERR2STR(kSMTP2_TipPopError); + ERR2STR(kSMTP2_PumpOverload); + ERR2STR(kSMTP2_TipDrop); + ERR2STR(kSMTP2_CanBusError); + ERR2STR(kSMTP2_InvalidChecksum); + ERR2STR(kSMTP2_EEPROMError); + ERR2STR(kSMTP2_CmdBufferEmpty); + ERR2STR(kSMTP2_CmdBufferOverflow); + ERR2STR(kSMTP2_TipBlock); + ERR2STR(kSMTP2_AirSuction); + ERR2STR(kSMTP2_Bubble); + ERR2STR(kSMTP2_VolumeError); + ERR2STR(kSMTP2_TipAlreadyLoad); + ERR2STR(kSMTP2_TipLoadFail); + ERR2STR(kmicro_noErr); + ERR2STR(kmicro_uartSendFail); + ERR2STR(kmicro_uartRecvFail); + + default: + return "known"; + break; + } +} +} // namespace err +} // namespace iflytop diff --git a/api/apibasic/errorcode.hpp b/api/apibasic/errorcode.hpp new file mode 100644 index 0000000..2bda9c7 --- /dev/null +++ b/api/apibasic/errorcode.hpp @@ -0,0 +1,110 @@ +#pragma once +#include + +namespace iflytop { +namespace err { +using namespace std; + +#define ERROR_CODE(errortype, suberrorcode) (errortype + suberrorcode) + +typedef enum { + ksucc = ERROR_CODE(0, 0), + kfail = ERROR_CODE(0, 1), + kparam_out_of_range = ERROR_CODE(0, 2), // 参数超出范围 + koperation_not_support = ERROR_CODE(0, 3), // 操作不支持 + kdevice_is_busy = ERROR_CODE(0, 4), // 设备忙 + kdevice_is_offline = ERROR_CODE(0, 5), // 设备离线 + kovertime = ERROR_CODE(0, 6), + knoack = ERROR_CODE(0, 7), + kerrorack = ERROR_CODE(0, 8), + kdevice_offline = ERROR_CODE(0, 9), + kparse_json_err = ERROR_CODE(0, 10), + ksubdevice_overtime = ERROR_CODE(0, 11), + kbuffer_not_enough = ERROR_CODE(0, 12), + kcmd_not_found = ERROR_CODE(0, 13), + kcmd_param_num_error = ERROR_CODE(0, 14), + kcheckcode_is_error = ERROR_CODE(0, 15), + kcatch_exception = ERROR_CODE(0, 16), + khwardware_error_fan_error = ERROR_CODE(0, 17), + khwardware_error = ERROR_CODE(0, 18), + + /** + * @brief 系统错误 + */ + ksys_error = ERROR_CODE(100, 0), + ksys_create_file_error = ERROR_CODE(100, 1), + ksys_create_dir_error = ERROR_CODE(100, 2), + ksys_open_file_error = ERROR_CODE(100, 3), + ksys_open_dir_error = ERROR_CODE(100, 4), + ksys_read_file_error = ERROR_CODE(100, 5), + ksys_write_file_error = ERROR_CODE(100, 6), + ksys_close_file_error = ERROR_CODE(100, 7), + ksys_close_dir_error = ERROR_CODE(100, 8), + ksys_delete_file_error = ERROR_CODE(100, 9), + ksys_delete_dir_error = ERROR_CODE(100, 10), + ksys_copy_file_error = ERROR_CODE(100, 11), + + /** + * @brief module error + */ + kmodule_not_inited = ERROR_CODE(200, 0), + kmodule_not_found = ERROR_CODE(200, 1), + kmodule_opeation_break_by_user = ERROR_CODE(200, 2), // 用户中断 + kmodule_error = ERROR_CODE(200, 3), // 未知错误 + kmodule_not_find_config_index = ERROR_CODE(200, 4), // 未找到配置索引 + kmodule_not_find_state_index = ERROR_CODE(200, 5), // 未找到配置索引 + kmodule_not_support_action = ERROR_CODE(200, 6), // 未找到配置索引 + + /** + * @brief motor error + */ + kmotor_not_found_zero_point = ERROR_CODE(300, 0), // 未找到零点 + kmotor_did_not_go_zero = ERROR_CODE(300, 1), // 设备未归零 + kmotor_over_temperature = ERROR_CODE(300, 2), // 过温 + kmotor_over_voltage = ERROR_CODE(300, 3), // 过压 + kxymotor_not_found_x_zero_point = ERROR_CODE(300, 4), // 未找到零点 + kxymotor_not_found_y_zero_point = ERROR_CODE(300, 5), // 未找到零点 + kxymotor_x_find_zero_edge_fail = ERROR_CODE(300, 6), // 离开零点失败 + kxymotor_y_find_zero_edge_fail = ERROR_CODE(300, 7), // 离开零点失败 + kmotor_run_overtime = ERROR_CODE(300, 8), // 运行超时 + + /** + * @brief STMP2错误 + */ + kSMTP2_NoError = ERROR_CODE(400, 0), // 无错误 + kSMTP2_InitFail = ERROR_CODE(400, 1), // 初始化失败 + kSMTP2_InvalidCmd = ERROR_CODE(400, 2), // 无效命令 + kSMTP2_InvalidArg = ERROR_CODE(400, 3), // 无效参数 + kSMTP2_PressureSensorError = ERROR_CODE(400, 4), // 压力传感器故障 + kSMTP2_OverPressure = ERROR_CODE(400, 5), // 超过压力 + kSMTP2_LLDError = ERROR_CODE(400, 6), // LLD 错误 + kSMTP2_DeviceNotInit = ERROR_CODE(400, 7), // 设备未初始化 + kSMTP2_TipPopError = ERROR_CODE(400, 8), // Tip 弹出错误 + kSMTP2_PumpOverload = ERROR_CODE(400, 9), // 泵过载 + kSMTP2_TipDrop = ERROR_CODE(400, 10), // Tip 脱落 + kSMTP2_CanBusError = ERROR_CODE(400, 11), // CAN 总线故障 + kSMTP2_InvalidChecksum = ERROR_CODE(400, 12), // 无效校验和 + kSMTP2_EEPROMError = ERROR_CODE(400, 13), // EEPROM 故障 + kSMTP2_CmdBufferEmpty = ERROR_CODE(400, 14), // 命令缓冲区为空 + kSMTP2_CmdBufferOverflow = ERROR_CODE(400, 15), // 命令溢出 + kSMTP2_TipBlock = ERROR_CODE(400, 16), // Tip 堵塞 + kSMTP2_AirSuction = ERROR_CODE(400, 17), // 吸入空气 + kSMTP2_Bubble = ERROR_CODE(400, 18), // 液体中有气泡/泡沫 + kSMTP2_VolumeError = ERROR_CODE(400, 19), // 吸取/分配量不准确 + kSMTP2_TipAlreadyLoad = ERROR_CODE(400, 20), // Tip已经装载 + kSMTP2_TipLoadFail = ERROR_CODE(400, 21), + + /** + * @brief 单片机硬件错误 + */ + kmicro_noErr = ERROR_CODE(500, 0), // + kmicro_uartSendFail = ERROR_CODE(500, 1), // + kmicro_uartRecvFail = ERROR_CODE(500, 2), // + kmicro_adcRecvFail = ERROR_CODE(500, 3), // + +} error_t; + +const char* error2str(int32_t code); + +} // namespace err +} // namespace iflytop \ No newline at end of file diff --git a/api/apibasic/module_type_index.hpp b/api/apibasic/module_type_index.hpp new file mode 100644 index 0000000..83df188 --- /dev/null +++ b/api/apibasic/module_type_index.hpp @@ -0,0 +1,17 @@ +#pragma once +#include + +namespace iflytop { +typedef enum { + kuniversal_module = 0, // 通用模块 + khbot_module = 1, // hbot模块 + kmotor_module = 2, // 电机控制 + ktemperature_ctrl_module = 3, // 温度控制 + kmini_servo_motor_module = 4, // 舵机 + kfan_ctrl_module = 5, // 风扇控制 + kcode_scaner = 6, // 风扇控制 + kpipette_ctrl_module = 7, // 移液体枪控制 + ka8000_optical_module = 8, // a8000光学模组 + klaster_scaner_module = 9, // a8000光学模组 +} module_type_t; +} \ No newline at end of file diff --git a/api/apibasic/packet_interface.hpp b/api/apibasic/packet_interface.hpp new file mode 100644 index 0000000..a0802e8 --- /dev/null +++ b/api/apibasic/packet_interface.hpp @@ -0,0 +1,31 @@ +#pragma once +#include + +namespace iflytop { +namespace zcr { +#pragma pack(push, 1) +typedef struct { + uint16_t packetindex; + uint16_t cmdMainId; // cmd main id + uint8_t cmdSubId; // cmd sub id + uint8_t packetType; // + uint16_t subModuleid; // module id + uint8_t data[]; +} zcr_cmd_header_t; +#pragma pack(pop) + +typedef enum { + kptv2_cmd = 0, + kptv2_ack = 1, + kptv2_error_ack = 2, + kptv2_event = 3, +} zcan_cmd_packet_type_t; + +} // namespace zcr +} // namespace iflytop + +#define CMD_SUB_ID(cmdid) (cmdid & 0xff) +#define MODULE_CMDID(cmdid) (cmdid >> 8) + +#define STEP_MOTOR_ID_OFF 100 +#define XY_MOTOR_ID_OFF 200 diff --git a/api/apibasic/protocol_constant.hpp b/api/apibasic/protocol_constant.hpp new file mode 100644 index 0000000..faa241f --- /dev/null +++ b/api/apibasic/protocol_constant.hpp @@ -0,0 +1 @@ +#define ZCANCMD_READ_BUF_MAX_SIZE 512 \ No newline at end of file diff --git a/api/apibasic/reg_index.hpp b/api/apibasic/reg_index.hpp new file mode 100644 index 0000000..69b6be4 --- /dev/null +++ b/api/apibasic/reg_index.hpp @@ -0,0 +1,189 @@ +#pragma once +#include + +namespace iflytop { +using namespace std; + +#define REG_INDEX(type, offset, subconfigindex) (type * 100 + offset + subconfigindex) +typedef enum { + /******************************************************************************* + * 模块通用配置和状态 * + *******************************************************************************/ + kreg_module_version = REG_INDEX(0, 0, 0), // 模块版本 + kreg_module_type = REG_INDEX(0, 0, 1), // 模块类型 + kreg_module_status = REG_INDEX(0, 0, 2), // 0idle,1busy,2error + kreg_module_errorcode = REG_INDEX(0, 0, 3), // inited_flag + // kreg_module_initflag = REG_INDEX(0, 0, 4), // inited_flag + // kreg_module_enableflag = REG_INDEX(0, 0, 5), // 0idle,1busy,2error + // kreg_module_errorbitflag0 = REG_INDEX(0, 0, 6), // 模块异常标志,bit,每个模块自定义 + // kreg_module_input_state = REG_INDEX(0, 0, 8), // + // kreg_module_output_state = REG_INDEX(0, 0, 9), // + kreg_module_raw_sector_size = REG_INDEX(0, 0, 10), // sector_size + kreg_module_raw_sector_num = REG_INDEX(0, 0, 11), // + + /******************************************************************************* + * SENSOR * + *******************************************************************************/ + kreg_sensor_temperature0 = REG_INDEX(2, 0, 0), // 温度1 + kreg_sensor_temperature1 = REG_INDEX(2, 0, 1), // 温度2 + kreg_sensor_temperature2 = REG_INDEX(2, 0, 2), // 温度3 + kreg_sensor_temperature3 = REG_INDEX(2, 0, 3), // 温度4 + + /******************************************************************************* + * 机械人通用配置 * + *******************************************************************************/ + + /******************************************************************************* + * MOTOR_DEFAULT * + *******************************************************************************/ + kreg_step_motor_pos = REG_INDEX(10, 0, 1), // 机器人x坐标 + kreg_step_motor_io_state = REG_INDEX(10, 0, 2), // IO状态 + kreg_step_motor_shift = REG_INDEX(10, 50, 0), // x偏移 + kreg_step_motor_shaft = REG_INDEX(10, 50, 1), // x轴是否反转 + kreg_step_motor_one_circle_pulse = REG_INDEX(10, 50, 2), // x轴一圈脉冲数 + kreg_step_motor_one_circle_pulse_denominator = REG_INDEX(10, 50, 3), // 设置一圈脉冲数的分母 + kreg_step_motor_default_velocity = REG_INDEX(10, 50, 4), // 默认速度 + kreg_step_motor_default_acc = REG_INDEX(10, 50, 5), // 默认加速度 + kreg_step_motor_default_dec = REG_INDEX(10, 50, 6), // 默认减速度 + kreg_step_motor_default_break_dec = REG_INDEX(10, 50, 7), // 默认减速度 + kreg_step_motor_ihold = REG_INDEX(10, 50, 8), // 步进电机电流配置 + kreg_step_motor_irun = REG_INDEX(10, 50, 9), // 步进电机电流配置 + kreg_step_motor_iholddelay = REG_INDEX(10, 50, 10), // 步进电机电流配置 + kreg_step_motor_iglobalscaler = REG_INDEX(10, 50, 11), // 步进电机电流配置 + kreg_step_motor_run_to_zero_max_d = REG_INDEX(10, 50, 21), // x轴回零最大距离 + kreg_step_motor_look_zero_edge_max_d = REG_INDEX(10, 50, 22), // x轴找零边缘最大距离 + kreg_step_motor_run_to_zero_speed = REG_INDEX(10, 50, 23), // 回零速度 + kreg_step_motor_run_to_zero_dec = REG_INDEX(10, 50, 24), // 回零减速度 + kreg_step_motor_look_zero_edge_speed = REG_INDEX(10, 50, 25), // 找零边缘速度 + kreg_step_motor_look_zero_edge_dec = REG_INDEX(10, 50, 26), // 找零边缘减速度 + kreg_step_motor_default_torque = REG_INDEX(10, 50, 27), // 默认扭矩 + kreg_step_motor_max_d = REG_INDEX(10, 50, 28), // 最大限制距离 + kreg_step_motor_min_d = REG_INDEX(10, 50, 29), // 最小限制距离 + + /******************************************************************************* + * MOTOR_X * + *******************************************************************************/ + + /******************************************************************************* + * PID控制器(3000->4000) * + *******************************************************************************/ + kreg_pid_target = REG_INDEX(30, 0, 0), // 目标数值 + kreg_pid_nowoutput = REG_INDEX(30, 0, 1), // 当前输出 + kreg_pid_feedbackval = REG_INDEX(30, 0, 2), // 当前输出 + kreg_pid_kp = REG_INDEX(30, 50, 0), // kp + kreg_pid_ki = REG_INDEX(30, 50, 1), // ki + kreg_pid_kd = REG_INDEX(30, 50, 2), // kd + kreg_pid_max_output = REG_INDEX(30, 50, 3), // 最大输出 + kreg_pid_min_output = REG_INDEX(30, 50, 4), // 最小输出 + kreg_pid_max_integral = REG_INDEX(30, 50, 5), // 最大积分 + kreg_pid_min_integral = REG_INDEX(30, 50, 6), // 最小积分 + kreg_error_limit = REG_INDEX(30, 50, 7), // 误差限制 + kreg_compute_interval = REG_INDEX(30, 50, 8), // 计算间隔 + + /******************************************************************************* + * 风扇控制 * + *******************************************************************************/ + kreg_fan0_ctrl_speed_level = REG_INDEX(31, 0, 0), // 风扇转速0,1,2,3 + kreg_fan1_ctrl_speed_level = REG_INDEX(31, 0, 1), // 风扇转速0,1,2,3 + kreg_fan2_ctrl_speed_level = REG_INDEX(31, 0, 2), // 风扇转速0,1,2,3 + kreg_fan3_ctrl_speed_level = REG_INDEX(31, 0, 3), // 风扇转速0,1,2,3 + kreg_fan4_ctrl_speed_level = REG_INDEX(31, 0, 4), // 风扇转速0,1,2,3 + + kreg_fan0_speed_level = REG_INDEX(31, 10, 0), // 风扇实时转速0,1,2,3 + kreg_fan1_speed_level = REG_INDEX(31, 10, 1), // 风扇实时转速0,1,2,3 + kreg_fan2_speed_level = REG_INDEX(31, 10, 2), // 风扇实时转速0,1,2,3 + kreg_fan3_speed_level = REG_INDEX(31, 10, 3), // 风扇实时转速0,1,2,3 + kreg_fan4_speed_level = REG_INDEX(31, 10, 4), // 风扇实时转速0,1,2,3 + + kreg_pwm_pump0_ctrl_speed_level = REG_INDEX(32, 0, 0), // PWM水泵0,1,2,3 + kreg_pwm_pump1_ctrl_speed_level = REG_INDEX(32, 0, 1), // PWM水泵0,1,2,3 + kreg_pwm_pump2_ctrl_speed_level = REG_INDEX(32, 0, 2), // PWM水泵0,1,2,3 + kreg_pwm_pump3_ctrl_speed_level = REG_INDEX(32, 0, 3), // PWM水泵0,1,2,3 + kreg_pwm_pump4_ctrl_speed_level = REG_INDEX(32, 0, 4), // PWM水泵0,1,2,3 + + kreg_pwm_pump0_speed_level = REG_INDEX(32, 10, 0), // PWM水泵0,1,2,3 + kreg_pwm_pump1_speed_level = REG_INDEX(32, 10, 1), // PWM水泵0,1,2,3 + kreg_pwm_pump2_speed_level = REG_INDEX(32, 10, 2), // PWM水泵0,1,2,3 + kreg_pwm_pump3_speed_level = REG_INDEX(32, 10, 3), // PWM水泵0,1,2,3 + kreg_pwm_pump4_speed_level = REG_INDEX(32, 10, 4), // PWM水泵0,1,2,3 + + /******************************************************************************* + * 移液枪状态 * + *******************************************************************************/ + kreg_pipette_pos_ul = REG_INDEX(40, 0, 0), // 移液枪位置 + kreg_pipette_capactitance_val = REG_INDEX(40, 0, 1), // 移液枪电容值 + kreg_pipette_tip_state = REG_INDEX(40, 0, 2), // 移动液枪tip状态 + kreg_pipette_limit_ul = REG_INDEX(40, 50, 0), // 移液枪ul限制 + + /******************************************************************************* + * smartADC * + *******************************************************************************/ + kreg_self_reflecting_laser_sensor_transmitting_power = REG_INDEX(41, 0, 0), // 发射功率 + kreg_self_reflecting_laser_sensor_receiving_tube_gain = REG_INDEX(41, 0, 1), // 接收管放大倍数 + kreg_self_reflecting_laser_sensor_sample_interval_ms = REG_INDEX(41, 0, 2), // 采样率 + kreg_self_reflecting_laser_sensor_num_samples = REG_INDEX(41, 0, 3), // 采样点数 + + // scan action + kreg_boditech_optical_scan_type = REG_INDEX(42, 0, 0), // 0 t光学,1 f光学 + kreg_boditech_optical_scan_start_pos = REG_INDEX(42, 0, 1), + kreg_boditech_optical_scan_direction = REG_INDEX(42, 0, 2), + kreg_boditech_optical_scan_step_interval = REG_INDEX(42, 0, 3), + kreg_boditech_optical_scan_pointnum = REG_INDEX(42, 0, 4), + kreg_boditech_optical_channel_select_num = REG_INDEX(42, 0, 5), + kreg_boditech_optical_laster_gain = REG_INDEX(42, 0, 6), + kreg_boditech_optical_scan_gain = REG_INDEX(42, 0, 7), + kreg_boditech_optical_trf_uvled_on_duration_us = REG_INDEX(42, 0, 8), + kreg_boditech_optical_trf_uvled_off_duration_us = REG_INDEX(42, 0, 9), + kreg_boditech_optical_trf_scan_delay_us = REG_INDEX(42, 0, 10), + kreg_boditech_optical_trf_scan_duration_us = REG_INDEX(42, 0, 11), + kreg_boditech_optical_scan_gain_adjust_suggestion = REG_INDEX(42, 0, 12), + kreg_boditech_optical_adc_result_overflow = REG_INDEX(42, 0, 13), + kreg_boditech_optical_laster_intensity = REG_INDEX(42, 0, 14), + + // + kreg_laster_scaner_scan_type = REG_INDEX(43, 0, 0), // 0 t光学,1 f光学 + + kreg_laster_scaner_scan_start_pos = REG_INDEX(43, 0, 1), + kreg_laster_scaner_scan_direction = REG_INDEX(43, 0, 2), + kreg_laster_scaner_scan_step_interval = REG_INDEX(43, 0, 3), + kreg_laster_scaner_scan_pointnum = REG_INDEX(43, 0, 4), + kreg_laster_scaner_laster_gain = REG_INDEX(43, 0, 5), + kreg_laster_scaner_scan_gain = REG_INDEX(43, 0, 6), + + kreg_laster_scaner_scan_gain_adjust_suggestion = REG_INDEX(43, 0, 12), + kreg_laster_scaner_adc_result_overflow = REG_INDEX(43, 0, 13), + kreg_laster_scaner_laster_intensity = REG_INDEX(43, 0, 14), + + /*********************************************************************************************************************** + * XYROBOT * + ***********************************************************************************************************************/ + + kreg_xyrobot_default_velocity = REG_INDEX(100, 0, 0), + kreg_xyrobot_default_acc = REG_INDEX(100, 0, 1), + kreg_xyrobot_default_dec = REG_INDEX(100, 0, 2), + kreg_xyrobot_default_break_dec = REG_INDEX(100, 0, 3), + kreg_xyrobot_run_to_zero_speed = REG_INDEX(100, 0, 4), + kreg_xyrobot_run_to_zero_dec = REG_INDEX(100, 0, 5), + kreg_xyrobot_look_zero_edge_speed = REG_INDEX(100, 0, 6), + kreg_xyrobot_look_zero_edge_dec = REG_INDEX(100, 0, 7), + kreg_xyrobot_ihold = REG_INDEX(100, 0, 8), + kreg_xyrobot_irun = REG_INDEX(100, 0, 9), + kreg_xyrobot_iholddelay = REG_INDEX(100, 0, 10), + + kreg_xyrobot_robot_type = REG_INDEX(100, 50, 0), // 机器人类型 0:hbot 1:corexy + kreg_xyrobot_x_shift = REG_INDEX(100, 50, 1), // x偏移 + kreg_xyrobot_y_shift = REG_INDEX(100, 50, 2), // y偏移 + kreg_xyrobot_x_shaft = REG_INDEX(100, 50, 3), // x轴是否反转 + kreg_xyrobot_y_shaft = REG_INDEX(100, 50, 4), // y轴是否反转 + kreg_xyrobot_x_one_circle_pulse = REG_INDEX(100, 50, 5), // x轴一圈脉冲数 + kreg_xyrobot_y_one_circle_pulse = REG_INDEX(100, 50, 6), // y轴一圈脉冲数 + kreg_xyrobot_run_to_zero_max_x_d = REG_INDEX(100, 50, 7), // x轴回零最大距离 + kreg_xyrobot_run_to_zero_max_y_d = REG_INDEX(100, 50, 8), // y轴回零最大距离 + kreg_xyrobot_look_zero_edge_max_x_d = REG_INDEX(100, 50, 9), // x轴找零边缘最大距离 + kreg_xyrobot_look_zero_edge_max_y_d = REG_INDEX(100, 50, 10), // y轴找零边缘最大距离 + kreg_xyrobot_io_state0 = REG_INDEX(100, 50, 11), // IO状态 + kreg_xyrobot_io_state1 = REG_INDEX(100, 50, 12), // IO状态 + +} reg_index_t; + +} // namespace iflytop diff --git a/api/errorcode.cpp b/api/errorcode.cpp deleted file mode 100644 index 09b11ce..0000000 --- a/api/errorcode.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "errorcode.hpp" - -#define ERR2STR(code) \ - case code: \ - return #code; - -namespace iflytop { -namespace err { -const char* error2str(int32_t code) { - switch (code) { - ERR2STR(ksucc); - ERR2STR(kfail); - ERR2STR(kparam_out_of_range); - ERR2STR(koperation_not_support); - ERR2STR(kdevice_is_busy); - ERR2STR(kdevice_is_offline); - ERR2STR(kovertime); - ERR2STR(knoack); - ERR2STR(kerrorack); - ERR2STR(kdevice_offline); - ERR2STR(kparse_json_err); - ERR2STR(ksubdevice_overtime); - ERR2STR(kbuffer_not_enough); - ERR2STR(kcmd_not_found); - ERR2STR(kcmd_param_num_error); - ERR2STR(kcheckcode_is_error); - ERR2STR(kcatch_exception); - ERR2STR(khwardware_error_fan_error); - ERR2STR(ksys_error); - ERR2STR(ksys_create_file_error); - ERR2STR(ksys_create_dir_error); - ERR2STR(ksys_open_file_error); - ERR2STR(ksys_open_dir_error); - ERR2STR(ksys_read_file_error); - ERR2STR(ksys_write_file_error); - ERR2STR(ksys_close_file_error); - ERR2STR(ksys_close_dir_error); - ERR2STR(ksys_delete_file_error); - ERR2STR(ksys_delete_dir_error); - ERR2STR(ksys_copy_file_error); - ERR2STR(kmodule_not_inited); - ERR2STR(kmodule_not_found); - ERR2STR(kmodule_opeation_break_by_user); - ERR2STR(kmodule_error); - ERR2STR(kmodule_not_find_config_index); - ERR2STR(kmodule_not_find_state_index); - ERR2STR(kmotor_not_found_zero_point); - ERR2STR(kmotor_did_not_go_zero); - ERR2STR(kmotor_over_temperature); - ERR2STR(kmotor_over_voltage); - ERR2STR(kxymotor_not_found_x_zero_point); - ERR2STR(kxymotor_not_found_y_zero_point); - ERR2STR(kxymotor_x_find_zero_edge_fail); - ERR2STR(kxymotor_y_find_zero_edge_fail); - ERR2STR(kSMTP2_NoError); - ERR2STR(kSMTP2_InitFail); - ERR2STR(kSMTP2_InvalidCmd); - ERR2STR(kSMTP2_InvalidArg); - ERR2STR(kSMTP2_PressureSensorError); - ERR2STR(kSMTP2_OverPressure); - ERR2STR(kSMTP2_LLDError); - ERR2STR(kSMTP2_DeviceNotInit); - ERR2STR(kSMTP2_TipPopError); - ERR2STR(kSMTP2_PumpOverload); - ERR2STR(kSMTP2_TipDrop); - ERR2STR(kSMTP2_CanBusError); - ERR2STR(kSMTP2_InvalidChecksum); - ERR2STR(kSMTP2_EEPROMError); - ERR2STR(kSMTP2_CmdBufferEmpty); - ERR2STR(kSMTP2_CmdBufferOverflow); - ERR2STR(kSMTP2_TipBlock); - ERR2STR(kSMTP2_AirSuction); - ERR2STR(kSMTP2_Bubble); - ERR2STR(kSMTP2_VolumeError); - ERR2STR(kSMTP2_TipAlreadyLoad); - ERR2STR(kSMTP2_TipLoadFail); - ERR2STR(kmicro_noErr); - ERR2STR(kmicro_uartSendFail); - ERR2STR(kmicro_uartRecvFail); - - default: - return "known"; - break; - } -} -} // namespace err -} // namespace iflytop diff --git a/api/errorcode.hpp b/api/errorcode.hpp deleted file mode 100644 index 2bda9c7..0000000 --- a/api/errorcode.hpp +++ /dev/null @@ -1,110 +0,0 @@ -#pragma once -#include - -namespace iflytop { -namespace err { -using namespace std; - -#define ERROR_CODE(errortype, suberrorcode) (errortype + suberrorcode) - -typedef enum { - ksucc = ERROR_CODE(0, 0), - kfail = ERROR_CODE(0, 1), - kparam_out_of_range = ERROR_CODE(0, 2), // 参数超出范围 - koperation_not_support = ERROR_CODE(0, 3), // 操作不支持 - kdevice_is_busy = ERROR_CODE(0, 4), // 设备忙 - kdevice_is_offline = ERROR_CODE(0, 5), // 设备离线 - kovertime = ERROR_CODE(0, 6), - knoack = ERROR_CODE(0, 7), - kerrorack = ERROR_CODE(0, 8), - kdevice_offline = ERROR_CODE(0, 9), - kparse_json_err = ERROR_CODE(0, 10), - ksubdevice_overtime = ERROR_CODE(0, 11), - kbuffer_not_enough = ERROR_CODE(0, 12), - kcmd_not_found = ERROR_CODE(0, 13), - kcmd_param_num_error = ERROR_CODE(0, 14), - kcheckcode_is_error = ERROR_CODE(0, 15), - kcatch_exception = ERROR_CODE(0, 16), - khwardware_error_fan_error = ERROR_CODE(0, 17), - khwardware_error = ERROR_CODE(0, 18), - - /** - * @brief 系统错误 - */ - ksys_error = ERROR_CODE(100, 0), - ksys_create_file_error = ERROR_CODE(100, 1), - ksys_create_dir_error = ERROR_CODE(100, 2), - ksys_open_file_error = ERROR_CODE(100, 3), - ksys_open_dir_error = ERROR_CODE(100, 4), - ksys_read_file_error = ERROR_CODE(100, 5), - ksys_write_file_error = ERROR_CODE(100, 6), - ksys_close_file_error = ERROR_CODE(100, 7), - ksys_close_dir_error = ERROR_CODE(100, 8), - ksys_delete_file_error = ERROR_CODE(100, 9), - ksys_delete_dir_error = ERROR_CODE(100, 10), - ksys_copy_file_error = ERROR_CODE(100, 11), - - /** - * @brief module error - */ - kmodule_not_inited = ERROR_CODE(200, 0), - kmodule_not_found = ERROR_CODE(200, 1), - kmodule_opeation_break_by_user = ERROR_CODE(200, 2), // 用户中断 - kmodule_error = ERROR_CODE(200, 3), // 未知错误 - kmodule_not_find_config_index = ERROR_CODE(200, 4), // 未找到配置索引 - kmodule_not_find_state_index = ERROR_CODE(200, 5), // 未找到配置索引 - kmodule_not_support_action = ERROR_CODE(200, 6), // 未找到配置索引 - - /** - * @brief motor error - */ - kmotor_not_found_zero_point = ERROR_CODE(300, 0), // 未找到零点 - kmotor_did_not_go_zero = ERROR_CODE(300, 1), // 设备未归零 - kmotor_over_temperature = ERROR_CODE(300, 2), // 过温 - kmotor_over_voltage = ERROR_CODE(300, 3), // 过压 - kxymotor_not_found_x_zero_point = ERROR_CODE(300, 4), // 未找到零点 - kxymotor_not_found_y_zero_point = ERROR_CODE(300, 5), // 未找到零点 - kxymotor_x_find_zero_edge_fail = ERROR_CODE(300, 6), // 离开零点失败 - kxymotor_y_find_zero_edge_fail = ERROR_CODE(300, 7), // 离开零点失败 - kmotor_run_overtime = ERROR_CODE(300, 8), // 运行超时 - - /** - * @brief STMP2错误 - */ - kSMTP2_NoError = ERROR_CODE(400, 0), // 无错误 - kSMTP2_InitFail = ERROR_CODE(400, 1), // 初始化失败 - kSMTP2_InvalidCmd = ERROR_CODE(400, 2), // 无效命令 - kSMTP2_InvalidArg = ERROR_CODE(400, 3), // 无效参数 - kSMTP2_PressureSensorError = ERROR_CODE(400, 4), // 压力传感器故障 - kSMTP2_OverPressure = ERROR_CODE(400, 5), // 超过压力 - kSMTP2_LLDError = ERROR_CODE(400, 6), // LLD 错误 - kSMTP2_DeviceNotInit = ERROR_CODE(400, 7), // 设备未初始化 - kSMTP2_TipPopError = ERROR_CODE(400, 8), // Tip 弹出错误 - kSMTP2_PumpOverload = ERROR_CODE(400, 9), // 泵过载 - kSMTP2_TipDrop = ERROR_CODE(400, 10), // Tip 脱落 - kSMTP2_CanBusError = ERROR_CODE(400, 11), // CAN 总线故障 - kSMTP2_InvalidChecksum = ERROR_CODE(400, 12), // 无效校验和 - kSMTP2_EEPROMError = ERROR_CODE(400, 13), // EEPROM 故障 - kSMTP2_CmdBufferEmpty = ERROR_CODE(400, 14), // 命令缓冲区为空 - kSMTP2_CmdBufferOverflow = ERROR_CODE(400, 15), // 命令溢出 - kSMTP2_TipBlock = ERROR_CODE(400, 16), // Tip 堵塞 - kSMTP2_AirSuction = ERROR_CODE(400, 17), // 吸入空气 - kSMTP2_Bubble = ERROR_CODE(400, 18), // 液体中有气泡/泡沫 - kSMTP2_VolumeError = ERROR_CODE(400, 19), // 吸取/分配量不准确 - kSMTP2_TipAlreadyLoad = ERROR_CODE(400, 20), // Tip已经装载 - kSMTP2_TipLoadFail = ERROR_CODE(400, 21), - - /** - * @brief 单片机硬件错误 - */ - kmicro_noErr = ERROR_CODE(500, 0), // - kmicro_uartSendFail = ERROR_CODE(500, 1), // - kmicro_uartRecvFail = ERROR_CODE(500, 2), // - kmicro_adcRecvFail = ERROR_CODE(500, 3), // - -} error_t; - -const char* error2str(int32_t code); - -} // namespace err -} // namespace iflytop \ No newline at end of file diff --git a/api/i_zcanreceiver.hpp b/api/i_zcanreceiver.hpp deleted file mode 100644 index 210a86e..0000000 --- a/api/i_zcanreceiver.hpp +++ /dev/null @@ -1,26 +0,0 @@ -// -// Created by zwsd -// - -#pragma once -#include "errorcode.hpp" -#include "packet_interface.hpp" -namespace iflytop { -using namespace zcr; - -class IZCanReceiverListener { - public: - virtual void onRceivePacket(zcr_cmd_header_t *rxcmd, uint8_t *data, int32_t len) = 0; -}; - -class IZCanReceiver { - public: - public: - virtual void registerListener(IZCanReceiverListener *listener) = 0; - virtual int32_t sendBufAck(zcr_cmd_header_t *rx_cmd_header, uint8_t *data, int32_t len) = 0; - virtual int32_t sendAck(zcr_cmd_header_t *rx_cmd_header, int32_t *ackvar, int32_t nack) = 0; - virtual int32_t sendErrorAck(zcr_cmd_header_t *rx_cmd_header, int32_t errorcode) = 0; - virtual int32_t triggerEvent(zcr_cmd_header_t *rx_cmd_header, uint8_t *data, int32_t len) = 0; -}; - -} // namespace iflytop \ No newline at end of file diff --git a/api/module_type_index.hpp b/api/module_type_index.hpp deleted file mode 100644 index 83df188..0000000 --- a/api/module_type_index.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once -#include - -namespace iflytop { -typedef enum { - kuniversal_module = 0, // 通用模块 - khbot_module = 1, // hbot模块 - kmotor_module = 2, // 电机控制 - ktemperature_ctrl_module = 3, // 温度控制 - kmini_servo_motor_module = 4, // 舵机 - kfan_ctrl_module = 5, // 风扇控制 - kcode_scaner = 6, // 风扇控制 - kpipette_ctrl_module = 7, // 移液体枪控制 - ka8000_optical_module = 8, // a8000光学模组 - klaster_scaner_module = 9, // a8000光学模组 -} module_type_t; -} \ No newline at end of file diff --git a/api/packet_interface.hpp b/api/packet_interface.hpp deleted file mode 100644 index 438a550..0000000 --- a/api/packet_interface.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include - -namespace iflytop { -namespace zcr { -#pragma pack(push, 1) -typedef struct { - uint16_t packetindex; - uint16_t cmdMainId; // cmd main id - uint8_t cmdSubId; // cmd sub id - uint8_t packetType; // - uint16_t subModuleid; // module id - uint8_t data[]; -} zcr_cmd_header_t; -#pragma pack(pop) - -typedef enum { - kptv2_cmd = 0, - kptv2_ack = 1, - kptv2_error_ack = 2, - kptv2_event = 3, -} zcan_cmd_packet_type_t; - -} // namespace zcr -} // namespace iflytop - -#define CMDID(cmdid, cmdSubId) ((cmdid << 8) + cmdSubId) -#define CMD_SUB_ID(cmdid) (cmdid & 0xff) -#define MODULE_CMDID(cmdid) (cmdid >> 8) - -#define STEP_MOTOR_ID_OFF 100 -#define XY_MOTOR_ID_OFF 200 diff --git a/api/protocol_constant.hpp b/api/protocol_constant.hpp deleted file mode 100644 index faa241f..0000000 --- a/api/protocol_constant.hpp +++ /dev/null @@ -1 +0,0 @@ -#define ZCANCMD_READ_BUF_MAX_SIZE 512 \ No newline at end of file diff --git a/api/reg_index.hpp b/api/reg_index.hpp deleted file mode 100644 index aea8fc8..0000000 --- a/api/reg_index.hpp +++ /dev/null @@ -1,189 +0,0 @@ -#pragma once -#include - -namespace iflytop { -using namespace std; - -#define REG_INDEX(type, offset, subconfigindex) (type * 100 + offset + subconfigindex) -typedef enum { - /******************************************************************************* - * 模块通用配置和状态 * - *******************************************************************************/ - kreg_module_version = REG_INDEX(0, 0, 0), // 模块版本 - kreg_module_type = REG_INDEX(0, 0, 1), // 模块类型 - kreg_module_status = REG_INDEX(0, 0, 2), // 0idle,1busy,2error - kreg_module_errorcode = REG_INDEX(0, 0, 3), // inited_flag - // kreg_module_initflag = REG_INDEX(0, 0, 4), // inited_flag - // kreg_module_enableflag = REG_INDEX(0, 0, 5), // 0idle,1busy,2error - // kreg_module_errorbitflag0 = REG_INDEX(0, 0, 6), // 模块异常标志,bit,每个模块自定义 - // kreg_module_input_state = REG_INDEX(0, 0, 8), // - // kreg_module_output_state = REG_INDEX(0, 0, 9), // - kreg_module_raw_sector_size = REG_INDEX(0, 0, 10), // sector_size - kreg_module_raw_sector_num = REG_INDEX(0, 0, 11), // - - /******************************************************************************* - * SENSOR * - *******************************************************************************/ - kreg_sensor_temperature0 = REG_INDEX(2, 0, 0), // 温度1 - kreg_sensor_temperature1 = REG_INDEX(2, 0, 1), // 温度2 - kreg_sensor_temperature2 = REG_INDEX(2, 0, 2), // 温度3 - kreg_sensor_temperature3 = REG_INDEX(2, 0, 3), // 温度4 - - /******************************************************************************* - * 机械人通用配置 * - *******************************************************************************/ - - /******************************************************************************* - * MOTOR_DEFAULT * - *******************************************************************************/ - kreg_step_motor_pos = REG_INDEX(10, 0, 1), // 机器人x坐标 - kreg_step_motor_io_state = REG_INDEX(10, 0, 2), // IO状态 - kreg_step_motor_shift = REG_INDEX(10, 50, 0), // x偏移 - kreg_step_motor_shaft = REG_INDEX(10, 50, 1), // x轴是否反转 - kreg_step_motor_one_circle_pulse = REG_INDEX(10, 50, 2), // x轴一圈脉冲数 - kreg_step_motor_one_circle_pulse_denominator = REG_INDEX(10, 50, 3), // 设置一圈脉冲数的分母 - kreg_step_motor_default_velocity = REG_INDEX(10, 50, 4), // 默认速度 - kreg_step_motor_default_acc = REG_INDEX(10, 50, 5), // 默认加速度 - kreg_step_motor_default_dec = REG_INDEX(10, 50, 6), // 默认减速度 - kreg_step_motor_default_break_dec = REG_INDEX(10, 50, 7), // 默认减速度 - kreg_step_motor_ihold = REG_INDEX(10, 50, 8), // 步进电机电流配置 - kreg_step_motor_irun = REG_INDEX(10, 50, 9), // 步进电机电流配置 - kreg_step_motor_iholddelay = REG_INDEX(10, 50, 10), // 步进电机电流配置 - kreg_step_motor_iglobalscaler = REG_INDEX(10, 50, 11), // 步进电机电流配置 - kreg_step_motor_run_to_zero_max_d = REG_INDEX(10, 50, 21), // x轴回零最大距离 - kreg_step_motor_look_zero_edge_max_d = REG_INDEX(10, 50, 22), // x轴找零边缘最大距离 - kreg_step_motor_run_to_zero_speed = REG_INDEX(10, 50, 23), // 回零速度 - kreg_step_motor_run_to_zero_dec = REG_INDEX(10, 50, 24), // 回零减速度 - kreg_step_motor_look_zero_edge_speed = REG_INDEX(10, 50, 25), // 找零边缘速度 - kreg_step_motor_look_zero_edge_dec = REG_INDEX(10, 50, 26), // 找零边缘减速度 - kreg_step_motor_default_torque = REG_INDEX(10, 50, 27), // 默认扭矩 - kreg_step_motor_max_d = REG_INDEX(10, 50, 28), // 最大限制距离 - kreg_step_motor_min_d = REG_INDEX(10, 50, 29), // 最小限制距离 - - /******************************************************************************* - * MOTOR_X * - *******************************************************************************/ - - /******************************************************************************* - * PID控制器(3000->4000) * - *******************************************************************************/ - kreg_pid_target = REG_INDEX(30, 0, 0), // 目标数值 - kreg_pid_nowoutput = REG_INDEX(30, 0, 1), // 当前输出 - kreg_pid_feedbackval = REG_INDEX(30, 0, 2), // 当前输出 - kreg_pid_kp = REG_INDEX(30, 50, 0), // kp - kreg_pid_ki = REG_INDEX(30, 50, 1), // ki - kreg_pid_kd = REG_INDEX(30, 50, 2), // kd - kreg_pid_max_output = REG_INDEX(30, 50, 3), // 最大输出 - kreg_pid_min_output = REG_INDEX(30, 50, 4), // 最小输出 - kreg_pid_max_integral = REG_INDEX(30, 50, 5), // 最大积分 - kreg_pid_min_integral = REG_INDEX(30, 50, 6), // 最小积分 - kreg_error_limit = REG_INDEX(30, 50, 7), // 误差限制 - kreg_compute_interval = REG_INDEX(30, 50, 8), // 计算间隔 - - /******************************************************************************* - * 风扇控制 * - *******************************************************************************/ - kreg_fan0_ctrl_speed_level = REG_INDEX(31, 0, 0), // 风扇转速0,1,2,3 - kreg_fan1_ctrl_speed_level = REG_INDEX(31, 0, 1), // 风扇转速0,1,2,3 - kreg_fan2_ctrl_speed_level = REG_INDEX(31, 0, 2), // 风扇转速0,1,2,3 - kreg_fan3_ctrl_speed_level = REG_INDEX(31, 0, 3), // 风扇转速0,1,2,3 - kreg_fan4_ctrl_speed_level = REG_INDEX(31, 0, 4), // 风扇转速0,1,2,3 - - kreg_fan0_speed_level = REG_INDEX(31, 10, 0), // 风扇实时转速0,1,2,3 - kreg_fan1_speed_level = REG_INDEX(31, 10, 1), // 风扇实时转速0,1,2,3 - kreg_fan2_speed_level = REG_INDEX(31, 10, 2), // 风扇实时转速0,1,2,3 - kreg_fan3_speed_level = REG_INDEX(31, 10, 3), // 风扇实时转速0,1,2,3 - kreg_fan4_speed_level = REG_INDEX(31, 10, 4), // 风扇实时转速0,1,2,3 - - kreg_pwm_pump0_ctrl_speed_level = REG_INDEX(32, 0, 0), // PWM水泵0,1,2,3 - kreg_pwm_pump1_ctrl_speed_level = REG_INDEX(32, 0, 1), // PWM水泵0,1,2,3 - kreg_pwm_pump2_ctrl_speed_level = REG_INDEX(32, 0, 2), // PWM水泵0,1,2,3 - kreg_pwm_pump3_ctrl_speed_level = REG_INDEX(32, 0, 3), // PWM水泵0,1,2,3 - kreg_pwm_pump4_ctrl_speed_level = REG_INDEX(32, 0, 4), // PWM水泵0,1,2,3 - - kreg_pwm_pump0_speed_level = REG_INDEX(32, 10, 0), // PWM水泵0,1,2,3 - kreg_pwm_pump1_speed_level = REG_INDEX(32, 10, 1), // PWM水泵0,1,2,3 - kreg_pwm_pump2_speed_level = REG_INDEX(32, 10, 2), // PWM水泵0,1,2,3 - kreg_pwm_pump3_speed_level = REG_INDEX(32, 10, 3), // PWM水泵0,1,2,3 - kreg_pwm_pump4_speed_level = REG_INDEX(32, 10, 4), // PWM水泵0,1,2,3 - - /******************************************************************************* - * 移液枪状态 * - *******************************************************************************/ - kreg_pipette_pos_ul = REG_INDEX(40, 0, 0), // 移液枪位置 - kreg_pipette_capactitance_val = REG_INDEX(40, 0, 1), // 移液枪电容值 - kreg_pipette_tip_state = REG_INDEX(40, 0, 2), // 移动液枪tip状态 - kreg_pipette_limit_ul = REG_INDEX(40, 50, 0), // 移液枪ul限制 - - /******************************************************************************* - * smartADC * - *******************************************************************************/ - kreg_self_reflecting_laser_sensor_transmitting_power = REG_INDEX(41, 0, 0), // 发射功率 - kreg_self_reflecting_laser_sensor_receiving_tube_gain = REG_INDEX(41, 0, 1), // 接收管放大倍数 - kreg_self_reflecting_laser_sensor_sample_interval_ms = REG_INDEX(41, 0, 2), // 采样率 - kreg_self_reflecting_laser_sensor_num_samples = REG_INDEX(41, 0, 3), // 采样点数 - - // scan action - kreg_boditech_optical_scan_type = REG_INDEX(42, 0, 0), // 0 t光学,1 f光学 - kreg_boditech_optical_scan_start_pos = REG_INDEX(42, 0, 1), - kreg_boditech_optical_scan_direction = REG_INDEX(42, 0, 2), - kreg_boditech_optical_scan_step_interval = REG_INDEX(42, 0, 3), - kreg_boditech_optical_scan_pointnum = REG_INDEX(42, 0, 4), - kreg_boditech_optical_channel_select_num = REG_INDEX(42, 0, 5), - kreg_boditech_optical_laster_gain = REG_INDEX(42, 0, 6), - kreg_boditech_optical_scan_gain = REG_INDEX(42, 0, 7), - kreg_boditech_optical_trf_uvled_on_duration_us = REG_INDEX(42, 0, 8), - kreg_boditech_optical_trf_uvled_off_duration_us = REG_INDEX(42, 0, 9), - kreg_boditech_optical_trf_scan_delay_us = REG_INDEX(42, 0, 10), - kreg_boditech_optical_trf_scan_duration_us = REG_INDEX(42, 0, 11), - kreg_boditech_optical_scan_gain_adjust_suggestion = REG_INDEX(42, 0, 12), - kreg_boditech_optical_adc_result_overflow = REG_INDEX(42, 0, 13), - kreg_boditech_optical_laster_intensity = REG_INDEX(42, 0, 14), - - // - kreg_laster_scaner_scan_type = REG_INDEX(43, 0, 0), // 0 t光学,1 f光学 - - kreg_laster_scaner_scan_start_pos = REG_INDEX(43, 0, 1), - kreg_laster_scaner_scan_direction = REG_INDEX(43, 0, 2), - kreg_laster_scaner_scan_step_interval = REG_INDEX(43, 0, 3), - kreg_laster_scaner_scan_pointnum = REG_INDEX(43, 0, 4), - kreg_laster_scaner_laster_gain = REG_INDEX(43, 0, 5), - kreg_laster_scaner_scan_gain = REG_INDEX(43, 0, 6), - - kreg_laster_scaner_scan_gain_adjust_suggestion = REG_INDEX(43, 0, 12), - kreg_laster_scaner_adc_result_overflow = REG_INDEX(43, 0, 13), - kreg_laster_scaner_laster_intensity = REG_INDEX(43, 0, 14), - - /*********************************************************************************************************************** - * NEW_API * - ***********************************************************************************************************************/ - - kreg_xyrobot_default_velocity = REG_INDEX(100, 0, 0), - kreg_xyrobot_default_acc = REG_INDEX(100, 0, 1), - kreg_xyrobot_default_dec = REG_INDEX(100, 0, 2), - kreg_xyrobot_default_break_dec = REG_INDEX(100, 0, 3), - kreg_xyrobot_run_to_zero_speed = REG_INDEX(100, 0, 4), - kreg_xyrobot_run_to_zero_dec = REG_INDEX(100, 0, 5), - kreg_xyrobot_look_zero_edge_speed = REG_INDEX(100, 0, 6), - kreg_xyrobot_look_zero_edge_dec = REG_INDEX(100, 0, 7), - kreg_xyrobot_ihold = REG_INDEX(100, 0, 8), - kreg_xyrobot_irun = REG_INDEX(100, 0, 9), - kreg_xyrobot_iholddelay = REG_INDEX(100, 0, 10), - - kreg_xyrobot_robot_type = REG_INDEX(100, 50, 0), // 机器人类型 0:hbot 1:corexy - kreg_xyrobot_x_shift = REG_INDEX(100, 50, 1), // x偏移 - kreg_xyrobot_y_shift = REG_INDEX(100, 50, 2), // y偏移 - kreg_xyrobot_x_shaft = REG_INDEX(100, 50, 3), // x轴是否反转 - kreg_xyrobot_y_shaft = REG_INDEX(100, 50, 4), // y轴是否反转 - kreg_xyrobot_x_one_circle_pulse = REG_INDEX(100, 50, 5), // x轴一圈脉冲数 - kreg_xyrobot_y_one_circle_pulse = REG_INDEX(100, 50, 6), // y轴一圈脉冲数 - kreg_xyrobot_run_to_zero_max_x_d = REG_INDEX(100, 50, 7), // x轴回零最大距离 - kreg_xyrobot_run_to_zero_max_y_d = REG_INDEX(100, 50, 8), // y轴回零最大距离 - kreg_xyrobot_look_zero_edge_max_x_d = REG_INDEX(100, 50, 9), // x轴找零边缘最大距离 - kreg_xyrobot_look_zero_edge_max_y_d = REG_INDEX(100, 50, 10), // y轴找零边缘最大距离 - kreg_xyrobot_io_state0 = REG_INDEX(100, 50, 11), // IO状态 - kreg_xyrobot_io_state1 = REG_INDEX(100, 50, 12), // IO状态 - -} reg_index_t; - -} // namespace iflytop diff --git a/api/reg_index_table.cpp b/api/reg_index_table.cpp deleted file mode 100644 index 587c154..0000000 --- a/api/reg_index_table.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "reg_index_table.hpp" - -#include -#include - -#include "reg_index.hpp" -using namespace iflytop; - -static reg_index_table_iterm_t iterms[] = {}; -namespace iflytop { -void reg_index_table_get(reg_index_table_iterm_t** table, int32_t* size) { - *size = sizeof(iterms) / sizeof(iterms[0]); - *table = iterms; -} - -int32_t str_to_reg_index(const char* val) { - for (int32_t i = 0; i < sizeof(iterms) / sizeof(iterms[0]); i++) { - if (strcmp(iterms[i].name, val) == 0) { - return iterms[i].index; - } - } - return atoi(val); -} -} // namespace iflytop \ No newline at end of file diff --git a/api/reg_index_table.hpp b/api/reg_index_table.hpp deleted file mode 100644 index a09bc45..0000000 --- a/api/reg_index_table.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once -#include - -namespace iflytop { -typedef struct { - const char* name; - int32_t index; -} reg_index_table_iterm_t; - -void reg_index_table_get(reg_index_table_iterm_t** table, int32_t* size); -int32_t str_to_reg_index(const char* val); - -} // namespace iflytop diff --git a/api/zi_a8000_optical_module.hpp b/api/zi_a8000_optical_module.hpp index cea5b63..f57d77c 100644 --- a/api/zi_a8000_optical_module.hpp +++ b/api/zi_a8000_optical_module.hpp @@ -3,7 +3,8 @@ #include -#include "errorcode.hpp" +#include "apibasic/basic.hpp" + namespace iflytop { using namespace std; diff --git a/api/zi_adc_capture.hpp b/api/zi_adc_capture.hpp deleted file mode 100644 index d91d186..0000000 --- a/api/zi_adc_capture.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include - -#include - -#include "errorcode.hpp" - -namespace iflytop { -using namespace std; -class ZICodeScaner { - public: - - -}; -} // namespace iflytop \ No newline at end of file diff --git a/api/zi_board_module.hpp b/api/zi_board_module.hpp deleted file mode 100644 index dc807f8..0000000 --- a/api/zi_board_module.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include - -#include - -#include "errorcode.hpp" - -namespace iflytop { -using namespace std; -class ZIBoardModule { - public: - typedef enum { - kf_optical = 0, - kt_optical = 1, - } optical_type_t; - - public: - virtual ~ZIBoardModule(){}; - - virtual int32_t board_reset() = 0; -}; -} // namespace iflytop diff --git a/api/zi_code_scaner.hpp b/api/zi_code_scaner.hpp deleted file mode 100644 index 18a0c8c..0000000 --- a/api/zi_code_scaner.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include - -#include - -#include "errorcode.hpp" - -namespace iflytop { -using namespace std; -#if 0 -class ZICodeScaner { - public: - virtual int32_t code_scaner_start_scan() { return err::koperation_not_support; } - virtual int32_t code_scaner_stop_scan() { return err::koperation_not_support; } - virtual int32_t code_scaner_read_scaner_result(int32_t startadd, uint8_t *data, int32_t *len) { return err::koperation_not_support; } -}; -#endif -} // namespace iflytop \ No newline at end of file diff --git a/api/zi_event_bus.hpp b/api/zi_event_bus.hpp index 549bca3..5af71eb 100644 --- a/api/zi_event_bus.hpp +++ b/api/zi_event_bus.hpp @@ -2,8 +2,11 @@ #include #include +#include "apibasic/basic.hpp" + + + -#include "errorcode.hpp" namespace iflytop { using namespace std; diff --git a/api/zi_module.hpp b/api/zi_module.hpp index c8a7519..ef76156 100644 --- a/api/zi_module.hpp +++ b/api/zi_module.hpp @@ -3,8 +3,8 @@ #include -#include "errorcode.hpp" -#include "module_type_index.hpp" +#include "apibasic/basic.hpp" + namespace iflytop { using namespace std; diff --git a/api/zi_motor.hpp b/api/zi_motor.hpp index d5fe9f4..5a9ff4d 100644 --- a/api/zi_motor.hpp +++ b/api/zi_motor.hpp @@ -3,7 +3,9 @@ #include -#include "errorcode.hpp" +#include "apibasic/basic.hpp" + + namespace iflytop { using namespace std; diff --git a/api/zi_pipette_ctrl_module.hpp b/api/zi_pipette_ctrl_module.hpp index 57230a9..3a39ca7 100644 --- a/api/zi_pipette_ctrl_module.hpp +++ b/api/zi_pipette_ctrl_module.hpp @@ -2,8 +2,9 @@ #include #include +#include "apibasic/basic.hpp" + -#include "errorcode.hpp" namespace iflytop { using namespace std; diff --git a/api/zi_xymotor.hpp b/api/zi_xymotor.hpp index d83a315..c0341ef 100644 --- a/api/zi_xymotor.hpp +++ b/api/zi_xymotor.hpp @@ -2,8 +2,9 @@ #include #include +#include "apibasic/basic.hpp" + -#include "errorcode.hpp" namespace iflytop { using namespace std; diff --git a/cmdid.hpp b/cmdid.hpp deleted file mode 100644 index d58a4d5..0000000 --- a/cmdid.hpp +++ /dev/null @@ -1,156 +0,0 @@ -#pragma once -#include "api/api.hpp" - -namespace iflytop { -namespace zcr { -typedef enum { -#if 0 - - virtual int32_t board_reset() = 0; -#endif - - kboard_reset = CMDID(0, 0), // para:{}, ack:{} - - kevent_bus_reg_change_report = CMDID(0, 100), // para:{}, ack:{} -#if 0 - virtual int32_t module_get_state(int32_t state_id, int32_t *state_value) { return err::koperation_not_support; } - virtual int32_t module_read_raw(int32_t startadd, int32_t *data, int32_t *len) { return err::koperation_not_support; } - virtual int32_t module_enable(int32_t enable) { return err::koperation_not_support; } - virtual int32_t module_start() { return err::koperation_not_support; } -#endif - kmodule_ping = CMDID(1, 0), // para:{}, ack:{} - kmodule_stop = CMDID(1, 1), // para:{}, ack:{} - kmodule_break = CMDID(1, 2), // para:{}, ack:{} - kmodule_get_last_exec_status = CMDID(1, 3), // para:{}, ack:{4} - kmodule_get_status = CMDID(1, 4), // para:{}, ack:{4} - kmodule_set_reg = CMDID(1, 5), // para:{4,4}, ack:{} - kmodule_get_reg = CMDID(1, 6), // para:{4}, ack:{4}I - kmodule_readio = CMDID(1, 7), // para:{}, ack:{4} - kmodule_writeio = CMDID(1, 8), // para:{4}, ack:{} - kmodule_read_adc = CMDID(1, 9), // para:{4}, ack:{4} - kmodule_get_error = CMDID(1, 10), // para:{}, ack:{1} - kmodule_clear_error = CMDID(1, 11), // para:{}, ack:{} - kmodule_set_inited_flag = CMDID(1, 12), // para:{4}, ack:{} - kmodule_get_inited_flag = CMDID(1, 13), // para:{}, ack:{4} - kmodule_factory_reset = CMDID(1, 14), // para:{}, ack:{} - kmodule_flush_cfg = CMDID(1, 15), // para:{}, ack:{} - kmodule_active_cfg = CMDID(1, 16), // para:{}, ack:{} - kmodule_read_raw = CMDID(1, 19), // para:{4,4}, ack:{4} - kmodule_enable = CMDID(1, 20), // para:{4}, ack:{} - kmodule_start = CMDID(1, 21), // para:{4}, ack:{} - -#if 0 - virtual int32_t motor_enable(int32_t enable) { return err::koperation_not_support; } - virtual int32_t motor_rotate(int32_t direction, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; } - virtual int32_t motor_move_by(int32_t distance, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; } - virtual int32_t motor_move_to(int32_t position, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; } - - virtual int32_t motor_rotate_acctime(int32_t direction, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; } - virtual int32_t motor_move_by_acctime(int32_t distance, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; } - virtual int32_t motor_move_to_acctime(int32_t position, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; } - - virtual int32_t motor_rotate_with_torque(int32_t direction, int32_t torque) { return err::koperation_not_support; } - virtual int32_t motor_move_to_torque(int32_t pos, int32_t torque, int32_t overtime) { return err::koperation_not_support; } - - virtual int32_t motor_move_to_zero_forward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; } - virtual int32_t motor_move_to_zero_backward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; } - - virtual int32_t motor_move_to_zero_forward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; } - virtual int32_t motor_move_to_zero_backward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; } - - virtual int32_t motor_read_pos(int32_t* pos) { return err::koperation_not_support; } - virtual int32_t motor_set_current_pos_by_change_shift(int32_t pos) { return err::koperation_not_support; } // 一般用于舵机 - - virtual int32_t motor_easy_rotate(int32_t direction) { return err::koperation_not_support; }; - virtual int32_t motor_easy_move_by(int32_t distance) { return err::koperation_not_support; }; - virtual int32_t motor_easy_move_to(int32_t position) { return err::koperation_not_support; }; - virtual int32_t motor_easy_move_to_zero(int32_t direction) { return err::koperation_not_support; }; - virtual int32_t motor_easy_move_to_io(int32_t ioindex, int32_t direction) { return err::koperation_not_support; }; - -#endif - - kmotor_enable = CMDID(2, 1), // para:{1}, ack:{} - kmotor_rotate = CMDID(2, 2), // para:{1,4}, ack:{} - kmotor_move_by = CMDID(2, 3), // para:{4,4}, ack:{} - kmotor_move_to = CMDID(2, 4), // para:{4,4}, ack:{} - kmotor_rotate_acctime = CMDID(2, 5), // para:{4,4}, ack:{} - kmotor_move_by_acctime = CMDID(2, 6), // para:{4,4}, ack:{} - kmotor_move_to_acctime = CMDID(2, 7), // para:{4,4}, ack:{} - kmotor_rotate_with_torque = CMDID(2, 8), // para:{4,4}, ack:{} - kmotor_move_to_zero_forward = CMDID(2, 9), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime - kmotor_move_to_zero_backward = CMDID(2, 10), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime - kmotor_read_pos = CMDID(2, 11), // para:{}, ack:{4} - kmotor_set_current_pos_by_change_shift = CMDID(2, 12), // para:{4}, ack:{} - kmotor_motor_move_to_zero_forward_and_calculated_shift = CMDID(2, 13), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime - kmotor_motor_move_to_zero_backward_and_calculated_shift = CMDID(2, 14), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime - kmotor_move_to_torque = CMDID(2, 15), // para:{4,4,4}, ack:{} - kmotor_calculated_pos_by_move_to_zero = CMDID(2, 16), // para:{}, ack:{} - - kmotor_easy_rotate = CMDID(2, 17), // para:{4}, ack:{} - kmotor_easy_move_by = CMDID(2, 18), // para:{4}, ack:{} - kmotor_easy_move_to = CMDID(2, 19), // para:{4}, ack:{} - kmotor_easy_move_to_zero = CMDID(2, 20), // para:{1}, ack:{} - kmotor_easy_set_current_pos = CMDID(2, 21), // para:{4}, ack:{} - kmotor_easy_move_to_io = CMDID(2, 22), // para:{4,4}, ack:{} - -#if 0 - virtual ~ZIXYMotor() {} - virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; } - virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; } - virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; } - virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; } - virtual int32_t xymotor_move_to_zero_and_calculated_shift() { return err::koperation_not_support; } - virtual int32_t xymotor_read_pos(int32_t *x, int32_t *y) { return err::koperation_not_support; } - virtual int32_t xymotor_calculated_pos_by_move_to_zero() { return err::koperation_not_support; } -#endif - kxymotor_enable = CMDID(3, 1), // para:{1}, ack:{} - kxymotor_move_by = CMDID(3, 2), // para:{4,4,4}, ack:{} - kxymotor_move_to = CMDID(3, 3), // para:{4,4,4}, ack:{} - kxymotor_move_to_zero = CMDID(3, 4), // para:{}, ack:{} - kxymotor_move_to_zero_and_calculated_shift = CMDID(3, 5), // para:{4,4,4,4}, ack:{} //int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime - kxymotor_read_pos = CMDID(3, 6), // para:{}, ack:{4,4} - kxymotor_calculated_pos_by_move_to_zero = CMDID(3, 7), // para:{}, ack:{} - -#if 0 - virtual int32_t code_scaner_start_scan() { return err::koperation_not_support; } - virtual int32_t code_scaner_stop_scan() { return err::koperation_not_support; } - virtual int32_t code_scaner_read_scaner_result(int32_t startadd, uint8_t *data, int32_t *len) { return err::koperation_not_support; } -#endif - - kcode_scaner_start_scan = CMDID(4, 1), // para:{}, ack:{} - kcode_scaner_stop_scan = CMDID(4, 2), // para:{}, ack:{} - kcode_scaner_read_scaner_result = CMDID(4, 3), // para:{4,4}, ack:{4} - -#if 0 - virtual int32_t pipette_ctrl_init_device() { return err::koperation_not_support; }; - virtual int32_t pipette_ctrl_put_tip() { return err::koperation_not_support; }; - virtual int32_t pipette_ctrl_move_to_ul(int32_t ul) { return err::koperation_not_support; }; -#endif - - kpipette_ctrl_init_device = CMDID(5, 1), // para:{}, ack:{} - kpipette_ctrl_put_tip = CMDID(5, 2), // para:{}, ack:{} - kpipette_ctrl_move_to_ul = CMDID(5, 3), // para:{4}, ack:{} - -#if 0 - virtual int32_t a8000_optical_module_power_ctrl(int32_t state) = 0; - virtual int32_t a8000_optical_open_laser(int32_t type) = 0; - virtual int32_t a8000_optical_close_laser(int32_t type) = 0; - virtual int32_t a8000_optical_set_laster_gain(int32_t type, int32_t gain) = 0; - virtual int32_t a8000_optical_set_scan_amp_gain(int32_t type, int32_t gain) = 0; - virtual int32_t a8000_optical_read_scanner_adc_val(int32_t type, int32_t* adcval) = 0; - virtual int32_t a8000_optical_read_laster_adc_val(int32_t type, int32_t* adcval) = 0; - virtual int32_t a8000_optical_scan_current_point_amp_adc_val(int32_t type, int32_t lastergain, int32_t ampgain, int32_t* laster_fb_val, int32_t* adcval) = 0; -#endif - ka8000_optical_module_power_ctrl = CMDID(6, 0), // para:{4}, ack:{} - ka8000_optical_open_laser = CMDID(6, 1), // para:{4}, ack:{} - ka8000_optical_close_laser = CMDID(6, 2), // para:{4}, ack:{} - ka8000_optical_set_laster_gain = CMDID(6, 3), // para:{4,4}, ack:{} - ka8000_optical_set_scan_amp_gain = CMDID(6, 4), // para:{4,4}, ack:{} - ka8000_optical_read_scanner_adc_val = CMDID(6, 5), // para:{4}, ack:{4} - ka8000_optical_read_laster_adc_val = CMDID(6, 6), // para:{4}, ack:{4} - ka8000_optical_scan_current_point_amp_adc_val = CMDID(6, 7), // para:{4,4,4,4}, ack:{4,4} - -} cmdid_t; - -} // namespace zcr -} // namespace iflytop \ No newline at end of file diff --git a/i_zcanreceiver.hpp b/i_zcanreceiver.hpp new file mode 100644 index 0000000..ebdd3ee --- /dev/null +++ b/i_zcanreceiver.hpp @@ -0,0 +1,25 @@ +// +// Created by zwsd +// + +#pragma once +#include "api/api.hpp" +namespace iflytop { +using namespace zcr; + +class IZCanReceiverListener { + public: + virtual void onRceivePacket(zcr_cmd_header_t *rxcmd, uint8_t *data, int32_t len) = 0; +}; + +class IZCanReceiver { + public: + public: + virtual void registerListener(IZCanReceiverListener *listener) = 0; + virtual int32_t sendBufAck(zcr_cmd_header_t *rx_cmd_header, uint8_t *data, int32_t len) = 0; + virtual int32_t sendAck(zcr_cmd_header_t *rx_cmd_header, int32_t *ackvar, int32_t nack) = 0; + virtual int32_t sendErrorAck(zcr_cmd_header_t *rx_cmd_header, int32_t errorcode) = 0; + virtual int32_t triggerEvent(zcr_cmd_header_t *rx_cmd_header, uint8_t *data, int32_t len) = 0; +}; + +} // namespace iflytop \ No newline at end of file diff --git a/protocol.hpp b/protocol.hpp new file mode 100644 index 0000000..412f90d --- /dev/null +++ b/protocol.hpp @@ -0,0 +1,8 @@ +#pragma once +#include "api/api.hpp" +// +#include "i_zcanreceiver.hpp" +// +#include "reg_index_table.hpp" +// +#include "protocol_event_bus_sender.hpp" \ No newline at end of file diff --git a/protocol_event_bus_sender.cpp b/protocol_event_bus_sender.cpp index c2189a8..353a387 100644 --- a/protocol_event_bus_sender.cpp +++ b/protocol_event_bus_sender.cpp @@ -1,7 +1,7 @@ #include "protocol_event_bus_sender.hpp" #include "api/api.hpp" -#include "cmdid.hpp" +#include "i_zcanreceiver.hpp" namespace iflytop { using namespace std; diff --git a/protocol_event_bus_sender.hpp b/protocol_event_bus_sender.hpp index 10af115..f740e07 100644 --- a/protocol_event_bus_sender.hpp +++ b/protocol_event_bus_sender.hpp @@ -1,5 +1,6 @@ #pragma once #include "api/api.hpp" +#include "i_zcanreceiver.hpp" namespace iflytop { using namespace std; @@ -11,4 +12,4 @@ class ProtocolEventBusSender : public ZIEventBusSender { virtual void push_reg_state_change_event(int32_t moduleid, int32_t regindex, int32_t oldval, int32_t toval) override; }; -} // namespace iflytop \ No newline at end of file +} // namespace iflytop diff --git a/reg_index_table.cpp b/reg_index_table.cpp new file mode 100644 index 0000000..650e017 --- /dev/null +++ b/reg_index_table.cpp @@ -0,0 +1,24 @@ +#include "reg_index_table.hpp" + +#include +#include + +#include "api/api.hpp" +using namespace iflytop; + +static reg_index_table_iterm_t iterms[] = {}; +namespace iflytop { +void reg_index_table_get(reg_index_table_iterm_t** table, int32_t* size) { + *size = sizeof(iterms) / sizeof(iterms[0]); + *table = iterms; +} + +int32_t str_to_reg_index(const char* val) { + for (int32_t i = 0; i < sizeof(iterms) / sizeof(iterms[0]); i++) { + if (strcmp(iterms[i].name, val) == 0) { + return iterms[i].index; + } + } + return atoi(val); +} +} // namespace iflytop \ No newline at end of file diff --git a/reg_index_table.hpp b/reg_index_table.hpp new file mode 100644 index 0000000..a09bc45 --- /dev/null +++ b/reg_index_table.hpp @@ -0,0 +1,13 @@ +#pragma once +#include + +namespace iflytop { +typedef struct { + const char* name; + int32_t index; +} reg_index_table_iterm_t; + +void reg_index_table_get(reg_index_table_iterm_t** table, int32_t* size); +int32_t str_to_reg_index(const char* val); + +} // namespace iflytop