mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
fix ems line quality calculation
This commit is contained in:
@@ -196,20 +196,22 @@ uint8_t EMSESP::bus_status() {
|
|||||||
// check if we have Tx issues.
|
// check if we have Tx issues.
|
||||||
uint32_t total_sent = txservice_.telegram_read_count() + txservice_.telegram_write_count();
|
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)) {
|
if ((total_sent == 0) && (txservice_.telegram_fail_count() == 0)) {
|
||||||
return BUS_STATUS_CONNECTED;
|
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)) {
|
if ((total_sent == 0) && (txservice_.telegram_fail_count() != 0)) {
|
||||||
return BUS_STATUS_TX_ERRORS;
|
return BUS_STATUS_TX_ERRORS;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tx Failure rate > 5%
|
// Tx Failure rate > 10%
|
||||||
|
if (txservice_.telegram_fail_count() < total_sent) {
|
||||||
if (((txservice_.telegram_fail_count() * 100) / total_sent) > EMSbus::EMS_TX_ERROR_LIMIT) {
|
if (((txservice_.telegram_fail_count() * 100) / total_sent) > EMSbus::EMS_TX_ERROR_LIMIT) {
|
||||||
return BUS_STATUS_TX_ERRORS;
|
return BUS_STATUS_TX_ERRORS;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return BUS_STATUS_CONNECTED;
|
return BUS_STATUS_CONNECTED;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -218,7 +218,11 @@ class RxService : public EMSbus {
|
|||||||
if (telegram_error_count_ == 0) {
|
if (telegram_error_count_ == 0) {
|
||||||
return 100; // all good, 100%
|
return 100; // all good, 100%
|
||||||
}
|
}
|
||||||
|
if (telegram_error_count_ >= telegram_count_) {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
uint8_t q = ((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);
|
return (q <= EMS_BUS_QUALITY_RX_THRESHOLD ? 100 : 100 - q);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,6 +312,9 @@ class TxService : public EMSbus {
|
|||||||
if (telegram_fail_count_ == 0) {
|
if (telegram_fail_count_ == 0) {
|
||||||
return 100; // all good, 100%
|
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)));
|
return (100 - (uint8_t)(((float)telegram_fail_count_ / telegram_read_count_ * 100)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user