ui: fix alert disappear when no controlState is received in a frame. (#28811)

* always return alert

* don't get old alert
old-commit-hash: d9d5ce3634
beeps
Dean Lee 2 years ago committed by GitHub
parent 724ef9d7ef
commit b987242655
  1. 21
      selfdrive/ui/ui.h

@ -48,38 +48,43 @@ struct Alert {
static Alert get(const SubMaster &sm, uint64_t started_frame) { static Alert get(const SubMaster &sm, uint64_t started_frame) {
const cereal::ControlsState::Reader &cs = sm["controlsState"].getControlsState(); const cereal::ControlsState::Reader &cs = sm["controlsState"].getControlsState();
if (sm.updated("controlsState")) { const uint64_t controls_frame = sm.rcv_frame("controlsState");
return {cs.getAlertText1().cStr(), cs.getAlertText2().cStr(),
Alert alert = {};
if (controls_frame >= started_frame) { // Don't get old alert.
alert = {cs.getAlertText1().cStr(), cs.getAlertText2().cStr(),
cs.getAlertType().cStr(), cs.getAlertSize(), cs.getAlertType().cStr(), cs.getAlertSize(),
cs.getAlertStatus(), cs.getAlertStatus(),
cs.getAlertSound()}; cs.getAlertSound()};
} else if ((sm.frame - started_frame) > 5 * UI_FREQ) { }
if (!sm.updated("controlsState") && (sm.frame - started_frame) > 5 * UI_FREQ) {
const int CONTROLS_TIMEOUT = 5; const int CONTROLS_TIMEOUT = 5;
const int controls_missing = (nanos_since_boot() - sm.rcv_time("controlsState")) / 1e9; const int controls_missing = (nanos_since_boot() - sm.rcv_time("controlsState")) / 1e9;
// Handle controls timeout // Handle controls timeout
if (sm.rcv_frame("controlsState") < started_frame) { if (controls_frame < started_frame) {
// car is started, but controlsState hasn't been seen at all // car is started, but controlsState hasn't been seen at all
return {"openpilot Unavailable", "Waiting for controls to start", alert = {"openpilot Unavailable", "Waiting for controls to start",
"controlsWaiting", cereal::ControlsState::AlertSize::MID, "controlsWaiting", cereal::ControlsState::AlertSize::MID,
cereal::ControlsState::AlertStatus::NORMAL, cereal::ControlsState::AlertStatus::NORMAL,
AudibleAlert::NONE}; AudibleAlert::NONE};
} else if (controls_missing > CONTROLS_TIMEOUT && !Hardware::PC()) { } else if (controls_missing > CONTROLS_TIMEOUT && !Hardware::PC()) {
// car is started, but controls is lagging or died // car is started, but controls is lagging or died
if (cs.getEnabled() && (controls_missing - CONTROLS_TIMEOUT) < 10) { if (cs.getEnabled() && (controls_missing - CONTROLS_TIMEOUT) < 10) {
return {"TAKE CONTROL IMMEDIATELY", "Controls Unresponsive", alert = {"TAKE CONTROL IMMEDIATELY", "Controls Unresponsive",
"controlsUnresponsive", cereal::ControlsState::AlertSize::FULL, "controlsUnresponsive", cereal::ControlsState::AlertSize::FULL,
cereal::ControlsState::AlertStatus::CRITICAL, cereal::ControlsState::AlertStatus::CRITICAL,
AudibleAlert::WARNING_IMMEDIATE}; AudibleAlert::WARNING_IMMEDIATE};
} else { } else {
return {"Controls Unresponsive", "Reboot Device", alert = {"Controls Unresponsive", "Reboot Device",
"controlsUnresponsivePermanent", cereal::ControlsState::AlertSize::MID, "controlsUnresponsivePermanent", cereal::ControlsState::AlertSize::MID,
cereal::ControlsState::AlertStatus::NORMAL, cereal::ControlsState::AlertStatus::NORMAL,
AudibleAlert::NONE}; AudibleAlert::NONE};
} }
} }
} }
return {}; return alert;
} }
}; };

Loading…
Cancel
Save