boardd: set can and pandaState valid flags (#20899)

* boardd: set can and pandaState valid flags

* add event

* bump cereal

* consistency
This commit is contained in:
Adeeb Shihadeh
2021-05-14 22:26:02 -06:00
committed by GitHub
parent 4b7ea0a032
commit e694f0b4d6
6 changed files with 18 additions and 3 deletions

2
cereal

Submodule cereal updated: 2acf89ed6f...4ecee78a76

View File

@@ -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()) {

View File

@@ -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<capnp::word>& 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

View File

@@ -54,6 +54,7 @@ class Panda {
~Panda();
std::atomic<bool> connected = true;
std::atomic<bool> comms_healthy = true;
cereal::PandaState::PandaType hw_type = cereal::PandaState::PandaType::UNKNOWN;
bool has_rtc = false;

View File

@@ -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:

View File

@@ -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(