Skip to content

Commit

Permalink
Merge pull request #214 from hacxo/snoop-fd-support
Browse files Browse the repository at this point in the history
iso statemachine make it work for CAN FD
  • Loading branch information
andlaus authored Oct 9, 2023
2 parents 2474d22 + 18d61e0 commit 93f9f84
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion odxtools/cli/_parser_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def add_pdx_argument(parser):
parser.add_argument("pdx_file", metavar="PDX_FILE", help="path to the .pdx file")
parser.add_argument("pdx_file", nargs="?", metavar="PDX_FILE", help="path to the .pdx file")
# parser.add_argument("pdx_files", metavar="PDX_FILES", nargs="+", help="PDX descriptions of all ECUs which shall be analyzed")


Expand Down
5 changes: 3 additions & 2 deletions odxtools/cli/snoop.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import odxtools
import odxtools.isotp_state_machine as ism
import odxtools.uds as uds
from odxtools.exceptions import DecodeError

from . import _parser_utils

Expand All @@ -36,7 +37,7 @@ def handle_telegram(telegram_id, payload):
if last_request is not None:
try:
decoded_message = odx_diag_layer.decode_response(payload, last_request)[0]
except odxtools.DecodeError:
except DecodeError:
pass

if decoded_message is not None:
Expand All @@ -52,7 +53,7 @@ def handle_telegram(telegram_id, payload):
try:
decoded_message = odx_diag_layer.decode(payload)[0]
last_request = payload
except odxtools.DecodeError:
except DecodeError:
last_request = None

if decoded_message:
Expand Down
13 changes: 9 additions & 4 deletions odxtools/isotp_state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import sys
from enum import IntEnum
from io import TextIOBase
from typing import AsyncGenerator, Iterable, List, Optional, TextIO, Tuple, Union

import bitstruct
Expand All @@ -26,8 +27,10 @@ class IsoTp(IntEnum):

class IsoTpStateMachine:
can_normal_frame_re = re.compile(
"([a-zA-Z0-9_-]*) *([0-9A-Fa-f ]*) *\\[[0-9]*\\] *([ 0-9A-Fa-f]*)")
can_log_frame_re = re.compile("\\([0-9.]*\\) *([a-zA-Z0-9_-]*) ([0-9A-Fa-f]*)#([0-9A-Fa-f]*)")
"([a-zA-Z0-9_-]*) *([0-9A-Fa-f ]*) *\\[[0-9]+\\] *([ 0-9A-Fa-f]+)")
can_log_frame_re = re.compile("\\([0-9.]*\\) *([a-zA-Z0-9_-]*) ([0-9A-Fa-f]+)#([0-9A-Fa-f]+)")
can_fd_log_frame_re = re.compile(
"\\([0-9.]*\\) *([a-zA-Z0-9_-]*) ([0-9A-Fa-f]+)##[0-9A-Fa-f]([0-9A-Fa-f]+)")

def __init__(self, can_rx_ids: Union[int, List[int]]):
if isinstance(can_rx_ids, int):
Expand Down Expand Up @@ -128,7 +131,7 @@ async def read_telegrams(self, bus: Union[can.Bus,
for tmp in self.decode_rx_frame(msg.arbitration_id, msg.data):
yield tmp
else:
assert isinstance(bus, TextIO)
assert isinstance(bus, TextIOBase)
# input is a file
while bus:
cur_line = bus.readline()
Expand All @@ -145,7 +148,9 @@ async def read_telegrams(self, bus: Union[can.Bus,
for tmp in self.decode_rx_frame(frame_id, frame_data):
yield tmp

elif m := self.can_log_frame_re.match(cur_line.strip()):
elif (m := self.can_log_frame_re.match(
cur_line.strip())) or (m := self.can_fd_log_frame_re.match(
cur_line.strip())):
#frame_interface = m.group(2)
frame_id = int(m.group(2), 16)

Expand Down

0 comments on commit 93f9f84

Please sign in to comment.