mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 01:09:51 +03:00
fixes to checking bus status
This commit is contained in:
@@ -107,8 +107,10 @@ void EMSESP::reset_tx(uint8_t const tx_mode) {
|
||||
txservice_.telegram_read_count(0);
|
||||
txservice_.telegram_write_count(0);
|
||||
txservice_.telegram_fail_count(0);
|
||||
EMSuart::stop();
|
||||
EMSuart::start(tx_mode); // reset the UART
|
||||
if (tx_mode) {
|
||||
EMSuart::stop();
|
||||
EMSuart::start(tx_mode); // reset the UART
|
||||
}
|
||||
}
|
||||
|
||||
// return status of bus: connected, connected but Tx is broken, disconnected
|
||||
@@ -117,8 +119,21 @@ uint8_t EMSESP::bus_status() {
|
||||
return BUS_STATUS_OFFLINE;
|
||||
}
|
||||
|
||||
// check if we have Tx issues
|
||||
if (txservice_.telegram_read_count() < 2) {
|
||||
// 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
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user