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.6 KiB
70 lines
2.6 KiB
#pragma once
|
|
#include <stddef.h>
|
|
#include <stdio.h>
|
|
|
|
#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; // Relative humidity %RH * 10
|
|
int16_t temp; // Temperature °C * 10
|
|
int16_t df_ptemp; // Dew/frost point temperature °C * 10
|
|
int16_t ah; // Absolute humidity g/m3 * 10
|
|
int16_t mr; // Mixing ratio g/kg * 10
|
|
int16_t wet_bulb_temp; // Wet-bulb temperature °C * 10
|
|
int16_t enthalpy; // 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
|