Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iso statemachine make it work for CAN FD #214

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 TextIOWrapper
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, (TextIO, TextIOWrapper))
kayoub5 marked this conversation as resolved.
Show resolved Hide resolved
# 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