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.

191 lines
14 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
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
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. m_cmdParser = cancmder;
  39. m_deviceManager = deviceManager;
  40. #if 0
  41. /*******************************************************************************
  42. * ZIModule *
  43. *******************************************************************************/
  44. int32_t module_stop(uint16_t id);
  45. int32_t module_break(uint16_t id);
  46. int32_t module_get_last_exec_status(uint16_t id, int32_t *status);
  47. int32_t module_get_status(uint16_t id, int32_t *status);
  48. int32_t module_set_reg(uint16_t id, int32_t param_id, int32_t param_value);
  49. int32_t module_get_reg(uint16_t id, int32_t param_id, int32_t *param_value);
  50. int32_t module_readio(uint16_t id, int32_t *io);
  51. int32_t module_writeio(uint16_t id, int32_t io);
  52. int32_t module_read_adc(uint16_t id, int32_t adcindex, int32_t *adc);
  53. int32_t module_get_error(uint16_t id, int32_t *iserror);
  54. int32_t module_clear_error(uint16_t id);
  55. int32_t module_set_inited_flag(uint16_t id, int32_t flag);
  56. int32_t module_get_inited_flag(uint16_t id, int32_t *flag);
  57. int32_t module_factory_reset(uint16_t id);
  58. int32_t module_flush_cfg(uint16_t id);
  59. int32_t module_active_cfg(uint16_t id);
  60. virtual int32_t module_read_raw(uint16_t id, int32_t startadd, int32_t readlen, uint8_t *data, int32_t *len);
  61. /*******************************************************************************
  62. * ZIMotor *
  63. *******************************************************************************/
  64. int32_t motor_enable(uint16_t id, int32_t enable);
  65. int32_t motor_rotate(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acc);
  66. int32_t motor_move_by(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acc);
  67. int32_t motor_move_to(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acc);
  68. int32_t motor_rotate_acctime(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acctime);
  69. int32_t motor_move_by_acctime(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acctime);
  70. int32_t motor_move_to_acctime(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acctime);
  71. int32_t motor_move_to_zero_forward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  72. int32_t motor_move_to_zero_backward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  73. int32_t motor_rotate_with_torque(uint16_t id, int32_t pos, int32_t torque);
  74. int32_t motor_read_pos(uint16_t id, int32_t *pos);
  75. int32_t motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos);
  76. 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;
  77. 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;
  78. virtual int32_t module_enable(uint16_t id, int32_t enable);
  79. #endif
  80. PROCESS_PACKET_10(module_stop, "(mid)");
  81. PROCESS_PACKET_10(module_start, "(mid)");
  82. PROCESS_PACKET_10(module_break, "(mid)");
  83. PROCESS_PACKET_11(module_get_last_exec_status, "(mid)");
  84. PROCESS_PACKET_11(module_get_status, "(mid)");
  85. PROCESS_PACKET_30(module_set_reg, "(mid, param_id, param_value)");
  86. PROCESS_PACKET_21(module_get_reg, "(mid, param_id)");
  87. PROCESS_PACKET_11(module_readio, "(mid)");
  88. PROCESS_PACKET_30(module_writeio, "(mid,ioindex,io)");
  89. PROCESS_PACKET_21(module_read_adc, "(mid,adc_id, adcindex)");
  90. PROCESS_PACKET_11(module_get_error, "(mid)");
  91. PROCESS_PACKET_10(module_clear_error, "(mid)");
  92. PROCESS_PACKET_20(module_set_inited_flag, "(mid, flag)");
  93. PROCESS_PACKET_11(module_get_inited_flag, "(mid)");
  94. PROCESS_PACKET_10(module_factory_reset, "(mid)");
  95. PROCESS_PACKET_10(module_flush_cfg, "(mid)");
  96. PROCESS_PACKET_10(module_active_cfg, "(mid)");
  97. cancmder->regCMD("module_read_raw", "(mid, readsize)", 2, [this](int32_t paramN, const char* paraV[], ICmdParserACK* ack) {
  98. if (atoi(paraV[2]) > (int32_t)sizeof(ack->rawdata)) {
  99. ack->ecode = err::kbuffer_not_enough;
  100. return;
  101. }
  102. ack->rawlen = sizeof(ack->rawdata);
  103. ack->ecode = m_deviceManager->module_read_raw(atoi(paraV[0]), atoi(paraV[1]), ack->rawdata, &ack->rawlen);
  104. ack->acktype = ICmdParserACK::kAckType_buf;
  105. });
  106. PROCESS_PACKET_20(module_enable, "(mid, enable)");
  107. #if 0
  108. virtual int32_t motor_enable(int32_t enable) { return err::koperation_not_support; }
  109. virtual int32_t motor_rotate(int32_t direction, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
  110. virtual int32_t motor_move_by(int32_t distance, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
  111. virtual int32_t motor_move_to(int32_t position, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
  112. virtual int32_t motor_rotate_acctime(int32_t direction, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
  113. virtual int32_t motor_move_by_acctime(int32_t distance, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
  114. virtual int32_t motor_move_to_acctime(int32_t position, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
  115. virtual int32_t motor_rotate_with_torque(int32_t direction, int32_t torque) { return err::koperation_not_support; }
  116. virtual int32_t motor_move_to_torque(int32_t pos, int32_t torque, int32_t overtime) { return err::koperation_not_support; }
  117. virtual int32_t motor_move_to_zero_forward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; }
  118. virtual int32_t motor_move_to_zero_backward(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; }
  119. virtual int32_t motor_move_to_zero_forward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; }
  120. virtual int32_t motor_move_to_zero_backward_and_calculated_shift(int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { return err::koperation_not_support; }
  121. virtual int32_t motor_read_pos(int32_t* pos) { return err::koperation_not_support; }
  122. virtual int32_t motor_set_current_pos_by_change_shift(int32_t pos) { return err::koperation_not_support; } // һ�����ڶ���
  123. virtual int32_t motor_calculated_pos_by_move_to_zero() { return err::koperation_not_support; }
  124. #endif
  125. PROCESS_PACKET_20(motor_enable, "(mid, enable)");
  126. PROCESS_PACKET_40(motor_rotate, "(mid, direction, motor_velocity, acc)");
  127. PROCESS_PACKET_40(motor_move_by, "(mid, distance, motor_velocity, acc)");
  128. PROCESS_PACKET_40(motor_move_to, "(mid, position, motor_velocity, acc)");
  129. PROCESS_PACKET_40(motor_rotate_acctime, "(mid, direction, motor_velocity, acctime)");
  130. PROCESS_PACKET_40(motor_move_by_acctime, "(mid, distance, motor_velocity, acctime)");
  131. PROCESS_PACKET_40(motor_move_to_acctime, "(mid, position, motor_velocity, acctime)");
  132. PROCESS_PACKET_30(motor_rotate_with_torque, "(mid, pos, torque)");
  133. PROCESS_PACKET_40(motor_move_to_torque, "(mid, pos, torque, overtime)");
  134. PROCESS_PACKET_50(motor_move_to_zero_forward, "(mid, findzerospeed, findzeroedge_speed, acc, overtime)");
  135. PROCESS_PACKET_50(motor_move_to_zero_backward, "(mid, findzerospeed, findzeroedge_speed, acc, overtime)");
  136. PROCESS_PACKET_11(motor_read_pos, "(mid)");
  137. PROCESS_PACKET_20(motor_set_current_pos_by_change_shift, "(mid, pos)");
  138. PROCESS_PACKET_50(motor_move_to_zero_forward_and_calculated_shift, "(mid, findzerospeed, findzeroedge_speed, acc, overtime)");
  139. PROCESS_PACKET_50(motor_move_to_zero_backward_and_calculated_shift, "(mid, findzerospeed, findzeroedge_speed, acc, overtime)");
  140. PROCESS_PACKET_10(motor_calculated_pos_by_move_to_zero, "(mid)");
  141. #if 0
  142. virtual ~ZIXYMotor() {}
  143. virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; }
  144. virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; }
  145. virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; }
  146. virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; }
  147. virtual int32_t xymotor_move_to_zero_and_calculated_shift() { return err::koperation_not_support; }
  148. virtual int32_t xymotor_read_pos(int32_t *x, int32_t *y) { return err::koperation_not_support; }
  149. virtual int32_t xymotor_calculated_pos_by_move_to_zero() { return err::koperation_not_support; }
  150. #endif
  151. PROCESS_PACKET_20(xymotor_enable, "(mid, enable)");
  152. PROCESS_PACKET_40(xymotor_move_by, "(mid, dx, dy, motor_velocity)");
  153. PROCESS_PACKET_40(xymotor_move_to, "(mid, x, y, motor_velocity)");
  154. PROCESS_PACKET_10(xymotor_move_to_zero, "(mid)");
  155. PROCESS_PACKET_10(xymotor_move_to_zero_and_calculated_shift, "(mid)");
  156. PROCESS_PACKET_12(xymotor_read_pos, "(mid)");
  157. PROCESS_PACKET_10(xymotor_calculated_pos_by_move_to_zero, "(mid)");
  158. }