From ed3a0cf518f68c3f21703652ac5125c97245e60f Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Fri, 14 Jan 2022 11:43:22 +0800 Subject: [PATCH] controlsd: cleanup parsing android log (#23421) * cleanup parse android log * global CSID_MAP * use generator express * cleanup * no walrus Co-authored-by: Adeeb Shihadeh --- selfdrive/controls/controlsd.py | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 3d94405c480c5e..49d6ea6e916a39 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -55,7 +55,7 @@ SafetyModel = car.CarParams.SafetyModel IGNORED_SAFETY_MODES = [SafetyModel.silent, SafetyModel.noOutput] - +CSID_MAP = {"0": EventName.roadCameraError, "1": EventName.wideRoadCameraError, "2": EventName.driverCameraError} class Controls: def __init__(self, sm=None, pm=None, can_sock=None): @@ -311,25 +311,17 @@ def update_events(self, CS): self.events.add(EventName.fcw) if TICI: - logs = messaging.drain_sock(self.log_sock, wait_for_one=False) - messages = [] - for m in logs: + for m in messaging.drain_sock(self.log_sock, wait_for_one=False): try: - messages.append(m.androidLog.message) + msg = m.androidLog.message + if any(err in msg for err in ("ERROR_CRC", "ERROR_ECC", "ERROR_STREAM_UNDERFLOW", "APPLY FAILED")): + csid = msg.split("CSID:")[-1].split(" ")[0] + evt = CSID_MAP.get(csid, None) + if evt is not None: + self.events.add(evt) except UnicodeDecodeError: pass - for err in ("ERROR_CRC", "ERROR_ECC", "ERROR_STREAM_UNDERFLOW", "APPLY FAILED"): - for m in messages: - if err not in m: - continue - - csid = m.split("CSID:")[-1].split(" ")[0] - evt = {"0": EventName.roadCameraError, "1": EventName.wideRoadCameraError, - "2": EventName.driverCameraError}.get(csid, None) - if evt is not None: - self.events.add(evt) - # TODO: fix simulator if not SIMULATION: if not NOSENSOR: