Skip to content
Merged
Changes from all 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
23 changes: 11 additions & 12 deletions can/io/asc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import re
import time
from datetime import datetime
from typing import Any, Dict, Generator, List, Optional, TextIO, Union
from typing import Any, Dict, Final, Generator, List, Optional, TextIO, Union

from ..message import Message
from ..typechecking import StringPathLike
Expand All @@ -20,6 +20,14 @@
CAN_ID_MASK = 0x1FFFFFFF
BASE_HEX = 16
BASE_DEC = 10
ASC_TRIGGER_REGEX: Final = re.compile(
r"begin\s+triggerblock\s+\w+\s+(?P<datetime_string>.+)", re.IGNORECASE
)
ASC_MESSAGE_REGEX: Final = re.compile(
r"\d+\.\d+\s+(\d+\s+(\w+\s+(Tx|Rx)|ErrorFrame)|CANFD)",
re.ASCII | re.IGNORECASE,
)


logger = logging.getLogger("can.io.asc")

Expand Down Expand Up @@ -258,12 +266,7 @@ def __iter__(self) -> Generator[Message, None, None]:
for _line in self.file:
line = _line.strip()

trigger_match = re.match(
r"begin\s+triggerblock\s+\w+\s+(?P<datetime_string>.+)",
line,
re.IGNORECASE,
)
if trigger_match:
if trigger_match := ASC_TRIGGER_REGEX.match(line):
datetime_str = trigger_match.group("datetime_string")
self.start_time = (
0.0
Expand All @@ -272,11 +275,7 @@ def __iter__(self) -> Generator[Message, None, None]:
)
continue

if not re.match(
r"\d+\.\d+\s+(\d+\s+(\w+\s+(Tx|Rx)|ErrorFrame)|CANFD)",
line,
re.ASCII | re.IGNORECASE,
):
if not ASC_MESSAGE_REGEX.match(line):
# line might be a comment, chip status,
# J1939 message or some other unsupported event
continue
Expand Down