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.

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