diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2025-01-14 22:38:08 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2025-02-02 18:43:34 -0500 |
commit | 2c90c97ccd5ceb9b4071f95866160344f013a86f (patch) | |
tree | 1b7028ae85b0cdd4aa1748cea9f5ba649170a1d7 /klippy/extras | |
parent | 2db2ef82f2c0ba08d7e72fbab355de0846272b3a (diff) | |
download | kutter-2c90c97ccd5ceb9b4071f95866160344f013a86f.tar.gz kutter-2c90c97ccd5ceb9b4071f95866160344f013a86f.tar.xz kutter-2c90c97ccd5ceb9b4071f95866160344f013a86f.zip |
usb_canbus: Detect canbus stalls when in usb to canbus bridge mode
If the low-level canbus stops working then it could become impossible
to send messages to and from the canbus bridge node itself. This can
make it difficult to diagnose canbus problems.
Change the canbus bridge code to detect if message transmits become
stalled for 50+ milliseconds and go into a "discarding" state. In
this discarding state, messages destined for the canbus will be
discarded until the canbus becomes active again. In this discarding
state it will therefore be possible to transmit messages to and from
the canbus bridge node.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras')
-rw-r--r-- | klippy/extras/canbus_stats.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/klippy/extras/canbus_stats.py b/klippy/extras/canbus_stats.py index b9ee3102..0ddafaf3 100644 --- a/klippy/extras/canbus_stats.py +++ b/klippy/extras/canbus_stats.py @@ -3,6 +3,7 @@ # Copyright (C) 2025 Kevin O'Connor <kevin@koconnor.net> # # This file may be distributed under the terms of the GNU GPLv3 license. +import logging class PrinterCANBusStats: def __init__(self, config): @@ -36,8 +37,19 @@ class PrinterCANBusStats: "get_canbus_status", "canbus_status rx_error=%u tx_error=%u tx_retries=%u" " canbus_bus_state=%u") + # Register usb_canbus_state message handling (for usb to canbus bridge) + self.mcu.register_response(self.handle_usb_canbus_state, + "usb_canbus_state") # Register periodic query timer self.reactor.register_timer(self.query_event, self.reactor.NOW) + def handle_usb_canbus_state(self, params): + discard = params['discard'] + if discard: + logging.warning("USB CANBUS bridge '%s' is discarding!" + % (self.name,)) + else: + logging.warning("USB CANBUS bridge '%s' is no longer discarding." + % (self.name,)) def query_event(self, eventtime): prev_rx = self.status['rx_error'] prev_tx = self.status['tx_error'] |