diff --git a/.cproject b/.cproject
index c4c2695..d0047e5 100644
--- a/.cproject
+++ b/.cproject
@@ -120,40 +120,40 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -164,6 +164,7 @@
+
diff --git a/app_protocols/transmit_disfection_protocol/transmit_disfection_protocol.hpp b/app_protocols/transmit_disfection_protocol/transmit_disfection_protocol.hpp
index dda0ee2..813de87 100644
--- a/app_protocols/transmit_disfection_protocol/transmit_disfection_protocol.hpp
+++ b/app_protocols/transmit_disfection_protocol/transmit_disfection_protocol.hpp
@@ -7,7 +7,7 @@ namespace transmit_disfection_protocol {
using namespace zscanprotocol;
#define PROTOCOL_VERSION 6
-#define HEART_OVERTIME (30 * 1000)
+
typedef enum {
klarge_space_disinfection_machine = 1, // 大空间消毒机
diff --git a/stm32basic b/stm32basic
index 049e643..54ccfa2 160000
--- a/stm32basic
+++ b/stm32basic
@@ -1 +1 @@
-Subproject commit 049e643b139652247636ddb1564345bb299b1aab
+Subproject commit 54ccfa2fd5128c9a2f243eb2394a51cb47595f13
diff --git a/stm32components b/stm32components
index bcca882..d387a6d 160000
--- a/stm32components
+++ b/stm32components
@@ -1 +1 @@
-Subproject commit bcca882e2f1f8688716246e4d376230dbc4de28f
+Subproject commit d387a6d07dd669a43fafc96016635e3b95830a0c
diff --git a/ucomponents/hmp110/HMM100-Datasheet-B210813ZH.pdf b/ucomponents/hmp110/HMM100-Datasheet-B210813ZH.pdf
new file mode 100644
index 0000000..d08dbeb
Binary files /dev/null and b/ucomponents/hmp110/HMM100-Datasheet-B210813ZH.pdf differ
diff --git a/ucomponents/hmp110/HMP110 DOC247480-A Simplified Models.zip b/ucomponents/hmp110/HMP110 DOC247480-A Simplified Models.zip
new file mode 100644
index 0000000..a1a47c8
Binary files /dev/null and b/ucomponents/hmp110/HMP110 DOC247480-A Simplified Models.zip differ
diff --git a/ucomponents/hmp110/HMP110-Datasheet-B210852ZH.pdf b/ucomponents/hmp110/HMP110-Datasheet-B210852ZH.pdf
new file mode 100644
index 0000000..fbfc201
Binary files /dev/null and b/ucomponents/hmp110/HMP110-Datasheet-B210852ZH.pdf differ
diff --git a/ucomponents/hmp110/HMP60-and-HMP110-Series-User-Guide-M211060EN-L.pdf b/ucomponents/hmp110/HMP60-and-HMP110-Series-User-Guide-M211060EN-L.pdf
new file mode 100644
index 0000000..3409388
Binary files /dev/null and b/ucomponents/hmp110/HMP60-and-HMP110-Series-User-Guide-M211060EN-L.pdf differ
diff --git a/ucomponents/hmp110/hmp110.cpp b/ucomponents/hmp110/hmp110.cpp
new file mode 100644
index 0000000..a162cd2
--- /dev/null
+++ b/ucomponents/hmp110/hmp110.cpp
@@ -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;
+}
diff --git a/ucomponents/hmp110/hmp110.hpp b/ucomponents/hmp110/hmp110.hpp
new file mode 100644
index 0000000..21a88b8
--- /dev/null
+++ b/ucomponents/hmp110/hmp110.hpp
@@ -0,0 +1,70 @@
+#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; // 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
\ No newline at end of file
diff --git a/ucomponents/hpp272/HPP272-使用说明书.pdf b/ucomponents/hpp272/HPP272-使用说明书.pdf
new file mode 100644
index 0000000..8efceaf
Binary files /dev/null and b/ucomponents/hpp272/HPP272-使用说明书.pdf differ
diff --git a/ucomponents/hpp272/README.md b/ucomponents/hpp272/README.md
new file mode 100644
index 0000000..2732662
--- /dev/null
+++ b/ucomponents/hpp272/README.md
@@ -0,0 +1,8 @@
+
+```
+注意事项:
+ 1. 串口停止位是2位
+ 2. 波特率19200
+ 3. 默认ID 240
+
+```
\ No newline at end of file
diff --git a/ucomponents/hpp272/hpp272.cpp b/ucomponents/hpp272/hpp272.cpp
new file mode 100644
index 0000000..7ea3161
--- /dev/null
+++ b/ucomponents/hpp272/hpp272.cpp
@@ -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;
+}
diff --git a/ucomponents/hpp272/hpp272.hpp b/ucomponents/hpp272/hpp272.hpp
new file mode 100644
index 0000000..7fdb0ec
--- /dev/null
+++ b/ucomponents/hpp272/hpp272.hpp
@@ -0,0 +1,78 @@
+#pragma once
+#include
+#include
+
+#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
\ No newline at end of file
diff --git a/ucomponents/hpp272/过氧化氢传感器读取.zip b/ucomponents/hpp272/过氧化氢传感器读取.zip
new file mode 100644
index 0000000..0e7ab1b
Binary files /dev/null and b/ucomponents/hpp272/过氧化氢传感器读取.zip differ
diff --git a/ucomponents/preportional_valve/preportional_valve_ctrl.cpp b/ucomponents/preportional_valve/preportional_valve_ctrl.cpp
new file mode 100644
index 0000000..b00e913
--- /dev/null
+++ b/ucomponents/preportional_valve/preportional_valve_ctrl.cpp
@@ -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;
+}
\ No newline at end of file
diff --git a/ucomponents/preportional_valve/preportional_valve_ctrl.hpp b/ucomponents/preportional_valve/preportional_valve_ctrl.hpp
new file mode 100644
index 0000000..a7d3184
--- /dev/null
+++ b/ucomponents/preportional_valve/preportional_valve_ctrl.hpp
@@ -0,0 +1,51 @@
+#pragma once
+#include
+#include
+
+#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
\ No newline at end of file
diff --git a/ucomponents/pxx_pressure_sensor_driver/DP600--RS485通讯说明书V0.1.docx b/ucomponents/pxx_pressure_sensor_driver/DP600--RS485通讯说明书V0.1.docx
new file mode 100644
index 0000000..f601635
Binary files /dev/null and b/ucomponents/pxx_pressure_sensor_driver/DP600--RS485通讯说明书V0.1.docx differ
diff --git a/ucomponents/pxx_pressure_sensor_driver/HCP300新说明书.pdf b/ucomponents/pxx_pressure_sensor_driver/HCP300新说明书.pdf
new file mode 100644
index 0000000..baf38ef
Binary files /dev/null and b/ucomponents/pxx_pressure_sensor_driver/HCP300新说明书.pdf differ
diff --git a/ucomponents/pxx_pressure_sensor_driver/P100标准MODBUS RTU通讯协议.pdf b/ucomponents/pxx_pressure_sensor_driver/P100标准MODBUS RTU通讯协议.pdf
new file mode 100644
index 0000000..f869cf1
Binary files /dev/null and b/ucomponents/pxx_pressure_sensor_driver/P100标准MODBUS RTU通讯协议.pdf differ
diff --git a/ucomponents/pxx_pressure_sensor_driver/pxx_pressure_sensor_bus.cpp b/ucomponents/pxx_pressure_sensor_driver/pxx_pressure_sensor_bus.cpp
new file mode 100644
index 0000000..735fcdb
--- /dev/null
+++ b/ucomponents/pxx_pressure_sensor_driver/pxx_pressure_sensor_bus.cpp
@@ -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() {}
diff --git a/ucomponents/pxx_pressure_sensor_driver/pxx_pressure_sensor_bus.hpp b/ucomponents/pxx_pressure_sensor_driver/pxx_pressure_sensor_bus.hpp
new file mode 100644
index 0000000..ad2c1d7
--- /dev/null
+++ b/ucomponents/pxx_pressure_sensor_driver/pxx_pressure_sensor_bus.hpp
@@ -0,0 +1,73 @@
+#pragma once
+#include
+#include
+
+#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
\ No newline at end of file
diff --git a/ucomponents/ucomponents.hpp b/ucomponents/ucomponents.hpp
new file mode 100644
index 0000000..c958bf5
--- /dev/null
+++ b/ucomponents/ucomponents.hpp
@@ -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"
\ No newline at end of file
diff --git a/usrc/app_main.cpp b/usrc/app_main.cpp
index bd032f5..6ad293e 100644
--- a/usrc/app_main.cpp
+++ b/usrc/app_main.cpp
@@ -1,21 +1,18 @@
#include
#include
+//
+#include "base/appdep.hpp"
//
#include "app/dmapp.hpp"
#include "app/ext_ch_selector_app.hpp"
#include "app/exth2o2_sensor.hpp"
-#include "base/appdep.hpp"
//
#include "board/public_board.hpp"
//
#include "base/protocol_processer_mgr.hpp"
#include "protocol_processer_impl/public_cmd_processer.hpp"
//
-#include "stm32basic/zcanreceiver/zcanreceiver.hpp"
-#include "stm32basic/zsdk.hpp"
-
-//
#define TAG "main"
using namespace iflytop;
diff --git a/usrc/base/appdep.hpp b/usrc/base/appdep.hpp
index b67a986..a7811d7 100644
--- a/usrc/base/appdep.hpp
+++ b/usrc/base/appdep.hpp
@@ -3,25 +3,16 @@
#include
#include "project_configs.h"
-
//
-#include "stm32basic/hmp110/hmp110.hpp"
-#include "stm32basic/hpp272/hpp272.hpp"
-#include "stm32basic/modbus/modbus_block_host.hpp"
-#include "stm32basic/pxx_pressure_sensor_driver/pxx_pressure_sensor_bus.hpp"
-#include "stm32basic/tmcdriver/tmc51x0/tmc51x0.hpp"
-#include "stm32basic/zadc.hpp"
-#include "stm32basic/zsdk.hpp"
+#include "stm32basic/stm32basic.hpp"
+#include "stm32components/stm32components.hpp"
+#include "ucomponents/ucomponents.hpp"
//
-#include "config_service.hpp"
+#include "appthread/app_period_task_mgr.hpp"
#include "device_info.hpp"
#include "gflag/gflag.h"
-#include "protocol_processer_mgr.hpp"
#include "idtable/IdMgr.hpp"
+#include "protocol_processer_mgr.hpp"
#include "transmit_disfection_protocol/transmit_disfection_protocol.hpp"
-//
-#include "appthread/app_period_task_mgr.hpp"
-#include "utils/formula.hpp"
-//
#include "utils/formula.hpp"
#include "utils/halutils.hpp"
diff --git a/usrc/base/appthread/app_period_task_mgr.hpp b/usrc/base/appthread/app_period_task_mgr.hpp
index 78cced0..27cbf4e 100644
--- a/usrc/base/appthread/app_period_task_mgr.hpp
+++ b/usrc/base/appthread/app_period_task_mgr.hpp
@@ -5,20 +5,20 @@
#include
-#include "stm32basic/zsdk.hpp"
-#include "stm32halport/stm32halport.hpp"
+#include "stm32basic/stm32basic.hpp"
+#include "stm32halport/stm32halport.hpp"
//
namespace iflytop {
typedef void (*task_fn_t)(void*);
typedef struct {
- task_fn_t fn;
+ task_fn_t fn;
std::function exfn;
- const char* taskname;
- void* cxt;
- int period;
- int32_t lastcalltp;
+ const char* taskname;
+ void* cxt;
+ int period;
+ int32_t lastcalltp;
} task_t;
class AppPeriodTaskMgr {
diff --git a/usrc/base/appthread/work_queue.hpp b/usrc/base/appthread/work_queue.hpp
index 0a8c728..9565c54 100644
--- a/usrc/base/appthread/work_queue.hpp
+++ b/usrc/base/appthread/work_queue.hpp
@@ -6,7 +6,6 @@
#include
#include "cmsis_os.h"
-#include "stm32basic/zsdk.hpp"
#include "stm32halport/stm32halport.hpp"
//
namespace iflytop {
diff --git a/usrc/base/config_service.cpp b/usrc/base/config_service.cpp
index 1fa6075..590e81d 100644
--- a/usrc/base/config_service.cpp
+++ b/usrc/base/config_service.cpp
@@ -1,6 +1,5 @@
#include "config_service.hpp"
-#include "stm32basic/zsdk.hpp"
static config_t _config;
static config_t _default_val_config;
diff --git a/usrc/base/config_service.hpp b/usrc/base/config_service.hpp
index c2c4bb2..c568cc3 100644
--- a/usrc/base/config_service.hpp
+++ b/usrc/base/config_service.hpp
@@ -1,8 +1,8 @@
#pragma once
#include
-#include "stm32basic/zsdk.hpp"
-
+#include "stm32basic/stm32basic.hpp"
+#include "stm32halport/stm32halport.hpp"
typedef struct {
uint32_t configMark;
diff --git a/usrc/base/device_info.hpp b/usrc/base/device_info.hpp
index 47a3f13..95e6133 100644
--- a/usrc/base/device_info.hpp
+++ b/usrc/base/device_info.hpp
@@ -1,9 +1,9 @@
+#pragma once
#include
#include
#include "project_configs.h"
#include "base/config_service.hpp"
-#include "stm32basic/zsdk.hpp"
// uint16_t boardType;
// uint16_t projectId;
diff --git a/usrc/base/idtable/IdMgr.cpp b/usrc/base/idtable/IdMgr.cpp
index 8282ea2..70d2ec2 100644
--- a/usrc/base/idtable/IdMgr.cpp
+++ b/usrc/base/idtable/IdMgr.cpp
@@ -1,6 +1,5 @@
#include "IdMgr.hpp"
-#include "stm32basic/zsdk.hpp"
using namespace iflytop;
void IdMgr::addIdItem(IdIterm item) {
diff --git a/usrc/base/idtable/IdMgr.hpp b/usrc/base/idtable/IdMgr.hpp
index 1467726..c93bf1f 100644
--- a/usrc/base/idtable/IdMgr.hpp
+++ b/usrc/base/idtable/IdMgr.hpp
@@ -1,5 +1,6 @@
#pragma once
-
+#include "stm32basic/stm32basic.hpp"
+#include "stm32halport/stm32halport.hpp"
#define MAX_IDITERM 64
namespace iflytop {
using namespace std;
diff --git a/usrc/base/protocol_processer_utils.hpp b/usrc/base/protocol_processer_utils.hpp
index 758d300..b514d5e 100644
--- a/usrc/base/protocol_processer_utils.hpp
+++ b/usrc/base/protocol_processer_utils.hpp
@@ -2,13 +2,12 @@
#include
#include
//
-#include "stm32basic/zsdk.hpp"
#include "stm32halport/stm32halport.hpp"
//
#include "base/device_info.hpp"
#include "gflag/gflag.h"
#include "transmit_disfection_protocol/transmit_disfection_protocol.hpp"
-#include "stm32basic/zcanreceiver/zcanreceiver.hpp"
+#include "stm32components/zcanreceiver/zcanreceiver.hpp"
namespace iflytop {
using namespace std;
diff --git a/usrc/base/utils/formula.hpp b/usrc/base/utils/formula.hpp
index 9bd2ec1..722cc60 100644
--- a/usrc/base/utils/formula.hpp
+++ b/usrc/base/utils/formula.hpp
@@ -1,6 +1,7 @@
#pragma once
#include
-
+#include "stm32basic/stm32basic.hpp"
+#include "stm32halport/stm32halport.hpp"
static inline int32_t h2o2adcToPPM(int32_t h2o2adcVal) {
double h2o2ma = (h2o2adcVal / 4095.0 * 3.3 * 1000) / 150.0;
int32_t h2o2ppm = (h2o2ma - 4) * 1.0 / (20 - 4) * 2000;
diff --git a/usrc/base/utils/halutils.hpp b/usrc/base/utils/halutils.hpp
index 91f7c0d..434f2fe 100644
--- a/usrc/base/utils/halutils.hpp
+++ b/usrc/base/utils/halutils.hpp
@@ -2,8 +2,8 @@
#include
#include
-#include "stm32basic/zsdk.hpp"
-#include "stm32halport/stm32halport.hpp"
+#include "stm32basic/stm32basic.hpp"
+#include "stm32halport/stm32halport.hpp"
namespace iflytop {
diff --git a/usrc/module/h2o2_sensor.cpp b/usrc/module/h2o2_sensor.cpp
index 7fd51f3..7357402 100644
--- a/usrc/module/h2o2_sensor.cpp
+++ b/usrc/module/h2o2_sensor.cpp
@@ -1,6 +1,6 @@
#include "h2o2_sensor.hpp"
-#include "stm32basic/zcanreceiver/zcanreceiver.hpp"
+#include "stm32components/zcanreceiver/zcanreceiver.hpp"
using namespace iflytop;
#define TAG "LSDMPowerCtrlBoard"
diff --git a/usrc/module/proportional_valve_ctrl.hpp b/usrc/module/proportional_valve_ctrl.hpp
index c44fc59..a41d6c4 100644
--- a/usrc/module/proportional_valve_ctrl.hpp
+++ b/usrc/module/proportional_valve_ctrl.hpp
@@ -1,6 +1,6 @@
#pragma once
#include "base/appdep.hpp"
-#include "stm32basic/preportional_valve/preportional_valve_ctrl.hpp"
+#include "ucomponents/ucomponents.hpp"
namespace iflytop {
using namespace transmit_disfection_protocol;