mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-10 20:02:13 +08:00
ui: fix alert disappear when no controlState is received in a frame. (#28811)
* always return alert * don't get old alert old-commit-hash: d9d5ce36345950db8471631a083c9a609595c311
This commit is contained in:
+25
-20
@@ -48,38 +48,43 @@ struct Alert {
|
||||
|
||||
static Alert get(const SubMaster &sm, uint64_t started_frame) {
|
||||
const cereal::ControlsState::Reader &cs = sm["controlsState"].getControlsState();
|
||||
if (sm.updated("controlsState")) {
|
||||
return {cs.getAlertText1().cStr(), cs.getAlertText2().cStr(),
|
||||
cs.getAlertType().cStr(), cs.getAlertSize(),
|
||||
cs.getAlertStatus(),
|
||||
cs.getAlertSound()};
|
||||
} else if ((sm.frame - started_frame) > 5 * UI_FREQ) {
|
||||
const uint64_t controls_frame = sm.rcv_frame("controlsState");
|
||||
|
||||
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.getAlertStatus(),
|
||||
cs.getAlertSound()};
|
||||
}
|
||||
|
||||
if (!sm.updated("controlsState") && (sm.frame - started_frame) > 5 * UI_FREQ) {
|
||||
const int CONTROLS_TIMEOUT = 5;
|
||||
const int controls_missing = (nanos_since_boot() - sm.rcv_time("controlsState")) / 1e9;
|
||||
|
||||
// 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
|
||||
return {"openpilot Unavailable", "Waiting for controls to start",
|
||||
"controlsWaiting", cereal::ControlsState::AlertSize::MID,
|
||||
cereal::ControlsState::AlertStatus::NORMAL,
|
||||
AudibleAlert::NONE};
|
||||
alert = {"openpilot Unavailable", "Waiting for controls to start",
|
||||
"controlsWaiting", cereal::ControlsState::AlertSize::MID,
|
||||
cereal::ControlsState::AlertStatus::NORMAL,
|
||||
AudibleAlert::NONE};
|
||||
} else if (controls_missing > CONTROLS_TIMEOUT && !Hardware::PC()) {
|
||||
// car is started, but controls is lagging or died
|
||||
if (cs.getEnabled() && (controls_missing - CONTROLS_TIMEOUT) < 10) {
|
||||
return {"TAKE CONTROL IMMEDIATELY", "Controls Unresponsive",
|
||||
"controlsUnresponsive", cereal::ControlsState::AlertSize::FULL,
|
||||
cereal::ControlsState::AlertStatus::CRITICAL,
|
||||
AudibleAlert::WARNING_IMMEDIATE};
|
||||
alert = {"TAKE CONTROL IMMEDIATELY", "Controls Unresponsive",
|
||||
"controlsUnresponsive", cereal::ControlsState::AlertSize::FULL,
|
||||
cereal::ControlsState::AlertStatus::CRITICAL,
|
||||
AudibleAlert::WARNING_IMMEDIATE};
|
||||
} else {
|
||||
return {"Controls Unresponsive", "Reboot Device",
|
||||
"controlsUnresponsivePermanent", cereal::ControlsState::AlertSize::MID,
|
||||
cereal::ControlsState::AlertStatus::NORMAL,
|
||||
AudibleAlert::NONE};
|
||||
alert = {"Controls Unresponsive", "Reboot Device",
|
||||
"controlsUnresponsivePermanent", cereal::ControlsState::AlertSize::MID,
|
||||
cereal::ControlsState::AlertStatus::NORMAL,
|
||||
AudibleAlert::NONE};
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
return alert;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user