mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
clear response_id on tx_error
This commit is contained in:
@@ -748,7 +748,7 @@ void EMSESP::publish_response(std::shared_ptr<const Telegram> telegram) {
|
|||||||
|
|
||||||
if (strlen(buffer) && strlen(buffer) <= 11) {
|
if (strlen(buffer) && strlen(buffer) <= 11) {
|
||||||
uint32_t value = Helpers::hextoint(buffer);
|
uint32_t value = Helpers::hextoint(buffer);
|
||||||
doc["value"] = value;
|
doc["value"] = value;
|
||||||
}
|
}
|
||||||
Mqtt::queue_publish("response", doc.as<JsonObject>());
|
Mqtt::queue_publish("response", doc.as<JsonObject>());
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
|
|||||||
@@ -523,7 +523,8 @@ void TxService::add(uint8_t operation, const uint8_t * data, const uint8_t lengt
|
|||||||
if (src != ems_bus_id() || dest == 0) {
|
if (src != ems_bus_id() || dest == 0) {
|
||||||
operation = Telegram::Operation::NONE; // do not check reply/ack for other ids and broadcasts
|
operation = Telegram::Operation::NONE; // do not check reply/ack for other ids and broadcasts
|
||||||
} else if (dest & 0x80) {
|
} else if (dest & 0x80) {
|
||||||
// keep RAW to set the response when sending
|
// keep operation RAW to set the response when sending
|
||||||
|
// Mqtt::clear_response(); // set here when receiving command or when sending?
|
||||||
} else {
|
} else {
|
||||||
operation = Telegram::Operation::TX_WRITE;
|
operation = Telegram::Operation::TX_WRITE;
|
||||||
validate_id = type_id;
|
validate_id = type_id;
|
||||||
@@ -607,6 +608,10 @@ void TxService::retry_tx(const uint8_t operation, const uint8_t * data, const ui
|
|||||||
if (operation == Telegram::Operation::TX_READ) {
|
if (operation == Telegram::Operation::TX_READ) {
|
||||||
if (telegram_last_->offset > 0) { // ignore errors for higher offsets
|
if (telegram_last_->offset > 0) { // ignore errors for higher offsets
|
||||||
LOG_DEBUG("Last Tx Read operation failed after %d retries. Ignoring request: %s", MAXIMUM_TX_RETRIES, telegram_last_->to_string().c_str());
|
LOG_DEBUG("Last Tx Read operation failed after %d retries. Ignoring request: %s", MAXIMUM_TX_RETRIES, telegram_last_->to_string().c_str());
|
||||||
|
if (EMSESP::response_id()) {
|
||||||
|
EMSESP::set_response_id(0);
|
||||||
|
EMSESP::set_read_id(0);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
increment_telegram_read_fail_count(); // another Tx fail
|
increment_telegram_read_fail_count(); // another Tx fail
|
||||||
@@ -646,11 +651,18 @@ void TxService::retry_tx(const uint8_t operation, const uint8_t * data, const ui
|
|||||||
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 max_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_length = telegram_last_->message_data[0] > old_length ? telegram_last_->message_data[0] - old_length - offset + telegram_last_->offset : 0;
|
||||||
uint8_t next_offset = offset + old_length;
|
uint8_t next_offset = offset + old_length;
|
||||||
|
|
||||||
// check telegram, length, offset and overflow
|
// check telegram, length, offset and overflow
|
||||||
// some telegrams only reply with one byte less, but have higher offsets (boiler 0x10)
|
// some telegrams only reply with one byte less, but have higher offsets (boiler 0x10)
|
||||||
// some reply with higher offset than requestes and have not_set values intermediate (boiler 0xEA)
|
// some reply with higher offset than requestes and have not_set values intermediate (boiler 0xEA)
|
||||||
|
|
||||||
|
// We have th last byte received
|
||||||
|
if (offset + old_length >= telegram_last_->offset + telegram_last_->message_data[0]) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// we request all and get a short telegram with requested offset
|
||||||
if ((next_length + next_offset) == 0xFF && old_length < max_length - 1 && offset <= telegram_last_->offset) {
|
if ((next_length + next_offset) == 0xFF && old_length < max_length - 1 && offset <= telegram_last_->offset) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user