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