diff --git a/api/api.hpp b/api/api.hpp index a72db9c..d95fb44 100644 --- a/api/api.hpp +++ b/api/api.hpp @@ -7,4 +7,5 @@ #include "packet_interface.hpp" #include "i_zcan_cmder.hpp" #include "i_zcan_cmder_master.hpp" -#include "i_cmdparser.hpp" \ No newline at end of file +#include "i_cmdparser.hpp" +#include "state_index.hpp" \ No newline at end of file diff --git a/api/errorcode.cpp b/api/errorcode.cpp index bb52f98..033b719 100644 --- a/api/errorcode.cpp +++ b/api/errorcode.cpp @@ -3,6 +3,96 @@ #define ERR2STR(code) \ case code: \ return #code; + +#if 0 + 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), + + /** + * @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), // 未找到配置索引 + + /** + * @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), // 离开零点失败 + + /** + * @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), // +#endif namespace iflytop { namespace err { const char* error2str(int32_t code) { @@ -38,6 +128,9 @@ const char* error2str(int32_t code) { 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); @@ -71,6 +164,7 @@ const char* error2str(int32_t code) { ERR2STR(kmicro_noErr); ERR2STR(kmicro_uartSendFail); ERR2STR(kmicro_uartRecvFail); + default: return "known"; break; diff --git a/api/errorcode.hpp b/api/errorcode.hpp index 0ca6b7c..00ad472 100644 --- a/api/errorcode.hpp +++ b/api/errorcode.hpp @@ -49,6 +49,7 @@ typedef enum { 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), // 未找到配置索引 /** * @brief motor error diff --git a/api/state_index.hpp b/api/state_index.hpp index 89e4d8d..51ad992 100644 --- a/api/state_index.hpp +++ b/api/state_index.hpp @@ -7,15 +7,44 @@ using namespace std; #define STATE_INDEX(type, subconfigindex) (type + subconfigindex) typedef enum { - kstate_module_status = STATE_INDEX(0, 0), // + /** + * @brief 电机状态 + * + * 0 -> 100 模块通用状态 + * 100 -> 199 电机1状态 + * 100 -> 299 电机2状态 + * 1000 -> 1100 xy电机状态 + * + * + */ + + kstate_module_status = STATE_INDEX(0, 0), // 0idle,1busy,2error kstate_module_errorcode = STATE_INDEX(0, 1), // - kstate_motor_x_pos = STATE_INDEX(100, 0), // x偏移 - kstate_motor_y_pos = STATE_INDEX(100, 1), // y偏移 - kstate_motor_z_pos = STATE_INDEX(100, 2), // z偏移 + kstate_motor1_move = STATE_INDEX(100, 0), // + kstate_motor1_enable = STATE_INDEX(100, 1), // + kstate_motor1_current = STATE_INDEX(100, 2), // + kstate_motor1_vel = STATE_INDEX(100, 3), // + kstate_motor1_pos = STATE_INDEX(100, 4), // + kstate_motor1_temperature = STATE_INDEX(100, 5), // + kstate_motor1_dpos = STATE_INDEX(100, 6), // + + kstate_motor2_move = STATE_INDEX(110, 0), // + kstate_motor2_enable = STATE_INDEX(110, 1), // + kstate_motor2_current = STATE_INDEX(110, 2), // + kstate_motor2_vel = STATE_INDEX(110, 3), // + kstate_motor2_pos = STATE_INDEX(110, 4), // + kstate_motor2_temperature = STATE_INDEX(110, 5), // + kstate_motor2_dpos = STATE_INDEX(110, 6), // - kstate_motor_move = STATE_INDEX(100, 3), // 电机是否移动 - kstate_motor_enable = STATE_INDEX(100, 4), // 电机是否使能 + kstate_xyrobot_move = STATE_INDEX(1000, 0), // + kstate_xyrobot_enable = STATE_INDEX(1000, 1), // + kstate_xyrobot_x_pos = STATE_INDEX(1000, 2), // + kstate_xyrobot_y_pos = STATE_INDEX(1000, 3), // + kstate_xyrobot_z_pos = STATE_INDEX(1000, 4), // + kstate_xyrobot_x_dpos = STATE_INDEX(1000, 5), // + kstate_xyrobot_y_dpos = STATE_INDEX(1000, 6), // + kstate_xyrobot_z_dpos = STATE_INDEX(1000, 7), // } state_index_t; diff --git a/api/zi_xymotor.hpp b/api/zi_xymotor.hpp index 35a01c8..d83a315 100644 --- a/api/zi_xymotor.hpp +++ b/api/zi_xymotor.hpp @@ -16,5 +16,6 @@ class ZIXYMotor { 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; } }; } // namespace iflytop \ No newline at end of file diff --git a/cmdid.hpp b/cmdid.hpp index a9eb223..c24c1ff 100644 --- a/cmdid.hpp +++ b/cmdid.hpp @@ -43,12 +43,14 @@ typedef enum { 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 #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:{} @@ -56,6 +58,7 @@ typedef enum { 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:{} } cmdid_t; diff --git a/protocol_parser.cpp b/protocol_parser.cpp index 78d753e..0d7e76f 100644 --- a/protocol_parser.cpp +++ b/protocol_parser.cpp @@ -178,12 +178,14 @@ void ZIProtocolParser::onRceivePacket(zcr_cmd_header_t* rxcmd, uint8_t* data, in * xymotor * *******************************************************************************/ #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 PROCESS_PACKET_10(kxymotor_enable, ZIXYMotor, xymotor_enable); @@ -192,4 +194,5 @@ void ZIProtocolParser::onRceivePacket(zcr_cmd_header_t* rxcmd, uint8_t* data, in PROCESS_PACKET_00(kxymotor_move_to_zero, ZIXYMotor, xymotor_move_to_zero); PROCESS_PACKET_00(kxymotor_move_to_zero_and_calculated_shift, ZIXYMotor, xymotor_move_to_zero_and_calculated_shift); PROCESS_PACKET_02(kxymotor_read_pos, ZIXYMotor, xymotor_read_pos); + PROCESS_PACKET_00(kxymotor_calculated_pos_by_move_to_zero, ZIXYMotor, xymotor_calculated_pos_by_move_to_zero); } \ No newline at end of file diff --git a/protocol_proxy.cpp b/protocol_proxy.cpp index 96a81fb..1f83194 100644 --- a/protocol_proxy.cpp +++ b/protocol_proxy.cpp @@ -124,12 +124,14 @@ int32_t ZIProtocolProxy::motor_move_to_zero_backward_and_calculated_shift(int32_ * ZIXYMotor * *******************************************************************************/ #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 int32_t ZIProtocolProxy::xymotor_enable(int32_t para0) { PROXY_IMPL_10(kxymotor_enable); } int32_t ZIProtocolProxy::xymotor_move_by(int32_t para0, int32_t para1, int32_t para2) { PROXY_IMPL_30(kxymotor_move_by); } @@ -137,3 +139,4 @@ int32_t ZIProtocolProxy::xymotor_move_to(int32_t para0, int32_t para1, int32_t p int32_t ZIProtocolProxy::xymotor_move_to_zero() { PROXY_IMPL_00(kxymotor_move_to_zero); } int32_t ZIProtocolProxy::xymotor_move_to_zero_and_calculated_shift() { PROXY_IMPL_00(kxymotor_move_to_zero_and_calculated_shift); } int32_t ZIProtocolProxy::xymotor_read_pos(int32_t *ack0, int32_t *ack1) { PROXY_IMPL_02(kxymotor_read_pos); } +int32_t ZIProtocolProxy::xymotor_calculated_pos_by_move_to_zero() { PROXY_IMPL_00(kxymotor_calculated_pos_by_move_to_zero); } diff --git a/protocol_proxy.hpp b/protocol_proxy.hpp index fdf3536..df65c18 100644 --- a/protocol_proxy.hpp +++ b/protocol_proxy.hpp @@ -84,12 +84,14 @@ class ZIProtocolProxy : public ZIMotor, // * ZIXYMotor * *******************************************************************************/ #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 virtual int32_t xymotor_enable(int32_t enable) override; virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) override; @@ -97,6 +99,7 @@ class ZIProtocolProxy : public ZIMotor, // virtual int32_t xymotor_move_to_zero() override; virtual int32_t xymotor_move_to_zero_and_calculated_shift() override; virtual int32_t xymotor_read_pos(int32_t *x, int32_t *y) override; + virtual int32_t xymotor_calculated_pos_by_move_to_zero() override; }; } // namespace iflytop \ No newline at end of file diff --git a/zmodule_device_manager.hpp b/zmodule_device_manager.hpp index 0c68bbb..30cf258 100644 --- a/zmodule_device_manager.hpp +++ b/zmodule_device_manager.hpp @@ -113,12 +113,14 @@ class ZModuleDeviceManager { * ZIXYMotor * *******************************************************************************/ #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 int32_t xymotor_enable(uint16_t id, int32_t enable); int32_t xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity); @@ -126,6 +128,7 @@ class ZModuleDeviceManager { int32_t xymotor_move_to_zero(uint16_t id); int32_t xymotor_move_to_zero_and_calculated_shift(uint16_t id); int32_t xymotor_read_pos(uint16_t id, int32_t *x, int32_t *y); + int32_t xymotor_calculated_pos_by_move_to_zero(uint16_t id); private: diff --git a/zmodule_device_script_cmder_paser.cpp b/zmodule_device_script_cmder_paser.cpp index 4295d77..0866cc9 100644 --- a/zmodule_device_script_cmder_paser.cpp +++ b/zmodule_device_script_cmder_paser.cpp @@ -133,12 +133,14 @@ void ZModuleDeviceScriptCmderPaser::initialize(ICmdParser* cancmder, ZModuleDevi PROCESS_PACKET_50(motor_move_to_zero_backward_and_calculated_shift, "(mid, findzerospeed, findzeroedge_speed, acc, overtime)"); #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 PROCESS_PACKET_20(xymotor_enable, "(mid, enable)"); PROCESS_PACKET_40(xymotor_move_by, "(mid, dx, dy, motor_velocity)"); @@ -146,4 +148,5 @@ void ZModuleDeviceScriptCmderPaser::initialize(ICmdParser* cancmder, ZModuleDevi PROCESS_PACKET_10(xymotor_move_to_zero, "(mid)"); PROCESS_PACKET_10(xymotor_move_to_zero_and_calculated_shift, "(mid)"); PROCESS_PACKET_12(xymotor_read_pos, "(mid)"); + PROCESS_PACKET_10(xymotor_calculated_pos_by_move_to_zero, "(mid)"); }