controlsd: cleanup parsing android log (#23421)

* cleanup parse android log

* global CSID_MAP

* use generator express

* cleanup

* no walrus

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
old-commit-hash: fd042a5924
This commit is contained in:
Dean Lee 2022-01-14 11:43:22 +08:00 committed by GitHub
parent d08d16bb6c
commit a1d3ab2ea1
1 changed files with 8 additions and 16 deletions

View File

@ -55,7 +55,7 @@ ButtonEvent = car.CarState.ButtonEvent
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 @@ class Controls:
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: