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.

79 lines
3.5 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
  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. int32_t module_stop(uint16_t id);
  18. int32_t module_break(uint16_t id);
  19. int32_t module_get_last_exec_status(uint16_t id, int32_t *status);
  20. int32_t module_get_status(uint16_t id, int32_t *status);
  21. int32_t module_set_param(uint16_t id, int32_t param_id, int32_t param_value);
  22. int32_t module_get_param(uint16_t id, int32_t param_id, int32_t *param_value);
  23. int32_t module_readio(uint16_t id, int32_t *io);
  24. int32_t module_writeio(uint16_t id, int32_t io);
  25. int32_t module_read_adc(uint16_t id, int32_t adcindex, int32_t *adc);
  26. int32_t module_get_error(uint16_t id, int32_t *iserror);
  27. int32_t module_clear_error(uint16_t id);
  28. int32_t module_set_inited_flag(uint16_t id, int32_t flag);
  29. int32_t module_get_inited_flag(uint16_t id, int32_t *flag);
  30. /*******************************************************************************
  31. * ZIMotor *
  32. *******************************************************************************/
  33. int32_t motor_enable(uint16_t id, int32_t enable);
  34. int32_t motor_rotate(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acc);
  35. int32_t motor_move_by(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acc);
  36. int32_t motor_move_to(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acc);
  37. int32_t motor_rotate_acctime(uint16_t id, int32_t direction, int32_t motor_velocity, int32_t acctime);
  38. int32_t motor_move_by_acctime(uint16_t id, int32_t distance, int32_t motor_velocity, int32_t acctime);
  39. int32_t motor_move_to_acctime(uint16_t id, int32_t position, int32_t motor_velocity, int32_t acctime);
  40. int32_t motor_move_to_zero_forward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  41. int32_t motor_move_to_zero_backward(uint16_t id, int32_t findzerospeed, int32_t findzeroedge_speed, int32_t acc, int32_t overtime);
  42. int32_t motor_move_to_with_torque(uint16_t id, int32_t pos, int32_t torque);
  43. int32_t motor_read_pos(uint16_t id, int32_t *pos);
  44. int32_t motor_set_current_pos_by_change_shift(uint16_t id, int32_t pos);
  45. /*******************************************************************************
  46. * ZIXYMotor *
  47. *******************************************************************************/
  48. int32_t xymotor_enable(uint16_t id, int32_t enable);
  49. int32_t xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t motor_velocity);
  50. int32_t xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t motor_velocity);
  51. private:
  52. template <typename T>
  53. int32_t findModule(uint16_t id, T **module) {
  54. auto it = m_modulers.find(id);
  55. if (it == m_modulers.end()) {
  56. return err::kmodule_not_found;
  57. }
  58. T *_module = dynamic_cast<T *>(it->second);
  59. if (_module == nullptr) {
  60. return err::koperation_not_support;
  61. }
  62. *module = _module;
  63. return 0;
  64. }
  65. };
  66. } // namespace iflytop