handle usb error in reading panda state (#23686)
parent
955c7435f8
commit
f2eb84eef0
|
@ -294,7 +294,7 @@ void send_empty_panda_state(PubMaster *pm) {
|
||||||
pm->send("pandaStates", msg);
|
pm->send("pandaStates", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool send_panda_states(PubMaster *pm, const std::vector<Panda *> &pandas, bool spoofing_started) {
|
std::optional<bool> send_panda_states(PubMaster *pm, const std::vector<Panda *> &pandas, bool spoofing_started) {
|
||||||
bool ignition_local = false;
|
bool ignition_local = false;
|
||||||
|
|
||||||
// build msg
|
// build msg
|
||||||
|
@ -304,7 +304,12 @@ bool send_panda_states(PubMaster *pm, const std::vector<Panda *> &pandas, bool s
|
||||||
|
|
||||||
std::vector<health_t> pandaStates;
|
std::vector<health_t> pandaStates;
|
||||||
for (const auto& panda : pandas){
|
for (const auto& panda : pandas){
|
||||||
health_t health = panda->get_state();
|
auto health_opt = panda->get_state();
|
||||||
|
if (!health_opt) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
health_t health = *health_opt;
|
||||||
|
|
||||||
if (spoofing_started) {
|
if (spoofing_started) {
|
||||||
health.ignition_line_pkt = 1;
|
health.ignition_line_pkt = 1;
|
||||||
|
@ -379,7 +384,12 @@ bool send_panda_states(PubMaster *pm, const std::vector<Panda *> &pandas, bool s
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_peripheral_state(PubMaster *pm, Panda *panda) {
|
void send_peripheral_state(PubMaster *pm, Panda *panda) {
|
||||||
health_t pandaState = panda->get_state();
|
auto pandaState_opt = panda->get_state();
|
||||||
|
if (!pandaState_opt) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
health_t pandaState = *pandaState_opt;
|
||||||
|
|
||||||
// build msg
|
// build msg
|
||||||
MessageBuilder msg;
|
MessageBuilder msg;
|
||||||
|
@ -427,7 +437,13 @@ void panda_state_thread(PubMaster *pm, std::vector<Panda *> pandas, bool spoofin
|
||||||
|
|
||||||
// send out peripheralState
|
// send out peripheralState
|
||||||
send_peripheral_state(pm, peripheral_panda);
|
send_peripheral_state(pm, peripheral_panda);
|
||||||
ignition = send_panda_states(pm, pandas, spoofing_started);
|
auto ignition_opt = send_panda_states(pm, pandas, spoofing_started);
|
||||||
|
|
||||||
|
if (!ignition_opt) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ignition = *ignition_opt;
|
||||||
|
|
||||||
// TODO: make this check fast, currently takes 16ms
|
// TODO: make this check fast, currently takes 16ms
|
||||||
// check if we have new pandas and are offroad
|
// check if we have new pandas and are offroad
|
||||||
|
|
|
@ -311,10 +311,10 @@ void Panda::set_ir_pwr(uint16_t ir_pwr) {
|
||||||
usb_write(0xb0, ir_pwr, 0);
|
usb_write(0xb0, ir_pwr, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
health_t Panda::get_state() {
|
std::optional<health_t> Panda::get_state() {
|
||||||
health_t health {0};
|
health_t health {0};
|
||||||
usb_read(0xd2, 0, 0, (unsigned char*)&health, sizeof(health));
|
int err = usb_read(0xd2, 0, 0, (unsigned char*)&health, sizeof(health));
|
||||||
return health;
|
return err >= 0 ? std::make_optional(health) : std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panda::set_loopback(bool loopback) {
|
void Panda::set_loopback(bool loopback) {
|
||||||
|
|
|
@ -80,7 +80,7 @@ class Panda {
|
||||||
void set_fan_speed(uint16_t fan_speed);
|
void set_fan_speed(uint16_t fan_speed);
|
||||||
uint16_t get_fan_speed();
|
uint16_t get_fan_speed();
|
||||||
void set_ir_pwr(uint16_t ir_pwr);
|
void set_ir_pwr(uint16_t ir_pwr);
|
||||||
health_t get_state();
|
std::optional<health_t> get_state();
|
||||||
void set_loopback(bool loopback);
|
void set_loopback(bool loopback);
|
||||||
std::optional<std::vector<uint8_t>> get_firmware_version();
|
std::optional<std::vector<uint8_t>> get_firmware_version();
|
||||||
std::optional<std::string> get_serial();
|
std::optional<std::string> get_serial();
|
||||||
|
|
Loading…
Reference in New Issue