Browse Source

update

master
zhaohe 2 years ago
parent
commit
eb85daa518
  1. 12
      components/modbus/modbus_block_host.cpp
  2. 4
      components/modbus/modbus_block_host.hpp
  3. 14
      components/vaisala_sensor/hpp272.cpp
  4. 1
      components/zcan_module/zcan_m211887_module_manager.cpp

12
components/modbus/modbus_block_host.cpp

@ -6,9 +6,7 @@ using namespace iflytop;
ModbusBlockHost::ModbusBlockHost() {}
ModbusBlockHost::~ModbusBlockHost() {}
void ModbusBlockHost::initialize(UART_HandleTypeDef *huart) {
this->huart = huart;
}
void ModbusBlockHost::initialize(UART_HandleTypeDef *huart) { this->huart = huart; }
void ModbusBlockHost::cleanRxBuff() { //
HAL_StatusTypeDef status;
do {
@ -17,6 +15,7 @@ void ModbusBlockHost::cleanRxBuff() { //
}
void ModbusBlockHost::uarttx(uint8_t *buff, size_t len) {
ZASSERT(len < sizeof(txbuff));
#if DEBUG
printf("uarttx:\n");
for (size_t i = 0; i < len; i++) {
@ -28,6 +27,8 @@ void ModbusBlockHost::uarttx(uint8_t *buff, size_t len) {
}
bool ModbusBlockHost::uartrx(uint8_t *buff, size_t len, int overtimems) {
HAL_StatusTypeDef status;
ZASSERT(len < sizeof(rxbuff));
status = HAL_UART_Receive(huart, buff, len, overtimems);
#if DEBUG
if (status == HAL_OK) {
@ -55,7 +56,7 @@ bool ModbusBlockHost::readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t *r
uarttx(txbuff, 6 + 2);
bool status;
status = uartrx(rxbuff, 7, overtimems);
status = uartrx(rxbuff, 5 + 2, overtimems);
if (status && modbus_checkcrc16(rxbuff, 7)) {
*regVal = rxbuff[3] << 8 | rxbuff[4];
@ -78,7 +79,8 @@ bool ModbusBlockHost::readReg03Muti(uint8_t slaveAddr, uint16_t regAddr, uint16_
uarttx(txbuff, 6 + 2);
bool status;
status = uartrx(rxbuff, 7 + regNum * 2, overtimems);
// 14*2 = 28
status = uartrx(rxbuff, 5 + regNum * 2, overtimems);
if (status && modbus_checkcrc16(rxbuff, 7 + regNum * 2)) {
for (int i = 0; i < regNum; i++) {

4
components/modbus/modbus_block_host.hpp

@ -6,8 +6,8 @@ namespace iflytop {
class ModbusBlockHost {
UART_HandleTypeDef *huart;
uint8_t txbuff[32];
uint8_t rxbuff[32];
uint8_t txbuff[100];
uint8_t rxbuff[100];
public:
ModbusBlockHost();

14
components/vaisala_sensor/hpp272.cpp

@ -9,18 +9,18 @@ void HPP272::initialize(UART_HandleTypeDef *huart, uint8_t id) {
this->id = id;
}
hpp272_data_t *HPP272::readVal() {
bool suc = modbusBlockHost.readReg03Muti(id, 0x0100, (uint16_t *)&datacache, sizeof(datacache) / 2, 30);
bool suc = modbusBlockHost.readReg03Muti(id, 0x0100, (uint16_t *)&datacache, sizeof(datacache) / 2, 200);
if (!suc) {
return NULL;
}
/**
* @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;
}
// 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;
}

1
components/zcan_module/zcan_m211887_module_manager.cpp

@ -45,6 +45,7 @@ void ZCanM211887ModuleManager::onRceivePacket(CanPacketRxBuffer* rxbuf, uint8_t*
memcpy(txbuff + 2, hpp272data, sizeof(hpp272_data_t));
m_zcanReceiver->sendAck(cmdheader, txbuff, sizeof(hpp272_data_t) + 2);
} else {
ZLOGE(TAG, "hpp272 is null");
int16_t errcode = 1002; // 设备不在线
m_zcanReceiver->sendErrorAck(cmdheader, errcode);
}

Loading…
Cancel
Save