fixes to checking bus status

This commit is contained in:
proddy
2020-07-06 13:29:41 +02:00
parent 58b93fb62d
commit cfce4964bf

View File

@@ -107,8 +107,10 @@ void EMSESP::reset_tx(uint8_t const tx_mode) {
txservice_.telegram_read_count(0); txservice_.telegram_read_count(0);
txservice_.telegram_write_count(0); txservice_.telegram_write_count(0);
txservice_.telegram_fail_count(0); txservice_.telegram_fail_count(0);
EMSuart::stop(); if (tx_mode) {
EMSuart::start(tx_mode); // reset the UART EMSuart::stop();
EMSuart::start(tx_mode); // reset the UART
}
} }
// return status of bus: connected, connected but Tx is broken, disconnected // return status of bus: connected, connected but Tx is broken, disconnected
@@ -117,8 +119,21 @@ uint8_t EMSESP::bus_status() {
return BUS_STATUS_OFFLINE; return BUS_STATUS_OFFLINE;
} }
// check if we have Tx issues // check if we have Tx issues.
if (txservice_.telegram_read_count() < 2) { uint32_t total_sent = txservice_.telegram_read_count() + txservice_.telegram_write_count();
// nothing sent successfully, 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
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) >= 5) {
return BUS_STATUS_TX_ERRORS; return BUS_STATUS_TX_ERRORS;
} }