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.

66 lines
2.5 KiB

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();
  13. void registerModule(uint16_t id, ZIModule *module);
  14. /*******************************************************************************
  15. * ZIModule *
  16. *******************************************************************************/
  17. int32_t stop(uint16_t id);
  18. int32_t brake(uint16_t id);
  19. int32_t get_last_exec_status(uint16_t id, int32_t *status);
  20. int32_t get_status(uint16_t id, int32_t *status);
  21. int32_t set_param(uint16_t id, int32_t param_id, int32_t param_value);
  22. int32_t get_param(uint16_t id, int32_t param_id, int32_t *param_value);
  23. int32_t readio(uint16_t id, int32_t *io);
  24. int32_t writeio(uint16_t id, int32_t io);
  25. int32_t read_adc(uint16_t id, int adcindex, int32_t *adc);
  26. /*******************************************************************************
  27. * ZIMotor *
  28. *******************************************************************************/
  29. int32_t motor_enable(uint16_t id, int32_t enable);
  30. int32_t motor_rotate(uint16_t id, int32_t direction, int32_t velocitylevel);
  31. int32_t motor_move_by(uint16_t id, int32_t distance, int32_t velocitylevel);
  32. int32_t motor_move_to(uint16_t id, int32_t position, int32_t velocitylevel);
  33. int32_t motor_move_to_with_torque(uint16_t id, int32_t pos, int32_t torque);
  34. /*******************************************************************************
  35. * ZIXYMotor *
  36. *******************************************************************************/
  37. int32_t xymotor_enable(uint16_t id, int32_t enable);
  38. int32_t xymotor_move_by(uint16_t id, int32_t dx, int32_t dy, int32_t velocitylevel);
  39. int32_t xymotor_move_to(uint16_t id, int32_t x, int32_t y, int32_t velocitylevel);
  40. private:
  41. template <typename T>
  42. int32_t findModule(uint16_t id, T **module) {
  43. auto it = m_modulers.find(id);
  44. if (it == m_modulers.end()) {
  45. return err::kce_no_such_module;
  46. }
  47. T *_module = dynamic_cast<T *>(it->second);
  48. if (_module == nullptr) {
  49. return err::kce_operation_not_support;
  50. }
  51. *module = _module;
  52. return 0;
  53. }
  54. };
  55. } // namespace iflytop