mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-02-18 21:14:01 +08:00
committed by
Adeeb Shihadeh
parent
afe7825130
commit
8a91f7cd30
@@ -472,6 +472,11 @@ void panda_state_thread(PubMaster *pm, std::vector<Panda *> pandas, bool spoofin
|
||||
bool is_onroad_last = false;
|
||||
std::future<bool> safety_future;
|
||||
|
||||
std::vector<std::string> connected_serials;
|
||||
for (Panda *p : pandas) {
|
||||
connected_serials.push_back(p->hw_serial());
|
||||
}
|
||||
|
||||
LOGD("start panda state thread");
|
||||
|
||||
// run at 2hz
|
||||
@@ -499,10 +504,15 @@ void panda_state_thread(PubMaster *pm, std::vector<Panda *> pandas, bool spoofin
|
||||
LOGE("Reconnecting, communication to pandas not healthy");
|
||||
do_exit = true;
|
||||
|
||||
// TODO: list is slow, takes 16ms
|
||||
} else if (pandas.size() != Panda::list().size()) {
|
||||
LOGW("Reconnecting to changed amount of pandas!");
|
||||
do_exit = true;
|
||||
} else {
|
||||
// check for new pandas
|
||||
for (std::string &s : Panda::list(true)) {
|
||||
if (!std::count(connected_serials.begin(), connected_serials.end(), s)) {
|
||||
LOGW("Reconnecting to new panda: %s", s.c_str());
|
||||
do_exit = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (do_exit) {
|
||||
|
||||
@@ -44,13 +44,15 @@ std::string Panda::hw_serial() {
|
||||
return handle->hw_serial;
|
||||
}
|
||||
|
||||
std::vector<std::string> Panda::list() {
|
||||
std::vector<std::string> Panda::list(bool usb_only) {
|
||||
std::vector<std::string> serials = PandaUsbHandle::list();
|
||||
|
||||
#ifndef __APPLE__
|
||||
for (auto s : PandaSpiHandle::list()) {
|
||||
if (std::find(serials.begin(), serials.end(), s) == serials.end()) {
|
||||
serials.push_back(s);
|
||||
if (!usb_only) {
|
||||
for (auto s : PandaSpiHandle::list()) {
|
||||
if (std::find(serials.begin(), serials.end(), s) == serials.end()) {
|
||||
serials.push_back(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
std::string hw_serial();
|
||||
|
||||
// Static functions
|
||||
static std::vector<std::string> list();
|
||||
static std::vector<std::string> list(bool usb_only=false);
|
||||
|
||||
// Panda functionality
|
||||
cereal::PandaState::PandaType get_hw_type();
|
||||
|
||||
Reference in New Issue
Block a user