diff --git a/cereal b/cereal index 2acf89ed6f..4ecee78a76 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit 2acf89ed6fb6444dce2bc738739270bdf6ccb5e4 +Subproject commit 4ecee78a761c5421a5a677aa802175ca19527426 diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index f1f885b0c5..1b36acbbbf 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -358,7 +358,10 @@ void panda_state_thread(bool spoofing_started) { // build msg MessageBuilder msg; - auto ps = msg.initEvent().initPandaState(); + auto evt = msg.initEvent(); + evt.setValid(panda->comms_healthy); + + auto ps = evt.initPandaState(); ps.setUptime(pandaState.uptime); if (Hardware::TICI()) { diff --git a/selfdrive/boardd/panda.cc b/selfdrive/boardd/panda.cc index 71f5770ed3..bf4f56c50e 100644 --- a/selfdrive/boardd/panda.cc +++ b/selfdrive/boardd/panda.cc @@ -152,6 +152,7 @@ int Panda::usb_bulk_read(unsigned char endpoint, unsigned char* data, int length if (err == LIBUSB_ERROR_TIMEOUT) { break; // timeout is okay to exit, recv still happened } else if (err == LIBUSB_ERROR_OVERFLOW) { + comms_healthy = false; LOGE_100("overflow got 0x%x", transferred); } else if (err != 0) { handle_usb_issue(err, __func__); @@ -296,9 +297,11 @@ int Panda::can_receive(kj::Array& out_buf) { size_t num_msg = recv / 0x10; MessageBuilder msg; - auto canData = msg.initEvent().initCan(num_msg); + auto evt = msg.initEvent(); + evt.setValid(comms_healthy); // populate message + auto canData = evt.initCan(num_msg); for (int i = 0; i < num_msg; i++) { if (data[i*4] & 4) { // extended diff --git a/selfdrive/boardd/panda.h b/selfdrive/boardd/panda.h index e725da4fa9..4eca7cc38f 100644 --- a/selfdrive/boardd/panda.h +++ b/selfdrive/boardd/panda.h @@ -54,6 +54,7 @@ class Panda { ~Panda(); std::atomic connected = true; + std::atomic comms_healthy = true; cereal::PandaState::PandaType hw_type = cereal::PandaState::PandaType::UNKNOWN; bool has_rtc = false; diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 661d87536b..cfd81bc451 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -225,6 +225,8 @@ class Controls: if len(self.sm['radarState'].radarErrors): self.events.add(EventName.radarFault) + elif not self.sm.valid["pandaState"]: + self.events.add(EventName.usbError) elif not self.sm.all_alive_and_valid(): self.events.add(EventName.commIssue) if not self.logged_comm_issue: diff --git a/selfdrive/controls/lib/events.py b/selfdrive/controls/lib/events.py index 87ea3d6fad..d826616fb7 100644 --- a/selfdrive/controls/lib/events.py +++ b/selfdrive/controls/lib/events.py @@ -672,6 +672,12 @@ EVENTS: Dict[int, Dict[str, Union[Alert, Callable[[Any, messaging.SubMaster, boo ET.IMMEDIATE_DISABLE: ImmediateDisableAlert("Controls Mismatch"), }, + EventName.usbError: { + ET.SOFT_DISABLE: SoftDisableAlert("USB Error: Reboot Your Device"), + ET.PERMANENT: NormalPermanentAlert("USB Error: Reboot Your Device", ""), + ET.NO_ENTRY: NoEntryAlert("USB Error: Reboot Your Device"), + }, + EventName.canError: { ET.IMMEDIATE_DISABLE: ImmediateDisableAlert("CAN Error: Check Connections"), ET.PERMANENT: Alert(