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.

149 lines
7.3 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
  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. #endif
  48. int32_t module_stop(uint16_t id);
  49. int32_t module_break(uint16_t id);
  50. int32_t module_get_last_exec_status(uint16_t id, int32_t *status);
  51. int32_t module_get_status(uint16_t id, int32_t *status);
  52. int32_t module_set_param(uint16_t id, int32_t param_id, int32_t param_value);
  53. int32_t module_get_param(uint16_t id, int32_t param_id, int32_t *param_value);
  54. int32_t module_readio(uint16_t id, int32_t *io);
  55. int32_t module_writeio(uint16_t id, int32_t io);
  56. int32_t module_read_adc(uint16_t id, int32_t adcindex, int32_t *adc);
  57. int32_t module_get_error(uint16_t id, int32_t *iserror);
  58. int32_t module_clear_error(uint16_t id);
  59. int32_t module_set_inited_flag(uint16_t id, int32_t flag);
  60. int32_t module_get_inited_flag(uint16_t id, int32_t *flag);
  61. int32_t module_factory_reset(uint16_t id);
  62. int32_t module_flush_cfg(uint16_t id);
  63. int32_t module_active_cfg(uint16_t id);
  64. int32_t module_set_state(uint16_t id, int32_t state_id, int32_t state_value);
  65. int32_t module_get_state(uint16_t id, int32_t state_id, int32_t *state_value);
  66. /*******************************************************************************
  67. * ZIMotor *
  68. *******************************************************************************/
  69. #if 0
  70. 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;
  71. 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;
  72. #endif
  73. int32_t motor_enable(uint16_t id, int32_t enable);
  74. int32_t motor_rotate(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acc);
  75. int32_t motor_move_by(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acc);
  76. int32_t motor_move_to(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acc);
  77. int32_t motor_rotate_acctime(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acctime);
  78. int32_t motor_move_by_acctime(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acctime);
  79. int32_t motor_move_to_acctime(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acctime);
  80. int32_t motor_move_to_zero_forward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  81. int32_t motor_move_to_zero_backward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  82. int32_t motor_move_to_with_torque(uint16_t id, int32_t pos, int32_t torque);
  83. int32_t motor_read_pos(uint16_t id, int32_t *pos);
  84. int32_t motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos);
  85. 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);
  86. 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);
  87. /*******************************************************************************
  88. * ZIXYMotor *
  89. *******************************************************************************/
  90. #if 0
  91. virtual ~ZIXYMotor() {}
  92. virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; }
  93. virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; }
  94. virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; }
  95. virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; }
  96. virtual int32_t xymotor_move_to_zero_and_calculated_shift() { return err::koperation_not_support; }
  97. virtual int32_t xymotor_read_pos(int32_t *x, int32_t *y) { return err::koperation_not_support; }
  98. virtual int32_t xymotor_calculated_pos_by_move_to_zero() { return err::koperation_not_support; }
  99. #endif
  100. int32_t xymotor_enable(uint16_t id, int32_t enable);
  101. int32_t xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity);
  102. int32_t xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity);
  103. int32_t xymotor_move_to_zero(uint16_t id);
  104. int32_t xymotor_move_to_zero_and_calculated_shift(uint16_t id);
  105. int32_t xymotor_read_pos(uint16_t id, int32_t *x, int32_t *y);
  106. int32_t xymotor_calculated_pos_by_move_to_zero(uint16_t id);
  107. private:
  108. template <typename T>
  109. int32_t findModule(uint16_t id, T **module) {
  110. auto it = m_modulers.find(id);
  111. if (it == m_modulers.end()) {
  112. return err::kmodule_not_found;
  113. }
  114. T *_module = dynamic_cast<T *>(it->second);
  115. if (_module == nullptr) {
  116. return err::koperation_not_support;
  117. }
  118. *module = _module;
  119. return 0;
  120. }
  121. };
  122. } // namespace iflytop