diff --git a/tools/car_porting/auto_fingerprint.py b/tools/car_porting/auto_fingerprint.py index e14a018917..7dae9ce048 100755 --- a/tools/car_porting/auto_fingerprint.py +++ b/tools/car_porting/auto_fingerprint.py @@ -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) diff --git a/tools/car_porting/examples/ford_vin_fingerprint.ipynb b/tools/car_porting/examples/ford_vin_fingerprint.ipynb index c4f2088b38..b020b1100b 100644 --- a/tools/car_porting/examples/ford_vin_fingerprint.ipynb +++ b/tools/car_porting/examples/ford_vin_fingerprint.ipynb @@ -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": [ { diff --git a/tools/lib/logreader.py b/tools/lib/logreader.py index 58883c6865..6c1174611b 100755 --- a/tools/lib/logreader.py +++ b/tools/lib/logreader.py @@ -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__": diff --git a/tools/lib/tests/test_comma_car_segments.py b/tools/lib/tests/test_comma_car_segments.py index 1d6088d821..484a4aae08 100644 --- a/tools/lib/tests/test_comma_car_segments.py +++ b/tools/lib/tests/test_comma_car_segments.py @@ -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)