@@ -69,6 +69,7 @@ def __init__(
69
69
# TODO - what is this used for? The ASC Writer only prints `absolute`
70
70
self .timestamps_format : Optional [str ] = None
71
71
self .internal_events_logged = False
72
+ self ._extract_header ()
72
73
73
74
def _extract_header (self ) -> None :
74
75
for _line in self .file :
@@ -110,9 +111,18 @@ def _extract_header(self) -> None:
110
111
111
112
if events_match :
112
113
self .internal_events_logged = events_match .group ("no_events" ) is None
113
- break
114
+ continue
114
115
115
- break
116
+ if trigger_match := ASC_TRIGGER_REGEX .match (line ):
117
+ datetime_str = trigger_match .group ("datetime_string" )
118
+ self .start_time = (
119
+ 0.0
120
+ if self .timestamps_format == "relative"
121
+ else self ._datetime_to_timestamp (datetime_str )
122
+ )
123
+ # attribute `start_timestamp` for unified as BLFReader
124
+ self .start_timestamp = self .start_time
125
+ break
116
126
117
127
@staticmethod
118
128
def _datetime_to_timestamp (datetime_string : str ) -> float :
@@ -260,20 +270,10 @@ def _process_fd_can_frame(self, line: str, msg_kwargs: Dict[str, Any]) -> Messag
260
270
return Message (** msg_kwargs )
261
271
262
272
def __iter__ (self ) -> Generator [Message , None , None ]:
263
- self ._extract_header ()
264
273
265
274
for _line in self .file :
266
275
line = _line .strip ()
267
276
268
- if trigger_match := ASC_TRIGGER_REGEX .match (line ):
269
- datetime_str = trigger_match .group ("datetime_string" )
270
- self .start_time = (
271
- 0.0
272
- if self .relative_timestamp
273
- else self ._datetime_to_timestamp (datetime_str )
274
- )
275
- continue
276
-
277
277
if not ASC_MESSAGE_REGEX .match (line ):
278
278
# line might be a comment, chip status,
279
279
# J1939 message or some other unsupported event
@@ -282,7 +282,7 @@ def __iter__(self) -> Generator[Message, None, None]:
282
282
msg_kwargs : Dict [str , Union [float , bool , int ]] = {}
283
283
try :
284
284
_timestamp , channel , rest_of_message = line .split (None , 2 )
285
- timestamp = float (_timestamp ) + self .start_time
285
+ timestamp = float (_timestamp ) + self .start_timestamp
286
286
msg_kwargs ["timestamp" ] = timestamp
287
287
if channel == "CANFD" :
288
288
msg_kwargs ["is_fd" ] = True
0 commit comments