-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <[email protected]>
- Loading branch information
1 parent
ee9814f
commit 6ab5ee6
Showing
2 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# Copyright (C) 2025 Kevin O'Connor <[email protected]> | ||
# | ||
# This file may be distributed under the terms of the GNU GPLv3 license. | ||
import logging | ||
|
||
class PrinterCANBusStats: | ||
def __init__(self, config): | ||
|
@@ -24,9 +25,20 @@ def _connect(self): | |
self.get_canbus_status_cmd = self.mcu.lookup_query_command( | ||
"get_canbus_status", | ||
"canbus_status rx_error=%u tx_error=%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 | ||
reactor = self.printer.get_reactor() | ||
reactor.register_timer(self.query_event, 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): | ||
params = self.get_canbus_status_cmd.send() | ||
rx = params['rx_error'] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters