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.
|
|
#include "hpp272.hpp"
#include "stm32basic/modbus/modbus_block_host.hpp"
using namespace iflytop;
#define TAG "HPP272"
void HPP272::init(ModbusBlockHost* modbusBlockHost) { m_modbusBlockHost = modbusBlockHost; m_id = 240;
m_cache_lock.init(); } bool HPP272::ping(int id) { int16_t val = 0; return m_modbusBlockHost->readReg03(id, 0x1F00, (uint16_t*)&val, 100); }
void HPP272::setid(int32_t id) { m_id = id; }
void HPP272::read_calibration_date(int32_t* year, int32_t* month, int32_t* day) { // TODO
*year = 0; *month = 0; *day = 0; } int32_t HPP272::read_errorcode() { int16_t val = 0; bool suc = m_modbusBlockHost->readReg03(m_id, 0x0200, (uint16_t*)&val, 100); if (!suc) { return -1; }
// 0 = Status OK.
// 1 = Critical error,maintenance needed.
// 2 = Error, device may recover automatically.
// 4 = Warning.
// 8 = Notification.
// 16 = Calibration enabled
return val; }
bool HPP272::read_reg(int32_t add, uint16_t* val, size_t len) { return m_modbusBlockHost->readReg03Muti(m_id, add, val, len, 100); }
bool HPP272::read_sensor_data(hpp272_data_t* sensordata) { //
return m_modbusBlockHost->readReg03Muti(m_id, 0x0100, (uint16_t*)sensordata, sizeof(*sensordata) / 2, 100); }
void HPP272::updateSensorDataAndErrorcode() { if (!read_sensor_data(&m_readbuf)) { return; } int32_t errorcode = read_errorcode();
{ zlock_guard lck(m_cache_lock); m_cachedata = m_readbuf; m_cache_errorcode = errorcode; } }
int32_t HPP272::read_cache_errorcode() { zlock_guard lck(m_cache_lock); return m_cache_errorcode; } bool HPP272::read_cache_sensor_data(hpp272_data_t* sensordata) { zlock_guard lck(m_cache_lock); *sensordata = m_cachedata; return true; }
|