Skip to content

Commit

Permalink
controlsd: cleanup parsing android log (commaai#23421)
Browse files Browse the repository at this point in the history
* cleanup parse android log

* global CSID_MAP

* use generator express

* cleanup

* no walrus

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
  • Loading branch information
deanlee and adeebshihadeh authored Jan 14, 2022
1 parent 9f4fd73 commit fd042a5
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions selfdrive/controls/controlsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit fd042a5

Please sign in to comment.