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.

138 lines
10 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include "zmodule_device_script_cmder_paser.hpp"
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. using namespace iflytop;
  6. using namespace std;
  7. #define PROCESS_PACKET_XX(var_funcname, cmdhelp, XP, XACK, ...) \
  8. cancmder->regCMD(#var_funcname, cmdhelp, XP, [this](int32_t paramN, const char* paraV[], ICmdParserACK* ack) { \
  9. ack->ecode = m_deviceManager->var_funcname(__VA_ARGS__); \
  10. ack->acktype = ICmdParserACK::kAckType_int32; \
  11. ack->rawlen = XACK * 4; \
  12. });
  13. #define PROCESS_PACKET_00(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 0, 0)
  14. #define PROCESS_PACKET_01(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 0, 1, ack->getAck(0))
  15. #define PROCESS_PACKET_02(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 0, 2, ack->getAck(0), ack->getAck(1))
  16. #define PROCESS_PACKET_03(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 0, 3, ack->getAck(0), ack->getAck(1), ack->getAck(2))
  17. #define PROCESS_PACKET_10(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 1, 0, atoi(paraV[0]))
  18. #define PROCESS_PACKET_11(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 1, 1, atoi(paraV[0]), ack->getAck(0))
  19. #define PROCESS_PACKET_12(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 1, 2, atoi(paraV[0]), ack->getAck(0), ack->getAck(1))
  20. #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))
  21. #define PROCESS_PACKET_20(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 2, 0, atoi(paraV[0]), atoi(paraV[1]))
  22. #define PROCESS_PACKET_21(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 2, 1, atoi(paraV[0]), atoi(paraV[1]), ack->getAck(0))
  23. #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))
  24. #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))
  25. #define PROCESS_PACKET_30(var_funcname, cmdhelp) PROCESS_PACKET_XX(var_funcname, cmdhelp, 3, 0, atoi(paraV[0]), atoi(paraV[1]), atoi(paraV[2]))
  26. #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))
  27. #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))
  28. #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))
  29. #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]))
  30. #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))
  31. #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))
  32. #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))
  33. #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]))
  34. #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))
  35. #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))
  36. #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))
  37. void ZModuleDeviceScriptCmderPaser::initialize(ICmdParser* cancmder, ZModuleDeviceManager* deviceManager) {
  38. #if 0
  39. /*******************************************************************************
  40. * ZIModule *
  41. *******************************************************************************/
  42. int32_t module_stop(uint16_t id);
  43. int32_t module_break(uint16_t id);
  44. int32_t module_get_last_exec_status(uint16_t id, int32_t *status);
  45. int32_t module_get_status(uint16_t id, int32_t *status);
  46. int32_t module_set_param(uint16_t id, int32_t param_id, int32_t param_value);
  47. int32_t module_get_param(uint16_t id, int32_t param_id, int32_t *param_value);
  48. int32_t module_readio(uint16_t id, int32_t *io);
  49. int32_t module_writeio(uint16_t id, int32_t io);
  50. int32_t module_read_adc(uint16_t id, int32_t adcindex, int32_t *adc);
  51. int32_t module_get_error(uint16_t id, int32_t *iserror);
  52. int32_t module_clear_error(uint16_t id);
  53. int32_t module_set_inited_flag(uint16_t id, int32_t flag);
  54. int32_t module_get_inited_flag(uint16_t id, int32_t *flag);
  55. int32_t module_factory_reset(uint16_t id);
  56. int32_t module_flush_cfg(uint16_t id);
  57. int32_t module_active_cfg(uint16_t id);
  58. /*******************************************************************************
  59. * ZIMotor *
  60. *******************************************************************************/
  61. int32_t motor_enable(uint16_t id, int32_t enable);
  62. int32_t motor_rotate(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acc);
  63. int32_t motor_move_by(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acc);
  64. int32_t motor_move_to(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acc);
  65. int32_t motor_rotate_acctime(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acctime);
  66. int32_t motor_move_by_acctime(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acctime);
  67. int32_t motor_move_to_acctime(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acctime);
  68. int32_t motor_move_to_zero_forward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  69. int32_t motor_move_to_zero_backward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  70. int32_t motor_move_to_with_torque(uint16_t id, int32_t pos, int32_t torque);
  71. int32_t motor_read_pos(uint16_t id, int32_t *pos);
  72. int32_t motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos);
  73. #endif
  74. PROCESS_PACKET_10(module_stop, "module_stop (mid)");
  75. PROCESS_PACKET_10(module_break, "module_break (mid)");
  76. PROCESS_PACKET_11(module_get_last_exec_status, "module_get_last_exec_status (mid)");
  77. PROCESS_PACKET_11(module_get_status, "module_get_status (mid)");
  78. PROCESS_PACKET_30(module_set_param, "module_set_param (mid, param_id, param_value)");
  79. PROCESS_PACKET_21(module_get_param, "module_get_param (mid, param_id)");
  80. PROCESS_PACKET_11(module_readio, "module_readio (mid)");
  81. PROCESS_PACKET_20(module_writeio, "module_writeio (mid, io)");
  82. PROCESS_PACKET_21(module_read_adc, "module_read_adc (mid,adc_id, adcindex)");
  83. PROCESS_PACKET_11(module_get_error, "module_get_error (mid)");
  84. PROCESS_PACKET_10(module_clear_error, "module_clear_error (mid)");
  85. PROCESS_PACKET_20(module_set_inited_flag, "module_set_inited_flag (mid, flag)");
  86. PROCESS_PACKET_11(module_get_inited_flag, "module_get_inited_flag (mid)");
  87. PROCESS_PACKET_10(module_factory_reset, "module_factory_reset (mid)");
  88. PROCESS_PACKET_10(module_flush_cfg, "module_flush_cfg (mid)");
  89. PROCESS_PACKET_10(module_active_cfg, "module_active_cfg (mid)");
  90. PROCESS_PACKET_20(motor_enable, "motor_enable (mid, enable)");
  91. PROCESS_PACKET_40(motor_rotate, "motor_rotate (mid, direction, motor_velocity, acc)");
  92. PROCESS_PACKET_40(motor_move_by, "motor_move_by (mid, distance, motor_velocity, acc)");
  93. PROCESS_PACKET_40(motor_move_to, "motor_move_to (mid, position, motor_velocity, acc)");
  94. PROCESS_PACKET_40(motor_rotate_acctime, "motor_rotate_acctime (mid, direction, motor_velocity, acctime)");
  95. PROCESS_PACKET_40(motor_move_by_acctime, "motor_move_by_acctime (mid, distance, motor_velocity, acctime)");
  96. PROCESS_PACKET_40(motor_move_to_acctime, "motor_move_to_acctime (mid, position, motor_velocity, acctime)");
  97. PROCESS_PACKET_30(motor_move_to_with_torque, "motor_move_to_with_torque (mid, pos, torque)");
  98. PROCESS_PACKET_50(motor_move_to_zero_forward, "motor_move_to_zero_forward (mid, findzerospeed, findzeroedge_speed, acc, overtime)");
  99. PROCESS_PACKET_50(motor_move_to_zero_backward, "motor_move_to_zero_backward (mid, findzerospeed, findzeroedge_speed, acc, overtime)");
  100. PROCESS_PACKET_11(motor_read_pos, "motor_read_pos (mid)");
  101. PROCESS_PACKET_20(motor_set_current_pos_by_change_shift, "motor_set_current_pos_by_change_shift (mid, pos)");
  102. #if 0
  103. virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; }
  104. virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; }
  105. virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; }
  106. virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; }
  107. #endif
  108. PROCESS_PACKET_20(xymotor_enable, "xymotor_enable (mid, enable)");
  109. PROCESS_PACKET_40(xymotor_move_by, "xymotor_move_by (mid, dx, dy, motor_velocity)");
  110. PROCESS_PACKET_40(xymotor_move_to, "xymotor_move_to (mid, x, y, motor_velocity)");
  111. PROCESS_PACKET_10(xymotor_move_to_zero, "xymotor_move_to_zero (mid)");
  112. }