diff --git a/src/telegram.h b/src/telegram.h index c168cdf87..ebcb7f1aa 100644 --- a/src/telegram.h +++ b/src/telegram.h @@ -189,12 +189,13 @@ class EMSbus { private: static constexpr uint32_t EMS_BUS_TIMEOUT = 30000; // timeout in ms before recognizing the ems bus is offline (30 seconds) - static uint32_t last_bus_activity_; // timestamp of last time a valid Rx came in - static bool bus_connected_; // start assuming the bus hasn't been connected - static uint8_t ems_mask_; // unset=0xFF, buderus=0x00, junkers/ht3=0x80 - static uint8_t ems_bus_id_; // the bus id, which configurable and stored in settings - static uint8_t tx_mode_; // local copy of the tx mode - static uint8_t tx_state_; // state of the Tx line (NONE or waiting on a TX_READ or TX_WRITE) + + static uint32_t last_bus_activity_; // timestamp of last time a valid Rx came in + static bool bus_connected_; // start assuming the bus hasn't been connected + static uint8_t ems_mask_; // unset=0xFF, buderus=0x00, junkers/ht3=0x80 + static uint8_t ems_bus_id_; // the bus id, which configurable and stored in settings + static uint8_t tx_mode_; // local copy of the tx mode + static uint8_t tx_state_; // state of the Tx line (NONE or waiting on a TX_READ or TX_WRITE) }; class RxService : public EMSbus { @@ -227,7 +228,8 @@ class RxService : public EMSbus { if (telegram_error_count_ == 0) { return 100; // all good, 100% } - return (100 - (((float)telegram_error_count_ / telegram_count_ * 100))); + uint8_t q = ((float)telegram_error_count_ / telegram_count_ * 100); + return (q <= EMS_BUS_QUALITY_RX_THRESHOLD ? 100 : 100 - q); } class QueuedRxTelegram { @@ -247,6 +249,8 @@ class RxService : public EMSbus { } private: + static constexpr uint8_t EMS_BUS_QUALITY_RX_THRESHOLD = 5; // % threshold before reporting quality issues + uint8_t rx_telegram_id_ = 0; // queue counter uint32_t telegram_count_ = 0; // # Rx received uint32_t telegram_error_count_ = 0; // # Rx CRC errors