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.

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