#pragma once #include #include #include "stm32basic/stm32basic.hpp" #include "stm32components/stm32components.hpp" namespace iflytop { #define PXX_PRESSURE_SENSOR_NUM 10 class HMP110 { public: #pragma pack(1) typedef struct { int16_t rh; // 257 Relative humidity %RH * 10 int16_t temp; // 258 Temperature °C * 10 int16_t placeholder0; // 259 int16_t placeholder1; // 260 int16_t df_ptemp; // 261 Dew/frost point temperature °C * 10 int16_t placeholder2; // 262 int16_t placeholder3; // 263 int16_t ah; // 264 Absolute humidity g/m3 * 10 int16_t mr; // 265 Mixing ratio g/kg * 10 int16_t wet_bulb_temp; // 266 Wet-bulb temperature °C * 10 int16_t placeholder4; // 267 int16_t placeholder5; // 268 int16_t placeholder6; // 269 int16_t enthalpy; // 270 Enthalpy kJ/kg * 10 } hmp110_sensordata_t; #pragma pack() private: /*********************************************************************************************************************** * DATA * ***********************************************************************************************************************/ ModbusBlockHost* m_modbusBlockHost = NULL; int32_t m_id = 0; zmutex m_lock = {"HMP110:m_lock"}; hmp110_sensordata_t m_rdbuf; hmp110_sensordata_t m_cachedata; int32_t m_cache_errorcode = 0; zmutex m_cache_lock = {"HMP110:m_cache_lock"}; zmutex m_chlock = {"HMP110:m_chlock"}; public: /*********************************************************************************************************************** * FUNC * ***********************************************************************************************************************/ void init(ModbusBlockHost* modbusBlockHost); bool ping(int id); bool ping(); void setid(int32_t id); void read_calibration_date(int32_t* year, int32_t* month, int32_t* day); // TODO int32_t read_errorcode(); // ret == -1 表明设备不在线 bool read_reg(int32_t add, uint16_t* val, size_t len); bool read_sensor_data(hmp110_sensordata_t* sensordata); void updateSensorDataAndErrorcode(); int32_t read_cache_errorcode(); bool read_cache_sensor_data(hmp110_sensordata_t* sensordata); public: bool readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal, int overtimems); bool readReg03Muti(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal, int regNum, int overtimems); }; } // namespace iflytop