Browse Source

update

master
zhaohe 2 years ago
parent
commit
0c83a0fefd
  1. 10
      components/huacheng_sensor/dp600_pressure_sensor.cpp
  2. 26
      components/vaisala_sensor/hpp272.cpp
  3. 51
      components/vaisala_sensor/hpp272.hpp
  4. 36
      components/zcan_module/zcan_m211887_module_manager.cpp
  5. 2
      components/zcan_module/zcan_m211887_module_manager.hpp

10
components/huacheng_sensor/dp600_pressure_sensor.cpp

@ -16,6 +16,16 @@ bool DP600PressureSensor::readVal(sensor_data_t *data) {
return false;
}
uint8_t *rxdata = (uint8_t *)val;
/**
* @brief
*/
for (int i = 0; i < 5; i++) {
uint8_t tmp = rxdata[2 * i];
rxdata[2 * i] = rxdata[2 * i + 1];
rxdata[2 * i + 1] = tmp;
}
data->precision = val[1];
data->pressure_unit = val[0];
data->value = val[2];

26
components/vaisala_sensor/hpp272.cpp

@ -8,19 +8,19 @@ void HPP272::initialize(UART_HandleTypeDef *huart, uint8_t id) {
modbusBlockHost.initialize(huart);
this->id = id;
}
bool HPP272::readVal(sensor_data_t *data) {
int16_t val[5] = {0};
bool suc = modbusBlockHost.readReg03Muti(id, 0x02, (uint16_t *)val, 5, 50);
hpp272_data_t *HPP272::readVal() {
bool suc = modbusBlockHost.readReg03Muti(id, 0x02, (uint16_t *)&datacache, sizeof(datacache) / 2, 50);
if (!suc) {
return false;
return NULL;
}
data->precision = val[1];
data->pressure_unit = val[0];
data->value = val[2];
data->zero_point = val[3];
data->range_full_point = val[4];
return true;
/**
* @brief
*/
uint8_t *rx = (uint8_t *)&datacache;
for (size_t i = 0; i < sizeof(datacache) / 2; i++) {
uint8_t tmp = rx[i * 2];
rx[i * 2] = rx[i * 2 + 1];
rx[i * 2 + 1] = tmp;
}
return &datacache;
}

51
components/vaisala_sensor/hpp272.hpp

@ -25,29 +25,58 @@
namespace iflytop {
using namespace std;
#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()
class HPP272 {
public:
typedef struct {
uint8_t precision;
uint8_t pressure_unit;
int16_t value;
int16_t zero_point;
int16_t range_full_point;
} sensor_data_t;
private:
/* data */
ModbusBlockHost modbusBlockHost;
uint8_t id;
/**
*
* 0100 ppm Vaporized hydrogen peroxide concentration by volume
* 0101 %RS * 100 H2O+H2O2 relative saturation
* 0102 °C * 100 Temperature used for calculation. By default, shows the temperature from the temperature probe
* 0103 %RH * 100 Relative humidity
* 0104 mg/m3 Absolute hydrogen peroxide
* 0105 °C * 100 H2O+H2O2 dew point temperature
* 0106
* 0107 ppm ppm Water concentration by volume
* 0108 hPa Water vapor pressure
* 0109 g/m3 Absolute humidity (water)
* 010A hPa Water vapor saturation pressure (H2O)
* 010B °C * 100 Temperature from the temperature probe
* 010C hPa H2O2 vapor pressure
* 010D hPa Water vapor saturation pressure (H2O+H2O2)
*
*/
hpp272_data_t datacache;
public:
HPP272(/* args */);
~HPP272();
void initialize(UART_HandleTypeDef *huart, uint8_t id);
bool readVal(sensor_data_t *data);
void initialize(UART_HandleTypeDef* huart, uint8_t id);
hpp272_data_t* readVal();
};
} // namespace iflytop

36
components/zcan_module/zcan_m211887_module_manager.cpp

@ -33,46 +33,20 @@ void ZCanM211887ModuleManager::onRceivePacket(CanPacketRxBuffer* rxbuf, uint8_t*
* ack : b0:boardid b2:5:presure pa
* ack_datalen : 6
*/
#if 0
[0]:ID
[2]
0,1,2,3
[3]
0-Mpa
1-Kpa
2-Pa
3-Bar
4-Mbar
5-kg/cm2
6-psi
7-mh2o
8-mmh2o
[4:5]
[6:7]
[8:9]
#endif
uint8_t id = cmdheader->data[0];
Submodule* subm = find(id);
if (subm) {
uint8_t txbuff[10] = {};
txbuff[0] = id;
HPP272::sensor_data_t data;
bool suc = subm->sensor.readVal(&data);
if (suc) {
txbuff[0] = id;
hpp272_data_t* hpp272data = subm->sensor.readVal();
if (hpp272data) {
txbuff[0] = id;
txbuff[1] = 0;
txbuff[2] = data.precision;
txbuff[3] = data.pressure_unit;
memcpy(txbuff + 4, &data.value, 2);
memcpy(txbuff + 6, &data.zero_point, 2);
memcpy(txbuff + 8, &data.range_full_point, 2);
m_zcanReceiver->sendAck(cmdheader, txbuff, sizeof(txbuff));
memcpy(txbuff + 2, hpp272data, sizeof(hpp272_data_t));
m_zcanReceiver->sendAck(cmdheader, txbuff, sizeof(hpp272_data_t) + 2);
} else {
int16_t errcode = 1002; // 设备不在线
m_zcanReceiver->sendErrorAck(cmdheader, errcode);
}
return;
}
}

2
components/zcan_module/zcan_m211887_module_manager.hpp

@ -26,6 +26,8 @@ class ZCanM211887ModuleManager : public ZCanRceiverListener {
list<Submodule*> m_submodules;
uint8_t txbuff[sizeof(hpp272_data_t) + 10];
public:
ZCanM211887ModuleManager(/* args */) {}
~ZCanM211887ModuleManager() {}

Loading…
Cancel
Save