Browse Source

add hpp272

master
zhaohe 2 years ago
parent
commit
7848b7b637
  1. BIN
      components/vaisala_sensor/HPP272-使用说明书.pdf
  2. 26
      components/vaisala_sensor/hpp272.cpp
  3. 53
      components/vaisala_sensor/hpp272.hpp
  4. 90
      components/zcan_module/zcan_m211887_module_manager.cpp
  5. 7
      components/zcan_module/zcan_m211887_module_manager.hpp

BIN
components/vaisala_sensor/HPP272-使用说明书.pdf

26
components/vaisala_sensor/hpp272.cpp

@ -0,0 +1,26 @@
#include "hpp272.hpp"
using namespace iflytop;
HPP272::HPP272(/* args */) {}
HPP272::~HPP272() {}
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);
if (!suc) {
return false;
}
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;
}

53
components/vaisala_sensor/hpp272.hpp

@ -0,0 +1,53 @@
//
// Created by zwsd
//
#pragma once
#include "sdk\components\modbus\modbus_block_host.hpp"
#include "sdk\hal\zhal.hpp"
/**
* @brief
*
* service: M3078
*
* :
* :
* :
* :
*
* :
* 1. :
* 2. :9600
* 3. :
*
*/
namespace iflytop {
using namespace std;
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;
public:
HPP272(/* args */);
~HPP272();
void initialize(UART_HandleTypeDef *huart, uint8_t id);
bool readVal(sensor_data_t *data);
};
} // namespace iflytop

90
components/zcan_module/zcan_m211887_module_manager.cpp

@ -0,0 +1,90 @@
#include "zcan_m211887_module_manager.hpp"
#include <stdio.h>
#include <string.h>
#ifdef HAL_CAN_MODULE_ENABLED
using namespace iflytop;
using namespace zcr;
#define TAG "ZCanM211887ModuleManager"
void ZCanM211887ModuleManager::initialize(ZCanReceiver* zcanReceiver) {
zcanReceiver->registerListener(this);
m_zcanReceiver = zcanReceiver;
}
void ZCanM211887ModuleManager::regSubmodule(int id, UART_HandleTypeDef* huart, uint8_t modbusid) {
ZASSERT(huart != NULL);
Submodule* submodule = new Submodule();
ZASSERT(submodule != NULL);
submodule->id = id;
submodule->sensor.initialize(huart, modbusid);
m_submodules.push_back(submodule);
}
void ZCanM211887ModuleManager::onRceivePacket(CanPacketRxBuffer* rxbuf, uint8_t* packet, size_t len) {
Cmdheader_t* cmdheader = (Cmdheader_t*)packet;
if (cmdheader->cmdid == kcmd_read_huacheng_pressure_sensor && cmdheader->subcmdid == 0) {
/**
* @brief (0)
* cmd : b0:sensorid
* 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;
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));
} else {
int16_t errcode = 1002; // 设备不在线
m_zcanReceiver->sendErrorAck(cmdheader, errcode);
}
return;
}
}
}
ZCanM211887ModuleManager::Submodule* ZCanM211887ModuleManager::find(int id) {
for (auto it = m_submodules.begin(); it != m_submodules.end(); it++) {
if ((*it)->id == id) {
return *it;
}
}
return NULL;
}
#endif

7
components/zcan_module/zcan_m211887_module_manager.hpp

@ -5,6 +5,7 @@
#pragma once
#include "sdk/hal/zhal.hpp"
//
#include "../vaisala_sensor/hpp272.hpp"
#include "../zcanreceiver/zcanreceiver.hpp"
#ifdef HAL_CAN_MODULE_ENABLED
@ -16,8 +17,8 @@ class ZCanM211887ModuleManager : public ZCanRceiverListener {
class Submodule {
public:
int id;
WarningLightCtrlFn_t ctrl_fn;
int id;
HPP272 sensor;
};
private:
@ -31,7 +32,7 @@ class ZCanM211887ModuleManager : public ZCanRceiverListener {
public:
void initialize(ZCanReceiver* zcanReceiver);
void regSubmodule(int id, WarningLightCtrlFn_t fn);
void regSubmodule(int id, UART_HandleTypeDef* huart, uint8_t modbusid);
public:
virtual void onRceivePacket(CanPacketRxBuffer* rxbuf, uint8_t* packet, size_t len);

Loading…
Cancel
Save