refactor tx retry

This commit is contained in:
proddy
2020-06-19 20:27:21 +02:00
parent cf8404be86
commit e0a35066fc
3 changed files with 15 additions and 19 deletions

View File

@@ -20,7 +20,7 @@ extra_configs = pio_local.ini
;debug_flags = -DDEBUG_ESP_PORT=Serial -DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_TLS_MEM ;debug_flags = -DDEBUG_ESP_PORT=Serial -DDEBUG_ESP_CORE -DDEBUG_ESP_SSL -DDEBUG_ESP_WIFI -DDEBUG_ESP_HTTP_CLIENT -DDEBUG_ESP_HTTP_UPDATE -DDEBUG_ESP_HTTP_SERVER -DDEBUG_ESP_UPDATER -DDEBUG_ESP_OTA -DDEBUG_TLS_MEM
debug_flags = debug_flags =
; -D EMSESP_DEBUG -D EMSESP_DEBUG
; -D EMSESP_SAFE_MODE ; -D EMSESP_SAFE_MODE
; -D ENABLE_CORS -D CORS_ORIGIN=\"http://localhost:3000\" ; -D ENABLE_CORS -D CORS_ORIGIN=\"http://localhost:3000\"

View File

@@ -162,7 +162,12 @@ void EMSESP::show_emsbus(uuid::console::Shell & shell) {
} else if ((it.telegram_->operation) == Telegram::Operation::TX_WRITE) { } else if ((it.telegram_->operation) == Telegram::Operation::TX_WRITE) {
op = read_flash_string(F("WRITE")); op = read_flash_string(F("WRITE"));
} }
shell.printfln(F(" [%02d] %s %s (offset %d)"), it.id_, op.c_str(), pretty_telegram(it.telegram_).c_str(), it.telegram_->offset); shell.printfln(F(" [%02d%c] %s %s (offset %d)"),
it.id_,
((it.retry_) ? '*' : ' '),
op.c_str(),
pretty_telegram(it.telegram_).c_str(),
it.telegram_->offset);
} }
} }
@@ -559,6 +564,7 @@ void EMSESP::send_write_request(const uint16_t type_id,
const uint8_t message_length, const uint8_t message_length,
const uint16_t validate_typeid) { const uint16_t validate_typeid) {
txservice_.add(Telegram::Operation::TX_WRITE, dest, type_id, offset, message_data, message_length); txservice_.add(Telegram::Operation::TX_WRITE, dest, type_id, offset, message_data, message_length);
txservice_.set_post_send_query(validate_typeid); // store which type_id to send Tx read after a write txservice_.set_post_send_query(validate_typeid); // store which type_id to send Tx read after a write
} }
@@ -584,6 +590,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
if (op != Telegram::Operation::NONE) { if (op != Telegram::Operation::NONE) {
bool tx_successful = false; bool tx_successful = false;
EMSbus::tx_waiting(Telegram::Operation::NONE); // reset Tx wait state EMSbus::tx_waiting(Telegram::Operation::NONE); // reset Tx wait state
// txservice_.print_last_tx();
// if we're waiting on a Write operation, we want a single byte 1 or 4 // if we're waiting on a Write operation, we want a single byte 1 or 4
if ((op == Telegram::Operation::TX_WRITE) && (length == 1)) { if ((op == Telegram::Operation::TX_WRITE) && (length == 1)) {
@@ -612,23 +619,9 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
} }
} }
// if Tx wasn't successful, retry or give up // if Tx wasn't successful, retry or just give up
if (!tx_successful) { if (!tx_successful) {
// the telegram we got wasn't what we had requested, so re-send the last Tx and increment retry count txservice_.retry_tx(op, data, length);
uint8_t retries = txservice_.retry_tx(); // returns 0 if exceeded count
#ifdef EMSESP_DEBUG
LOG_DEBUG(F("[DEBUG] Last Tx %s operation failed. Retry #%d. Sent: %s, received: %s"),
(op == Telegram::Operation::TX_WRITE) ? F("Write") : F("Read"),
retries,
txservice_.last_tx_to_string().c_str(),
Helpers::data_to_hex(data, length).c_str());
#endif
if (!retries) {
LOG_ERROR(F("Last Tx %s operation failed after %d retries. Ignoring request."),
(op == Telegram::Operation::TX_WRITE) ? F("Write") : F("Read"),
txservice_.MAXIMUM_TX_RETRIES);
}
return; return;
} }
} }

View File

@@ -53,6 +53,7 @@ void EMSuart::emsuart_recvTask(void * para) {
} }
} }
} }
/* /*
* UART interrupt, on break read the fifo and put the whole telegram to ringbuffer * UART interrupt, on break read the fifo and put the whole telegram to ringbuffer
*/ */
@@ -83,7 +84,6 @@ void IRAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) {
} }
} }
void IRAM_ATTR EMSuart::emsuart_tx_timer_intr_handler() { void IRAM_ATTR EMSuart::emsuart_tx_timer_intr_handler() {
if (emsTxBufIdx > EMS_MAXBUFFERSIZE) { if (emsTxBufIdx > EMS_MAXBUFFERSIZE) {
return; return;
@@ -104,6 +104,9 @@ void IRAM_ATTR EMSuart::emsuart_tx_timer_intr_handler() {
* init UART driver * init UART driver
*/ */
void EMSuart::start(uint8_t tx_mode) { void EMSuart::start(uint8_t tx_mode) {
return;
emsTxWait = EMSUART_TX_BIT_TIME * (tx_mode + 10); emsTxWait = EMSUART_TX_BIT_TIME * (tx_mode + 10);
if (tx_mode_ != 0xFF) { // uart already initialized if (tx_mode_ != 0xFF) { // uart already initialized
tx_mode_ = tx_mode; tx_mode_ = tx_mode;