calculate length of telegram next part

This commit is contained in:
MichaelDvP
2022-09-13 07:27:41 +02:00
parent 702af4b1c8
commit df8a36c695
3 changed files with 14 additions and 19 deletions

View File

@@ -625,24 +625,19 @@ void TxService::retry_tx(const uint8_t operation, const uint8_t * data, const ui
}
// send a request to read the next block of data from longer telegrams
uint16_t TxService::read_next_tx(uint8_t offset) {
// add to the top/front of the queue
uint8_t message_data[1] = {EMS_MAX_TELEGRAM_LENGTH}; // request all data, 32 bytes
if (telegram_last_->offset != offset) {
return 0;
// send a request to read the next block of data from longer telegrams
uint16_t TxService::read_next_tx(const uint8_t offset, const uint8_t length) {
uint8_t old_length = telegram_last_->type_id > 0xFF ? length - 7 : length - 5;
uint8_t next_length = telegram_last_->type_id > 0xFF ? EMS_MAX_TELEGRAM_MESSAGE_LENGTH - 2 : EMS_MAX_TELEGRAM_MESSAGE_LENGTH;
uint8_t next_offset = telegram_last_->offset + old_length;
uint8_t message_data = (UINT8_MAX - next_offset) >= next_length ? next_length : UINT8_MAX - next_offset;
// check telegram, offset and overflow
// some telegrams only reply with one byte less, but have higher offsets (0x10)
if (old_length >= (next_length - 1) && telegram_last_->offset == offset) {
add(Telegram::Operation::TX_READ, telegram_last_->dest, telegram_last_->type_id, next_offset, &message_data, 1, 0, true);
return telegram_last_->type_id;
}
uint8_t add_offset = 25; // for EMS+ telegram increase offset by 25
if (telegram_last_->type_id < 0x100) { // but for EMS1.0 by 27
add_offset = 27;
}
if (UINT8_MAX - telegram_last_->offset < add_offset) { // stop if new offset would overflow
return 0;
}
add(Telegram::Operation::TX_READ, telegram_last_->dest, telegram_last_->type_id, telegram_last_->offset + add_offset, message_data, 1, 0, true);
return telegram_last_->type_id;
return 0;
}
// checks if a telegram is sent to us matches the last Tx request