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.

240 lines
13 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
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. void for_each_module(function<void(int32_t moduleid)> cb) {
  25. for (auto &it : m_modulers) {
  26. if (cb) cb(it.first);
  27. }
  28. }
  29. /*******************************************************************************
  30. * ZIModule *
  31. *******************************************************************************/
  32. #if 0
  33. virtual ~ZIModule() {}
  34. virtual int32_t getid(int32_t *id) = 0;
  35. virtual int32_t module_stop() = 0;
  36. virtual int32_t module_break() = 0;
  37. virtual int32_t module_get_last_exec_status(int32_t *status) = 0;
  38. virtual int32_t module_get_status(int32_t *status) = 0;
  39. virtual int32_t module_get_error(int32_t *iserror) = 0;
  40. virtual int32_t module_clear_error() = 0;
  41. virtual int32_t module_set_reg(int32_t param_id, int32_t param_value) { return err::koperation_not_support; }
  42. virtual int32_t module_get_reg(int32_t param_id, int32_t *param_value) { return err::koperation_not_support; }
  43. virtual int32_t module_readio(int32_t *io) { return err::koperation_not_support; }
  44. virtual int32_t module_writeio(int32_t io) { return err::koperation_not_support; }
  45. virtual int32_t module_read_adc(int32_t adcindex, int32_t *adc) { return err::koperation_not_support; }
  46. virtual int32_t module_set_inited_flag(int32_t flag) {
  47. m_inited_flag = flag;
  48. return 0;
  49. }
  50. virtual int32_t module_get_inited_flag(int32_t *flag) {
  51. *flag = m_inited_flag;
  52. return 0;
  53. }
  54. // kmodule_factory_reset = CMDID(1, 14), // para:{}, ack:{}
  55. // kmodule_flush_cfg = CMDID(1, 15), // para:{}, ack:{}
  56. // kmodule_active_cfg = CMDID(1, 16), // para:{}, ack:{}
  57. virtual int32_t module_factory_reset() { return err::koperation_not_support; }
  58. virtual int32_t module_flush_cfg() { return err::koperation_not_support; }
  59. virtual int32_t module_active_cfg() { return err::koperation_not_support; }
  60. virtual int32_t module_enable(int32_t enable) override;
  61. #endif
  62. virtual int32_t module_ping(uint16_t id);
  63. virtual int32_t module_stop(uint16_t id);
  64. virtual int32_t module_break(uint16_t id);
  65. virtual int32_t module_get_last_exec_status(uint16_t id, int32_t *status);
  66. virtual int32_t module_get_status(uint16_t id, int32_t *status);
  67. virtual int32_t module_set_reg(uint16_t id, int32_t param_id, int32_t param_value);
  68. virtual int32_t module_get_reg(uint16_t id, int32_t param_id, int32_t *param_value);
  69. virtual int32_t module_readio(uint16_t id, int32_t *io);
  70. virtual int32_t module_writeio(uint16_t id, int32_t ioindex, int32_t io);
  71. virtual int32_t module_read_adc(uint16_t id, int32_t adcindex, int32_t *adc);
  72. virtual int32_t module_get_error(uint16_t id, int32_t *iserror);
  73. virtual int32_t module_clear_error(uint16_t id);
  74. virtual int32_t module_set_inited_flag(uint16_t id, int32_t flag);
  75. virtual int32_t module_get_inited_flag(uint16_t id, int32_t *flag);
  76. virtual int32_t module_factory_reset(uint16_t id);
  77. virtual int32_t module_flush_cfg(uint16_t id);
  78. virtual int32_t module_active_cfg(uint16_t id);
  79. virtual int32_t module_read_raw(uint16_t id, int32_t startadd, uint8_t *data, int32_t *len);
  80. virtual int32_t module_enable(uint16_t id, int32_t enable);
  81. virtual int32_t module_start(uint16_t id);
  82. /*******************************************************************************
  83. * ZIMotor *
  84. *******************************************************************************/
  85. #if 0
  86. virtual int32_t motor_enable(int32_t enable) { return err::koperation_not_support; }
  87. virtual int32_t motor_rotate(int32_t direction, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
  88. virtual int32_t motor_move_by(int32_t distance, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
  89. virtual int32_t motor_move_to(int32_t position, int32_t motor_velocity, int32_t acc) { return err::koperation_not_support; }
  90. virtual int32_t motor_rotate_acctime(int32_t direction, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
  91. virtual int32_t motor_move_by_acctime(int32_t distance, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
  92. virtual int32_t motor_move_to_acctime(int32_t position, int32_t motor_velocity, int32_t acctime) { return err::koperation_not_support; }
  93. virtual int32_t motor_rotate_with_torque(int32_t direction, int32_t torque) { return err::koperation_not_support; }
  94. virtual int32_t motor_move_to_torque(int32_t pos, int32_t torque, int32_t overtime) { return err::koperation_not_support; }
  95. 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; }
  96. 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; }
  97. 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; }
  98. 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; }
  99. virtual int32_t motor_read_pos(int32_t* pos) { return err::koperation_not_support; }
  100. virtual int32_t motor_set_current_pos_by_change_shift(int32_t pos) { return err::koperation_not_support; } // һ�����ڶ���?
  101. virtual int32_t motor_calculated_pos_by_move_to_zero() { return err::koperation_not_support; }
  102. virtual int32_t motor_easy_rotate(int32_t direction) { return err::koperation_not_support; };
  103. virtual int32_t motor_easy_move_by(int32_t distance) { return err::koperation_not_support; };
  104. virtual int32_t motor_easy_move_to(int32_t position) { return err::koperation_not_support; };
  105. virtual int32_t motor_easy_move_to_zero(int32_t direction) { return err::koperation_not_support; };
  106. #endif
  107. virtual int32_t motor_enable(uint16_t id, int32_t enable);
  108. virtual int32_t motor_rotate(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acc);
  109. virtual int32_t motor_move_by(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acc);
  110. virtual int32_t motor_move_to(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acc);
  111. virtual int32_t motor_rotate_acctime(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acctime);
  112. virtual int32_t motor_move_by_acctime(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acctime);
  113. virtual int32_t motor_move_to_acctime(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acctime);
  114. virtual int32_t motor_move_to_zero_forward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  115. virtual int32_t motor_move_to_zero_backward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  116. virtual int32_t motor_rotate_with_torque(uint16_t id, int32_t direction, int32_t torque);
  117. virtual int32_t motor_read_pos(uint16_t id, int32_t *pos);
  118. virtual int32_t motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos);
  119. 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);
  120. 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);
  121. virtual int32_t motor_move_to_torque(uint16_t id, int32_t pos, int32_t torque, int32_t overtime);
  122. virtual int32_t motor_calculated_pos_by_move_to_zero(uint16_t id);
  123. virtual int32_t motor_easy_rotate(uint16_t id, int32_t direction);
  124. virtual int32_t motor_easy_move_by(uint16_t id, int32_t distance);
  125. virtual int32_t motor_easy_move_to(uint16_t id, int32_t position);
  126. virtual int32_t motor_easy_move_to_zero(uint16_t id, int32_t direction);
  127. /*******************************************************************************
  128. * ZIXYMotor *
  129. *******************************************************************************/
  130. #if 0
  131. virtual ~ZIXYMotor() {}
  132. virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; }
  133. virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; }
  134. virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; }
  135. virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; }
  136. virtual int32_t xymotor_move_to_zero_and_calculated_shift() { return err::koperation_not_support; }
  137. virtual int32_t xymotor_read_pos(int32_t *x, int32_t *y) { return err::koperation_not_support; }
  138. virtual int32_t xymotor_calculated_pos_by_move_to_zero() { return err::koperation_not_support; }
  139. #endif
  140. virtual int32_t xymotor_enable(uint16_t id, int32_t enable);
  141. virtual int32_t xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity);
  142. virtual int32_t xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity);
  143. virtual int32_t xymotor_move_to_zero(uint16_t id);
  144. virtual int32_t xymotor_move_to_zero_and_calculated_shift(uint16_t id);
  145. virtual int32_t xymotor_read_pos(uint16_t id, int32_t *x, int32_t *y);
  146. virtual int32_t xymotor_calculated_pos_by_move_to_zero(uint16_t id);
  147. #if 0
  148. virtual int32_t code_scaner_start_scan() { return err::koperation_not_support; }
  149. virtual int32_t code_scaner_stop_scan() { return err::koperation_not_support; }
  150. virtual int32_t code_scaner_read_scaner_result(int32_t startadd, uint8_t *data, int32_t *len) { return err::koperation_not_support; }
  151. #endif
  152. virtual int32_t code_scaner_start_scan(uint16_t id);
  153. virtual int32_t code_scaner_stop_scan(uint16_t id);
  154. virtual int32_t code_scaner_read_scaner_result(uint16_t id, int32_t startadd, uint8_t *data, int32_t *len);
  155. #if 0
  156. virtual int32_t pipette_ctrl_init_device() { return err::koperation_not_support; };
  157. virtual int32_t pipette_ctrl_put_tip() { return err::koperation_not_support; };
  158. virtual int32_t pipette_ctrl_move_to_ul(int32_t ul) { return err::koperation_not_support; };
  159. #endif
  160. virtual int32_t pipette_ctrl_init_device(uint16_t id);
  161. virtual int32_t pipette_ctrl_put_tip(uint16_t id);
  162. virtual int32_t pipette_ctrl_move_to_ul(uint16_t id, int32_t ul);
  163. #if 0
  164. virtual int32_t a8000_optical_module_power_ctrl(int32_t state) = 0;
  165. virtual int32_t a8000_optical_open_laser(int32_t type) = 0;
  166. virtual int32_t a8000_optical_close_laser(int32_t type) = 0;
  167. virtual int32_t a8000_optical_set_laster_gain(int32_t type, int32_t gain) = 0;
  168. virtual int32_t a8000_optical_set_scan_amp_gain(int32_t type, int32_t gain) = 0;
  169. virtual int32_t a8000_optical_read_scanner_adc_val(int32_t type, int32_t* adcval) = 0;
  170. virtual int32_t a8000_optical_read_laster_adc_val(int32_t type, int32_t* adcval) = 0;
  171. virtual int32_t a8000_optical_scan_current_point_amp_adc_val(int32_t type, int32_t lastergain, int32_t ampgain, int32_t* laster_fb_val, int32_t* adcval) = 0;
  172. #endif
  173. virtual int32_t a8000_optical_module_power_ctrl(uint16_t id, int32_t state);
  174. virtual int32_t a8000_optical_open_laser(uint16_t id, int32_t type);
  175. virtual int32_t a8000_optical_close_laser(uint16_t id, int32_t type);
  176. virtual int32_t a8000_optical_set_laster_gain(uint16_t id, int32_t type, int32_t gain);
  177. virtual int32_t a8000_optical_set_scan_amp_gain(uint16_t id, int32_t type, int32_t gain);
  178. virtual int32_t a8000_optical_read_scanner_adc_val(uint16_t id, int32_t type, int32_t *adcval);
  179. virtual int32_t a8000_optical_read_laster_adc_val(uint16_t id, int32_t type, int32_t *adcval);
  180. virtual int32_t a8000_optical_scan_current_point_amp_adc_val(uint16_t id, int32_t type, int32_t lastergain, int32_t ampgain, int32_t *laster_fb_val, int32_t *adcval);
  181. virtual ~ZModuleDeviceManager() {}
  182. private:
  183. template <typename T>
  184. int32_t findModule(uint16_t id, T **module) {
  185. auto it = m_modulers.find(id);
  186. if (it == m_modulers.end()) {
  187. return err::kmodule_not_found;
  188. }
  189. T *_module = dynamic_cast<T *>(it->second);
  190. if (_module == nullptr) {
  191. return err::koperation_not_support;
  192. }
  193. *module = _module;
  194. return 0;
  195. }
  196. };
  197. } // namespace iflytop