Skip to content
Closed
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
28 changes: 26 additions & 2 deletions can/io/asc.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,31 @@ def __init__(self, file, base="hex"):
"""
super().__init__(file, mode="r")
self.base = base
self.date = None
self.timestamps_format = None
self.internal_events_logged = None

def _extract_header(self):
for line in self.file:
line = line.strip()
lower_case = line.lower()
if lower_case.startswith("date"):
self.date = line[5:]
elif lower_case.startswith("base"):
try:
_, base, _, timestamp_format = line.split()
except ValueError:
raise Exception("Unsupported header string format: {}".format(line))
self.base = base
self.timestamps_format = timestamp_format
elif lower_case.endswith("internal events logged"):
if lower_case.startswith("no"):
self.internal_events_logged = False
else:
self.internal_events_logged = True
return
else:
return

@staticmethod
def _extract_can_id(str_can_id, base):
Expand All @@ -61,11 +86,10 @@ def _check_base(base):
return BASE_DEC if base == "dec" else BASE_HEX

def __iter__(self):
self._extract_header()
base = self._check_base(self.base)
for line in self.file:
# logger.debug("ASCReader: parsing line: '%s'", line.splitlines()[0])
if line.split(" ")[0] == "base":
base = self._check_base(line.split(" ")[1])

temp = line.strip()
if not temp or not temp[0].isdigit():
Expand Down