@@ -125,10 +125,11 @@ def detect_beacon(timeout_ms: int = 3100) -> List[can.typechecking.AutoDetectedC
125
125
126
126
127
127
def convert_ascii_message_to_can_message (ascii_msg : str ) -> can .Message :
128
- if not ascii_msg .startswith ( "< frame " ) or not ascii_msg . endswith (" >" ):
129
- log .warning (f"Could not parse ascii message: { ascii_msg } " )
128
+ if not ascii_msg .endswith (" >" ):
129
+ log .warning (f"Missing ending character in ascii message: { ascii_msg } " )
130
130
return None
131
- else :
131
+
132
+ if ascii_msg .startswith ("< frame " ):
132
133
# frame_string = ascii_msg.removeprefix("< frame ").removesuffix(" >")
133
134
frame_string = ascii_msg [8 :- 2 ]
134
135
parts = frame_string .split (" " , 3 )
@@ -147,6 +148,31 @@ def convert_ascii_message_to_can_message(ascii_msg: str) -> can.Message:
147
148
)
148
149
return can_message
149
150
151
+ if ascii_msg .startswith ("< error " ):
152
+ frame_string = ascii_msg [8 :- 2 ]
153
+ parts = frame_string .split (" " , 3 )
154
+ can_id , timestamp = int (parts [0 ], 16 ), float (parts [1 ])
155
+ is_ext = len (parts [0 ]) != 3
156
+
157
+ # socketcand sends no data in the error message so we don't have information
158
+ # about the error details, therefore the can frame is created with one
159
+ # data byte set to zero
160
+ data = bytearray ([0 ])
161
+ can_dlc = len (data )
162
+ can_message = can .Message (
163
+ timestamp = timestamp ,
164
+ arbitration_id = can_id & 0x1FFFFFFF ,
165
+ is_error_frame = True ,
166
+ data = data ,
167
+ dlc = can_dlc ,
168
+ is_extended_id = True ,
169
+ is_rx = True ,
170
+ )
171
+ return can_message
172
+
173
+ log .warning (f"Could not parse ascii message: { ascii_msg } " )
174
+ return None
175
+
150
176
151
177
def convert_can_message_to_ascii_message (can_message : can .Message ) -> str :
152
178
# Note: socketcan bus adds extended flag, remote_frame_flag & error_flag to id
0 commit comments