21 changed files with 884 additions and 3 deletions
-
3README.md
-
8api/api.hpp
-
12api/config_index.hpp
-
81api/errorcode.cpp
-
106api/errorcode.hpp
-
43api/i_cmdparser.hpp
-
26api/i_zcan_cmder.hpp
-
21api/i_zcan_cmder_master.hpp
-
31api/packet_interface.hpp
-
29api/zi_module.hpp
-
21api/zi_motor.hpp
-
17api/zi_xymotor.hpp
-
30cmdid.hpp
-
100protocol_parser.cpp
-
19protocol_parser.hpp
-
101protocol_proxy.cpp
-
58protocol_proxy.hpp
-
37zmodule_device_manager.cpp
-
67zmodule_device_manager.hpp
-
57zmodule_device_script_cmder_paser.cpp
-
20zmodule_device_script_cmder_paser.hpp
@ -1,3 +0,0 @@ |
|||
# zcancmder_v2 |
|||
|
|||
zcancmder_v2 |
@ -0,0 +1,8 @@ |
|||
#pragma once
|
|||
#include "config_index.hpp"
|
|||
#include "errorcode.hpp"
|
|||
#include "zi_module.hpp"
|
|||
#include "zi_motor.hpp"
|
|||
#include "zi_xymotor.hpp"
|
|||
#include "packet_interface.hpp"
|
|||
#include "i_zcan_cmder.hpp"
|
@ -0,0 +1,12 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
|
|||
#define CONFIG_CODE(type, subconfigindex) (type + subconfigindex)
|
|||
typedef enum { |
|||
|
|||
} config_index_t; |
|||
|
|||
} // namespace iflytop
|
@ -0,0 +1,81 @@ |
|||
#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(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(kce_device_not_zero); |
|||
ERR2STR(kce_over_temperature); |
|||
ERR2STR(kce_over_voltage); |
|||
ERR2STR(kce_param_out_of_range); |
|||
ERR2STR(kce_not_found_zero_point); |
|||
ERR2STR(kce_not_found_x_zero_point); |
|||
ERR2STR(kce_not_found_y_zero_point); |
|||
ERR2STR(kce_x_leave_away_zero_point_fail); |
|||
ERR2STR(kce_y_leave_away_zero_point_fail); |
|||
ERR2STR(kce_operation_not_support); |
|||
ERR2STR(kce_device_is_busy); |
|||
ERR2STR(kce_device_is_offline); |
|||
ERR2STR(kce_break_by_user); |
|||
ERR2STR(kce_overtime); |
|||
ERR2STR(kce_noack); |
|||
ERR2STR(kce_errorack); |
|||
ERR2STR(kce_device_offline); |
|||
ERR2STR(kce_parse_json_err); |
|||
ERR2STR(kce_subdevice_overtime); |
|||
ERR2STR(kdbe_user_not_exist); |
|||
ERR2STR(kdbe_catch_exception); |
|||
ERR2STR(kharde_unfound); |
|||
ERR2STR(kre_catch_exception); |
|||
ERR2STR(kinteraction_error_passwd_error); |
|||
ERR2STR(kinteraction_error_user_not_exist); |
|||
ERR2STR(kce_buffer_not_enough); |
|||
ERR2STR(kce_cmd_not_found); |
|||
ERR2STR(kce_cmd_param_num_error); |
|||
ERR2STR(kce_no_such_module); |
|||
|
|||
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); |
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
} // namespace err
|
|||
} // namespace iflytop
|
@ -0,0 +1,106 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
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), |
|||
|
|||
/**
|
|||
* @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 50000通用 |
|||
*/ |
|||
kce_device_not_zero = ERROR_CODE(10000, 0), // 设备未归零
|
|||
kce_over_temperature = ERROR_CODE(10000, 1), // 过温
|
|||
kce_over_voltage = ERROR_CODE(10000, 2), // 过压
|
|||
kce_param_out_of_range = ERROR_CODE(10000, 3), // 参数超出范围
|
|||
kce_not_found_zero_point = ERROR_CODE(10000, 4), // 未找到零点
|
|||
kce_not_found_x_zero_point = ERROR_CODE(10000, 5), // 未找到零点
|
|||
kce_not_found_y_zero_point = ERROR_CODE(10000, 6), // 未找到零点
|
|||
kce_x_leave_away_zero_point_fail = ERROR_CODE(10000, 7), // 离开零点失败
|
|||
kce_y_leave_away_zero_point_fail = ERROR_CODE(10000, 8), // 离开零点失败
|
|||
kce_operation_not_support = ERROR_CODE(10000, 9), // 操作不支持
|
|||
kce_device_is_busy = ERROR_CODE(10000, 10), // 设备忙
|
|||
kce_device_is_offline = ERROR_CODE(10000, 11), // 设备离线
|
|||
kce_break_by_user = ERROR_CODE(10000, 12), // 用户中断
|
|||
kce_overtime = ERROR_CODE(10000, 13), |
|||
kce_noack = ERROR_CODE(10000, 14), |
|||
kce_errorack = ERROR_CODE(10000, 15), |
|||
kce_device_offline = ERROR_CODE(10000, 16), |
|||
kce_parse_json_err = ERROR_CODE(10000, 17), |
|||
kce_subdevice_overtime = ERROR_CODE(10000, 18), |
|||
kdbe_user_not_exist = ERROR_CODE(10000, 19), |
|||
kdbe_catch_exception = ERROR_CODE(10000, 20), |
|||
kharde_unfound = ERROR_CODE(10000, 21), |
|||
kre_catch_exception = ERROR_CODE(10000, 22), |
|||
kinteraction_error_passwd_error = ERROR_CODE(10000, 23), // 密码错误
|
|||
kinteraction_error_user_not_exist = ERROR_CODE(10000, 24), // 用户不存在
|
|||
kce_buffer_not_enough = ERROR_CODE(10000, 25), |
|||
kce_cmd_not_found = ERROR_CODE(10000, 26), |
|||
kce_cmd_param_num_error = ERROR_CODE(10000, 27), |
|||
kce_no_such_module = ERROR_CODE(10000, 28), |
|||
kce_modbusCRC16checkfail = ERROR_CODE(10000, 29), |
|||
|
|||
/**
|
|||
* @brief STMP2错误 |
|||
*/ |
|||
kSMTP2_NoError = ERROR_CODE(20000, 0), // 无错误
|
|||
kSMTP2_InitFail = ERROR_CODE(20000, 1), // 初始化失败
|
|||
kSMTP2_InvalidCmd = ERROR_CODE(20000, 2), // 无效命令
|
|||
kSMTP2_InvalidArg = ERROR_CODE(20000, 3), // 无效参数
|
|||
kSMTP2_PressureSensorError = ERROR_CODE(20000, 4), // 压力传感器故障
|
|||
kSMTP2_OverPressure = ERROR_CODE(20000, 5), // 超过压力
|
|||
kSMTP2_LLDError = ERROR_CODE(20000, 6), // LLD 错误
|
|||
kSMTP2_DeviceNotInit = ERROR_CODE(20000, 7), // 设备未初始化
|
|||
kSMTP2_TipPopError = ERROR_CODE(20000, 8), // Tip 弹出错误
|
|||
kSMTP2_PumpOverload = ERROR_CODE(20000, 9), // 泵过载
|
|||
kSMTP2_TipDrop = ERROR_CODE(20000, 10), // Tip 脱落
|
|||
kSMTP2_CanBusError = ERROR_CODE(20000, 11), // CAN 总线故障
|
|||
kSMTP2_InvalidChecksum = ERROR_CODE(20000, 12), // 无效校验和
|
|||
kSMTP2_EEPROMError = ERROR_CODE(20000, 13), // EEPROM 故障
|
|||
kSMTP2_CmdBufferEmpty = ERROR_CODE(20000, 14), // 命令缓冲区为空
|
|||
kSMTP2_CmdBufferOverflow = ERROR_CODE(20000, 15), // 命令溢出
|
|||
kSMTP2_TipBlock = ERROR_CODE(20000, 16), // Tip 堵塞
|
|||
kSMTP2_AirSuction = ERROR_CODE(20000, 17), // 吸入空气
|
|||
kSMTP2_Bubble = ERROR_CODE(20000, 18), // 液体中有气泡/泡沫
|
|||
kSMTP2_VolumeError = ERROR_CODE(20000, 19), // 吸取/分配量不准确
|
|||
kSMTP2_TipAlreadyLoad = ERROR_CODE(20000, 20), // Tip已经装载
|
|||
kSMTP2_TipLoadFail = ERROR_CODE(20000, 21), |
|||
|
|||
/**
|
|||
* @brief 单片机硬件错误 |
|||
*/ |
|||
kmicro_noErr = ERROR_CODE(20050, 0), //
|
|||
kmicro_uartSendFail = ERROR_CODE(20050, 1), //
|
|||
kmicro_uartRecvFail = ERROR_CODE(20050, 2), //
|
|||
|
|||
/**
|
|||
* @brief modbus错误 |
|||
*/ |
|||
|
|||
} error_t; |
|||
|
|||
const char* error2str(int32_t code); |
|||
|
|||
} // namespace err
|
|||
} // namespace iflytop
|
@ -0,0 +1,43 @@ |
|||
//
|
|||
// Created by zwsd
|
|||
//
|
|||
|
|||
#pragma once
|
|||
#include <functional>
|
|||
|
|||
#include "config_index.hpp"
|
|||
#include "errorcode.hpp"
|
|||
#include "packet_interface.hpp"
|
|||
namespace iflytop { |
|||
using namespace zcr; |
|||
|
|||
class ICmdParserACK { |
|||
public: |
|||
typedef enum { |
|||
kAckType_none, |
|||
kAckType_int32, |
|||
kAckType_buf, |
|||
} ICmdParserACKType_t; |
|||
|
|||
public: |
|||
int32_t ecode; |
|||
ICmdParserACKType_t acktype; |
|||
uint8_t rawdata[512]; |
|||
int32_t rawlen; |
|||
|
|||
int32_t *getAck(int index) { |
|||
if (index < 0 || index >= rawlen / sizeof(int32_t)) { |
|||
return nullptr; |
|||
} |
|||
return (int32_t *)rawdata + index; |
|||
} |
|||
}; |
|||
|
|||
typedef function<void(int32_t paramN, const char *paraV[], ICmdParserACK *ack)> ICmdFunction_t; |
|||
|
|||
class ICmdParser { |
|||
public: |
|||
virtual void regCMD(const char *cmdname, const char *helpinfo, int paraNum, ICmdFunction_t cmdimpl) = 0; |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -0,0 +1,26 @@ |
|||
//
|
|||
// Created by zwsd
|
|||
//
|
|||
|
|||
#pragma once
|
|||
#include "config_index.hpp"
|
|||
#include "errorcode.hpp"
|
|||
#include "packet_interface.hpp"
|
|||
namespace iflytop { |
|||
using namespace zcr; |
|||
|
|||
class IZcanCmderListener { |
|||
public: |
|||
virtual void onRceivePacket(cmd_header_t *rxcmd, uint8_t *data, int32_t len) = 0; |
|||
}; |
|||
|
|||
class IZCanCmder { |
|||
public: |
|||
public: |
|||
virtual void registerListener(IZcanCmderListener *listener) = 0; |
|||
virtual void sendAck(cmd_header_t *rx_cmd_header, uint8_t *data, int32_t len) = 0; |
|||
virtual void sendAck(cmd_header_t *rx_cmd_header, int32_t *ackvar, uint8_t nack) = 0; |
|||
virtual void sendErrorAck(cmd_header_t *rx_cmd_header, int32_t errorcode) = 0; |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -0,0 +1,21 @@ |
|||
//
|
|||
// Created by zwsd
|
|||
//
|
|||
|
|||
#pragma once
|
|||
#include <functional>
|
|||
|
|||
#include "config_index.hpp"
|
|||
#include "errorcode.hpp"
|
|||
#include "packet_interface.hpp"
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
using namespace zcr; |
|||
|
|||
class IZcanCmderMaster { |
|||
public: |
|||
virtual int32_t sendCmd(int32_t cmdid, int32_t subcmdid, int32_t *param, size_t npara, int32_t *ack, size_t nack, int overtime_ms) = 0; |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -0,0 +1,31 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
namespace iflytop { |
|||
namespace zcr { |
|||
#pragma pack(push, 1)
|
|||
typedef struct { |
|||
uint16_t packetindex; |
|||
uint16_t cmdmoduleid; |
|||
uint8_t subcmdid; |
|||
uint8_t packetType; |
|||
uint16_t submoduleid; |
|||
uint8_t data[]; |
|||
} cmd_header_t; |
|||
#pragma pack(pop)
|
|||
|
|||
typedef enum { |
|||
kpt_cmd = 0, |
|||
kpt_ack = 1, |
|||
kpt_error_ack = 2, |
|||
} packet_type_t; |
|||
|
|||
} // namespace zcr
|
|||
} // namespace iflytop
|
|||
|
|||
#define CMDID(cmdid, subcmdid) ((cmdid << 8) + subcmdid)
|
|||
#define SUBCMDID(cmdid) (cmdid & 0xff)
|
|||
#define MODULE_CMDID(cmdid) (cmdid >> 8)
|
|||
|
|||
#define ZCAN_CMD_PUBLIC_DEVICE_ID_STEP_MOTOR_BOARD_OFFEST 200
|
|||
#define ZCAN_CMD_PUBLIC_DEVICE_ID_XY_ROBOT_BOARD_OFFEST 230
|
@ -0,0 +1,29 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
#include <functional>
|
|||
|
|||
#include "errorcode.hpp"
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
class ZIModule { |
|||
public: |
|||
virtual ~ZIModule() {} |
|||
|
|||
virtual int32_t getid(int32_t *id) = 0; |
|||
|
|||
virtual int32_t stop() = 0; |
|||
virtual int32_t brake() = 0; |
|||
virtual int32_t get_last_exec_status(int32_t *status) = 0; |
|||
virtual int32_t get_status(int32_t *status) = 0; |
|||
|
|||
virtual int32_t set_param( int32_t param_id, int32_t param_value) { return err::kce_operation_not_support; } |
|||
virtual int32_t get_param( int32_t param_id, int32_t *param_value) { return err::kce_operation_not_support; } |
|||
|
|||
virtual int32_t readio(int32_t *io) { return err::kce_operation_not_support; } |
|||
virtual int32_t writeio(int32_t io) { return err::kce_operation_not_support; } |
|||
|
|||
virtual int32_t read_adc(int adcindex, int32_t *adc) { return err::kce_operation_not_support; } |
|||
}; |
|||
} // namespace iflytop
|
@ -0,0 +1,21 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
#include <functional>
|
|||
|
|||
#include "errorcode.hpp"
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
class ZIMotor { |
|||
public: |
|||
virtual ~ZIMotor() {} |
|||
virtual int32_t motor_enable(int32_t enable) { return err::kce_operation_not_support; } |
|||
virtual int32_t motor_rotate(int32_t direction, int32_t velocitylevel) { return err::kce_operation_not_support; } |
|||
virtual int32_t motor_move_by(int32_t distance, int32_t velocitylevel) { return err::kce_operation_not_support; } |
|||
virtual int32_t motor_move_to(int32_t position, int32_t velocitylevel) { return err::kce_operation_not_support; } |
|||
virtual int32_t motor_move_to_with_torque(int32_t pos, int32_t torque) { return err::kce_operation_not_support; } |
|||
|
|||
// s32 pos, s32 speed, s32 torque,
|
|||
}; |
|||
} // namespace iflytop
|
@ -0,0 +1,17 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
|
|||
#include <functional>
|
|||
|
|||
#include "errorcode.hpp"
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
class ZIXYMotor { |
|||
public: |
|||
virtual ~ZIXYMotor() {} |
|||
virtual int32_t xymotor_enable(bool enable) { return err::kce_operation_not_support; } |
|||
virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t velocitylevel) { return err::kce_operation_not_support; } |
|||
virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t velocitylevel) { return err::kce_operation_not_support; } |
|||
}; |
|||
} // namespace iflytop
|
@ -0,0 +1,30 @@ |
|||
#pragma once
|
|||
#include "api/api.hpp"
|
|||
|
|||
namespace iflytop { |
|||
namespace zcr { |
|||
typedef enum { |
|||
kmodule_stop = CMDID(1, 1), // para:{}, ack:{}
|
|||
kmodule_brake = 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_param = CMDID(1, 5), // para:{4,4}, ack:{}
|
|||
kmodule_get_param = 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}
|
|||
|
|||
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_move_to_with_torque = CMDID(2, 5), // para:{4,4}, ack:{}
|
|||
|
|||
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:{}
|
|||
|
|||
} cmdid_t; |
|||
|
|||
} // namespace zcr
|
|||
} // namespace iflytop
|
@ -0,0 +1,100 @@ |
|||
#include "protocol_parser.hpp"
|
|||
|
|||
using namespace iflytop; |
|||
using namespace std; |
|||
#define TAG "ZIProtocolParser"
|
|||
|
|||
#define PROCESS_PACKET_BEGIN(var_cmdid, var_moduleType) \
|
|||
int32_t* param = (int32_t*)data; \ |
|||
int paramNum = (len - sizeof(cmd_header_t)) / sizeof(int32_t); \ |
|||
if (cmdid == var_cmdid) { \ |
|||
auto* mod = dynamic_cast<var_moduleType*>(module); \ |
|||
if (mod == nullptr) { \ |
|||
m_cancmder->sendErrorAck(rxcmd, err::kce_operation_not_support); \ |
|||
return; \ |
|||
} |
|||
|
|||
#define CHECK_PARAM_NUM(num) \
|
|||
if (paramNum != num) { \ |
|||
m_cancmder->sendErrorAck(rxcmd, err::kce_cmd_param_num_error); \ |
|||
return; \ |
|||
} |
|||
|
|||
#define PROCESS_PACKET_XX_END(ackNum) \
|
|||
if (ecode != 0) { \ |
|||
m_cancmder->sendAck(rxcmd, ack, ackNum); \ |
|||
return; \ |
|||
} \ |
|||
m_cancmder->sendErrorAck(rxcmd, ecode); \ |
|||
return; \ |
|||
} |
|||
|
|||
#define PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, XP, XACK, ...) \
|
|||
PROCESS_PACKET_BEGIN(var_cmdid, var_moduleType) \ |
|||
CHECK_PARAM_NUM(XP) \ |
|||
int32_t ack[XACK + 1] = {0}; \ |
|||
int32_t ecode = mod->var_funcname(__VA_ARGS__); \ |
|||
PROCESS_PACKET_XX_END(XACK) |
|||
|
|||
#define PROCESS_PACKET_00(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 0, 0)
|
|||
#define PROCESS_PACKET_01(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 0, 1, &ack[1])
|
|||
#define PROCESS_PACKET_02(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 0, 2, &ack[1], &ack[2])
|
|||
#define PROCESS_PACKET_03(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 0, 3, &ack[1], &ack[2], &ack[3])
|
|||
|
|||
#define PROCESS_PACKET_10(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 1, 0, param[0])
|
|||
#define PROCESS_PACKET_11(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 1, 1, param[0], &ack[1])
|
|||
#define PROCESS_PACKET_12(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 1, 2, param[0], &ack[1], &ack[2])
|
|||
#define PROCESS_PACKET_13(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 1, 3, param[0], &ack[1], &ack[2], &ack[3])
|
|||
|
|||
#define PROCESS_PACKET_20(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 2, 0, param[0], param[1])
|
|||
#define PROCESS_PACKET_21(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 2, 1, param[0], param[1], &ack[1])
|
|||
#define PROCESS_PACKET_22(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 2, 2, param[0], param[1], &ack[1], &ack[2])
|
|||
#define PROCESS_PACKET_23(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 2, 3, param[0], param[1], &ack[1], &ack[2], &ack[3])
|
|||
|
|||
#define PROCESS_PACKET_30(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 3, 0, param[0], param[1], param[2])
|
|||
#define PROCESS_PACKET_31(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 3, 1, param[0], param[1], param[2], &ack[1])
|
|||
#define PROCESS_PACKET_32(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 3, 2, param[0], param[1], param[2], &ack[1], &ack[2])
|
|||
#define PROCESS_PACKET_33(var_cmdid, var_moduleType, var_funcname) PROCESS_PACKET_XX(var_cmdid, var_moduleType, var_funcname, 3, 3, param[0], param[1], param[2], &ack[1], &ack[2], &ack[3])
|
|||
|
|||
void ZIProtocolParser::initialize(IZCanCmder* cancmder) { |
|||
m_cancmder = cancmder; |
|||
m_cancmder->registerListener(this); |
|||
} |
|||
void ZIProtocolParser::registerModule(uint16_t id, ZIModule* module) { m_modulers[id] = module; } |
|||
void ZIProtocolParser::onRceivePacket(cmd_header_t* rxcmd, uint8_t* data, int32_t len) { |
|||
uint16_t submoduleid = rxcmd->submoduleid; |
|||
auto it = m_modulers.find(submoduleid); |
|||
if (it == m_modulers.end()) { |
|||
return; |
|||
} |
|||
|
|||
ZIModule* module = it->second; |
|||
int32_t cmdid = CMDID(rxcmd->cmdmoduleid, rxcmd->subcmdid); |
|||
|
|||
/*******************************************************************************
|
|||
* module * |
|||
*******************************************************************************/ |
|||
PROCESS_PACKET_00(kmodule_stop, ZIModule, stop); |
|||
PROCESS_PACKET_00(kmodule_brake, ZIModule, brake); |
|||
PROCESS_PACKET_01(kmodule_get_last_exec_status, ZIModule, get_last_exec_status); |
|||
PROCESS_PACKET_01(kmodule_get_status, ZIModule, get_status); |
|||
PROCESS_PACKET_20(kmodule_set_param, ZIModule, set_param); |
|||
PROCESS_PACKET_11(kmodule_get_param, ZIModule, get_param); |
|||
PROCESS_PACKET_01(kmodule_readio, ZIModule, readio); |
|||
PROCESS_PACKET_10(kmodule_writeio, ZIModule, writeio); |
|||
PROCESS_PACKET_11(kmodule_read_adc, ZIModule, read_adc); |
|||
/*******************************************************************************
|
|||
* motor * |
|||
*******************************************************************************/ |
|||
PROCESS_PACKET_10(kmotor_enable, ZIMotor, motor_enable); |
|||
PROCESS_PACKET_20(kmotor_rotate, ZIMotor, motor_rotate); |
|||
PROCESS_PACKET_20(kmotor_move_by, ZIMotor, motor_move_by); |
|||
PROCESS_PACKET_20(kmotor_move_to, ZIMotor, motor_move_to); |
|||
PROCESS_PACKET_20(kmotor_move_to_with_torque, ZIMotor, motor_move_to_with_torque); |
|||
/*******************************************************************************
|
|||
* xymotor * |
|||
*******************************************************************************/ |
|||
PROCESS_PACKET_10(kxymotor_enable, ZIXYMotor, xymotor_enable); |
|||
PROCESS_PACKET_30(kxymotor_move_by, ZIXYMotor, xymotor_move_by); |
|||
PROCESS_PACKET_30(kxymotor_move_to, ZIXYMotor, xymotor_move_to); |
|||
} |
@ -0,0 +1,19 @@ |
|||
#pragma once
|
|||
#include <map>
|
|||
|
|||
#include "api/api.hpp"
|
|||
#include "cmdid.hpp"
|
|||
|
|||
namespace iflytop { |
|||
class ZIProtocolParser : public IZcanCmderListener { |
|||
private: |
|||
IZCanCmder* m_cancmder = nullptr; |
|||
map<uint16_t, ZIModule*> m_modulers; |
|||
|
|||
public: |
|||
void initialize(IZCanCmder* cancmder); |
|||
virtual void onRceivePacket(cmd_header_t* rxcmd, uint8_t* data, int32_t len); |
|||
void registerModule(uint16_t id, ZIModule* module); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -0,0 +1,101 @@ |
|||
#include "protocol_proxy.hpp"
|
|||
using namespace iflytop; |
|||
|
|||
#define PROXY_IMPL_0X_PARA()
|
|||
#define PROXY_IMPL_1X_PARA() param[0] = para0;
|
|||
#define PROXY_IMPL_2X_PARA() \
|
|||
PROXY_IMPL_1X_PARA(); \ |
|||
param[1] = para1; |
|||
|
|||
#define PROXY_IMPL_3X_PARA() \
|
|||
PROXY_IMPL_2X_PARA(); \ |
|||
param[2] = para2; |
|||
|
|||
#define PROXY_IMPL_4X_PARA() \
|
|||
PROXY_IMPL_3X_PARA(); \ |
|||
param[3] = para3; |
|||
|
|||
#define PROXY_IMPL_5X_PARA() \
|
|||
PROXY_IMPL_4X_PARA(); \ |
|||
param[4] = para4; |
|||
|
|||
#define PROXY_IMPL_X0_ACK()
|
|||
#define PROXY_IMPL_X1_ACK() *ack0 = ack[0];
|
|||
#define PROXY_IMPL_X2_ACK() \
|
|||
PROXY_IMPL_X1_ACK(); \ |
|||
*ack1 = ack[1]; |
|||
|
|||
#define PROXY_IMPL_X3_ACK() \
|
|||
PROXY_IMPL_X2_ACK(); \ |
|||
*ack2 = ack[2]; |
|||
|
|||
#define PROXY_IMPL_X4_ACK() \
|
|||
PROXY_IMPL_X3_ACK(); \ |
|||
*ack3 = ack[3] |
|||
|
|||
#define PROXY_IMPL_X5_ACK() \
|
|||
PROXY_IMPL_X4_ACK(); \ |
|||
*ack4 = ack[4]; |
|||
|
|||
#define PROXY_IMPL_XX(cmdindex, paramnum, acknum, paraassign, ackassign) \
|
|||
int32_t param[1 + paramnum] = {0}; \ |
|||
int32_t ack[1 + acknum] = {0}; \ |
|||
paraassign; \ |
|||
int32_t ecode = m_cancmder->sendCmd(cmdindex, m_id, param, paramnum, ack, acknum, 30); \ |
|||
ackassign; \ |
|||
return ecode; |
|||
|
|||
#define PROXY_IMPL_00(cmdindex) PROXY_IMPL_XX(cmdindex, 0, 0, PROXY_IMPL_0X_PARA(), PROXY_IMPL_X0_ACK());
|
|||
#define PROXY_IMPL_01(cmdindex) PROXY_IMPL_XX(cmdindex, 0, 1, PROXY_IMPL_0X_PARA(), PROXY_IMPL_X1_ACK());
|
|||
#define PROXY_IMPL_02(cmdindex) PROXY_IMPL_XX(cmdindex, 0, 2, PROXY_IMPL_0X_PARA(), PROXY_IMPL_X2_ACK());
|
|||
#define PROXY_IMPL_03(cmdindex) PROXY_IMPL_XX(cmdindex, 0, 3, PROXY_IMPL_0X_PARA(), PROXY_IMPL_X3_ACK());
|
|||
#define PROXY_IMPL_04(cmdindex) PROXY_IMPL_XX(cmdindex, 0, 4, PROXY_IMPL_0X_PARA(), PROXY_IMPL_X4_ACK());
|
|||
|
|||
#define PROXY_IMPL_10(cmdindex) PROXY_IMPL_XX(cmdindex, 1, 0, PROXY_IMPL_1X_PARA(), PROXY_IMPL_X0_ACK());
|
|||
#define PROXY_IMPL_11(cmdindex) PROXY_IMPL_XX(cmdindex, 1, 1, PROXY_IMPL_1X_PARA(), PROXY_IMPL_X1_ACK());
|
|||
#define PROXY_IMPL_12(cmdindex) PROXY_IMPL_XX(cmdindex, 1, 2, PROXY_IMPL_1X_PARA(), PROXY_IMPL_X2_ACK());
|
|||
#define PROXY_IMPL_13(cmdindex) PROXY_IMPL_XX(cmdindex, 1, 3, PROXY_IMPL_1X_PARA(), PROXY_IMPL_X3_ACK());
|
|||
#define PROXY_IMPL_14(cmdindex) PROXY_IMPL_XX(cmdindex, 1, 4, PROXY_IMPL_1X_PARA(), PROXY_IMPL_X4_ACK());
|
|||
|
|||
#define PROXY_IMPL_20(cmdindex) PROXY_IMPL_XX(cmdindex, 2, 0, PROXY_IMPL_2X_PARA(), PROXY_IMPL_X0_ACK());
|
|||
#define PROXY_IMPL_21(cmdindex) PROXY_IMPL_XX(cmdindex, 2, 1, PROXY_IMPL_2X_PARA(), PROXY_IMPL_X1_ACK());
|
|||
#define PROXY_IMPL_22(cmdindex) PROXY_IMPL_XX(cmdindex, 2, 2, PROXY_IMPL_2X_PARA(), PROXY_IMPL_X2_ACK());
|
|||
#define PROXY_IMPL_23(cmdindex) PROXY_IMPL_XX(cmdindex, 2, 3, PROXY_IMPL_2X_PARA(), PROXY_IMPL_X3_ACK());
|
|||
#define PROXY_IMPL_24(cmdindex) PROXY_IMPL_XX(cmdindex, 2, 4, PROXY_IMPL_2X_PARA(), PROXY_IMPL_X4_ACK());
|
|||
|
|||
#define PROXY_IMPL_30(cmdindex) PROXY_IMPL_XX(cmdindex, 3, 0, PROXY_IMPL_3X_PARA(), PROXY_IMPL_X0_ACK());
|
|||
#define PROXY_IMPL_31(cmdindex) PROXY_IMPL_XX(cmdindex, 3, 1, PROXY_IMPL_3X_PARA(), PROXY_IMPL_X1_ACK());
|
|||
#define PROXY_IMPL_32(cmdindex) PROXY_IMPL_XX(cmdindex, 3, 2, PROXY_IMPL_3X_PARA(), PROXY_IMPL_X2_ACK());
|
|||
#define PROXY_IMPL_33(cmdindex) PROXY_IMPL_XX(cmdindex, 3, 3, PROXY_IMPL_3X_PARA(), PROXY_IMPL_X3_ACK());
|
|||
|
|||
|
|||
|
|||
|
|||
int32_t ZIProtocolProxy::stop() { PROXY_IMPL_00(kmodule_stop); } |
|||
int32_t ZIProtocolProxy::brake() { PROXY_IMPL_00(kmodule_brake); } |
|||
int32_t ZIProtocolProxy::get_last_exec_status(int32_t *ack0) { PROXY_IMPL_01(kmodule_get_last_exec_status); } |
|||
int32_t ZIProtocolProxy::get_status(int32_t *ack0) { PROXY_IMPL_01(kmodule_get_status); } |
|||
|
|||
int32_t ZIProtocolProxy::set_param(int32_t para0, int32_t para1) { PROXY_IMPL_20(kmodule_set_param); } |
|||
int32_t ZIProtocolProxy::get_param(int32_t para0, int32_t *ack0) { PROXY_IMPL_11(kmodule_get_param); } |
|||
|
|||
int32_t ZIProtocolProxy::readio(int32_t *ack0) { PROXY_IMPL_01(kmodule_readio); } |
|||
int32_t ZIProtocolProxy::writeio(int32_t para0) { PROXY_IMPL_10(kmodule_writeio); } |
|||
|
|||
int32_t ZIProtocolProxy::read_adc(int para0, int32_t *ack0) { PROXY_IMPL_11(kmodule_read_adc); } |
|||
|
|||
/*******************************************************************************
|
|||
* ZIMotor * |
|||
*******************************************************************************/ |
|||
int32_t ZIProtocolProxy::motor_enable(int32_t para0) { PROXY_IMPL_10(kmotor_enable); } |
|||
int32_t ZIProtocolProxy::motor_rotate(int32_t para0, int32_t para1) { PROXY_IMPL_20(kmotor_rotate); } |
|||
int32_t ZIProtocolProxy::motor_move_by(int32_t para0, int32_t para1) { PROXY_IMPL_20(kmotor_move_by); } |
|||
int32_t ZIProtocolProxy::motor_move_to(int32_t para0, int32_t para1) { PROXY_IMPL_20(kmotor_move_to); } |
|||
int32_t ZIProtocolProxy::motor_move_to_with_torque(int32_t para0, int32_t para1) { PROXY_IMPL_20(kmotor_move_to_with_torque); } |
|||
|
|||
/*******************************************************************************
|
|||
* ZIXYMotor * |
|||
*******************************************************************************/ |
|||
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); } |
|||
int32_t ZIProtocolProxy::xymotor_move_to(int32_t para0, int32_t para1, int32_t para2) { PROXY_IMPL_30(kxymotor_move_to); } |
@ -0,0 +1,58 @@ |
|||
#pragma once
|
|||
#include <map>
|
|||
|
|||
#include "api/api.hpp"
|
|||
#include "api\i_zcan_cmder_master.hpp"
|
|||
#include "cmdid.hpp"
|
|||
|
|||
namespace iflytop { |
|||
class ZIProtocolProxy : public ZIMotor, //
|
|||
public ZIXYMotor, //
|
|||
public ZIModule { |
|||
private: |
|||
IZcanCmderMaster *m_cancmder; |
|||
int32_t m_id = 0; |
|||
|
|||
public: |
|||
void initialize(IZCanCmder *cancmder, int32_t id); |
|||
|
|||
virtual int32_t getid(int32_t *id) { |
|||
*id = m_id; |
|||
return 0; |
|||
}; |
|||
|
|||
/*******************************************************************************
|
|||
* ZIModule * |
|||
*******************************************************************************/ |
|||
virtual int32_t stop(); |
|||
virtual int32_t brake(); |
|||
virtual int32_t get_last_exec_status(int32_t *status); |
|||
virtual int32_t get_status(int32_t *status); |
|||
|
|||
virtual int32_t set_param(int32_t param_id, int32_t param_value); |
|||
virtual int32_t get_param(int32_t param_id, int32_t *param_value); |
|||
|
|||
virtual int32_t readio(int32_t *io); |
|||
virtual int32_t writeio(int32_t io); |
|||
|
|||
virtual int32_t read_adc(int adcindex, int32_t *adc); |
|||
|
|||
/*******************************************************************************
|
|||
* ZIMotor * |
|||
*******************************************************************************/ |
|||
|
|||
virtual int32_t motor_enable(int32_t enable); |
|||
virtual int32_t motor_rotate(int32_t direction, int32_t velocitylevel); |
|||
virtual int32_t motor_move_by(int32_t distance, int32_t velocitylevel); |
|||
virtual int32_t motor_move_to(int32_t position, int32_t velocitylevel); |
|||
virtual int32_t motor_move_to_with_torque(int32_t pos, int32_t torque); |
|||
|
|||
/*******************************************************************************
|
|||
* ZIXYMotor * |
|||
*******************************************************************************/ |
|||
virtual int32_t xymotor_enable(int32_t enable); |
|||
virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t velocitylevel); |
|||
virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t velocitylevel); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -0,0 +1,37 @@ |
|||
#include "zmodule_device_manager.hpp"
|
|||
using namespace iflytop; |
|||
using namespace std; |
|||
|
|||
#define PROXY_IMPL(type, functionName, ...) \
|
|||
type *module = nullptr; \ |
|||
int32_t ecode = findModule<type>(id, &module); \ |
|||
if (ecode != 0) { \ |
|||
return ecode; \ |
|||
} \ |
|||
return module->functionName(__VA_ARGS__); |
|||
/*******************************************************************************
|
|||
* ZIModule * |
|||
*******************************************************************************/ |
|||
int32_t ZModuleDeviceManager::stop(uint16_t id) { PROXY_IMPL(ZIModule, stop); } |
|||
int32_t ZModuleDeviceManager::brake(uint16_t id) { PROXY_IMPL(ZIModule, brake); } |
|||
int32_t ZModuleDeviceManager::get_last_exec_status(uint16_t id, int32_t *ack0) { PROXY_IMPL(ZIModule, get_last_exec_status, ack0); } |
|||
int32_t ZModuleDeviceManager::get_status(uint16_t id, int32_t *status) { PROXY_IMPL(ZIModule, get_status, status); } |
|||
int32_t ZModuleDeviceManager::set_param(uint16_t id, int32_t param_id, int32_t param_value) { PROXY_IMPL(ZIModule, set_param, param_id, param_value); } |
|||
int32_t ZModuleDeviceManager::get_param(uint16_t id, int32_t param_id, int32_t *param_value) { PROXY_IMPL(ZIModule, get_param, param_id, param_value); } |
|||
int32_t ZModuleDeviceManager::readio(uint16_t id, int32_t *io) { PROXY_IMPL(ZIModule, readio, io); } |
|||
int32_t ZModuleDeviceManager::writeio(uint16_t id, int32_t io) { PROXY_IMPL(ZIModule, writeio, io); } |
|||
int32_t ZModuleDeviceManager::read_adc(uint16_t id, int adcindex, int32_t *adc) { PROXY_IMPL(ZIModule, read_adc, adcindex, adc); } |
|||
/*******************************************************************************
|
|||
* ZIMotor * |
|||
*******************************************************************************/ |
|||
int32_t ZModuleDeviceManager::motor_enable(uint16_t id, int32_t enable) { PROXY_IMPL(ZIMotor, motor_enable, enable); } |
|||
int32_t ZModuleDeviceManager::motor_rotate(uint16_t id, int32_t direction, int32_t velocitylevel) { PROXY_IMPL(ZIMotor, motor_rotate, direction, velocitylevel); } |
|||
int32_t ZModuleDeviceManager::motor_move_by(uint16_t id, int32_t distance, int32_t velocitylevel) { PROXY_IMPL(ZIMotor, motor_move_by, distance, velocitylevel); } |
|||
int32_t ZModuleDeviceManager::motor_move_to(uint16_t id, int32_t position, int32_t velocitylevel) { PROXY_IMPL(ZIMotor, motor_move_to, position, velocitylevel); } |
|||
int32_t ZModuleDeviceManager::motor_move_to_with_torque(uint16_t id, int32_t pos, int32_t torque) { PROXY_IMPL(ZIMotor, motor_move_to_with_torque, pos, torque); } |
|||
/*******************************************************************************
|
|||
* ZIXYMotor * |
|||
*******************************************************************************/ |
|||
int32_t ZModuleDeviceManager::xymotor_enable(uint16_t id, int32_t enable) { PROXY_IMPL(ZIXYMotor, xymotor_enable, enable); } |
|||
int32_t ZModuleDeviceManager::xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t velocitylevel) { PROXY_IMPL(ZIXYMotor, xymotor_move_by, dx, dy, velocitylevel); } |
|||
int32_t ZModuleDeviceManager::xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t velocitylevel) { PROXY_IMPL(ZIXYMotor, xymotor_move_to, x, y, velocitylevel); } |
@ -0,0 +1,67 @@ |
|||
#pragma once
|
|||
#include <map>
|
|||
|
|||
#include "api/api.hpp"
|
|||
#include "api\i_zcan_cmder_master.hpp"
|
|||
#include "cmdid.hpp"
|
|||
|
|||
namespace iflytop { |
|||
class ZModuleDeviceManager { |
|||
private: |
|||
map<uint16_t, ZIModule *> m_modulers; |
|||
IZcanCmderMaster *m_cancmder = nullptr; |
|||
|
|||
public: |
|||
void initialize(); |
|||
void registerModule(uint16_t id, ZIModule *module); |
|||
/*******************************************************************************
|
|||
* ZIModule * |
|||
*******************************************************************************/ |
|||
int32_t stop(uint16_t id); |
|||
int32_t brake(uint16_t id); |
|||
|
|||
int32_t get_last_exec_status(uint16_t id, int32_t *status); |
|||
int32_t get_status(uint16_t id, int32_t *status); |
|||
|
|||
int32_t set_param(uint16_t id, int32_t param_id, int32_t param_value); |
|||
int32_t get_param(uint16_t id, int32_t param_id, int32_t *param_value); |
|||
|
|||
int32_t readio(uint16_t id, int32_t *io); |
|||
int32_t writeio(uint16_t id, int32_t io); |
|||
|
|||
int32_t read_adc(uint16_t id, int adcindex, int32_t *adc); |
|||
|
|||
/*******************************************************************************
|
|||
* ZIMotor * |
|||
*******************************************************************************/ |
|||
|
|||
int32_t motor_enable(uint16_t id, int32_t enable); |
|||
int32_t motor_rotate(uint16_t id, int32_t direction, int32_t velocitylevel); |
|||
int32_t motor_move_by(uint16_t id, int32_t distance, int32_t velocitylevel); |
|||
int32_t motor_move_to(uint16_t id, int32_t position, int32_t velocitylevel); |
|||
int32_t motor_move_to_with_torque(uint16_t id, int32_t pos, int32_t torque); |
|||
|
|||
/*******************************************************************************
|
|||
* ZIXYMotor * |
|||
*******************************************************************************/ |
|||
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 velocitylevel); |
|||
int32_t xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t velocitylevel); |
|||
|
|||
private: |
|||
template <typename T> |
|||
int32_t findModule(uint16_t id, T **module) { |
|||
auto it = m_modulers.find(id); |
|||
if (it == m_modulers.end()) { |
|||
return err::kce_no_such_module; |
|||
} |
|||
T *_module = dynamic_cast<T *>(it->second); |
|||
if (_module == nullptr) { |
|||
return err::kce_operation_not_support; |
|||
} |
|||
*module = _module; |
|||
return 0; |
|||
} |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -0,0 +1,57 @@ |
|||
#include "zmodule_device_script_cmder_paser.hpp"
|
|||
|
|||
using namespace iflytop; |
|||
using namespace std; |
|||
#define PROCESS_PACKET_XX(var_funcname, cmdhelp, XP, XACK, ...) \
|
|||
cancmder->regCMD(#var_funcname, cmdhelp, XP, [this](int32_t paramN, const char* paraV[], ICmdParserACK* ack) { \ |
|||
ack->ecode = m_deviceManager->var_funcname(__VA_ARGS__); \ |
|||
ack->acktype = ICmdParserACK::kAckType_int32; \ |
|||
ack->rawlen = XACK * 4; \ |
|||
}); |
|||
|
|||
#define PROCESS_PACKET_00(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 0, 0)
|
|||
#define PROCESS_PACKET_01(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 0, 1, ack->getAck(0))
|
|||
#define PROCESS_PACKET_02(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 0, 2, ack->getAck(0), ack->getAck(1))
|
|||
#define PROCESS_PACKET_03(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 0, 3, ack->getAck(0), ack->getAck(1), ack->getAck(2))
|
|||
|
|||
#define PROCESS_PACKET_10(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 1, 0, atoi(paraV[0]))
|
|||
#define PROCESS_PACKET_11(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 1, 1, atoi(paraV[0]), ack->getAck(0))
|
|||
#define PROCESS_PACKET_12(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 1, 2, atoi(paraV[0]), ack->getAck(0), ack->getAck(1))
|
|||
#define PROCESS_PACKET_13(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 1, 3, atoi(paraV[0]), ack->getAck(0), ack->getAck(1), ack->getAck(2))
|
|||
|
|||
#define PROCESS_PACKET_20(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 2, 0, atoi(paraV[0]), atoi(paraV[1]))
|
|||
#define PROCESS_PACKET_21(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 2, 1, atoi(paraV[0]), atoi(paraV[1]), ack->getAck(0))
|
|||
#define PROCESS_PACKET_22(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 2, 2, atoi(paraV[0]), atoi(paraV[1]), ack->getAck(0), ack->getAck(1))
|
|||
#define PROCESS_PACKET_23(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 2, 3, atoi(paraV[0]), atoi(paraV[1]), ack->getAck(0), ack->getAck(1), ack->getAck(2))
|
|||
|
|||
#define PROCESS_PACKET_30(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 3, 0, atoi(paraV[0]), atoi(paraV[1]), atoi(paraV[2]))
|
|||
#define PROCESS_PACKET_31(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 3, 1, atoi(paraV[0]), atoi(paraV[1]), atoi(paraV[2]), ack->getAck(0))
|
|||
#define PROCESS_PACKET_32(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 3, 2, atoi(paraV[0]), atoi(paraV[1]), atoi(paraV[2]), ack->getAck(0), ack->getAck(1))
|
|||
#define PROCESS_PACKET_33(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 3, 3, atoi(paraV[0]), atoi(paraV[1]), atoi(paraV[2]), ack->getAck(0), ack->getAck(1), ack->getAck(2))
|
|||
|
|||
#define PROCESS_PACKET_40(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 4, 0, atoi(paraV[0]), atoi(paraV[1]), atoi(paraV[2]), atoi(paraV[3]))
|
|||
#define PROCESS_PACKET_41(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 4, 1, atoi(paraV[0]), atoi(paraV[1]), atoi(paraV[2]), atoi(paraV[3]), ack->getAck(0))
|
|||
#define PROCESS_PACKET_42(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 4, 2, atoi(paraV[0]), atoi(paraV[1]), atoi(paraV[2]), atoi(paraV[3]), ack->getAck(0), ack->getAck(1))
|
|||
#define PROCESS_PACKET_43(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 4, 3, atoi(paraV[0]), atoi(paraV[1]), atoi(paraV[2]), atoi(paraV[3]), ack->getAck(0), ack->getAck(1), ack->getAck(2))
|
|||
|
|||
void ZModuleDeviceScriptCmderPaser::initialize(ICmdParser* cancmder, ZModuleDeviceManager* deviceManager) { |
|||
PROCESS_PACKET_10(stop, "stop (id)"); |
|||
PROCESS_PACKET_10(brake, "brake (id)"); |
|||
PROCESS_PACKET_11(get_last_exec_status, "get_last_exec_status (id)"); |
|||
PROCESS_PACKET_11(get_status, "get_status (id)"); |
|||
PROCESS_PACKET_30(set_param, "set_param (id, param_id, param_value)"); |
|||
PROCESS_PACKET_21(get_param, "get_param (id, param_id)"); |
|||
PROCESS_PACKET_11(readio, "readio (id)"); |
|||
PROCESS_PACKET_20(writeio, "writeio (id, io)"); |
|||
PROCESS_PACKET_21(read_adc, "read_adc (id, adcindex)"); |
|||
|
|||
PROCESS_PACKET_20(motor_enable, "motor_enable (id, enable)"); |
|||
PROCESS_PACKET_30(motor_rotate, "motor_rotate (id, direction, velocitylevel)"); |
|||
PROCESS_PACKET_30(motor_move_by, "motor_move_by (id, distance, velocitylevel)"); |
|||
PROCESS_PACKET_30(motor_move_to, "motor_move_to (id, position, velocitylevel)"); |
|||
PROCESS_PACKET_30(motor_move_to_with_torque, "motor_move_to_with_torque (id, pos, torque)"); |
|||
|
|||
PROCESS_PACKET_20(xymotor_enable, "xymotor_enable (id, enable)"); |
|||
PROCESS_PACKET_40(xymotor_move_by, "xymotor_move_by (id, dx, dy, velocitylevel)"); |
|||
PROCESS_PACKET_40(xymotor_move_to, "xymotor_move_to (id, x, y, velocitylevel)"); |
|||
} |
@ -0,0 +1,20 @@ |
|||
#pragma once
|
|||
#include <map>
|
|||
|
|||
#include "api/api.hpp"
|
|||
#include "api/i_cmdparser.hpp"
|
|||
#include "cmdid.hpp"
|
|||
#include "zmodule_device_manager.hpp"
|
|||
|
|||
namespace iflytop { |
|||
class ZModuleDeviceScriptCmderPaser { |
|||
private: |
|||
ICmdParser* m_cmdParser = nullptr; |
|||
ZModuleDeviceManager* m_deviceManager; |
|||
|
|||
public: |
|||
void initialize(ICmdParser* cancmder, ZModuleDeviceManager* deviceManager); |
|||
|
|||
}; |
|||
|
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue