mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-19 00:43:54 +08:00
Events: debug script (#28898)
* Move to separate branch
* Fix mypy
* Better printout
* Fix spacing
* cleanup
---------
Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
old-commit-hash: 22c413af6d
This commit is contained in:
33
selfdrive/controls/lib/events.py
Normal file → Executable file
33
selfdrive/controls/lib/events.py
Normal file → Executable file
@@ -954,3 +954,36 @@ EVENTS: Dict[int, Dict[str, Union[Alert, AlertCallbackType]]] = {
|
||||
},
|
||||
|
||||
}
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# print all alerts by type and priority
|
||||
from cereal.services import service_list
|
||||
from collections import defaultdict, OrderedDict
|
||||
|
||||
event_names = {v: k for k, v in EventName.schema.enumerants.items()}
|
||||
alerts_by_type: Dict[str, Dict[int, List[str]]] = defaultdict(lambda: defaultdict(list))
|
||||
|
||||
CP = car.CarParams.new_message()
|
||||
CS = car.CarState.new_message()
|
||||
sm = messaging.SubMaster(list(service_list.keys()))
|
||||
|
||||
for i, alerts in EVENTS.items():
|
||||
for et, alert in alerts.items():
|
||||
if callable(alert):
|
||||
alert = alert(CP, CS, sm, False, 1)
|
||||
priority = alert.priority
|
||||
alerts_by_type[et][priority].append(event_names[i])
|
||||
|
||||
all_alerts = {}
|
||||
for et, priority_alerts in alerts_by_type.items():
|
||||
all_alerts[et] = OrderedDict([
|
||||
(str(priority), l)
|
||||
for priority, l in sorted(priority_alerts.items(), key=lambda x: -int(x[0]))
|
||||
])
|
||||
|
||||
for status, evs in sorted(all_alerts.items(), key=lambda x: x[0]):
|
||||
print(f"**** {status} ****")
|
||||
for p, alert_list in evs.items():
|
||||
print(f" {p}:")
|
||||
print(" ", ', '.join(alert_list), "\n")
|
||||
|
||||
Reference in New Issue
Block a user