diff --git a/cereal/messaging/__init__.py b/cereal/messaging/__init__.py index 4ba55cf7b9..8dfa42056d 100644 --- a/cereal/messaging/__init__.py +++ b/cereal/messaging/__init__.py @@ -17,8 +17,8 @@ from cereal.services import SERVICE_LIST NO_TRAVERSAL_LIMIT = 2**64-1 -def log_from_bytes(dat: bytes) -> capnp.lib.capnp._DynamicStructReader: - with log.Event.from_bytes(dat, traversal_limit_in_words=NO_TRAVERSAL_LIMIT) as msg: +def log_from_bytes(dat: bytes, struct: capnp.lib.capnp._StructModule = log.Event) -> capnp.lib.capnp._DynamicStructReader: + with struct.from_bytes(dat, traversal_limit_in_words=NO_TRAVERSAL_LIMIT) as msg: return msg diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 416a9aa8c5..583cbaea1f 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -64,8 +64,7 @@ class Controls: if CI is None: cloudlog.info("controlsd is waiting for CarParams") - with car.CarParams.from_bytes(self.params.get("CarParams", block=True)) as msg: - self.CP = msg + self.CP = messaging.log_from_bytes(self.params.get("CarParams", block=True), car.CarParams) cloudlog.info("controlsd got CarParams") # Uses car interface helper functions, altering state won't be considered by card for actuation diff --git a/selfdrive/controls/plannerd.py b/selfdrive/controls/plannerd.py index 681518be19..a9577cbefd 100755 --- a/selfdrive/controls/plannerd.py +++ b/selfdrive/controls/plannerd.py @@ -12,8 +12,7 @@ def plannerd_thread(): cloudlog.info("plannerd is waiting for CarParams") params = Params() - with car.CarParams.from_bytes(params.get("CarParams", block=True)) as msg: - CP = msg + CP = messaging.log_from_bytes(params.get("CarParams", block=True), car.CarParams) cloudlog.info("plannerd got CarParams: %s", CP.carName) longitudinal_planner = LongitudinalPlanner(CP) diff --git a/selfdrive/controls/radard.py b/selfdrive/controls/radard.py index ac3ec97dcc..c3fb60c61a 100755 --- a/selfdrive/controls/radard.py +++ b/selfdrive/controls/radard.py @@ -288,8 +288,7 @@ def main(): # wait for stats about the car to come in from controls cloudlog.info("radard is waiting for CarParams") - with car.CarParams.from_bytes(Params().get("CarParams", block=True)) as msg: - CP = msg + CP = messaging.log_from_bytes(Params().get("CarParams", block=True), car.CarParams) cloudlog.info("radard got CarParams") # import the radar from the fingerprint diff --git a/selfdrive/locationd/paramsd.py b/selfdrive/locationd/paramsd.py index d124eb5f05..650ee06017 100755 --- a/selfdrive/locationd/paramsd.py +++ b/selfdrive/locationd/paramsd.py @@ -5,8 +5,7 @@ import json import numpy as np import cereal.messaging as messaging -from cereal import car -from cereal import log +from cereal import car, log from openpilot.common.params import Params from openpilot.common.realtime import config_realtime_process, DT_MDL from openpilot.common.numpy_fast import clip @@ -129,8 +128,7 @@ def main(): params_reader = Params() # wait for stats about the car to come in from controls cloudlog.info("paramsd is waiting for CarParams") - with car.CarParams.from_bytes(params_reader.get("CarParams", block=True)) as msg: - CP = msg + CP = messaging.log_from_bytes(params_reader.get("CarParams", block=True), car.CarParams) cloudlog.info("paramsd got CarParams") min_sr, max_sr = 0.5 * CP.steerRatio, 2.0 * CP.steerRatio diff --git a/selfdrive/locationd/torqued.py b/selfdrive/locationd/torqued.py index 06f9044738..569496b584 100755 --- a/selfdrive/locationd/torqued.py +++ b/selfdrive/locationd/torqued.py @@ -223,8 +223,7 @@ def main(demo=False): sm = messaging.SubMaster(['carControl', 'carOutput', 'carState', 'liveLocationKalman'], poll='liveLocationKalman') params = Params() - with car.CarParams.from_bytes(params.get("CarParams", block=True)) as CP: - estimator = TorqueEstimator(CP) + estimator = TorqueEstimator(messaging.log_from_bytes(params.get("CarParams", block=True), car.CarParams)) while True: sm.update() diff --git a/selfdrive/modeld/modeld.py b/selfdrive/modeld/modeld.py index d5812d6f5a..d2cc9d8fd7 100755 --- a/selfdrive/modeld/modeld.py +++ b/selfdrive/modeld/modeld.py @@ -172,8 +172,8 @@ def main(demo=False): if demo: CP = get_demo_car_params() else: - with car.CarParams.from_bytes(params.get("CarParams", block=True)) as msg: - CP = msg + CP = messaging.log_from_bytes(params.get("CarParams", block=True), car.CarParams) + cloudlog.info("modeld got CarParams: %s", CP.carName) # TODO this needs more thought, use .2s extra for now to estimate other delays