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.

243 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
  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 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 regindex, int32_t oldval, int32_t toval) {
  21. for (auto &cb : m_on_reg_val_change_event_cbs)
  22. if (cb) cb(moduleid, regindex, oldval,toval);
  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. virtual int32_t motor_easy_set_current_pos(int32_t pos) { return err::koperation_not_support; };
  107. #endif
  108. virtual int32_t motor_enable(uint16_t id, int32_t enable);
  109. virtual int32_t motor_rotate(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acc);
  110. virtual int32_t motor_move_by(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acc);
  111. virtual int32_t motor_move_to(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acc);
  112. virtual int32_t motor_rotate_acctime(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acctime);
  113. virtual int32_t motor_move_by_acctime(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acctime);
  114. virtual int32_t motor_move_to_acctime(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acctime);
  115. virtual int32_t motor_move_to_zero_forward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  116. virtual int32_t motor_move_to_zero_backward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  117. virtual int32_t motor_rotate_with_torque(uint16_t id, int32_t direction, int32_t torque);
  118. virtual int32_t motor_read_pos(uint16_t id, int32_t *pos);
  119. virtual int32_t motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos);
  120. 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);
  121. 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);
  122. virtual int32_t motor_move_to_torque(uint16_t id, int32_t pos, int32_t torque, int32_t overtime);
  123. virtual int32_t motor_calculated_pos_by_move_to_zero(uint16_t id);
  124. virtual int32_t motor_easy_rotate(uint16_t id, int32_t direction);
  125. virtual int32_t motor_easy_move_by(uint16_t id, int32_t distance);
  126. virtual int32_t motor_easy_move_to(uint16_t id, int32_t position);
  127. virtual int32_t motor_easy_move_to_zero(uint16_t id, int32_t direction);
  128. virtual int32_t motor_easy_set_current_pos(uint16_t id, int32_t pos);
  129. /*******************************************************************************
  130. * ZIXYMotor *
  131. *******************************************************************************/
  132. #if 0
  133. virtual ~ZIXYMotor() {}
  134. virtual int32_t xymotor_enable(int32_t enable) { return err::koperation_not_support; }
  135. virtual int32_t xymotor_move_by(int32_t dx, int32_t dy, int32_t motor_velocity) { return err::koperation_not_support; }
  136. virtual int32_t xymotor_move_to(int32_t x, int32_t y, int32_t motor_velocity) { return err::koperation_not_support; }
  137. virtual int32_t xymotor_move_to_zero() { return err::koperation_not_support; }
  138. virtual int32_t xymotor_move_to_zero_and_calculated_shift() { return err::koperation_not_support; }
  139. virtual int32_t xymotor_read_pos(int32_t *x, int32_t *y) { return err::koperation_not_support; }
  140. virtual int32_t xymotor_calculated_pos_by_move_to_zero() { return err::koperation_not_support; }
  141. #endif
  142. virtual int32_t xymotor_enable(uint16_t id, int32_t enable);
  143. virtual int32_t xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity);
  144. virtual int32_t xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity);
  145. virtual int32_t xymotor_move_to_zero(uint16_t id);
  146. virtual int32_t xymotor_move_to_zero_and_calculated_shift(uint16_t id);
  147. virtual int32_t xymotor_read_pos(uint16_t id, int32_t *x, int32_t *y);
  148. virtual int32_t xymotor_calculated_pos_by_move_to_zero(uint16_t id);
  149. #if 0
  150. virtual int32_t code_scaner_start_scan() { return err::koperation_not_support; }
  151. virtual int32_t code_scaner_stop_scan() { return err::koperation_not_support; }
  152. virtual int32_t code_scaner_read_scaner_result(int32_t startadd, uint8_t *data, int32_t *len) { return err::koperation_not_support; }
  153. virtual int32_t code_scaner_start_scan(uint16_t id);
  154. virtual int32_t code_scaner_stop_scan(uint16_t id);
  155. virtual int32_t code_scaner_read_scaner_result(uint16_t id, int32_t startadd, uint8_t *data, int32_t *len);
  156. #endif
  157. #if 0
  158. virtual int32_t pipette_ctrl_init_device() { return err::koperation_not_support; };
  159. virtual int32_t pipette_ctrl_put_tip() { return err::koperation_not_support; };
  160. virtual int32_t pipette_ctrl_move_to_ul(int32_t ul) { return err::koperation_not_support; };
  161. #endif
  162. virtual int32_t pipette_ctrl_init_device(uint16_t id);
  163. virtual int32_t pipette_ctrl_put_tip(uint16_t id);
  164. virtual int32_t pipette_ctrl_move_to_ul(uint16_t id, int32_t ul);
  165. #if 0
  166. virtual int32_t a8000_optical_module_power_ctrl(int32_t state) = 0;
  167. virtual int32_t a8000_optical_open_laser(int32_t type) = 0;
  168. virtual int32_t a8000_optical_close_laser(int32_t type) = 0;
  169. virtual int32_t a8000_optical_set_laster_gain(int32_t type, int32_t gain) = 0;
  170. virtual int32_t a8000_optical_set_scan_amp_gain(int32_t type, int32_t gain) = 0;
  171. virtual int32_t a8000_optical_read_scanner_adc_val(int32_t type, int32_t* adcval) = 0;
  172. virtual int32_t a8000_optical_read_laster_adc_val(int32_t type, int32_t* adcval) = 0;
  173. 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;
  174. #endif
  175. virtual int32_t a8000_optical_module_power_ctrl(uint16_t id, int32_t state);
  176. virtual int32_t a8000_optical_open_laser(uint16_t id, int32_t type);
  177. virtual int32_t a8000_optical_close_laser(uint16_t id, int32_t type);
  178. virtual int32_t a8000_optical_set_laster_gain(uint16_t id, int32_t type, int32_t gain);
  179. virtual int32_t a8000_optical_set_scan_amp_gain(uint16_t id, int32_t type, int32_t gain);
  180. virtual int32_t a8000_optical_read_scanner_adc_val(uint16_t id, int32_t type, int32_t *adcval);
  181. virtual int32_t a8000_optical_read_laster_adc_val(uint16_t id, int32_t type, int32_t *adcval);
  182. 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);
  183. virtual ~ZModuleDeviceManager() {}
  184. private:
  185. template <typename T>
  186. int32_t findModule(uint16_t id, T **module) {
  187. auto it = m_modulers.find(id);
  188. if (it == m_modulers.end()) {
  189. return err::kmodule_not_found;
  190. }
  191. T *_module = dynamic_cast<T *>(it->second);
  192. if (_module == nullptr) {
  193. return err::koperation_not_support;
  194. }
  195. *module = _module;
  196. return 0;
  197. }
  198. };
  199. } // namespace iflytop