Skip to content

Commit

Permalink
iso statemachine make it work for CAN FD
Browse files Browse the repository at this point in the history
Make it work without a PDX-file

Signed-off-by: Christian Hackenbeck <christian.hackenbeck@mbition.io>
Signed-off-by: Andreas Lauser <andreas.lauser@mbition.io>
  • Loading branch information
Christian Hackenbeck committed Oct 4, 2023
1 parent 861a462 commit a4d142b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 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
10 changes: 6 additions & 4 deletions odxtools/isotp_state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import sys
from enum import IntEnum
from typing import AsyncGenerator, Iterable, List, Optional, TextIO, Tuple, Union
from io import TextIOWrapper

import bitstruct
import can
Expand All @@ -26,8 +27,9 @@ 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 +130,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, (TextIO, TextIOWrapper))
# input is a file
while bus:
cur_line = bus.readline()
Expand All @@ -145,7 +147,7 @@ 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 a4d142b

Please sign in to comment.