improve Tx retry code

This commit is contained in:
proddy
2020-06-03 23:33:23 +02:00
parent a5e60d9e39
commit a6549bc66d

View File

@@ -568,21 +568,21 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
}
// are we waiting for a response from a recent Tx Read or Write?
bool tx_successful = false;
if (EMSbus::tx_waiting()) {
// if it's a single byte 1 or 4 then its maybe a response from the last write action
EMSbus::tx_waiting(false); // reset Tx wait state
// if it's a single byte 1 or 4 then its maybe a response from the last write action
if (length == 1) {
if (first_value == TxService::TX_WRITE_SUCCESS) {
LOG_DEBUG(F("Last Tx write successful. Sending read request."));
txservice_.increment_telegram_write_count(); // last tx/write was confirmed ok
txservice_.send_poll(); // close the bus
txservice_.post_send_query(); // send type_id to last destination
txservice_.post_send_query(); // follow up with any post-read
tx_successful = true;
} else if (first_value == TxService::TX_WRITE_FAIL) {
LOG_ERROR(F("Last Tx write rejected by host"));
txservice_.send_poll(); // close the bus
} else {
// ignore it, it's probably a poll and we can wait for the next one
return;
}
} else {
// got a telegram with data in it. See if the src/dest matches that from the last one we sent
@@ -592,18 +592,24 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
if (txservice_.is_last_tx(src, dest)) {
LOG_DEBUG(F("Last Tx read successful"));
txservice_.increment_telegram_read_count();
txservice_.send_poll();
} else {
// the telegram we got wasn't what we had requested
// So re-send the last Tx and increment retry count
uint8_t retries = txservice_.retry_tx(); // returns 0 if exceeded count
if (retries) {
LOG_ERROR(F("Last Tx read failed. Retrying #%d..."), retries);
} else {
LOG_ERROR(F("Last Tx read failed after %d retries"), txservice_.MAXIMUM_TX_RETRIES);
}
txservice_.send_poll(); // close the bus
tx_successful = true;
}
}
// if Tx wasn't successful, retry
if (!tx_successful) {
// the telegram we got wasn't what we had requested
// So re-send the last Tx and increment retry count
uint8_t retries = txservice_.retry_tx(); // returns 0 if exceeded count
if (retries) {
LOG_ERROR(F("Last Tx read failed. Retrying #%d..."), retries);
} else {
LOG_ERROR(F("Last Tx read failed after %d retries. Abandoning Tx operation."), txservice_.MAXIMUM_TX_RETRIES);
}
return;
}
}
// check for poll
@@ -826,7 +832,7 @@ void EMSESP::loop() {
fetch_device_values();
}
// helps ease wifi outages
// helps ease wifi dropouts effecting MQTT and Telnet services
// https://github.com/esp8266/Arduino/blob/e721089e601985e633641ab7323f81a84ea0cd1b/cores/esp8266/core_esp8266_wiring.cpp#L41-L57
delay(1);
}