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.

173 lines
9.7 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
2 years ago
2 years ago
2 years ago
  1. #pragma once
  2. #include <map>
  3. #include "api/api.hpp"
  4. #include "api\i_zcan_cmder_master.hpp"
  5. #include "cmdid.hpp"
  6. namespace iflytop {
  7. class ZModuleDeviceManager {
  8. private:
  9. map<uint16_t, ZIModule *> m_modulers;
  10. IZcanCmderMaster *m_cancmder = nullptr;
  11. public:
  12. void initialize(IZcanCmderMaster *m_cancmder);
  13. void registerModule(ZIModule *module);
  14. /*******************************************************************************
  15. * ZIModule *
  16. *******************************************************************************/
  17. #if 0
  18. virtual ~ZIModule() {}
  19. virtual int32_t getid(int32_t *id) = 0;
  20. virtual int32_t module_stop() = 0;
  21. virtual int32_t module_break() = 0;
  22. virtual int32_t module_get_last_exec_status(int32_t *status) = 0;
  23. virtual int32_t module_get_status(int32_t *status) = 0;
  24. virtual int32_t module_get_error(int32_t *iserror) = 0;
  25. virtual int32_t module_clear_error() = 0;
  26. virtual int32_t module_set_param(int32_t param_id, int32_t param_value) { return err::koperation_not_support; }
  27. virtual int32_t module_get_param(int32_t param_id, int32_t *param_value) { return err::koperation_not_support; }
  28. virtual int32_t module_readio(int32_t *io) { return err::koperation_not_support; }
  29. virtual int32_t module_writeio(int32_t io) { return err::koperation_not_support; }
  30. virtual int32_t module_read_adc(int32_t adcindex, int32_t *adc) { return err::koperation_not_support; }
  31. virtual int32_t module_set_inited_flag(int32_t flag) {
  32. m_inited_flag = flag;
  33. return 0;
  34. }
  35. virtual int32_t module_get_inited_flag(int32_t *flag) {
  36. *flag = m_inited_flag;
  37. return 0;
  38. }
  39. // kmodule_factory_reset = CMDID(1, 14), // para:{}, ack:{}
  40. // kmodule_flush_cfg = CMDID(1, 15), // para:{}, ack:{}
  41. // kmodule_active_cfg = CMDID(1, 16), // para:{}, ack:{}
  42. virtual int32_t module_factory_reset() { return err::koperation_not_support; }
  43. virtual int32_t module_flush_cfg() { return err::koperation_not_support; }
  44. virtual int32_t module_active_cfg() { return err::koperation_not_support; }
  45. virtual int32_t module_set_state(int32_t state_id, int32_t state_value) { return err::koperation_not_support; }
  46. virtual int32_t module_get_state(int32_t state_id, int32_t *state_value) { return err::koperation_not_support; }
  47. virtual int32_t module_enable(int32_t enable) override;
  48. #endif
  49. virtual int32_t module_stop(uint16_t id);
  50. virtual int32_t module_break(uint16_t id);
  51. virtual int32_t module_get_last_exec_status(uint16_t id, int32_t *status);
  52. virtual int32_t module_get_status(uint16_t id, int32_t *status);
  53. virtual int32_t module_set_param(uint16_t id, int32_t param_id, int32_t param_value);
  54. virtual int32_t module_get_param(uint16_t id, int32_t param_id, int32_t *param_value);
  55. virtual int32_t module_readio(uint16_t id, int32_t *io);
  56. virtual int32_t module_writeio(uint16_t id, int32_t ioindex, int32_t io);
  57. virtual int32_t module_read_adc(uint16_t id, int32_t adcindex, int32_t *adc);
  58. virtual int32_t module_get_error(uint16_t id, int32_t *iserror);
  59. virtual int32_t module_clear_error(uint16_t id);
  60. virtual int32_t module_set_inited_flag(uint16_t id, int32_t flag);
  61. virtual int32_t module_get_inited_flag(uint16_t id, int32_t *flag);
  62. virtual int32_t module_factory_reset(uint16_t id);
  63. virtual int32_t module_flush_cfg(uint16_t id);
  64. virtual int32_t module_active_cfg(uint16_t id);
  65. virtual int32_t module_set_state(uint16_t id, int32_t state_id, int32_t state_value);
  66. virtual int32_t module_get_state(uint16_t id, int32_t state_id, int32_t *state_value);
  67. virtual int32_t module_read_raw(uint16_t id, int32_t startadd, uint8_t *data, int32_t *len);
  68. virtual int32_t module_enable(uint16_t id, int32_t enable);
  69. virtual int32_t module_start(uint16_t id);
  70. /*******************************************************************************
  71. * ZIMotor *
  72. *******************************************************************************/
  73. #if 0
  74. virtual int32_t motor_enable(int32_t enable) { return err::koperation_not_support; }
  75. virtual int32_t motor_rotate(int32_t direction, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
  76. virtual int32_t motor_move_by(int32_t distance, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
  77. virtual int32_t motor_move_to(int32_t position, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
  78. virtual int32_t motor_rotate_acctime(int32_t direction, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
  79. virtual int32_t motor_move_by_acctime(int32_t distance, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
  80. virtual int32_t motor_move_to_acctime(int32_t position, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
  81. virtual int32_t motor_rotate_with_torque(int32_t direction, int32_t torque) { return err::koperation_not_support; }
  82. virtual int32_t motor_move_to_torque(int32_t pos, int32_t torque, int32_t overtime) { return err::koperation_not_support; }
  83. 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; }
  84. 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; }
  85. 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; }
  86. 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; }
  87. virtual int32_t motor_read_pos(int32_t* pos) { return err::koperation_not_support; }
  88. virtual int32_t motor_set_current_pos_by_change_shift(int32_t pos) { return err::koperation_not_support; } // һ�����ڶ���
  89. #endif
  90. virtual int32_t motor_enable(uint16_t id, int32_t enable);
  91. virtual int32_t motor_rotate(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acc);
  92. virtual int32_t motor_move_by(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acc);
  93. virtual int32_t motor_move_to(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acc);
  94. virtual int32_t motor_rotate_acctime(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acctime);
  95. virtual int32_t motor_move_by_acctime(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acctime);
  96. virtual int32_t motor_move_to_acctime(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acctime);
  97. virtual int32_t motor_move_to_zero_forward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  98. virtual int32_t motor_move_to_zero_backward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  99. virtual int32_t motor_rotate_with_torque(uint16_t id, int32_t direction, int32_t torque);
  100. virtual int32_t motor_read_pos(uint16_t id, int32_t *pos);
  101. virtual int32_t motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos);
  102. virtual int32_t motor_move_to_zero_forward_and_calculated_shift(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  103. virtual int32_t motor_move_to_zero_backward_and_calculated_shift(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  104. virtual int32_t motor_move_to_torque(uint16_t id, int32_t pos, int32_t torque, int32_t overtime);
  105. /*******************************************************************************
  106. * ZIXYMotor *
  107. *******************************************************************************/
  108. #if 0
  109. virtual ~ZIXYMotor() {}
  110. virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; }
  111. virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; }
  112. virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; }
  113. virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; }
  114. virtual int32_t xymotor_move_to_zero_and_calculated_shift() { return err::koperation_not_support; }
  115. virtual int32_t xymotor_read_pos(int32_t *x, int32_t *y) { return err::koperation_not_support; }
  116. virtual int32_t xymotor_calculated_pos_by_move_to_zero() { return err::koperation_not_support; }
  117. #endif
  118. virtual int32_t xymotor_enable(uint16_t id, int32_t enable);
  119. virtual int32_t xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity);
  120. virtual int32_t xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity);
  121. virtual int32_t xymotor_move_to_zero(uint16_t id);
  122. virtual int32_t xymotor_move_to_zero_and_calculated_shift(uint16_t id);
  123. virtual int32_t xymotor_read_pos(uint16_t id, int32_t *x, int32_t *y);
  124. virtual int32_t xymotor_calculated_pos_by_move_to_zero(uint16_t id);
  125. virtual ~ZModuleDeviceManager() {}
  126. private:
  127. template <typename T>
  128. int32_t findModule(uint16_t id, T **module) {
  129. auto it = m_modulers.find(id);
  130. if (it == m_modulers.end()) {
  131. return err::kmodule_not_found;
  132. }
  133. T *_module = dynamic_cast<T *>(it->second);
  134. if (_module == nullptr) {
  135. return err::koperation_not_support;
  136. }
  137. *module = _module;
  138. return 0;
  139. }
  140. };
  141. } // namespace iflytop