From e23dcec07d5cf70bfc876cc03974434fc059309c Mon Sep 17 00:00:00 2001 From: Comma Device Date: Mon, 22 Jun 2020 16:25:44 -0700 Subject: [PATCH] bring back cycle_alerts.py old-commit-hash: c3171e66b35a5db2625bc15d5d82de31d5c2ff4e --- selfdrive/debug/cycle_alerts.py | 56 +++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 selfdrive/debug/cycle_alerts.py diff --git a/selfdrive/debug/cycle_alerts.py b/selfdrive/debug/cycle_alerts.py new file mode 100755 index 000000000..bd48e6c6d --- /dev/null +++ b/selfdrive/debug/cycle_alerts.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +import argparse +import time +import zmq + +import cereal.messaging as messaging +from cereal.services import service_list +from selfdrive.controls.lib.events import EVENTS, Alert + +def now_millis(): return time.time() * 1000 + +ALERTS = [a for _, et in EVENTS.items() for _, a in et.items() if isinstance(a, Alert)] + +#from cereal import car +#ALERTS = [a for a in ALERTS if a.audible_alert == car.CarControl.HUDControl.AudibleAlert.chimeWarningRepeat] + +default_alerts = sorted(ALERTS, key=lambda alert: (alert.alert_size, len(alert.alert_text_2))) + +def cycle_alerts(duration_millis, alerts=None): + if alerts is None: + alerts = default_alerts + + controls_state = messaging.pub_sock('controlsState') + + idx, last_alert_millis = 0, 0 + alert = alerts[0] + while 1: + if (now_millis() - last_alert_millis) > duration_millis: + alert = alerts[idx] + idx = (idx + 1) % len(alerts) + last_alert_millis = now_millis() + print('sending {}'.format(str(alert))) + + dat = messaging.new_message() + dat.init('controlsState') + + dat.controlsState.alertType = alert.alert_type + dat.controlsState.alertText1 = alert.alert_text_1 + dat.controlsState.alertText2 = alert.alert_text_2 + dat.controlsState.alertSize = alert.alert_size + #dat.controlsState.alertStatus = alert.alert_status + dat.controlsState.alertSound = alert.audible_alert + controls_state.send(dat.to_bytes()) + + time.sleep(0.01) + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--duration', type=int, default=1000) + parser.add_argument('--alert-types', nargs='+') + args = parser.parse_args() + alerts = None + if args.alert_types: + alerts = [next(a for a in ALERTS if a.alert_type==alert_type) for alert_type in args.alert_types] + + cycle_alerts(args.duration, alerts=alerts)