Browse Source

update

master
zhaohe 2 years ago
parent
commit
f051569d89
  1. 33
      api/basic_type.hpp
  2. 112
      api/i_xyrobot_ctrl_module.hpp
  3. 523
      zcancmder_protocol.hpp
  4. 74
      zcancmder_protocol_basic.hpp

33
api/basic_type.hpp

@ -0,0 +1,33 @@
#pragma once
#include <stdint.h>
namespace iflytop {
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
typedef float f32;
typedef double f64;
typedef enum {
kset_cmd_type_read = 0,
kset_cmd_type_set = 1,
} SetCmdOperationType_t;
typedef enum {
kMotorStopType_stop = 0,
kMotorStopType_break = 1,
} MotorStopType_t;
typedef enum {
kmodule_statu_idle,
kmodule_statu_work,
kmodule_statu_exception,
} module_statu_type_t;
} // namespace iflytop

112
api/i_xyrobot_ctrl_module.hpp

@ -0,0 +1,112 @@
#pragma once
#include <stdint.h>
#include <functional>
#include "basic_type.hpp"
//
namespace iflytop {
using namespace std;
class I_XYRobotCtrlModule {
public:
typedef enum { hbot, corexy } RobotType_t;
typedef enum { kNormalStop, kBreakStop } StopType_t;
/*******************************************************************************
* ACTION *
*******************************************************************************/
typedef struct {
int32_t exec_status;
int32_t tox;
int32_t toy;
} move_to_cb_status_t;
typedef struct {
int32_t exec_status;
int32_t dx;
int32_t dy;
} move_by_cb_status_t;
typedef struct {
int32_t exec_status;
} move_to_zero_cb_status_t;
typedef struct {
int32_t exec_status;
int32_t zero_shift_x;
int32_t zero_shift_y;
} move_to_zero_with_calibrate_cb_status_t;
/*******************************************************************************
* READ *
*******************************************************************************/
typedef struct {
int32_t version;
} version_t;
typedef struct {
uint8_t status;
int32_t x;
int32_t y;
} status_t;
typedef struct {
uint8_t status;
int32_t x;
int32_t y;
} debug_info_t;
/*******************************************************************************
* CFG *
*******************************************************************************/
typedef struct {
u8 robot_type;
u8 x_shaft;
u8 y_shaft;
u8 ihold;
u8 irun;
u16 iholddelay;
s32 distance_scale; // 0.001
s32 shift_x;
s32 shift_y;
s32 acc;
s32 dec;
s32 maxspeed;
s32 min_x;
s32 max_x;
s32 min_y;
s32 max_y;
} run_param_t;
typedef struct {
uint8_t pad;
} warning_limit_param_t;
typedef struct {
u32 move_to_zero_max_d;
u32 leave_from_zero_max_d;
u32 speed;
u32 dec;
} run_to_zero_param_t;
public:
virtual int32_t move_to(int32_t x, int32_t y, function<void(move_to_cb_status_t& status)> status_cb) = 0;
virtual int32_t move_by(int32_t dx, int32_t dy, function<void(move_by_cb_status_t& status)> status_cb) = 0;
virtual int32_t move_to_zero(function<void(move_to_zero_cb_status_t& status)> status_cb) = 0;
virtual int32_t move_to_zero_with_calibrate(int32_t x, int32_t y, function<void(move_to_zero_with_calibrate_cb_status_t& status)> status_cb) = 0;
virtual int32_t enable(bool venable) = 0;
virtual int32_t stop(uint8_t stopType) = 0;
virtual int32_t force_change_current_pos(int32_t x, int32_t y) = 0;
virtual int32_t read_version(version_t& version) = 0;
virtual int32_t read_status(status_t& status) = 0;
virtual int32_t read_debug_info(debug_info_t& debug_info) = 0;
virtual int32_t set_run_param(uint8_t operation, const run_param_t& param, run_param_t& ack) = 0;
virtual int32_t set_run_to_zero_param(uint8_t operation, const run_to_zero_param_t& param, run_to_zero_param_t& ack) = 0;
virtual int32_t set_warning_limit_param(uint8_t operation, const warning_limit_param_t& param, warning_limit_param_t& ack) = 0;
};
} // namespace iflytop

523
zcancmder_protocol.hpp

@ -0,0 +1,523 @@
#pragma once
#include <stdint.h>
#include "api/basic_type.hpp"
#include "api/i_xyrobot_ctrl_module.hpp"
#include "zcancmder_protocol_basic.hpp"
namespace iflytop {
namespace zcr {
typedef enum {
kcmd_ping = CMDID(0, 0),
kcmd_read_io = CMDID(1, 0),
kcmd_set_io = CMDID(2, 0),
kcmd_readadc_raw = CMDID(3, 0),
kcmd_m211887_operation = CMDID(1000, 0), // 维萨拉臭氧传感器
kcmd_read_presure_sensor = CMDID(1001, 0), // 压力传感器
kcmd_triple_warning_light_ctl = CMDID(1002, 0), // 三色警示灯控制
kcmd_high_power_electrical_ctl = CMDID(1003, 0), // 大功率电源控制
kcmd_peristaltic_pump_ctl = CMDID(1004, 0), // 液泵控制
kcmd_read_huacheng_pressure_sensor = CMDID(1005, 0), // 华诚压力传感器
/*******************************************************************************
* |Module_1006:XYRobot机器人控制模组 *
*******************************************************************************/
kcmd_xy_robot_ctrl_enable = CMDID(1006, 0), // 机器人使能
kcmd_xy_robot_ctrl_stop = CMDID(1006, 1), // 机器人停止
kcmd_xy_robot_ctrl_move_to_zero = CMDID(1006, 2), // 机器人回零
kcmd_xy_robot_ctrl_move_to_zero_with_calibrate = CMDID(1006, 3), // 机器人回零并标定
kcmd_xy_robot_ctrl_move_to = CMDID(1006, 4), // 机器人移动到指定位置
kcmd_xy_robot_ctrl_move_by = CMDID(1006, 5), // 机器人移动指定距离
kcmd_xy_robot_ctrl_force_change_current_pos = CMDID(1006, 6), // 强制修改当前位置
kcmd_xy_robot_ctrl_read_version = CMDID(1006, 50), // 读取模块型号版本信息
kcmd_xy_robot_ctrl_read_status = CMDID(1006, 51), // 读取模块精简状态信息
kcmd_xy_robot_ctrl_read_debug_info = CMDID(1006, 52), // 读取模块详细状态信息
kcmd_xy_robot_ctrl_set_run_param = CMDID(1006, 100), // 设置运行参数
kcmd_xy_robot_ctrl_set_warning_limit_param = CMDID(1006, 101), // 设置控制限制参数
kcmd_xy_robot_ctrl_set_run_to_zero_param = CMDID(1006, 102), // 设置归零参数
/*******************************************************************************
* |Module_1007: *
*******************************************************************************/
kcmd_step_motor_ctrl_enable = CMDID(1007, 0), // 使能
kcmd_step_motor_ctrl_stop = CMDID(1007, 1), // 停止
kcmd_step_motor_ctrl_move_to_zero = CMDID(1007, 2), // 回零
kcmd_step_motor_ctrl_move_to_zero_with_calibrate = CMDID(1007, 3), // 回零并校准
kcmd_step_motor_ctrl_move_to = CMDID(1007, 4), // 移动到
kcmd_step_motor_ctrl_move_by = CMDID(1007, 5), // 相对移动
kcmd_step_motor_ctrl_rotate = CMDID(1007, 6), // 相对移动
kcmd_step_motor_ctrl_read_version = CMDID(1007, 50), // 读取模块型号版本信息
kcmd_step_motor_ctrl_read_status = CMDID(1007, 51), // 读取模块精简状态信息
kcmd_step_motor_ctrl_read_debug_info = CMDID(1007, 52), // 读取模块详细状态信息
kcmd_step_motor_ctrl_set_run_param = CMDID(1007, 100), // 设置运行参数
kcmd_step_motor_ctrl_set_warning_limit_param = CMDID(1007, 101), // 设置警告限制参数
kcmd_step_motor_ctrl_set_run_to_zero_param = CMDID(1007, 102), // 设置归零参数
/*******************************************************************************
* |Module_1008: *
*******************************************************************************/
kcmd_mini_servo_ctrl_enable = CMDID(1008, 0), // 使能
kcmd_mini_servo_ctrl_stop = CMDID(1008, 1), // 停止
kcmd_mini_servo_ctrl_position_calibrate = CMDID(1008, 2), // 校准
kcmd_mini_servo_ctrl_rotate = CMDID(1008, 3), // 速度模式
kcmd_mini_servo_ctrl_move_to = CMDID(1008, 4), // 位置模式舵机
kcmd_mini_servo_ctrl_move_by = CMDID(1008, 5), // 位置模式舵机
kcmd_mini_servo_ctrl_run_with_torque = CMDID(1008, 6), // 开环扭矩模式
kcmd_mini_servo_ctrl_move_by_nolimit = CMDID(1008, 7), // 相对移动,位置模式无限制,移动不受最大位置和最小位置限制,但无法读取到当前位置
kcmd_mini_servo_ctrl_read_version = CMDID(1008, 50), // 读取模块型号版本信息
kcmd_mini_servo_ctrl_read_status = CMDID(1008, 51), // 读取模块精简状态信息
kcmd_mini_servo_ctrl_read_debug_info = CMDID(1008, 52), // 读取模块详细状态信息
kcmd_mini_servo_ctrl_set_run_param = CMDID(1008, 100), // 位置限制 最大位置,最小位置
kcmd_mini_servo_ctrl_set_warning_limit_param = CMDID(1008, 101), // 过压保护设置 最大电压 最小电压
/*******************************************************************************
* |Module_1009:EEPROM *
*******************************************************************************/
kcmd_eeprom_read_block = CMDID(1009, 0), // 读取EEPROM
kcmd_eeprom_write_block = CMDID(1009, 1), // 写入EEPROM
/*******************************************************************************
* |Module_1010: *
*******************************************************************************/
kcmd_barcode_reader_start_scan = CMDID(1010, 0), // 读取扫码器
kcmd_barcode_reader_stop_scan = CMDID(1010, 1), // 停止读取扫码器
/*******************************************************************************
* |Module_1011:-- *
*******************************************************************************/
// 设置目标温度
kcmd_heater_ctrl_module_start_ctrl_temperature = CMDID(1011, 0), // 设置目标温度
kcmd_heater_ctrl_module_read_stop_temperature = CMDID(1011, 1), // 读取停止温度
kcmd_heater_ctrl_module_read_version = CMDID(1011, 50), // 读取模块型号版本信息
kcmd_heater_ctrl_module_read_status = CMDID(1011, 51), // 读取模块精简状态信息
kcmd_heater_ctrl_module_read_debug_info = CMDID(1011, 52), // 读取模块详细状态信息
kcmd_heater_ctrl_module_set_run_param = CMDID(1011, 100), // 设置运行参数
kcmd_heater_ctrl_module_set_warning_limit_param = CMDID(1011, 101), // 设置限制参数
/*******************************************************************************
* |Module_1012: *
*******************************************************************************/
kcmd_optical_barcode_reader_start_scan = CMDID(1012, 0), // 开始扫码
kcmd_optical_barcode_reader_stop_scan = CMDID(1012, 1), // 停止扫码
kcmd_optical_barcode_reader_motor_move_to = CMDID(1012, 4), // 水平电机移动到
kcmd_optical_barcode_reader_motor_move_to_zero = CMDID(1012, 6), // 电机校准
kcmd_optical_barcode_reader_motor_move_to_zero_with_calibrate = CMDID(1012, 7), // 电机校准
kcmd_optical_barcode_reader_motor_stop = CMDID(1012, 8), // 电机停止
kcmd_optical_barcode_reader_motor_enable = CMDID(1012, 9), // 电机使能
kcmd_optical_barcode_reader_read_version = CMDID(1012, 50), // 读取模块型号版本信息
kcmd_optical_barcode_reader_read_status = CMDID(1012, 51), // 读取模块精简状态信息
kcmd_optical_barcode_reader_read_debug_info = CMDID(1012, 52), // 读取模块详细状态信息
kcmd_optical_barcode_reader_set_run_param = CMDID(1012, 100), // 设置运行参数
kcmd_optical_barcode_reader_set_warning_limit_param = CMDID(1012, 101), // 设置限制参数
kcmd_optical_barcode_reader_set_run_to_zero_param = CMDID(1012, 102), // 设置归零参数
/*******************************************************************************
* |Module_1013: *
*******************************************************************************/
kcmd_board_clamp_module_push_and_scan = CMDID(1013, 0), // 推出反应板并扫码
kcmd_board_clamp_module_moter_move_to = CMDID(1013, 1), // 电机移动到
kcmd_board_clamp_module_moter_move_by = CMDID(1013, 2), // 电机移动到
kcmd_board_clamp_module_moter_move_to_zero = CMDID(1013, 3), // 电机归零
kcmd_board_clamp_module_moter_move_to_zero_with_calibrate = CMDID(1013, 4), // 电机归零并校准
kcmd_board_clamp_module_moter_stop = CMDID(1013, 5), // 电机停止
kcmd_board_clamp_module_moter_enable = CMDID(1013, 6), // 电机使能
kcmd_board_clamp_module_read_version = CMDID(1013, 50), // 读取模块型号版本信息
kcmd_board_clamp_module_read_status = CMDID(1013, 51), // 读取模块精简状态信息
kcmd_board_clamp_module_read_debug_info = CMDID(1013, 52), // 读取模块详细状态信息
kcmd_board_clamp_module_set_run_param = CMDID(1013, 100), // 设置运行参数
kcmd_board_clamp_module_set_warning_limit_param = CMDID(1013, 101), // 设置限制参数
kcmd_board_clamp_module_set_run_to_zero_param = CMDID(1013, 102), // 设置归零参数
// 风扇
/*******************************************************************************
* |Module_1014: *
*******************************************************************************/
kcmd_fan_module_fan_ctrl = CMDID(1014, 0), // 风扇控制
kcmd_fan_module_fan_read_status = CMDID(1014, 50), // 读取模块精简状态信息
kcmd_fan_module_fan_read_debug_info = CMDID(1014, 51), // 读取模块详细状态信息
// 串口透传
/*******************************************************************************
* |Module_1015: *
*******************************************************************************/
kcmd_serial_module_send_data = CMDID(1015, 0), // 串口透传发送数据
kcmd_serial_module_start_read_data = CMDID(1015, 1), // 串口透传读取数据
kcmd_serial_module_start_stop_data = CMDID(1015, 2), // 串口透传停止读取数据
kcmd_serial_module_read_status = CMDID(1015, 50), // 读取模块状态信息
kcmd_serial_module_set_cfg = CMDID(1015, 100), // 串口透传设置配置
// 移液枪控制
/*******************************************************************************
* |Module_1016: *
*******************************************************************************/
kcmd_pipette_module_z_motor_enable = CMDID(1016, 0), // 使能
kcmd_pipette_module_z_motor_move_to = CMDID(1016, 1), // 移动到
kcmd_pipette_module_z_motor_move_to_zero = CMDID(1016, 2), // 归零
kcmd_pipette_module_z_motor_move_to_zero_with_calibrate = CMDID(1016, 3), // 归零并校准
kcmd_pipette_module_z_motor_stop = CMDID(1016, 4), // 停止
kcmd_pipette_module_take_liquid = CMDID(1016, 4), // 取液体
kcmd_pipette_module_split_liquid = CMDID(1016, 5), // 吐液体
kcmd_pipette_module_take_tip = CMDID(1016, 6), // 取tip
kcmd_pipette_module_remove_tip = CMDID(1016, 7), // 移除tip
kcmd_pipette_module_read_version = CMDID(1016, 50), // 读取模块型号版本信息
kcmd_pipette_module_read_status = CMDID(1016, 51), // 读取模块精简状态信息
kcmd_pipette_module_read_debug_info = CMDID(1016, 52), // 读取模块详细状态信息
kcmd_pipette_module_set_run_param = CMDID(1016, 100), // 设置运行参数
kcmd_pipette_module_set_warning_limit_param = CMDID(1016, 101), // 设置限制参数
kcmd_pipette_module_set_run_to_zero_param = CMDID(1016, 102), // 设置归零参数
} CmdID_t;
#pragma pack(push, 1)
ZPACKET_CMD_ACK(kcmd_ping, //
CMD(u8 boardid;), //
ACK(u8 boardid;));
ZPACKET_CMD_ACK(kcmd_read_io, //
CMD(u8 ioid;), //
ACK(u8 ioid; u8 val;));
ZPACKET_CMD_ACK(kcmd_set_io, //
CMD(u8 ioid; u8 val;), //
ACK(u8 ioid; u8 val;));
ZPACKET_CMD_ACK(kcmd_readadc_raw, //
CMD(u8 sensorid;), //
ACK(u8 sensorid; s32 val;));
/*******************************************************************************
* |Module_1006:XYRobot机器人控制模组 *
*******************************************************************************/
// ACTION
ZPACKET_CMD_ACK(kcmd_xy_robot_ctrl_enable, CMD(u8 id; u8 enable;), ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_xy_robot_ctrl_stop, CMD(u8 id; u8 stop_type;), ACK(u8 id;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_xy_robot_ctrl_move_to_zero, CMD(u8 id;), ACK(u8 id;), REPORT(u8 id; I_XYRobotCtrlModule::move_to_zero_cb_status_t status;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_xy_robot_ctrl_move_to_zero_with_calibrate, CMD(u8 id; s32 nowx; s32 nowy;), ACK(u8 id;), REPORT(u8 id; I_XYRobotCtrlModule::move_to_zero_with_calibrate_cb_status_t status;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_xy_robot_ctrl_move_to, CMD(u8 id; s32 x; s32 y; s32 speed;), ACK(u8 id;), REPORT(u8 id; I_XYRobotCtrlModule::move_to_cb_status_t status;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_xy_robot_ctrl_move_by, CMD(u8 id; s32 dx; s32 dy; s32 speed;), ACK(u8 id;), REPORT(u8 id; I_XYRobotCtrlModule::move_by_cb_status_t status;));
ZPACKET_CMD_ACK(kcmd_xy_robot_ctrl_force_change_current_pos, CMD(u8 id; s32 x; s32 y;), ACK(u8 id;));
// READ
ZPACKET_CMD_ACK(kcmd_xy_robot_ctrl_read_version, CMD(u8 id;), ACK(u8 id; I_XYRobotCtrlModule::version_t ack;));
ZPACKET_CMD_ACK(kcmd_xy_robot_ctrl_read_status, CMD(u8 id;), ACK(u8 id; I_XYRobotCtrlModule::status_t ack;));
ZPACKET_CMD_ACK(kcmd_xy_robot_ctrl_read_debug_info, CMD(u8 id;), ACK(u8 id; I_XYRobotCtrlModule::debug_info_t ack;));
// SET
ZPACKET_CMD_ACK(kcmd_xy_robot_ctrl_set_run_param, CMD(u8 id; u8 opt_type; I_XYRobotCtrlModule::run_param_t param;), ACK(u8 id; I_XYRobotCtrlModule::run_param_t ack;));
ZPACKET_CMD_ACK(kcmd_xy_robot_ctrl_set_warning_limit_param, CMD(u8 id; u8 opt_type; I_XYRobotCtrlModule::warning_limit_param_t param;), ACK(u8 id; I_XYRobotCtrlModule::warning_limit_param_t ack;));
ZPACKET_CMD_ACK(kcmd_xy_robot_ctrl_set_run_to_zero_param, CMD(u8 id; u8 opt_type; I_XYRobotCtrlModule::run_to_zero_param_t param;), ACK(u8 id; I_XYRobotCtrlModule::run_to_zero_param_t ack;));
/*******************************************************************************
* |Module_1007: *
*******************************************************************************/
ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_enable,
CMD(u8 id; u8 enable;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_stop,
CMD(u8 id; u8 stop_type;), //
ACK(u8 id;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_move_to_zero,
CMD(u8 id;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_move_to_zero_with_calibrate,
CMD(u8 id; s32 nowx; s32 nowy;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 zero_shift_x;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_move_to,
CMD(u8 id; s32 x; s32 speed;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; u32 x;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_move_by,
CMD(u8 id; s32 dx; s32 speed;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 dx;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_step_motor_ctrl_rotate,
CMD(u8 id; s32 speed; s32 run_time;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 has_run_time;));
ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_read_version, //
CMD(u8 id;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_read_status, //
CMD(u8 id;), //
ACK(u8 id; u8 status; s32 x; s32 velocity;));
ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_read_debug_info, //
CMD(u8 id;), //
ACK(u8 id; u8 status; s32 x; s32 velocity; s32 acc; s32 dec; s32 speed;));
ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_set_run_param, //
CMD(u8 id; u8 opt_type; u8 shaft; s32 d_scale; s32 x_shift; s32 acc; s32 dec; s32 breakdec; s32 maxv; s32 minpos; s32 maxpos;), //
ACK(u8 id; u8 opt_type; u8 shaft; s32 d_scale; s32 x_shift; s32 acc; s32 dec; s32 breakdec; s32 maxv; s32 minpos; s32 maxpos;));
ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_set_warning_limit_param, //
CMD(u8 id; u8 opt_type; s32 pad;), //
ACK(u8 id; u8 opt_type; s32 pad;));
ZPACKET_CMD_ACK(kcmd_step_motor_ctrl_set_run_to_zero_param, //
CMD(u8 id; u8 opt_type; u32 move_to_zero_max_d; u32 leave_from_zero_max_d; u32 speed; u32 dec;), //
ACK(u8 id; u8 opt_type; u32 move_to_zero_max_d; u32 leave_from_zero_max_d; u32 speed; u32 dec;));
/*******************************************************************************
* |Module_1008: *
*******************************************************************************/
ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_enable,
CMD(u8 id; u8 enable;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_stop,
CMD(u8 id; u8 stop_type;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_mini_servo_ctrl_position_calibrate,
CMD(u8 id; s32 calibrate_pos;), //
ACK(u8 id;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_mini_servo_ctrl_rotate,
CMD(u8 id; s32 speed; s32 run_time;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 has_run_time;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_mini_servo_ctrl_move_to,
CMD(u8 id; s32 pos; s32 speed; s32 torque;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 pos;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_mini_servo_ctrl_move_by,
CMD(u8 id; s32 pos; s32 speed; s32 torque;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 pos;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_mini_servo_ctrl_run_with_torque,
CMD(u8 id; s32 torque; s32 run_time;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 has_run_time;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_mini_servo_ctrl_move_by_nolimit,
CMD(u8 id; s32 pos; s32 speed; s32 torque;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 pos;));
/*******************************************************************************
* |Module_1009:EEPROM *
*******************************************************************************/
ZPACKET_CMD_ACK(kcmd_eeprom_read_block,
CMD(u8 id; u16 addr; u16 len;), //
ACK(u8 id; u16 addr; u16 len; u8 data[0];));
ZPACKET_CMD_ACK(kcmd_eeprom_write_block,
CMD(u8 id; u16 addr; u16 len; u8 data[0];), //
ACK(u8 id; u16 addr; u16 len;));
/*******************************************************************************
* |Module_1010: *
*******************************************************************************/
ZPACKET_CMD_ACK_AND_REPORT(kcmd_barcode_reader_start_scan,
CMD(u8 id;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; u16 barcodelen; u8 barcode[0];));
ZPACKET_CMD_ACK(kcmd_barcode_reader_stop_scan,
CMD(u8 id;), //
ACK(u8 id;));
/*******************************************************************************
* |Module_1011:-- *
*******************************************************************************/
ZPACKET_CMD_ACK(kcmd_heater_ctrl_module_start_ctrl_temperature,
CMD(u8 id; s32 target_temperature;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_heater_ctrl_module_read_stop_temperature,
CMD(u8 id;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_heater_ctrl_module_read_version,
CMD(u8 id;), //
ACK(u8 id; uint32_t version;));
ZPACKET_CMD_ACK(kcmd_heater_ctrl_module_read_status,
CMD(u8 id;), //
ACK(u8 id; u8 status; s32 temperature;));
ZPACKET_CMD_ACK(kcmd_heater_ctrl_module_read_debug_info,
CMD(u8 id;), //
ACK(u8 id; u8 status; s32 temperature;));
ZPACKET_CMD_ACK(kcmd_heater_ctrl_module_set_run_param,
CMD(u8 id; u8 opt_type; s32 kp; s32 ki; s32 kd; s32 max_pwm; s32 min_temperature; s32 max_temperature;), //
ACK(u8 id; u8 opt_type; s32 kp; s32 ki; s32 kd; s32 max_pwm; s32 min_temperature; s32 max_temperature;));
ZPACKET_CMD_ACK(kcmd_heater_ctrl_module_set_warning_limit_param,
CMD(u8 id; u8 opt_type;), //
ACK(u8 id; u8 opt_type;));
/*******************************************************************************
* |Module_1012: *
*******************************************************************************/
ZPACKET_CMD_ACK_AND_REPORT(kcmd_optical_barcode_reader_start_scan,
CMD(u8 id;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; u16 codelen; u16 code[0];));
ZPACKET_CMD_ACK(kcmd_optical_barcode_reader_stop_scan,
CMD(u8 id;), //
ACK(u8 id;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_optical_barcode_reader_motor_move_to,
CMD(u8 id; u8 motor_id; s32 pos; s32 speed;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 pos;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_optical_barcode_reader_motor_move_to_zero,
CMD(u8 id; u8 motor_id;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_optical_barcode_reader_motor_move_to_zero_with_calibrate,
CMD(u8 id; u8 motor_id; s32 now_pos;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 zero_shift;));
ZPACKET_CMD_ACK(kcmd_optical_barcode_reader_motor_stop,
CMD(u8 id; u8 motor_id;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_optical_barcode_reader_read_version,
CMD(u8 id;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_optical_barcode_reader_read_status,
CMD(u8 id;), //
ACK(u8 id; u8 status; u8 hasmove2zero[2]; s32 pos[2];));
ZPACKET_CMD_ACK(kcmd_optical_barcode_reader_read_debug_info,
CMD(u8 id;), //
ACK(u8 id; u8 status; u8 hasmove2zero[2]; s32 pos[2]; s32 acc[2]; s32 speed[2];));
ZPACKET_CMD_ACK(kcmd_optical_barcode_reader_set_run_param, //
CMD(u8 id; u8 opt_type; s32 acc[2]; s32 dec[2]; s32 max_speed[2]; s32 min_pos[2]; s32 max_pos[2];), //
ACK(u8 id; u8 opt_type; s32 acc[2]; s32 dec[2]; s32 max_speed[2]; s32 min_pos[2]; s32 max_pos[2];));
ZPACKET_CMD_ACK(kcmd_optical_barcode_reader_set_warning_limit_param,
CMD(u8 id; u8 opt_type; s32 pad;), //
ACK(u8 id; u8 opt_type; s32 pad;));
ZPACKET_CMD_ACK(kcmd_optical_barcode_reader_set_run_to_zero_param,
CMD(u8 id; u8 opt_type; s32 move_to_zero_max_d[2]; s32 leave_from_zero_max_d[2]; s32 speed[2]; s32 dec[2];), //
ACK(u8 id; u8 opt_type; s32 move_to_zero_max_d[2]; s32 leave_from_zero_max_d[2]; s32 speed[2]; s32 dec[2];));
/*******************************************************************************
* Module_1013: *
*******************************************************************************/
ZPACKET_CMD_ACK_AND_REPORT(kcmd_board_clamp_module_push_and_scan,
CMD(u8 id;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; u16 barcodelen; u8 barcode[0];));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_board_clamp_module_moter_move_to,
CMD(u8 id; u8 motor_id; s32 pos; s32 speed;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 pos;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_board_clamp_module_moter_move_by,
CMD(u8 id; u8 motor_id; s32 pos; s32 speed;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 pos;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_board_clamp_module_moter_move_to_zero,
CMD(u8 id; u8 motor_id;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_board_clamp_module_moter_move_to_zero_with_calibrate,
CMD(u8 id; u8 motor_id; s32 now_pos;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 zero_shift;));
ZPACKET_CMD_ACK(kcmd_board_clamp_module_moter_stop,
CMD(u8 id; u8 motor_id;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_board_clamp_module_read_version,
CMD(u8 id;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_board_clamp_module_read_status,
CMD(u8 id;), //
ACK(u8 id; u8 status; u8 hasmove2zero[2]; s32 pos[2];));
ZPACKET_CMD_ACK(kcmd_board_clamp_module_read_debug_info,
CMD(u8 id;), //
ACK(u8 id; u8 status; u8 hasmove2zero[2]; s32 pos[2]; s32 acc[2]; s32 speed[2];));
ZPACKET_CMD_ACK(kcmd_board_clamp_module_set_run_param, //
CMD(u8 id; u8 opt_type; s32 acc[2]; s32 dec[2]; s32 max_speed[2]; s32 min_pos[2]; s32 max_pos[2];), //
ACK(u8 id; u8 opt_type; s32 acc[2]; s32 dec[2]; s32 max_speed[2]; s32 min_pos[2]; s32 max_pos[2];));
ZPACKET_CMD_ACK(kcmd_board_clamp_module_set_warning_limit_param,
CMD(u8 id; u8 opt_type; s32 pad;), //
ACK(u8 id; u8 opt_type; s32 pad;));
ZPACKET_CMD_ACK(kcmd_board_clamp_module_set_run_to_zero_param,
CMD(u8 id; u8 opt_type; s32 move_to_zero_max_d[2]; s32 leave_from_zero_max_d[2]; s32 speed[2]; s32 dec[2];), //
ACK(u8 id; u8 opt_type; s32 move_to_zero_max_d[2]; s32 leave_from_zero_max_d[2]; s32 speed[2]; s32 dec[2];));
/*******************************************************************************
* |Module_1014: *
*******************************************************************************/
ZPACKET_CMD_ACK(kcmd_fan_module_fan_ctrl,
CMD(u8 id; u8 level;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_fan_module_fan_read_status,
CMD(u8 id;), //
ACK(u8 id; u8 status; u8 level;));
ZPACKET_CMD_ACK(kcmd_fan_module_fan_read_debug_info,
CMD(u8 id;), //
ACK(u8 id; u8 status; u8 level; int16_t fbcount;));
/*******************************************************************************
* |Module_1016: *
*******************************************************************************/
ZPACKET_CMD_ACK(kcmd_pipette_module_motor_enable,
CMD(u8 id; u8 enable;), //
ACK(u8 id;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_pipette_module_motor_move_to,
CMD(u8 id; u8 motor_id; s32 pos; s32 speed;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 pos;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_pipette_module_motor_move_to_zero,
CMD(u8 id; u8 motor_id;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status;));
ZPACKET_CMD_ACK_AND_REPORT(kcmd_pipette_module_motor_move_to_zero_with_calibrate,
CMD(u8 id; u8 motor_id; s32 now_pos;), //
ACK(u8 id;), //
REPORT(u8 id; u8 status; s32 zero_shift;));
ZPACKET_CMD_ACK(kcmd_pipette_module_motor_stop,
CMD(u8 id; u8 motor_id;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_pipette_module_take_liquid,
CMD(u8 id; u8 motor_id; s32 speed; s32 pos;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_pipette_module_split_liquid,
CMD(u8 id; u8 motor_id; s32 speed; s32 pos;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_pipette_module_take_tip,
CMD(u8 id; u8 motor_id; s32 speed; s32 pos;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_pipette_module_remove_tip,
CMD(u8 id; u8 motor_id; s32 speed; s32 pos;), //
ACK(u8 id;));
#if 0
kcmd_pipette_module_read_status = CMDID(1016, 51), // 读取模块精简状态信息
kcmd_pipette_module_read_debug_info = CMDID(1016, 52), // 读取模块详细状态信息
kcmd_pipette_module_set_run_param = CMDID(1016, 100), // 设置运行参数
kcmd_pipette_module_set_warning_limit_param = CMDID(1016, 101), // 设置限制参数
kcmd_pipette_module_set_run_to_zero_param = CMDID(1016, 102), // 设置归零参数
#endif
ZPACKET_CMD_ACK(kcmd_pipette_module_read_version,
CMD(u8 id;), //
ACK(u8 id;));
ZPACKET_CMD_ACK(kcmd_pipette_module_read_status,
CMD(u8 id;), //
ACK(u8 id; u8 status; s32 pos[2];));
ZPACKET_CMD_ACK(kcmd_pipette_module_read_debug_info,
CMD(u8 id;), //
ACK(u8 id; u8 status; s32 pos[2]; s32 acc[2]; s32 speed[2];));
ZPACKET_CMD_ACK(kcmd_pipette_module_set_run_param,
CMD(u8 id; u8 opt_type; s32 acc[2]; s32 dec[2]; s32 max_speed[2]; s32 min_pos[2]; s32 max_pos[2];), //
ACK(u8 id; u8 opt_type; s32 acc[2]; s32 dec[2]; s32 max_speed[2]; s32 min_pos[2]; s32 max_pos[2];));
ZPACKET_CMD_ACK(kcmd_pipette_module_set_warning_limit_param,
CMD(u8 id; u8 opt_type; s32 pad;), //
ACK(u8 id; u8 opt_type; s32 pad;));
#pragma pack(pop)
} // namespace zcr
} // namespace iflytop

74
zcancmder_protocol_basic.hpp

@ -0,0 +1,74 @@
#pragma once
#include <stdint.h>
#define ZPACKET_STRUCT(ordername, type, ...) \
typedef struct { \
__VA_ARGS__ \
} ordername##_##type##_t
#define ZPACKET_CMD_ACK(ordername, cmdpara, ackpara) \
typedef struct { \
cmdpara \
} ordername##_##cmd##_t; \
typedef struct { \
ackpara \
} ordername##_##ack##_t
#define ZPACKET_CMD_ACK_AND_REPORT(ordername, cmdpara, ackpara, reportpara) \
typedef struct { \
cmdpara \
} ordername##_##cmd##_t; \
typedef struct { \
ackpara \
} ordername##_##ack##_t; \
typedef struct { \
reportpara \
} ordername##_##report##_t
#define PROCESS_PACKET(ordername, varid) \
if (rxcmd->iscmd(ordername)) { \
auto* cmd = rxcmd->get_data_as<ordername##_##cmd##_t>(); \
auto* ack = (ordername##_##ack##_t*)m_txbuf; \
auto cmdheader = rxcmd->get_cmdheader(); \
uint32_t errorcode = 0; \
if (cmd->id == varid) { \
ack->id = cmd->id;
#define END_PROCESS_PACKET() \
if (errorcode == 0) { \
m_cancmder->sendAck(rxcmd->get_cmdheader(), m_txbuf, sizeof(*ack)); \
} else { \
m_cancmder->sendErrorAck(rxcmd->get_cmdheader(), errorcode); \
} \
} \
return; \
}
#define END_PP END_PROCESS_PACKET
#define CMD(x) x
#define ACK(x) x
#define REPORT(x) x
namespace iflytop {
namespace zcr {
#pragma pack(push, 1)
typedef struct {
uint16_t packetindex;
uint16_t cmdid;
uint8_t subcmdid;
uint8_t packetType;
uint8_t data[];
} Cmdheader_t;
#pragma pack(pop)
typedef enum {
kpt_cmd = 0,
kpt_ack = 1,
kpt_error_ack = 2,
kpt_cmd_exec_status_report = 3,
} PacketType_t;
#define CMDID(cmdid, subcmdid) ((cmdid << 8) + subcmdid)
} // namespace zcr
} // namespace iflytop
Loading…
Cancel
Save