LogReader: replace get_first_message with LogReader.first (#31146)
* first * str old-commit-hash: dd0c474e6cc09d17cd07b51098d826dc40bc5403
This commit is contained in:
@@ -7,7 +7,7 @@ from openpilot.selfdrive.debug.format_fingerprints import format_brand_fw_versio
|
||||
|
||||
from openpilot.selfdrive.car.fw_versions import match_fw_to_car
|
||||
from openpilot.selfdrive.car.interfaces import get_interface_attr
|
||||
from openpilot.tools.lib.logreader import LogReader, ReadMode, get_first_message
|
||||
from openpilot.tools.lib.logreader import LogReader, ReadMode
|
||||
|
||||
|
||||
ALL_FW_VERSIONS = get_interface_attr("FW_VERSIONS")
|
||||
@@ -32,14 +32,14 @@ if __name__ == "__main__":
|
||||
|
||||
platform: Optional[str] = None
|
||||
|
||||
CP = get_first_message(lr, "carParams")
|
||||
CP = lr.first("carParams")
|
||||
|
||||
if CP is None:
|
||||
raise Exception("No fw versions in the provided route...")
|
||||
|
||||
carFw = CP.carParams.carFw
|
||||
carVin = CP.carParams.carVin
|
||||
carPlatform = CP.carParams.carFingerprint
|
||||
carFw = CP.carFw
|
||||
carVin = CP.carVin
|
||||
carPlatform = CP.carFingerprint
|
||||
|
||||
if args.platform is None: # attempt to auto-determine platform with other fuzzy fingerprints
|
||||
_, possible_platforms = match_fw_to_car(carFw, log=False)
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"kj/filesystem-disk-unix.c++:1703: warning: PWD environment variable doesn't match current directory; pwd = /mnt/c/Users/jnewb/AppData/Local/Programs/Microsoft VS Code\n"
|
||||
"kj/filesystem-disk-unix.c++:1703: warning: PWD environment variable doesn't match current directory; pwd = /home/batman\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
@@ -74,9 +74,6 @@
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from openpilot.tools.lib.logreader import get_first_message\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"VINS_TO_CHECK = set()\n",
|
||||
"\n",
|
||||
"for platform in platforms:\n",
|
||||
@@ -86,13 +83,13 @@
|
||||
"\n",
|
||||
" for segment in database[platform]:\n",
|
||||
" lr = LogReader(segment)\n",
|
||||
" CP = get_first_message(lr, \"carParams\").carParams\n",
|
||||
" CP = lr.first(\"carParams\")\n",
|
||||
" VINS_TO_CHECK.add((CP.carVin, CP.carFingerprint))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
|
||||
@@ -264,9 +264,9 @@ are uploaded or auto fallback to qlogs with '/a' selector at the end of the rout
|
||||
def from_bytes(dat):
|
||||
return _LogFileReader("", dat=dat)
|
||||
|
||||
|
||||
def get_first_message(lr: LogIterable, msg_type):
|
||||
return next(filter(lambda m: m.which() == msg_type, lr), None)
|
||||
def first(self, msg_type: str):
|
||||
m = next(filter(lambda m: m.which() == msg_type, self), None)
|
||||
return None if m is None else getattr(m, msg_type)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -4,7 +4,7 @@ import unittest
|
||||
|
||||
import requests
|
||||
from openpilot.tools.lib.comma_car_segments import get_comma_car_segments_database, get_url
|
||||
from openpilot.tools.lib.logreader import LogReader, get_first_message
|
||||
from openpilot.tools.lib.logreader import LogReader
|
||||
from openpilot.tools.lib.route import SegmentRange
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ class TestCommaCarSegments(unittest.TestCase):
|
||||
|
||||
lr = LogReader(url)
|
||||
|
||||
CP = get_first_message(lr, "carParams").carParams
|
||||
CP = lr.first("carParams")
|
||||
|
||||
self.assertEqual(CP.carFingerprint, fp)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user