Skip to content

Commit 05a60f8

Browse files
eerimoqhardbyte
authored andcommitted
socketcan_native rx-logger and log nicly formatted message.
1 parent 1e2643b commit 05a60f8

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

can/interfaces/socketcan/socketcan_native.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
import os
1717

1818
log = logging.getLogger('can.socketcan.native')
19+
log_tx = log.getChild("tx")
20+
log_rx = log.getChild("rx")
21+
1922
log.info("Loading socketcan native backend")
2023

2124
try:
@@ -321,7 +324,6 @@ def captureMessage(sock):
321324
return None
322325

323326
can_id, can_dlc, data = dissect_can_frame(cf)
324-
log.debug('Received: can_id=%x, can_dlc=%x, data=%s', can_id, can_dlc, data)
325327

326328
# Fetching the timestamp
327329
binary_structure = "@LL"
@@ -347,13 +349,17 @@ def captureMessage(sock):
347349
log.debug("CAN: Standard")
348350
arbitration_id = can_id & 0x000007FF
349351

350-
return Message(timestamp=timestamp,
351-
arbitration_id=arbitration_id,
352-
extended_id=is_extended_frame_format,
353-
is_remote_frame=is_remote_transmission_request,
354-
is_error_frame=is_error_frame,
355-
dlc=can_dlc,
356-
data=data)
352+
msg = Message(timestamp=timestamp,
353+
arbitration_id=arbitration_id,
354+
extended_id=is_extended_frame_format,
355+
is_remote_frame=is_remote_transmission_request,
356+
is_error_frame=is_error_frame,
357+
dlc=can_dlc,
358+
data=data)
359+
360+
log_rx.debug('Received: %s', msg)
361+
362+
return msg
357363

358364

359365
class SocketcanNative_Bus(BusABC):
@@ -417,8 +423,7 @@ def send(self, msg, timeout=None):
417423
if msg.is_error_frame:
418424
log.warning("Trying to send an error frame - this won't work")
419425
arbitration_id |= 0x20000000
420-
l = log.getChild("tx")
421-
l.debug("sending: %s", msg)
426+
log_tx.debug("Sending: %s", msg)
422427
if timeout:
423428
# Wait for write availability. send will fail below on timeout
424429
select.select([], [self.socket], [], timeout)

0 commit comments

Comments
 (0)