37 changed files with 885 additions and 74 deletions
-
63.cproject
-
2app_protocols/transmit_disfection_protocol/transmit_disfection_protocol.hpp
-
2stm32basic
-
2stm32components
-
BINucomponents/hmp110/HMM100-Datasheet-B210813ZH.pdf
-
BINucomponents/hmp110/HMP110 DOC247480-A Simplified Models.zip
-
BINucomponents/hmp110/HMP110-Datasheet-B210852ZH.pdf
-
BINucomponents/hmp110/HMP60-and-HMP110-Series-User-Guide-M211060EN-L.pdf
-
118ucomponents/hmp110/hmp110.cpp
-
70ucomponents/hmp110/hmp110.hpp
-
BINucomponents/hpp272/HPP272-使用说明书.pdf
-
8ucomponents/hpp272/README.md
-
71ucomponents/hpp272/hpp272.cpp
-
78ucomponents/hpp272/hpp272.hpp
-
BINucomponents/hpp272/过氧化氢传感器读取.zip
-
107ucomponents/preportional_valve/preportional_valve_ctrl.cpp
-
51ucomponents/preportional_valve/preportional_valve_ctrl.hpp
-
BINucomponents/pxx_pressure_sensor_driver/DP600--RS485通讯说明书V0.1.docx
-
BINucomponents/pxx_pressure_sensor_driver/HCP300新说明书.pdf
-
BINucomponents/pxx_pressure_sensor_driver/P100标准MODBUS RTU通讯协议.pdf
-
243ucomponents/pxx_pressure_sensor_driver/pxx_pressure_sensor_bus.cpp
-
73ucomponents/pxx_pressure_sensor_driver/pxx_pressure_sensor_bus.hpp
-
5ucomponents/ucomponents.hpp
-
7usrc/app_main.cpp
-
19usrc/base/appdep.hpp
-
14usrc/base/appthread/app_period_task_mgr.hpp
-
1usrc/base/appthread/work_queue.hpp
-
1usrc/base/config_service.cpp
-
4usrc/base/config_service.hpp
-
2usrc/base/device_info.hpp
-
1usrc/base/idtable/IdMgr.cpp
-
3usrc/base/idtable/IdMgr.hpp
-
3usrc/base/protocol_processer_utils.hpp
-
3usrc/base/utils/formula.hpp
-
4usrc/base/utils/halutils.hpp
-
2usrc/module/h2o2_sensor.cpp
-
2usrc/module/proportional_valve_ctrl.hpp
@ -1 +1 @@ |
|||||
Subproject commit 049e643b139652247636ddb1564345bb299b1aab |
|
||||
|
Subproject commit 54ccfa2fd5128c9a2f243eb2394a51cb47595f13 |
@ -1 +1 @@ |
|||||
Subproject commit bcca882e2f1f8688716246e4d376230dbc4de28f |
|
||||
|
Subproject commit d387a6d07dd669a43fafc96016635e3b95830a0c |
@ -0,0 +1,118 @@ |
|||||
|
#include "hmp110.hpp"
|
||||
|
|
||||
|
#include "stm32components/modbus/modbus_block_host.hpp"
|
||||
|
|
||||
|
using namespace iflytop; |
||||
|
|
||||
|
#define TAG "HMP110"
|
||||
|
|
||||
|
void HMP110::init(ModbusBlockHost* modbusBlockHost) { |
||||
|
m_modbusBlockHost = modbusBlockHost; |
||||
|
m_id = 240; |
||||
|
|
||||
|
m_cache_lock.init(); |
||||
|
m_chlock.init(); |
||||
|
} |
||||
|
|
||||
|
bool HMP110::readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal, int overtimems) { //
|
||||
|
zlock_guard lck(m_chlock); |
||||
|
// ZLOGI(TAG, "=============== readReg03 %d %d", slaveAddr, regAddr);
|
||||
|
bool ret = m_modbusBlockHost->readReg03(slaveAddr, regAddr, regVal, overtimems); |
||||
|
// ZLOGI(TAG, "=============== END%d", ret);
|
||||
|
|
||||
|
|
||||
|
return ret; |
||||
|
} |
||||
|
bool HMP110::readReg03Muti(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal, int regNum, int overtimems) { //
|
||||
|
zlock_guard lck(m_chlock); |
||||
|
// ZLOGI(TAG, "=============== readReg03Muti %d %d %d", slaveAddr, regAddr, regNum);
|
||||
|
bool ret = m_modbusBlockHost->readReg03Muti(slaveAddr, regAddr, regVal, regNum, overtimems); |
||||
|
// ZLOGI(TAG, "=============== END%d", ret);
|
||||
|
return ret; |
||||
|
} |
||||
|
bool HMP110::ping(int id) { |
||||
|
int16_t val = 0; |
||||
|
return readReg03(id, 0x1F00, (uint16_t*)&val, 300); |
||||
|
} |
||||
|
|
||||
|
void HMP110::setid(int32_t id) { m_id = id; } |
||||
|
|
||||
|
void HMP110::read_calibration_date(int32_t* year, int32_t* month, int32_t* day) { // TODO
|
||||
|
*year = 1; |
||||
|
*month = 2; |
||||
|
*day = 3; |
||||
|
} |
||||
|
int32_t HMP110::read_errorcode() { |
||||
|
int16_t val = 0; |
||||
|
bool suc = readReg03(m_id, 0x0200, (uint16_t*)&val, 300); |
||||
|
if (!suc) { |
||||
|
return -1; |
||||
|
} |
||||
|
|
||||
|
if (val == 1) { |
||||
|
return 0; |
||||
|
} |
||||
|
uint16_t ecodebuf[2]; |
||||
|
suc = readReg03Muti(m_id, 0x0203, ecodebuf, 2, 300); |
||||
|
|
||||
|
uint32_t ecode = ecodebuf[0] | (((uint32_t)ecodebuf[1]) << 16); |
||||
|
return ecode; |
||||
|
} |
||||
|
|
||||
|
bool HMP110::read_reg(int32_t add, uint16_t* val, size_t len) { |
||||
|
// ZLOGI(TAG, "read_reg %x %d", add, len);
|
||||
|
bool suc = readReg03Muti(m_id, add, val, len, 300); |
||||
|
// if (suc)
|
||||
|
// for (size_t i = 0; i < len; i++) {
|
||||
|
// ZLOGI(TAG, "val[%d] = %d", i, val[i]);
|
||||
|
// }
|
||||
|
// else
|
||||
|
// ZLOGE(TAG, "read_reg failed");
|
||||
|
return suc; |
||||
|
} |
||||
|
|
||||
|
bool HMP110::read_sensor_data(hmp110_sensordata_t* sensordata) { |
||||
|
uint16_t buf[7]; |
||||
|
bool suc = readReg03Muti(m_id, 0x0100, buf, 7, 300); |
||||
|
if (!suc) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
sensordata->rh = buf[0]; |
||||
|
sensordata->temp = buf[1]; |
||||
|
sensordata->df_ptemp = buf[2]; |
||||
|
sensordata->ah = buf[3]; |
||||
|
sensordata->mr = buf[4]; |
||||
|
sensordata->wet_bulb_temp = buf[5]; |
||||
|
sensordata->enthalpy = buf[6]; |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
void HMP110::updateSensorDataAndErrorcode() { |
||||
|
bool suc = read_sensor_data(&m_rdbuf); |
||||
|
osDelay(100); |
||||
|
int32_t errorcode = read_errorcode(); |
||||
|
if (errorcode != 0) { |
||||
|
ZLOGE(TAG, "errorcode: %d", errorcode); |
||||
|
} |
||||
|
if (!suc) { |
||||
|
ZLOGE(TAG, "read_sensor_data failed"); |
||||
|
errorcode = -1; |
||||
|
} |
||||
|
|
||||
|
{ |
||||
|
zlock_guard lck(m_cache_lock); |
||||
|
m_cachedata = m_rdbuf; |
||||
|
m_cache_errorcode = errorcode; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
int32_t HMP110::read_cache_errorcode() { |
||||
|
zlock_guard lck(m_cache_lock); |
||||
|
return m_cache_errorcode; |
||||
|
} |
||||
|
bool HMP110::read_cache_sensor_data(hmp110_sensordata_t* sensordata) { |
||||
|
zlock_guard lck(m_cache_lock); |
||||
|
*sensordata = m_cachedata; |
||||
|
return true; |
||||
|
} |
@ -0,0 +1,70 @@ |
|||||
|
#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_sensordata_t m_rdbuf; |
||||
|
|
||||
|
hmp110_sensordata_t m_cachedata; |
||||
|
int32_t m_cache_errorcode = 0; |
||||
|
zmutex m_cache_lock; |
||||
|
|
||||
|
zmutex 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
|
@ -0,0 +1,8 @@ |
|||||
|
|
||||
|
``` |
||||
|
注意事项: |
||||
|
1. 串口停止位是2位 |
||||
|
2. 波特率19200 |
||||
|
3. 默认ID 240 |
||||
|
|
||||
|
``` |
@ -0,0 +1,71 @@ |
|||||
|
#include "hpp272.hpp"
|
||||
|
|
||||
|
#include "stm32components/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; |
||||
|
} |
@ -0,0 +1,78 @@ |
|||||
|
#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 HPP272 { |
||||
|
public: |
||||
|
#pragma pack(1)
|
||||
|
typedef struct { |
||||
|
uint16_t hydrogen_peroxide_volume; // ppm 0x0100
|
||||
|
uint16_t h2o_h2o2_rs; // %RS * 100
|
||||
|
uint16_t temperature1; // °C * 100
|
||||
|
uint16_t relative_humidity; // %RH * 100
|
||||
|
uint16_t absolute_hydrogen_peroxide; // mg/m3
|
||||
|
uint16_t h2o_h2o2dew_point_temperature; // °C * 100
|
||||
|
uint16_t reserved1; //
|
||||
|
uint16_t water_volume; // ppm
|
||||
|
uint16_t water_vapor_pressure; // hpa
|
||||
|
uint16_t absolute_humidity; // g/m3
|
||||
|
uint16_t water_vapor_saturation_pressure_h2o; // hpa
|
||||
|
uint16_t temperature2; // °C * 100
|
||||
|
uint16_t h2o2_vapor_pressure; // hpa
|
||||
|
uint16_t water_vapor_saturation_pressure_h2o_h2o2; // hpa
|
||||
|
} hpp272_data_t; |
||||
|
#pragma pack()
|
||||
|
|
||||
|
private: |
||||
|
/***********************************************************************************************************************
|
||||
|
* DATA * |
||||
|
***********************************************************************************************************************/ |
||||
|
|
||||
|
ModbusBlockHost* m_modbusBlockHost = NULL; |
||||
|
|
||||
|
int32_t m_id = 0; |
||||
|
zmutex m_lock; |
||||
|
|
||||
|
hpp272_data_t m_readbuf; |
||||
|
|
||||
|
hpp272_data_t m_cachedata; |
||||
|
int32_t m_cache_errorcode = 0; |
||||
|
zmutex m_cache_lock; |
||||
|
|
||||
|
public: |
||||
|
/***********************************************************************************************************************
|
||||
|
* FUNC * |
||||
|
***********************************************************************************************************************/ |
||||
|
|
||||
|
/**
|
||||
|
* @brief |
||||
|
* |
||||
|
* @param modbusBlockHost |
||||
|
*/ |
||||
|
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(); // see datasheet page83
|
||||
|
bool read_reg(int32_t add, uint16_t* val, size_t len); |
||||
|
bool read_sensor_data(hpp272_data_t* sensordata); |
||||
|
|
||||
|
void updateSensorDataAndErrorcode(); |
||||
|
|
||||
|
int32_t read_cache_errorcode(); |
||||
|
bool read_cache_sensor_data(hpp272_data_t* sensordata); |
||||
|
|
||||
|
public: |
||||
|
}; |
||||
|
|
||||
|
} // namespace iflytop
|
@ -0,0 +1,107 @@ |
|||||
|
#include "preportional_valve_ctrl.hpp"
|
||||
|
|
||||
|
#include "transmit_disfection_protocol/transmit_disfection_protocol.hpp"
|
||||
|
using namespace iflytop; |
||||
|
using namespace zscanprotocol; |
||||
|
|
||||
|
#define WORK_STATE_REG 0x0000
|
||||
|
#define CTRL_STATE_REG 0x0001
|
||||
|
#define POS_STATE_REG 0x0013
|
||||
|
#define OVERTIME 30
|
||||
|
#define TAG "PreportionalValveCtrl"
|
||||
|
|
||||
|
void PreportionalValveCtrl::initialize(UART_HandleTypeDef* huart) { m_modbusBlockHost.initialize(huart); } |
||||
|
|
||||
|
int32_t PreportionalValveCtrl::writeReg06(uint8_t slaveAddr, uint16_t regAddr, uint16_t regVal) { |
||||
|
// 重发三次
|
||||
|
for (size_t i = 0; i < 3; i++) { |
||||
|
int32_t err = m_modbusBlockHost.writeReg06(slaveAddr, regAddr, regVal, OVERTIME); |
||||
|
if (err == 0) return 0; |
||||
|
} |
||||
|
return err::kerr_subdevice_offline; |
||||
|
} |
||||
|
int32_t PreportionalValveCtrl::readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal) { |
||||
|
// 重发三次
|
||||
|
for (size_t i = 0; i < 3; i++) { |
||||
|
int32_t err = m_modbusBlockHost.readReg03(slaveAddr, regAddr, regVal, OVERTIME); |
||||
|
if (err == 0) return 0; |
||||
|
} |
||||
|
return err::kerr_subdevice_offline; |
||||
|
} |
||||
|
|
||||
|
int32_t PreportionalValveCtrl::setValvePos(int32_t valueid, int32_t pos) { //
|
||||
|
int32_t ret = 0; |
||||
|
if (valueid > 255 || valueid < 1) { |
||||
|
return err::kerr_invalid_param; |
||||
|
} |
||||
|
ret = writeReg06(valueid, CTRL_STATE_REG, pos); |
||||
|
if (!ret) return err::kerr_subdevice_offline; |
||||
|
|
||||
|
m_last_set_valve_ticket = HAL_GetTick(); |
||||
|
m_targetpos[valueid] = pos; |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
int32_t PreportionalValveCtrl::getValvePos(int32_t valueid, int32_t* pos) { |
||||
|
int32_t ret = 0; |
||||
|
if (valueid > 255 || valueid < 1) { |
||||
|
return err::kerr_invalid_param; |
||||
|
} |
||||
|
|
||||
|
uint16_t pos16 = 0; |
||||
|
ret = readReg03(valueid, POS_STATE_REG, &pos16); |
||||
|
if (!ret) return err::kerr_subdevice_offline; |
||||
|
|
||||
|
*pos = pos16; |
||||
|
return 0; |
||||
|
} |
||||
|
int32_t PreportionalValveCtrl::getValveOrderPos(int32_t valueid, int32_t* pos) { |
||||
|
int32_t ret = 0; |
||||
|
if (valueid > 255 || valueid < 1) { |
||||
|
return err::kerr_invalid_param; |
||||
|
} |
||||
|
|
||||
|
uint16_t pos16 = 0; |
||||
|
ret = readReg03(valueid, CTRL_STATE_REG, &pos16); |
||||
|
if (!ret) return err::kerr_subdevice_offline; |
||||
|
|
||||
|
*pos = pos16; |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
int32_t PreportionalValveCtrl::isBusy(int32_t valueid, int32_t* busy) { |
||||
|
#if 1
|
||||
|
int32_t orderpos = 0; |
||||
|
int32_t pos = 0; |
||||
|
int32_t err = 0; |
||||
|
|
||||
|
#if 0
|
||||
|
err = getValveOrderPos(valueid, &orderpos); |
||||
|
if (err != 0) return err; |
||||
|
#endif
|
||||
|
orderpos = m_targetpos[valueid]; |
||||
|
|
||||
|
err = getValvePos(valueid, &pos); |
||||
|
if (err != 0) return err; |
||||
|
|
||||
|
if (abs(m_targetpos[valueid] - pos) <= 11) { |
||||
|
*busy = 0; |
||||
|
} else { |
||||
|
*busy = 1; |
||||
|
} |
||||
|
return 0; |
||||
|
#endif
|
||||
|
} |
||||
|
|
||||
|
int32_t PreportionalValveCtrl::getValveWorkState(int32_t valueid, int32_t* state) { |
||||
|
int32_t ret = 0; |
||||
|
if (valueid > 255 || valueid < 1) { |
||||
|
return err::kerr_invalid_param; |
||||
|
} |
||||
|
|
||||
|
uint16_t state16 = 0; |
||||
|
ret = readReg03(valueid, WORK_STATE_REG, &state16); |
||||
|
if (!ret) return err::kerr_subdevice_offline; |
||||
|
*state = state16; |
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,51 @@ |
|||||
|
#pragma once
|
||||
|
#include <stddef.h>
|
||||
|
#include <stdio.h>
|
||||
|
|
||||
|
#include "base/config_service.hpp"
|
||||
|
#include "stm32components/modbus/modbus_block_host.hpp"
|
||||
|
#include "stm32basic/stm32basic.hpp"
|
||||
|
#include "stm32components/stm32components.hpp"
|
||||
|
|
||||
|
/**
|
||||
|
* @brief |
||||
|
* |
||||
|
* https://iflytop1.feishu.cn/wiki/GQwCwHMqFiaJRwks80ncwaYKnSe
|
||||
|
*/ |
||||
|
|
||||
|
namespace iflytop { |
||||
|
using namespace std; |
||||
|
class PreportionalValveCtrl { |
||||
|
public: |
||||
|
typedef enum { |
||||
|
kstate_stop = 0x0, |
||||
|
kstate_running_forward = 0xaa, |
||||
|
kstate_running_backward = 0xbb, |
||||
|
kstate_err_state = 0xea, |
||||
|
} work_state_t; |
||||
|
|
||||
|
private: |
||||
|
/* data */ |
||||
|
ModbusBlockHost m_modbusBlockHost; |
||||
|
int32_t val = 0; |
||||
|
uint32_t m_last_set_valve_ticket = 0; |
||||
|
uint16_t m_targetpos[255]; |
||||
|
|
||||
|
public: |
||||
|
PreportionalValveCtrl() {}; |
||||
|
~PreportionalValveCtrl() {}; |
||||
|
|
||||
|
void initialize(UART_HandleTypeDef* huart); |
||||
|
int32_t setValvePos(int32_t valueid, int32_t pos); |
||||
|
int32_t getValvePos(int32_t valueid, int32_t* pos); |
||||
|
int32_t getValveOrderPos(int32_t valueid, int32_t* pos); |
||||
|
int32_t isBusy(int32_t valueid, int32_t* busy); |
||||
|
int32_t getValveWorkState(int32_t valueid, int32_t* state); |
||||
|
|
||||
|
private: |
||||
|
|
||||
|
int32_t writeReg06(uint8_t slaveAddr, uint16_t regAddr, uint16_t regVal); |
||||
|
int32_t readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal); |
||||
|
}; |
||||
|
|
||||
|
} // namespace iflytop
|
@ -0,0 +1,243 @@ |
|||||
|
#include "pxx_pressure_sensor_bus.hpp"
|
||||
|
|
||||
|
|
||||
|
using namespace iflytop; |
||||
|
|
||||
|
#define TAG "PxxSensor"
|
||||
|
|
||||
|
/**
|
||||
|
* @brief |
||||
|
* |
||||
|
* |
||||
|
* p100_protocol |
||||
|
* 0x0000:从机地址位 |
||||
|
* p600_protocol |
||||
|
* 0x0018H:从机地址位 |
||||
|
* |
||||
|
* |
||||
|
* |
||||
|
* 程序编写指标参考: |
||||
|
* 响应频率 : 模拟信号输出≤500Hz、数字信号输出≤5Hz |
||||
|
* 指令回执响应时间 : 20ms |
||||
|
* |
||||
|
* 推荐指令间隔: |
||||
|
* 指令间隔至少30ms |
||||
|
*/ |
||||
|
|
||||
|
#define OVERTIME_MS 50
|
||||
|
|
||||
|
static const char* protocolType2Str(PXXPressureSensorBus::protocol_type_t type) { |
||||
|
switch (type) { |
||||
|
case PXXPressureSensorBus::kp100_protocol: |
||||
|
return "P100"; |
||||
|
case PXXPressureSensorBus::kdp600_protocol: |
||||
|
return "DP600"; |
||||
|
case PXXPressureSensorBus::kothers_protocol: |
||||
|
return "OTHERS"; |
||||
|
default: |
||||
|
return "UNKNOWN"; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
static const char* p100uint2Str(uint8_t uint) { |
||||
|
switch (uint) { |
||||
|
case 0: |
||||
|
return "Mpa"; |
||||
|
case 1: |
||||
|
return "kpa"; |
||||
|
case 2: |
||||
|
return "pa"; |
||||
|
case 3: |
||||
|
return "bar"; |
||||
|
case 4: |
||||
|
return "Mbar"; |
||||
|
case 5: |
||||
|
return "kgcm2"; |
||||
|
case 6: |
||||
|
return "psi"; |
||||
|
case 7: |
||||
|
return "mh2o"; |
||||
|
case 8: |
||||
|
return "mh2o"; |
||||
|
default: |
||||
|
return "UNKNOWN"; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/***********************************************************************************************************************
|
||||
|
* GLOBAL * |
||||
|
***********************************************************************************************************************/ |
||||
|
|
||||
|
static osThreadId PxxPressureSensorThread; |
||||
|
static void onPxxPressureSensorThreadStart(void const* argument) { ((PXXPressureSensorBus*)argument)->threadFuncStart(); } |
||||
|
|
||||
|
/***********************************************************************************************************************
|
||||
|
* CLASS * |
||||
|
***********************************************************************************************************************/ |
||||
|
|
||||
|
bool PXXPressureSensorBus::pingDevice(int id) { |
||||
|
uint16_t add = 0; |
||||
|
bool suc = m_modbusBlockHost->readReg03(id, 0x0000, &add, OVERTIME_MS); |
||||
|
return suc; |
||||
|
} |
||||
|
|
||||
|
bool PXXPressureSensorBus::tryProbeProtocolP100(int id, sensor_t* sensor) { |
||||
|
uint16_t add = 0; |
||||
|
bool suc = m_modbusBlockHost->readReg03(id, 0x0000, &add, OVERTIME_MS); |
||||
|
if (!suc) { |
||||
|
return false; |
||||
|
} |
||||
|
if (id != add) { |
||||
|
return false; |
||||
|
} |
||||
|
osDelay(10); |
||||
|
int16_t val[6] = {0}; |
||||
|
|
||||
|
suc = m_modbusBlockHost->readReg03Muti(id, 0x02, (uint16_t*)val, 5, 50); |
||||
|
if (!suc) { |
||||
|
return false; |
||||
|
} |
||||
|
sensor->p100_sensor_info.precision = val[1]; |
||||
|
sensor->p100_sensor_info.pressure_unit = val[0]; |
||||
|
sensor->p100_sensor_info.value = val[2]; |
||||
|
sensor->p100_sensor_info.zero_point = val[3]; |
||||
|
sensor->p100_sensor_info.range_full_point = val[4]; |
||||
|
|
||||
|
sensor->id = id; |
||||
|
sensor->type = kp100_protocol; |
||||
|
sensor->detected = true; |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
bool PXXPressureSensorBus::tryProbeProtocolDP600(int id, sensor_t* sensor) { |
||||
|
uint16_t add = 0; |
||||
|
bool suc = m_modbusBlockHost->readReg03(id, 0x0018, &add, OVERTIME_MS); |
||||
|
// ZLOGI(TAG, "tryProbeProtocolDP600 id:%d add:%d suc:%d", id, add, suc);
|
||||
|
if (!suc) { |
||||
|
return false; |
||||
|
} |
||||
|
if (id != add) { |
||||
|
return false; |
||||
|
} |
||||
|
|
||||
|
sensor->id = id; |
||||
|
sensor->type = kdp600_protocol; |
||||
|
sensor->detected = true; |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
void PXXPressureSensorBus::probeSensor() { |
||||
|
memset(sensors, 0, sizeof(sensors)); |
||||
|
for (size_t i = 1; i < ZARRAY_SIZE(sensors); i++) { |
||||
|
osDelay(30); |
||||
|
bool pingSuc = false; |
||||
|
pingSuc = pingDevice(i); |
||||
|
ZLOGI(TAG, "pingDevice id:%d,%s", i, pingSuc ? "online" : "offline"); |
||||
|
if (pingSuc) { |
||||
|
sensorNum++; |
||||
|
if (tryProbeProtocolP100(i, &sensors[i])) continue; |
||||
|
osDelay(30); |
||||
|
if (tryProbeProtocolDP600(i, &sensors[i])) continue; |
||||
|
|
||||
|
sensors[i].id = i; |
||||
|
sensors[i].type = kothers_protocol; |
||||
|
sensors[i].detected = true; |
||||
|
} else { |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/**
|
||||
|
* @brief DUMP Sensor State |
||||
|
*/ |
||||
|
ZLOGI(TAG, "detect pressure sensor list:(%d)", sensorNum); |
||||
|
for (size_t i = 0; i < ZARRAY_SIZE(sensors); i++) { |
||||
|
if (sensors[i].detected) { |
||||
|
if (sensors[i].type == kp100_protocol) { |
||||
|
ZLOGI(TAG, " Sensor[%d] id:%d ptype:%s precision:%d unit:%s zero:%d full:%d", i, sensors[i].id, //
|
||||
|
protocolType2Str(sensors[i].type), //
|
||||
|
sensors[i].p100_sensor_info.precision, //
|
||||
|
p100uint2Str(sensors[i].p100_sensor_info.pressure_unit), //
|
||||
|
sensors[i].p100_sensor_info.zero_point, //
|
||||
|
sensors[i].p100_sensor_info.range_full_point); |
||||
|
} else { |
||||
|
ZLOGI(TAG, " Sensor[%d] id:%d ptype:%s detected:%d", i, sensors[i].id, protocolType2Str(sensors[i].type), sensors[i].detected); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
ZLOGI(TAG, "end"); |
||||
|
initedEnd = true; |
||||
|
} |
||||
|
|
||||
|
void PXXPressureSensorBus::threadFuncStart() { |
||||
|
/**
|
||||
|
* @brief 枚举传感器设备 |
||||
|
*/ |
||||
|
probeSensor(); |
||||
|
/**
|
||||
|
* @brief 周期采集传感器数据 |
||||
|
*/ |
||||
|
while (true) { |
||||
|
//
|
||||
|
for (size_t i = 0; i < ZARRAY_SIZE(sensors); i++) { |
||||
|
if (!sensors[i].detected) { |
||||
|
continue; |
||||
|
} |
||||
|
|
||||
|
bool suc = false; |
||||
|
|
||||
|
if (sensors[i].type == kp100_protocol) { |
||||
|
int16_t val = 0; |
||||
|
suc = m_modbusBlockHost->readReg03(i, 0x0004, (uint16_t*)&val, OVERTIME_MS); |
||||
|
{ |
||||
|
zlock_guard l(m_lock); |
||||
|
if (suc) sensors[i].val = val; |
||||
|
sensors[i].online = suc; |
||||
|
} |
||||
|
} else if (sensors[i].type == kdp600_protocol) { |
||||
|
int16_t val = 0; |
||||
|
suc = m_modbusBlockHost->readReg03(i, 0x0000, (uint16_t*)&val, OVERTIME_MS); |
||||
|
|
||||
|
{ |
||||
|
zlock_guard l(m_lock); |
||||
|
if (suc) sensors[i].val = val; |
||||
|
sensors[i].online = suc; |
||||
|
} |
||||
|
} else { |
||||
|
{ |
||||
|
zlock_guard l(m_lock); |
||||
|
sensors[i].online = false; |
||||
|
} |
||||
|
continue; |
||||
|
} |
||||
|
osDelay(50); |
||||
|
} |
||||
|
osDelay(50); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void PXXPressureSensorBus::init(UART_HandleTypeDef* huart) { |
||||
|
//
|
||||
|
m_lock.init(); |
||||
|
|
||||
|
m_modbusBlockHost = new ModbusBlockHost(); //
|
||||
|
m_modbusBlockHost->initialize(huart); |
||||
|
|
||||
|
osThreadDef(PxxPressureSensorThread, onPxxPressureSensorThreadStart, osPriorityNormal, 0, 1024); |
||||
|
PxxPressureSensorThread = osThreadCreate(osThread(PxxPressureSensorThread), this); |
||||
|
|
||||
|
while (!initedEnd) { |
||||
|
osDelay(10); |
||||
|
} |
||||
|
} |
||||
|
bool PXXPressureSensorBus::readData(int32_t id, int16_t* data) { |
||||
|
zlock_guard l(m_lock); |
||||
|
if (id < 0 || id >= ZARRAY_SIZE(sensors)) { |
||||
|
return false; |
||||
|
} |
||||
|
if (!sensors[id].online) { |
||||
|
return false; |
||||
|
} |
||||
|
*data = sensors[id].val; |
||||
|
return true; |
||||
|
} |
||||
|
void PXXPressureSensorBus::probe() {} |
@ -0,0 +1,73 @@ |
|||||
|
#pragma once
|
||||
|
#include <stddef.h>
|
||||
|
#include <stdio.h>
|
||||
|
|
||||
|
#include "stm32components/modbus/modbus_block_host.hpp"
|
||||
|
|
||||
|
namespace iflytop { |
||||
|
|
||||
|
#define PXX_PRESSURE_SENSOR_NUM 10
|
||||
|
|
||||
|
class PXXPressureSensorBus { |
||||
|
public: |
||||
|
/***********************************************************************************************************************
|
||||
|
* STRUCT * |
||||
|
***********************************************************************************************************************/ |
||||
|
|
||||
|
typedef enum { |
||||
|
kp100_protocol, |
||||
|
kdp600_protocol, |
||||
|
kothers_protocol, |
||||
|
} protocol_type_t; |
||||
|
|
||||
|
typedef struct { |
||||
|
uint8_t precision; // 0,1,2,3
|
||||
|
uint8_t pressure_unit; // 0:map,1:kpa,2:pa
|
||||
|
int16_t value; |
||||
|
int16_t zero_point; |
||||
|
int16_t range_full_point; |
||||
|
} p100_sensor_info_t; |
||||
|
|
||||
|
typedef struct { |
||||
|
uint16_t id; |
||||
|
protocol_type_t type; |
||||
|
bool detected; |
||||
|
bool online; |
||||
|
p100_sensor_info_t p100_sensor_info; |
||||
|
|
||||
|
int32_t val; |
||||
|
} sensor_t; |
||||
|
|
||||
|
private: |
||||
|
/***********************************************************************************************************************
|
||||
|
* DATA * |
||||
|
***********************************************************************************************************************/ |
||||
|
|
||||
|
ModbusBlockHost* m_modbusBlockHost; |
||||
|
bool initedEnd = false; |
||||
|
zmutex m_lock; |
||||
|
|
||||
|
public: |
||||
|
sensor_t sensors[PXX_PRESSURE_SENSOR_NUM] = {0}; |
||||
|
int32_t sensorNum = 0; |
||||
|
|
||||
|
public: |
||||
|
/***********************************************************************************************************************
|
||||
|
* FUNC * |
||||
|
***********************************************************************************************************************/ |
||||
|
void init(UART_HandleTypeDef *huart); |
||||
|
bool readData(int32_t id, int16_t* data); |
||||
|
|
||||
|
private: |
||||
|
void probe(); |
||||
|
|
||||
|
public: |
||||
|
void threadFuncStart(); |
||||
|
|
||||
|
bool pingDevice(int id); |
||||
|
bool tryProbeProtocolP100(int id, sensor_t* sensor); |
||||
|
bool tryProbeProtocolDP600(int id, sensor_t* sensor); |
||||
|
void probeSensor(); |
||||
|
}; |
||||
|
|
||||
|
} // namespace iflytop
|
@ -0,0 +1,5 @@ |
|||||
|
#pragma once
|
||||
|
#include "hmp110/hmp110.hpp"
|
||||
|
#include "hpp272/hpp272.hpp"
|
||||
|
#include "preportional_valve/preportional_valve_ctrl.hpp"
|
||||
|
#include "pxx_pressure_sensor_driver/pxx_pressure_sensor_bus.hpp"
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue