zcancmder_v2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

155 lines
11 KiB

#include "zmodule_device_script_cmder_paser.hpp"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
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) { \
printf("%s\n",paraV[0]);\
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))
#define PROCESS_PACKET_50(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 5, 0, atoi(paraV[0]), atoi(paraV[1]), atoi(paraV[2]), atoi(paraV[3]), atoi(paraV[4]))
#define PROCESS_PACKET_51(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 5, 1, atoi(paraV[0]), atoi(paraV[1]), atoi(paraV[2]), atoi(paraV[3]), atoi(paraV[4]), ack->getAck(0))
#define PROCESS_PACKET_52(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 5, 2, atoi(paraV[0]), atoi(paraV[1]), atoi(paraV[2]), atoi(paraV[3]), atoi(paraV[4]), ack->getAck(0), ack->getAck(1))
#define PROCESS_PACKET_53(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 5, 3, atoi(paraV[0]), atoi(paraV[1]), atoi(paraV[2]), atoi(paraV[3]), atoi(paraV[4]), ack->getAck(0), ack->getAck(1), ack->getAck(2))
void ZModuleDeviceScriptCmderPaser::initialize(ICmdParser* cancmder, ZModuleDeviceManager* deviceManager) {
m_cmdParser = cancmder;
m_deviceManager = deviceManager;
#if 0
/*******************************************************************************
* ZIModule *
*******************************************************************************/
int32_t module_stop(uint16_t id);
int32_t module_break(uint16_t id);
int32_t module_get_last_exec_status(uint16_t id, int32_t *status);
int32_t module_get_status(uint16_t id, int32_t *status);
int32_t module_set_param(uint16_t id, int32_t param_id, int32_t param_value);
int32_t module_get_param(uint16_t id, int32_t param_id, int32_t *param_value);
int32_t module_readio(uint16_t id, int32_t *io);
int32_t module_writeio(uint16_t id, int32_t io);
int32_t module_read_adc(uint16_t id, int32_t adcindex, int32_t *adc);
int32_t module_get_error(uint16_t id, int32_t *iserror);
int32_t module_clear_error(uint16_t id);
int32_t module_set_inited_flag(uint16_t id, int32_t flag);
int32_t module_get_inited_flag(uint16_t id, int32_t *flag);
int32_t module_factory_reset(uint16_t id);
int32_t module_flush_cfg(uint16_t id);
int32_t module_active_cfg(uint16_t id);
int32_t module_set_state(uint16_t id, int32_t state_id, int32_t state_value);
int32_t module_get_state(uint16_t id, int32_t state_id, int32_t *state_value);
/*******************************************************************************
* ZIMotor *
*******************************************************************************/
int32_t motor_enable(uint16_t id, int32_t enable);
int32_t motor_rotate(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acc);
int32_t motor_move_by(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acc);
int32_t motor_move_to(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acc);
int32_t motor_rotate_acctime(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acctime);
int32_t motor_move_by_acctime(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acctime);
int32_t motor_move_to_acctime(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acctime);
int32_t motor_move_to_zero_forward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
int32_t motor_move_to_zero_backward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
int32_t motor_move_to_with_torque(uint16_t id, int32_t pos, int32_t torque);
int32_t motor_read_pos(uint16_t id, int32_t *pos);
int32_t motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos);
virtual int32_t motor_move_to_zero_forward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) override;
virtual int32_t motor_move_to_zero_backward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) override;
#endif
PROCESS_PACKET_10(module_stop, "(mid)");
PROCESS_PACKET_10(module_break, "(mid)");
PROCESS_PACKET_11(module_get_last_exec_status, "(mid)");
PROCESS_PACKET_11(module_get_status, "(mid)");
PROCESS_PACKET_30(module_set_param, "(mid, param_id, param_value)");
PROCESS_PACKET_21(module_get_param, "(mid, param_id)");
PROCESS_PACKET_11(module_readio, "(mid)");
PROCESS_PACKET_20(module_writeio, "(mid, io)");
PROCESS_PACKET_21(module_read_adc, "(mid,adc_id, adcindex)");
PROCESS_PACKET_11(module_get_error, "(mid)");
PROCESS_PACKET_10(module_clear_error, "(mid)");
PROCESS_PACKET_20(module_set_inited_flag, "(mid, flag)");
PROCESS_PACKET_11(module_get_inited_flag, "(mid)");
PROCESS_PACKET_10(module_factory_reset, "(mid)");
PROCESS_PACKET_10(module_flush_cfg, "(mid)");
PROCESS_PACKET_10(module_active_cfg, "(mid)");
PROCESS_PACKET_30(module_set_state, "(mid, state_id, state_value)");
PROCESS_PACKET_21(module_get_state, "(mid, state_id)");
PROCESS_PACKET_20(motor_enable, "(mid, enable)");
PROCESS_PACKET_40(motor_rotate, "(mid, direction, motor_velocity, acc)");
PROCESS_PACKET_40(motor_move_by, "(mid, distance, motor_velocity, acc)");
PROCESS_PACKET_40(motor_move_to, "(mid, position, motor_velocity, acc)");
PROCESS_PACKET_40(motor_rotate_acctime, "(mid, direction, motor_velocity, acctime)");
PROCESS_PACKET_40(motor_move_by_acctime, "(mid, distance, motor_velocity, acctime)");
PROCESS_PACKET_40(motor_move_to_acctime, "(mid, position, motor_velocity, acctime)");
PROCESS_PACKET_30(motor_move_to_with_torque, "(mid, pos, torque)");
PROCESS_PACKET_50(motor_move_to_zero_forward, "(mid, findzerospeed, findzeroedge_speed, acc, overtime)");
PROCESS_PACKET_50(motor_move_to_zero_backward, "(mid, findzerospeed, findzeroedge_speed, acc, overtime)");
PROCESS_PACKET_11(motor_read_pos, "(mid)");
PROCESS_PACKET_20(motor_set_current_pos_by_change_shift, "(mid, pos)");
PROCESS_PACKET_50(motor_move_to_zero_forward_and_calculated_shift, "(mid, findzerospeed, findzeroedge_speed, acc, overtime)");
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)");
PROCESS_PACKET_40(xymotor_move_to, "(mid, x, y, motor_velocity)");
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)");
}