Skip to content

Commit 96b83e3

Browse files
committed
fix ems line quality calculation
1 parent e21ad6a commit 96b83e3

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/emsesp.cpp

+7-5
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,21 @@ uint8_t EMSESP::bus_status() {
196196
// check if we have Tx issues.
197197
uint32_t total_sent = txservice_.telegram_read_count() + txservice_.telegram_write_count();
198198

199-
// nothing sent successfully, also no errors - must be ok
199+
// nothing sent and also no errors - must be ok
200200
if ((total_sent == 0) && (txservice_.telegram_fail_count() == 0)) {
201201
return BUS_STATUS_CONNECTED;
202202
}
203203

204-
// nothing sent successfully, but have Tx errors
204+
// nothing sent, but have Tx errors
205205
if ((total_sent == 0) && (txservice_.telegram_fail_count() != 0)) {
206206
return BUS_STATUS_TX_ERRORS;
207207
}
208208

209-
// Tx Failure rate > 5%
210-
if (((txservice_.telegram_fail_count() * 100) / total_sent) > EMSbus::EMS_TX_ERROR_LIMIT) {
211-
return BUS_STATUS_TX_ERRORS;
209+
// Tx Failure rate > 10%
210+
if (txservice_.telegram_fail_count() < total_sent) {
211+
if (((txservice_.telegram_fail_count() * 100) / total_sent) > EMSbus::EMS_TX_ERROR_LIMIT) {
212+
return BUS_STATUS_TX_ERRORS;
213+
}
212214
}
213215

214216
return BUS_STATUS_CONNECTED;

src/telegram.h

+7
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ class RxService : public EMSbus {
218218
if (telegram_error_count_ == 0) {
219219
return 100; // all good, 100%
220220
}
221+
if (telegram_error_count_ >= telegram_count_) {
222+
return 100;
223+
}
221224
uint8_t q = ((float)telegram_error_count_ / telegram_count_ * 100);
225+
222226
return (q <= EMS_BUS_QUALITY_RX_THRESHOLD ? 100 : 100 - q);
223227
}
224228

@@ -308,6 +312,9 @@ class TxService : public EMSbus {
308312
if (telegram_fail_count_ == 0) {
309313
return 100; // all good, 100%
310314
}
315+
if (telegram_fail_count_ >= telegram_read_count_) {
316+
return 100;
317+
}
311318
return (100 - (uint8_t)(((float)telegram_fail_count_ / telegram_read_count_ * 100)));
312319
}
313320

0 commit comments

Comments
 (0)