Skip to content

Commit

Permalink
boardd: add controls heartbeat (commaai#23185)
Browse files Browse the repository at this point in the history
* boardd: add controls heartbeat

* bump panda

* bump again

* bump panda
  • Loading branch information
adeebshihadeh authored Dec 16, 2021
1 parent 768cfdb commit a793b94
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion selfdrive/boardd/boardd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,8 @@ void panda_state_thread(PubMaster *pm, std::vector<Panda *> pandas, bool spoofin
util::set_thread_name("boardd_panda_state");

Params params;
SubMaster sm({"controlsState"});

Panda *peripheral_panda = pandas[0];
bool ignition_last = false;
std::future<bool> safety_future;
Expand Down Expand Up @@ -445,8 +447,11 @@ void panda_state_thread(PubMaster *pm, std::vector<Panda *> pandas, bool spoofin

ignition_last = ignition;

sm.update(0);
const bool engaged = sm.allAliveAndValid({"controlsState"}) && sm["controlsState"].getControlsState().getEnabled();

for (const auto &panda : pandas) {
panda->send_heartbeat();
panda->send_heartbeat(engaged);
}
util::sleep_for(500);
}
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/boardd/panda.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ void Panda::set_usb_power_mode(cereal::PeripheralState::UsbPowerMode power_mode)
usb_write(0xe6, (uint16_t)power_mode, 0);
}

void Panda::send_heartbeat() {
usb_write(0xf3, 1, 0);
void Panda::send_heartbeat(bool engaged) {
usb_write(0xf3, engaged, 0);
}

void Panda::set_can_speed_kbps(uint16_t bus, uint16_t speed) {
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/boardd/panda.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Panda {
std::optional<std::string> get_serial();
void set_power_saving(bool power_saving);
void set_usb_power_mode(cereal::PeripheralState::UsbPowerMode power_mode);
void send_heartbeat();
void send_heartbeat(bool engaged);
void set_can_speed_kbps(uint16_t bus, uint16_t speed);
void set_data_speed_kbps(uint16_t bus, uint16_t speed);
void can_send(capnp::List<cereal::CanData>::Reader can_data_list);
Expand Down

0 comments on commit a793b94

Please sign in to comment.