正点原子开发板 alientek_develop_board cancmder
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.

198 lines
9.4 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #include "app_zmodule_device_manager.hpp"
  2. #include "sdk/os/zos.hpp"
  3. #define TAG "APPDM"
  4. #define DM ZModuleDeviceManager
  5. using namespace iflytop;
  6. void APPDM::initialize(IZcanCmderMaster *m_cancmder) { //
  7. DM::initialize(m_cancmder);
  8. }
  9. void APPDM::registerModule(ZIModule *module) { DM::registerModule(module); }
  10. /*******************************************************************************
  11. * ZIModule *
  12. *******************************************************************************/
  13. #define DOCMD(exptr) \
  14. { \
  15. int32_t errcode = exptr; \
  16. if (errcode != 0) { \
  17. ZLOGE(TAG, "do %s fail,errcode %s(%d)", #exptr, err::error2str(errcode), errcode); \
  18. } \
  19. return errcode; \
  20. }
  21. int32_t APPDM::module_stop(uint16_t id) { //
  22. ZLOGI(TAG, "module_stop %d", id);
  23. DOCMD(DM::module_stop(id));
  24. }
  25. int32_t APPDM::module_break(uint16_t id) { //
  26. ZLOGI(TAG, "module_break %d", id);
  27. DOCMD(DM::module_break(id));
  28. }
  29. int32_t APPDM::module_get_last_exec_status(uint16_t id, int32_t *status) { //
  30. DOCMD(DM::module_get_last_exec_status(id, status));
  31. }
  32. int32_t APPDM::module_get_status(uint16_t id, int32_t *status) { //
  33. DOCMD(DM::module_get_status(id, status));
  34. }
  35. int32_t APPDM::module_set_param(uint16_t id, int32_t param_id, int32_t param_value) { //
  36. ZLOGI(TAG, "module_set_param %d %d", id, param_value);
  37. DOCMD(DM::module_set_param(id, param_id, param_value));
  38. }
  39. int32_t APPDM::module_get_param(uint16_t id, int32_t param_id, int32_t *param_value) { //
  40. DOCMD(DM::module_get_param(id, param_id, param_value));
  41. }
  42. int32_t APPDM::module_readio(uint16_t id, int32_t *io) { //
  43. DOCMD(DM::module_readio(id, io));
  44. }
  45. int32_t APPDM::module_writeio(uint16_t id, int32_t io) { //
  46. ZLOGI(TAG, "module_writeio %d %d", id, io);
  47. DOCMD(DM::module_writeio(id, io));
  48. }
  49. int32_t APPDM::module_read_adc(uint16_t id, int32_t adcindex, int32_t *adc) { //
  50. DOCMD(DM::module_read_adc(id, adcindex, adc));
  51. }
  52. int32_t APPDM::module_get_error(uint16_t id, int32_t *iserror) { //
  53. DOCMD(DM::module_get_error(id, iserror));
  54. }
  55. int32_t APPDM::module_clear_error(uint16_t id) { //
  56. ZLOGI(TAG, "module_clear_error %d", id);
  57. DOCMD(DM::module_clear_error(id));
  58. }
  59. int32_t APPDM::module_set_inited_flag(uint16_t id, int32_t flag) { //
  60. ZLOGI(TAG, "module_set_inited_flag %d %d", id, flag);
  61. DOCMD(DM::module_set_inited_flag(id, flag));
  62. }
  63. int32_t APPDM::module_get_inited_flag(uint16_t id, int32_t *flag) { //
  64. DOCMD(DM::module_get_inited_flag(id, flag));
  65. }
  66. int32_t APPDM::module_factory_reset(uint16_t id) { //
  67. ZLOGI(TAG, "module_factory_reset %d", id);
  68. DOCMD(DM::module_factory_reset(id));
  69. }
  70. int32_t APPDM::module_flush_cfg(uint16_t id) { //
  71. ZLOGI(TAG, "module_flush_cfg %d", id);
  72. DOCMD(DM::module_flush_cfg(id));
  73. }
  74. int32_t APPDM::module_active_cfg(uint16_t id) { //
  75. ZLOGI(TAG, "module_active_cfg %d", id);
  76. DOCMD(DM::module_active_cfg(id));
  77. }
  78. int32_t APPDM::module_set_state(uint16_t id, int32_t state_id, int32_t state_value) { //
  79. ZLOGI(TAG, "module_set_state %d %d %d", id, state_id, state_value);
  80. DOCMD(DM::module_set_state(id, state_id, state_value));
  81. }
  82. int32_t APPDM::module_get_state(uint16_t id, int32_t state_id, int32_t *state_value) { //
  83. DOCMD(DM::module_get_state(id, state_id, state_value));
  84. }
  85. /*******************************************************************************
  86. * ZIMotor *
  87. *******************************************************************************/
  88. int32_t APPDM::motor_enable(uint16_t id, int32_t enable) { //
  89. ZLOGI(TAG, "motor_enable %d %d", id, enable);
  90. DOCMD(DM::motor_enable(id, enable));
  91. }
  92. int32_t APPDM::motor_rotate(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acc) { //
  93. ZLOGI(TAG, "motor_rotate %d %d %d %d", id, direction, motor_velocity, acc);
  94. DOCMD(DM::motor_rotate(id, direction, motor_velocity, acc));
  95. }
  96. int32_t APPDM::motor_move_by(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acc) { //
  97. ZLOGI(TAG, "motor_move_by %d %d %d %d", id, distance, motor_velocity, acc);
  98. DOCMD(DM::motor_move_by(id, distance, motor_velocity, acc));
  99. }
  100. int32_t APPDM::motor_move_to(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acc) { //
  101. ZLOGI(TAG, "motor_move_to %d %d %d %d", id, position, motor_velocity, acc);
  102. DOCMD(DM::motor_move_to(id, position, motor_velocity, acc));
  103. }
  104. int32_t APPDM::motor_rotate_acctime(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acctime) { //
  105. ZLOGI(TAG, "motor_rotate_acctime %d %d %d %d", id, direction, motor_velocity, acctime);
  106. DOCMD(DM::motor_rotate_acctime(id, direction, motor_velocity, acctime));
  107. }
  108. int32_t APPDM::motor_move_by_acctime(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acctime) { //
  109. ZLOGI(TAG, "motor_move_by_acctime %d %d %d %d", id, distance, motor_velocity, acctime);
  110. DOCMD(DM::motor_move_by_acctime(id, distance, motor_velocity, acctime));
  111. }
  112. int32_t APPDM::motor_move_to_acctime(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acctime) { //
  113. ZLOGI(TAG, "motor_move_to_acctime %d %d %d %d", id, position, motor_velocity, acctime);
  114. DOCMD(DM::motor_move_to_acctime(id, position, motor_velocity, acctime));
  115. }
  116. int32_t APPDM::motor_move_to_zero_forward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { //
  117. ZLOGI(TAG, "motor_move_to_zero_forward %d %d %d %d %d", id, findzerospeed, findzeroedge_speed, acc, overtime);
  118. DOCMD(DM::motor_move_to_zero_forward(id, findzerospeed, findzeroedge_speed, acc, overtime));
  119. }
  120. int32_t APPDM::motor_move_to_zero_backward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { //
  121. ZLOGI(TAG, "motor_move_to_zero_backward %d %d %d %d %d", id, findzerospeed, findzeroedge_speed, acc, overtime);
  122. DOCMD(DM::motor_move_to_zero_backward(id, findzerospeed, findzeroedge_speed, acc, overtime));
  123. }
  124. int32_t APPDM::motor_rotate_with_torque(uint16_t id, int32_t direction, int32_t torque) { //
  125. ZLOGI(TAG, "motor_rotate_with_torque %d %d %d", id, direction, torque);
  126. DOCMD(DM::motor_rotate_with_torque(id, direction, torque));
  127. }
  128. int32_t APPDM::motor_move_to_torque(uint16_t id, int32_t pos, int32_t torque, int32_t overtime) { //
  129. ZLOGI(TAG, "motor_move_to_torque %d %d %d %d", id, pos, torque, overtime);
  130. DOCMD(DM::motor_move_to_torque(id, pos, torque, overtime));
  131. }
  132. int32_t APPDM::motor_read_pos(uint16_t id, int32_t *pos) { //
  133. DOCMD(DM::motor_read_pos(id, pos));
  134. }
  135. int32_t APPDM::motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos) { //
  136. ZLOGI(TAG, "motor_set_current_pos_by_change_shift %d %d", id, pos);
  137. DOCMD(DM::motor_set_current_pos_by_change_shift(id, pos));
  138. }
  139. int32_t APPDM::motor_move_to_zero_forward_and_calculated_shift(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { //
  140. ZLOGI(TAG, "motor_move_to_zero_forward_and_calculated_shift %d %d %d %d %d", id, findzerospeed, findzeroedge_speed, acc, overtime);
  141. DOCMD(DM::motor_move_to_zero_forward_and_calculated_shift(id, findzerospeed, findzeroedge_speed, acc, overtime));
  142. }
  143. int32_t APPDM::motor_move_to_zero_backward_and_calculated_shift(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime) { //
  144. ZLOGI(TAG, "motor_move_to_zero_backward_and_calculated_shift %d %d %d %d %d", id, findzerospeed, findzeroedge_speed, acc, overtime);
  145. DOCMD(DM::motor_move_to_zero_backward_and_calculated_shift(id, findzerospeed, findzeroedge_speed, acc, overtime));
  146. }
  147. /*******************************************************************************
  148. * ZIXYMotor *
  149. *******************************************************************************/
  150. int32_t APPDM::xymotor_enable(uint16_t id, int32_t enable) { //
  151. ZLOGI(TAG, "xymotor_enable %d %d", id, enable);
  152. DOCMD(DM::xymotor_enable(id, enable));
  153. }
  154. int32_t APPDM::xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity) { //
  155. ZLOGI(TAG, "xymotor_move_by %d %d %d %d", id, dx, dy, motor_velocity);
  156. DOCMD(DM::xymotor_move_by(id, dx, dy, motor_velocity));
  157. }
  158. int32_t APPDM::xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity) { //
  159. ZLOGI(TAG, "xymotor_move_to %d %d %d %d", id, x, y, motor_velocity);
  160. DOCMD(DM::xymotor_move_to(id, x, y, motor_velocity));
  161. }
  162. int32_t APPDM::xymotor_move_to_zero(uint16_t id) { //
  163. ZLOGI(TAG, "xymotor_move_to_zero %d", id);
  164. DOCMD(DM::xymotor_move_to_zero(id));
  165. }
  166. int32_t APPDM::xymotor_move_to_zero_and_calculated_shift(uint16_t id) { //
  167. ZLOGI(TAG, "xymotor_move_to_zero_and_calculated_shift %d", id);
  168. DOCMD(DM::xymotor_move_to_zero_and_calculated_shift(id));
  169. }
  170. int32_t APPDM::xymotor_read_pos(uint16_t id, int32_t *x, int32_t *y) { //
  171. DOCMD(DM::xymotor_read_pos(id, x, y));
  172. }
  173. int32_t APPDM::xymotor_calculated_pos_by_move_to_zero(uint16_t id) { //
  174. ZLOGI(TAG, "xymotor_calculated_pos_by_move_to_zero %d", id);
  175. DOCMD(DM::xymotor_calculated_pos_by_move_to_zero(id));
  176. }