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.

77 lines
2.8 KiB

12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
12 months ago
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include "stm32basic/stm32basic.hpp"
  5. #include "stm32components/stm32components.hpp"
  6. namespace iflytop {
  7. #define PXX_PRESSURE_SENSOR_NUM 10
  8. class HMP110 {
  9. public:
  10. #pragma pack(1)
  11. typedef struct {
  12. int16_t rh; // 257 Relative humidity %RH * 10
  13. int16_t temp; // 258 Temperature °C * 10
  14. int16_t placeholder0; // 259
  15. int16_t placeholder1; // 260
  16. int16_t df_ptemp; // 261 Dew/frost point temperature °C * 10
  17. int16_t placeholder2; // 262
  18. int16_t placeholder3; // 263
  19. int16_t ah; // 264 Absolute humidity g/m3 * 10
  20. int16_t mr; // 265 Mixing ratio g/kg * 10
  21. int16_t wet_bulb_temp; // 266 Wet-bulb temperature °C * 10
  22. int16_t placeholder4; // 267
  23. int16_t placeholder5; // 268
  24. int16_t placeholder6; // 269
  25. int16_t enthalpy; // 270 Enthalpy kJ/kg * 10
  26. } hmp110_sensordata_t;
  27. #pragma pack()
  28. private:
  29. /***********************************************************************************************************************
  30. * DATA *
  31. ***********************************************************************************************************************/
  32. ModbusBlockHost* m_modbusBlockHost = NULL;
  33. int32_t m_id = 0;
  34. zmutex m_lock = {"HMP110:m_lock"};
  35. hmp110_sensordata_t m_rdbuf;
  36. hmp110_sensordata_t m_cachedata;
  37. int32_t m_cache_errorcode = 0;
  38. zmutex m_cache_lock = {"HMP110:m_cache_lock"};
  39. zmutex m_chlock = {"HMP110:m_chlock"};
  40. public:
  41. /***********************************************************************************************************************
  42. * FUNC *
  43. ***********************************************************************************************************************/
  44. void init(ModbusBlockHost* modbusBlockHost);
  45. bool ping(int id);
  46. bool ping();
  47. void setid(int32_t id);
  48. void read_calibration_date(int32_t* year, int32_t* month, int32_t* day); // TODO
  49. int32_t read_errorcode(); // ret == -1 表明设备不在线
  50. bool read_reg(int32_t add, uint16_t* val, size_t len);
  51. bool read_sensor_data(hmp110_sensordata_t* sensordata);
  52. void updateSensorDataAndErrorcode();
  53. int32_t read_cache_errorcode();
  54. bool read_cache_sensor_data(hmp110_sensordata_t* sensordata);
  55. public:
  56. bool readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal, int overtimems);
  57. bool readReg03Muti(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal, int regNum, int overtimems);
  58. };
  59. } // namespace iflytop