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.

70 lines
2.5 KiB

12 months ago
12 months ago
12 months ago
  1. #pragma once
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include "stm32basic/modbus/modbus_block_host.hpp"
  5. #include "stm32basic/zsdk.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; // Relative humidity %RH * 10
  13. int16_t temp; // Temperature °C * 10
  14. int16_t df_ptemp; // Dew/frost point temperature °C * 10
  15. int16_t ah; // Absolute humidity g/m3 * 10
  16. int16_t mr; // Mixing ratio g/kg * 10
  17. int16_t wet_bulb_temp; // Wet-bulb temperature °C * 10
  18. int16_t enthalpy; // Enthalpy kJ/kg * 10
  19. } hmp110_sensordata_t;
  20. #pragma pack()
  21. private:
  22. /***********************************************************************************************************************
  23. * DATA *
  24. ***********************************************************************************************************************/
  25. ModbusBlockHost* m_modbusBlockHost = NULL;
  26. int32_t m_id = 0;
  27. zmutex m_lock;
  28. hmp110_sensordata_t m_rdbuf;
  29. hmp110_sensordata_t m_cachedata;
  30. int32_t m_cache_errorcode = 0;
  31. zmutex m_cache_lock;
  32. zmutex m_chlock;
  33. public:
  34. /***********************************************************************************************************************
  35. * FUNC *
  36. ***********************************************************************************************************************/
  37. void init(ModbusBlockHost* modbusBlockHost);
  38. bool ping(int id);
  39. bool ping();
  40. void setid(int32_t id);
  41. void read_calibration_date(int32_t* year, int32_t* month, int32_t* day); // TODO
  42. int32_t read_errorcode(); // ret == -1 表明设备不在线
  43. bool read_reg(int32_t add, uint16_t* val, size_t len);
  44. bool read_sensor_data(hmp110_sensordata_t* sensordata);
  45. void updateSensorDataAndErrorcode();
  46. int32_t read_cache_errorcode();
  47. bool read_cache_sensor_data(hmp110_sensordata_t* sensordata);
  48. public:
  49. bool readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal, int overtimems);
  50. bool readReg03Muti(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal, int regNum, int overtimems);
  51. };
  52. } // namespace iflytop