fix 1886 raw telegram

This commit is contained in:
MichaelDvP
2024-07-23 17:19:56 +02:00
parent 39199e1701
commit bc7d848b9b
2 changed files with 17 additions and 11 deletions

View File

@@ -1492,6 +1492,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
read_next_ = true;
txservice_.send();
} else {
read_next_ = false;
txservice_.send_poll(); // close the bus
}
}

View File

@@ -516,7 +516,8 @@ void TxService::add(uint8_t operation, const uint8_t * data, const uint8_t lengt
EMSESP::set_response_id(type_id);
// trigger read of all parts of telegram if requested length is more than 32
// compatibility to earlier versions
if (message_data[0] >= 32) {
const uint8_t part_length = type_id > 0xFF ? 25 : 27;
if (message_data[0] >= part_length) {
EMSESP::set_read_id(type_id);
}
} else {
@@ -556,7 +557,7 @@ 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, const bool front) {
LOG_DEBUG("Tx read request to device 0x%02X for type ID 0x%02X", dest, type_id);
uint8_t message_data = (type_id > 0xFF) ? (EMS_MAX_TELEGRAM_MESSAGE_LENGTH - 2) : EMS_MAX_TELEGRAM_MESSAGE_LENGTH;
uint8_t message_data = 0xFF;
if (length > 0 && length < message_data) {
message_data = length;
}
@@ -570,11 +571,11 @@ bool TxService::send_raw(const char * telegram_data) {
}
// since the telegram data is a const, make a copy. add 1 to grab the \0 EOS
char telegram[EMS_MAX_TELEGRAM_LENGTH * 3];
char telegram[strlen(telegram_data) + 1];
strlcpy(telegram, telegram_data, sizeof(telegram));
uint8_t count = 0;
uint8_t data[EMS_MAX_TELEGRAM_LENGTH];
uint8_t data[2 + strlen(telegram) / 3];
// get values
char * p = strtok(telegram, " ,"); // delimiter
@@ -628,7 +629,10 @@ void TxService::retry_tx(const uint8_t operation, const uint8_t * data, const ui
// add to the top of the queue
if (tx_telegrams_.size() >= MAX_TX_TELEGRAMS) {
tx_telegrams_.pop_back();
LOG_WARNING("Tx queue overflow, skip retry");
reset_retry_count(); // give up
EMSESP::wait_validate(0); // do not wait for validation
return;
}
tx_telegrams_.emplace_front(tx_telegram_id_++, std::move(telegram_last_), true, get_post_send_query());
@@ -636,15 +640,16 @@ 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(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 = offset + old_length;
uint8_t message_data = (UINT8_MAX - next_offset) >= next_length ? next_length : UINT8_MAX - next_offset;
uint8_t old_length = telegram_last_->type_id > 0xFF ? length - 7 : length - 5;
uint8_t max_length = telegram_last_->type_id > 0xFF ? EMS_MAX_TELEGRAM_MESSAGE_LENGTH - 2 : EMS_MAX_TELEGRAM_MESSAGE_LENGTH;
uint8_t next_length = telegram_last_->message_data[0] - old_length - offset + telegram_last_->offset;
uint8_t next_offset = offset + old_length;
// check telegram, offset and overflow
// some telegrams only reply with one byte less, but have higher offsets (0x10)
// some reply with higher offset than requestes and have not_set values intermediate (0xEA)
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);
if (offset >= telegram_last_->offset && old_length > 0 && next_length > 0) { // } || telegram_last_->offset < offset) {
add(Telegram::Operation::TX_READ, telegram_last_->dest, telegram_last_->type_id, next_offset, &next_length, 1, 0, true);
return telegram_last_->type_id;
}
return 0;