From 6b7371e1bf03e64173efbdaa6184eea27101f873 Mon Sep 17 00:00:00 2001 From: PaulN Date: Sat, 2 Jul 2022 12:06:15 -0700 Subject: [PATCH] Thill more fixes (#249) * fixes lap logging makes obd initialization more forgiving * obd timing tweaks only once we get a connection to the car do we start timing whether to disregard some settings --- lemon_pi/car/lap_tracker.py | 2 ++ lemon_pi/car/obd_reader.py | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lemon_pi/car/lap_tracker.py b/lemon_pi/car/lap_tracker.py index a0c402d..9cda3d0 100644 --- a/lemon_pi/car/lap_tracker.py +++ b/lemon_pi/car/lap_tracker.py @@ -18,6 +18,7 @@ logger = logging.getLogger(__name__) gps_logger = logging.getLogger("gps-logger") +lap_logger = logging.getLogger("lap-logger") class LapTracker(PositionUpdater, LapProvider, EventHandler): @@ -64,6 +65,7 @@ def update_position(self, lat: float, long: float, heading: float, time: float, self.last_lap_time = lap_time if self.best_lap_time is None or lap_time < self.best_lap_time: self.best_lap_time = lap_time + lap_logger.info(f"{self.lap_count},{self.last_lap_time:.1f}") self.lap_start_time = cross_time RadioSyncEvent.emit(ts=cross_time) diff --git a/lemon_pi/car/obd_reader.py b/lemon_pi/car/obd_reader.py index 186a738..424e66a 100644 --- a/lemon_pi/car/obd_reader.py +++ b/lemon_pi/car/obd_reader.py @@ -19,7 +19,8 @@ class ObdReader(Thread, TemperatureProvider, FuelProvider): refresh_rate = { obd.commands.COOLANT_TEMP: 10, - obd.commands.FUEL_LEVEL: 10, + # temporarily deleting this + # obd.commands.FUEL_LEVEL: 10, } def __init__(self): @@ -53,8 +54,14 @@ def run(self) -> None: time.sleep(30) continue + while connection.status() != obd.OBDStatus.CAR_CONNECTED and not self.finished: + time.sleep(30) + + self.initialization_time = time.time() + while connection.status() == obd.OBDStatus.CAR_CONNECTED and not self.finished: now = time.time() + keys_to_delete = [] for cmd in ObdReader.refresh_rate.keys(): if now - self.last_update_time[cmd] > ObdReader.refresh_rate[cmd]: r = connection.query(cmd) @@ -67,10 +74,13 @@ def run(self) -> None: # keep trying for 5 minutes, then remove the setting if self.last_update_time[cmd] == 0.0 and time.time() - self.initialization_time > 300: # we never got any data for this command, remove it - del ObdReader.refresh_rate[cmd] - logger.info(f"removed {cmd}") + keys_to_delete.append(cmd) time.sleep(10) time.sleep(0.5) + for dead_key in keys_to_delete: + del ObdReader.refresh_rate[dead_key] + logger.info(f"removed {dead_key}") + except Exception as e: logger.exception("bad stuff in OBD land %s", e) if connection: