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.

78 lines
2.7 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. namespace iflytop {
  8. #define PXX_PRESSURE_SENSOR_NUM 10
  9. class HPP272 {
  10. public:
  11. #pragma pack(1)
  12. typedef struct {
  13. uint16_t hydrogen_peroxide_volume; // ppm 0x0100
  14. uint16_t h2o_h2o2_rs; // %RS * 100
  15. uint16_t temperature1; // °C * 100
  16. uint16_t relative_humidity; // %RH * 100
  17. uint16_t absolute_hydrogen_peroxide; // mg/m3
  18. uint16_t h2o_h2o2dew_point_temperature; // °C * 100
  19. uint16_t reserved1; //
  20. uint16_t water_volume; // ppm
  21. uint16_t water_vapor_pressure; // hpa
  22. uint16_t absolute_humidity; // g/m3
  23. uint16_t water_vapor_saturation_pressure_h2o; // hpa
  24. uint16_t temperature2; // °C * 100
  25. uint16_t h2o2_vapor_pressure; // hpa
  26. uint16_t water_vapor_saturation_pressure_h2o_h2o2; // hpa
  27. } hpp272_data_t;
  28. #pragma pack()
  29. private:
  30. /***********************************************************************************************************************
  31. * DATA *
  32. ***********************************************************************************************************************/
  33. ModbusBlockHost* m_modbusBlockHost = NULL;
  34. int32_t m_id = 0;
  35. zmutex m_lock;
  36. hpp272_data_t m_readbuf;
  37. hpp272_data_t m_cachedata;
  38. int32_t m_cache_errorcode = 0;
  39. zmutex m_cache_lock;
  40. public:
  41. /***********************************************************************************************************************
  42. * FUNC *
  43. ***********************************************************************************************************************/
  44. /**
  45. * @brief
  46. *
  47. * @param modbusBlockHost
  48. */
  49. void init(ModbusBlockHost* modbusBlockHost);
  50. bool ping(int id);
  51. bool ping();
  52. void setid(int32_t id);
  53. void read_calibration_date(int32_t* year, int32_t* month, int32_t* day); // TODO
  54. int32_t read_errorcode(); // see datasheet page83
  55. bool read_reg(int32_t add, uint16_t* val, size_t len);
  56. bool read_sensor_data(hpp272_data_t* sensordata);
  57. void updateSensorDataAndErrorcode();
  58. int32_t read_cache_errorcode();
  59. bool read_cache_sensor_data(hpp272_data_t* sensordata);
  60. public:
  61. };
  62. } // namespace iflytop