diff --git a/src/telegram.cpp b/src/telegram.cpp index 0fa1b531e..59c0921b8 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -536,13 +536,13 @@ void TxService::add(uint8_t operation, const uint8_t * data, const uint8_t lengt void TxService::read_request(const uint16_t type_id, const uint8_t dest, const uint8_t offset, const uint8_t length) { LOG_DEBUG(F("Tx read request to device 0x%02X for type ID 0x%02X"), dest, type_id); - uint8_t message_data[1] = {EMS_MAX_TELEGRAM_LENGTH}; // request all data, 32 bytes + uint8_t message_data = (type_id > 0xFF) ? (EMS_MAX_TELEGRAM_MESSAGE_LENGTH - 2) : EMS_MAX_TELEGRAM_MESSAGE_LENGTH; // if length set, publish result and set telegram to front if (length) { - message_data[0] = length; + message_data = length; EMSESP::set_read_id(type_id); } - add(Telegram::Operation::TX_READ, dest, type_id, offset, message_data, 1, 0, length != 0); + add(Telegram::Operation::TX_READ, dest, type_id, offset, &message_data, 1, 0, length != 0); } // Send a raw telegram to the bus, telegram is a text string of hex values @@ -663,9 +663,10 @@ uint16_t TxService::post_send_query() { if (post_typeid) { uint8_t dest = (this->telegram_last_->dest & 0x7F); // when set a value with large offset before and validate on same type, we have to add offset 0, 26, 52, ... - uint8_t offset = (this->telegram_last_->type_id == post_typeid) ? ((this->telegram_last_->offset / 26) * 26) : 0; - uint8_t message_data[1] = {EMS_MAX_TELEGRAM_LENGTH}; // request all data, 32 bytes - this->add(Telegram::Operation::TX_READ, dest, post_typeid, offset, message_data, 1, 0, true); // add to top/front of queue + uint8_t offset = (this->telegram_last_->type_id == post_typeid) ? ((this->telegram_last_->offset / 26) * 26) : 0; + uint8_t message_data = + (this->telegram_last_->type_id > 0xFF) ? (EMS_MAX_TELEGRAM_MESSAGE_LENGTH - 2) : EMS_MAX_TELEGRAM_MESSAGE_LENGTH; // request all data, 32 bytes + this->add(Telegram::Operation::TX_READ, dest, post_typeid, offset, &message_data, 1, 0, true); // add to top/front of queue // read_request(telegram_last_post_send_query_, dest, 0); // no offset LOG_DEBUG(F("Sending post validate read, type ID 0x%02X to dest 0x%02X"), post_typeid, dest); set_post_send_query(0); // reset