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.

48 lines
1.3 KiB

12 months ago
12 months ago
12 months ago
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include "base/config_service.hpp"
  5. #include "stm32basic/modbus/modbus_block_host.hpp"
  6. #include "stm32basic/zsdk.hpp"
  7. /**
  8. * @brief
  9. *
  10. * https://iflytop1.feishu.cn/wiki/GQwCwHMqFiaJRwks80ncwaYKnSe
  11. */
  12. namespace iflytop {
  13. using namespace std;
  14. class PreportionalValveCtrl {
  15. public:
  16. typedef enum {
  17. kstate_stop = 0x0,
  18. kstate_running_forward = 0xaa,
  19. kstate_running_backward = 0xbb,
  20. kstate_err_state = 0xea,
  21. } work_state_t;
  22. private:
  23. /* data */
  24. ModbusBlockHost m_modbusBlockHost;
  25. int32_t val = 0;
  26. uint32_t m_last_set_valve_ticket = 0;
  27. uint16_t m_targetpos[255];
  28. public:
  29. PreportionalValveCtrl() {};
  30. ~PreportionalValveCtrl() {};
  31. void initialize(UART_HandleTypeDef* huart);
  32. int32_t setValvePos(int32_t valueid, int32_t pos);
  33. int32_t getValvePos(int32_t valueid, int32_t* pos);
  34. int32_t getValveOrderPos(int32_t valueid, int32_t* pos);
  35. int32_t isBusy(int32_t valueid, int32_t* busy);
  36. int32_t getValveWorkState(int32_t valueid, int32_t* state);
  37. private:
  38. int32_t writeReg06(uint8_t slaveAddr, uint16_t regAddr, uint16_t regVal);
  39. int32_t readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal);
  40. };
  41. } // namespace iflytop