|
6 | 6 | - under `test/data/logfile.asc`
|
7 | 7 | """
|
8 | 8 | import gzip
|
9 |
| -from typing import cast, Any, Generator, IO, List, Optional, Dict, Union, TextIO |
| 9 | +import re |
| 10 | +from typing import Any, Generator, List, Optional, Dict, Union, TextIO |
10 | 11 |
|
11 | 12 | from datetime import datetime
|
12 | 13 | import time
|
@@ -85,8 +86,8 @@ def _extract_header(self):
|
85 | 86 | self.timestamps_format = timestamp_format
|
86 | 87 | elif lower_case.endswith("internal events logged"):
|
87 | 88 | self.internal_events_logged = not lower_case.startswith("no")
|
88 |
| - elif lower_case.startswith("// version"): |
89 |
| - # the test files include `// version 9.0.0` - not sure what this is |
| 89 | + elif lower_case.startswith("//"): |
| 90 | + # ignore comments |
90 | 91 | continue
|
91 | 92 | # grab absolute timestamp
|
92 | 93 | elif lower_case.startswith("begin triggerblock"):
|
@@ -210,14 +211,20 @@ def __iter__(self) -> Generator[Message, None, None]:
|
210 | 211 | self._extract_header()
|
211 | 212 |
|
212 | 213 | for line in self.file:
|
213 |
| - temp = line.strip() |
214 |
| - if not temp or not temp[0].isdigit(): |
215 |
| - # Could be a comment |
| 214 | + line = line.strip() |
| 215 | + |
| 216 | + if not re.match( |
| 217 | + r"\d+\.\d+\s+(\d+\s+(\w+\s+(Tx|Rx)|ErrorFrame)|CANFD)", |
| 218 | + line, |
| 219 | + re.ASCII | re.IGNORECASE, |
| 220 | + ): |
| 221 | + # line might be a comment, chip status, |
| 222 | + # J1939 message or some other unsupported event |
216 | 223 | continue
|
217 | 224 |
|
218 | 225 | msg_kwargs: Dict[str, Union[float, bool, int]] = {}
|
219 | 226 | try:
|
220 |
| - _timestamp, channel, rest_of_message = temp.split(None, 2) |
| 227 | + _timestamp, channel, rest_of_message = line.split(None, 2) |
221 | 228 | timestamp = float(_timestamp) + self.start_time
|
222 | 229 | msg_kwargs["timestamp"] = timestamp
|
223 | 230 | if channel == "CANFD":
|
|
0 commit comments