mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
fix 1886 raw telegram
This commit is contained in:
@@ -1492,6 +1492,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
|||||||
read_next_ = true;
|
read_next_ = true;
|
||||||
txservice_.send();
|
txservice_.send();
|
||||||
} else {
|
} else {
|
||||||
|
read_next_ = false;
|
||||||
txservice_.send_poll(); // close the bus
|
txservice_.send_poll(); // close the bus
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -516,7 +516,8 @@ void TxService::add(uint8_t operation, const uint8_t * data, const uint8_t lengt
|
|||||||
EMSESP::set_response_id(type_id);
|
EMSESP::set_response_id(type_id);
|
||||||
// trigger read of all parts of telegram if requested length is more than 32
|
// trigger read of all parts of telegram if requested length is more than 32
|
||||||
// compatibility to earlier versions
|
// 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);
|
EMSESP::set_read_id(type_id);
|
||||||
}
|
}
|
||||||
} else {
|
} 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) {
|
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);
|
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) {
|
if (length > 0 && length < message_data) {
|
||||||
message_data = length;
|
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
|
// 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));
|
strlcpy(telegram, telegram_data, sizeof(telegram));
|
||||||
|
|
||||||
uint8_t count = 0;
|
uint8_t count = 0;
|
||||||
uint8_t data[EMS_MAX_TELEGRAM_LENGTH];
|
uint8_t data[2 + strlen(telegram) / 3];
|
||||||
|
|
||||||
// get values
|
// get values
|
||||||
char * p = strtok(telegram, " ,"); // delimiter
|
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
|
// add to the top of the queue
|
||||||
if (tx_telegrams_.size() >= MAX_TX_TELEGRAMS) {
|
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());
|
tx_telegrams_.emplace_front(tx_telegram_id_++, std::move(telegram_last_), true, get_post_send_query());
|
||||||
@@ -637,14 +641,15 @@ 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
|
// 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) {
|
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 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 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;
|
uint8_t next_offset = offset + old_length;
|
||||||
uint8_t message_data = (UINT8_MAX - next_offset) >= next_length ? next_length : UINT8_MAX - next_offset;
|
|
||||||
// check telegram, offset and overflow
|
// check telegram, offset and overflow
|
||||||
// some telegrams only reply with one byte less, but have higher offsets (0x10)
|
// 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)
|
// some reply with higher offset than requestes and have not_set values intermediate (0xEA)
|
||||||
if (old_length >= (next_length - 1) || telegram_last_->offset < offset) {
|
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, &message_data, 1, 0, true);
|
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 telegram_last_->type_id;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user