Skip to content

Commit 39541b1

Browse files
author
Caleb Perkinson
committed
rebase changes
still need to update docs, create test, and add option flag
1 parent d86020e commit 39541b1

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

can/io/asc.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ def __init__(
5353
self.base = base
5454
self._converted_base = self._check_base(base)
5555
self.date = None
56+
# TODO - what is this used for? The ASC Writer only prints `absolute`
5657
self.timestamps_format = None
5758
self.internal_events_logged = None
5859

@@ -72,6 +73,14 @@ def _extract_header(self):
7273
self.timestamps_format = timestamp_format
7374
elif lower_case.endswith("internal events logged"):
7475
self.internal_events_logged = not lower_case.startswith("no")
76+
# grab absolute timestamp
77+
elif lower_case.startswith("begin triggerblock"):
78+
try:
79+
_, _, start_time = lower_case.split(None, 2)
80+
start_time = datetime.strptime(start_time, "%a %b %m %I:%M:%S.%f %p %Y").timestamp()
81+
except ValueError:
82+
start_time = 0.0
83+
self.start_time = start_time
7584
# Currently the last line in the header which is parsed
7685
break
7786
else:
@@ -183,23 +192,13 @@ def __iter__(self) -> Generator[Message, None, None]:
183192

184193
for line in self.file:
185194
temp = line.strip()
186-
187-
#check for timestamp
188-
if "begin triggerblock" in temp.lower():
189-
try:
190-
_, _, start_time = temp.split(None, 2)
191-
start_time = datetime.strptime(start_time, "%a %b %m %I:%M:%S.%f %p %Y").timestamp()
192-
except ValueError:
193-
start_time = 0.0
194-
continue
195-
196195
if not temp or not temp[0].isdigit():
197196
# Could be a comment
198197
continue
199198
msg_kwargs = {}
200199
try:
201200
timestamp, channel, rest_of_message = temp.split(None, 2)
202-
timestamp = float(timestamp)
201+
timestamp = float(timestamp) + self.start_time
203202
msg_kwargs["timestamp"] = timestamp
204203
if channel == "CANFD":
205204
msg_kwargs["is_fd"] = True

0 commit comments

Comments
 (0)