diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 7bf62a44a..701221dbf 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -196,19 +196,21 @@ uint8_t EMSESP::bus_status() { // check if we have Tx issues. uint32_t total_sent = txservice_.telegram_read_count() + txservice_.telegram_write_count(); - // nothing sent successfully, also no errors - must be ok + // nothing sent and also no errors - must be ok if ((total_sent == 0) && (txservice_.telegram_fail_count() == 0)) { return BUS_STATUS_CONNECTED; } - // nothing sent successfully, but have Tx errors + // nothing sent, but have Tx errors if ((total_sent == 0) && (txservice_.telegram_fail_count() != 0)) { return BUS_STATUS_TX_ERRORS; } - // Tx Failure rate > 5% - if (((txservice_.telegram_fail_count() * 100) / total_sent) > EMSbus::EMS_TX_ERROR_LIMIT) { - return BUS_STATUS_TX_ERRORS; + // Tx Failure rate > 10% + if (txservice_.telegram_fail_count() < total_sent) { + if (((txservice_.telegram_fail_count() * 100) / total_sent) > EMSbus::EMS_TX_ERROR_LIMIT) { + return BUS_STATUS_TX_ERRORS; + } } return BUS_STATUS_CONNECTED; diff --git a/src/telegram.h b/src/telegram.h index 80032e0d0..199aff51e 100644 --- a/src/telegram.h +++ b/src/telegram.h @@ -218,7 +218,11 @@ class RxService : public EMSbus { if (telegram_error_count_ == 0) { return 100; // all good, 100% } + if (telegram_error_count_ >= telegram_count_) { + return 100; + } uint8_t q = ((float)telegram_error_count_ / telegram_count_ * 100); + return (q <= EMS_BUS_QUALITY_RX_THRESHOLD ? 100 : 100 - q); } @@ -308,6 +312,9 @@ class TxService : public EMSbus { if (telegram_fail_count_ == 0) { return 100; // all good, 100% } + if (telegram_fail_count_ >= telegram_read_count_) { + return 100; + } return (100 - (uint8_t)(((float)telegram_fail_count_ / telegram_read_count_ * 100))); }