diff --git a/components/modbus/modbus_block_host.cpp b/components/modbus/modbus_block_host.cpp index 721d904..5ce0d83 100644 --- a/components/modbus/modbus_block_host.cpp +++ b/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++) { diff --git a/components/modbus/modbus_block_host.hpp b/components/modbus/modbus_block_host.hpp index ec168dc..7edc6e0 100644 --- a/components/modbus/modbus_block_host.hpp +++ b/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(); diff --git a/components/vaisala_sensor/hpp272.cpp b/components/vaisala_sensor/hpp272.cpp index a8b3d19..1d91f8c 100644 --- a/components/vaisala_sensor/hpp272.cpp +++ b/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; } \ No newline at end of file diff --git a/components/zcan_module/zcan_m211887_module_manager.cpp b/components/zcan_module/zcan_m211887_module_manager.cpp index 2d27ded..b8d0f3d 100644 --- a/components/zcan_module/zcan_m211887_module_manager.cpp +++ b/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); }