|
|
@ -628,10 +628,6 @@ void pigeon_thread(Panda *panda) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
int main(int argc, char *argv[]) { |
|
|
|
std::vector<std::thread> threads; |
|
|
|
|
|
|
|
std::vector<Panda *> pandas; |
|
|
|
|
|
|
|
Panda *peripheral_panda; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LOGW("starting boardd"); |
|
|
|
LOGW("starting boardd"); |
|
|
|
|
|
|
|
|
|
|
|
if (!Hardware::PC()) { |
|
|
|
if (!Hardware::PC()) { |
|
|
@ -645,37 +641,29 @@ int main(int argc, char* argv[]) { |
|
|
|
LOGW("attempting to connect"); |
|
|
|
LOGW("attempting to connect"); |
|
|
|
PubMaster pm({"pandaStates", "peripheralState"}); |
|
|
|
PubMaster pm({"pandaStates", "peripheralState"}); |
|
|
|
|
|
|
|
|
|
|
|
// connect loop
|
|
|
|
|
|
|
|
while (!do_exit) { |
|
|
|
|
|
|
|
std::vector<std::string> serials(argv + 1, argv + argc); |
|
|
|
std::vector<std::string> serials(argv + 1, argv + argc); |
|
|
|
if (serials.size() == 0) serials.push_back(""); |
|
|
|
if (serials.size() == 0) serials.push_back(""); |
|
|
|
|
|
|
|
|
|
|
|
// connect to all provided serials
|
|
|
|
// connect to all provided serials
|
|
|
|
for (int i=0; i<serials.size(); i++) { |
|
|
|
std::vector<Panda *> pandas; |
|
|
|
|
|
|
|
for (int i = 0; i < serials.size() && !do_exit; /**/) { |
|
|
|
Panda *p = usb_connect(serials[i], i); |
|
|
|
Panda *p = usb_connect(serials[i], i); |
|
|
|
if (p != NULL) { |
|
|
|
if (!p) { |
|
|
|
pandas.push_back(p); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// send empty pandaState & peripheralState and try again
|
|
|
|
// send empty pandaState & peripheralState and try again
|
|
|
|
if (pandas.size() != serials.size()) { |
|
|
|
|
|
|
|
send_empty_panda_state(&pm); |
|
|
|
send_empty_panda_state(&pm); |
|
|
|
send_empty_peripheral_state(&pm); |
|
|
|
send_empty_peripheral_state(&pm); |
|
|
|
util::sleep_for(500); |
|
|
|
util::sleep_for(500); |
|
|
|
} else { |
|
|
|
continue; |
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (pandas.size() == 0) { |
|
|
|
pandas.push_back(p); |
|
|
|
// do_exit was set while not connected to a panda
|
|
|
|
++i; |
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
peripheral_panda = pandas[0]; |
|
|
|
if (!do_exit) { |
|
|
|
|
|
|
|
|
|
|
|
LOGW("connected to board"); |
|
|
|
LOGW("connected to board"); |
|
|
|
|
|
|
|
Panda *peripheral_panda = pandas[0]; |
|
|
|
|
|
|
|
std::vector<std::thread> threads; |
|
|
|
|
|
|
|
|
|
|
|
threads.emplace_back(panda_state_thread, &pm, pandas, getenv("STARTED") != nullptr); |
|
|
|
threads.emplace_back(panda_state_thread, &pm, pandas, getenv("STARTED") != nullptr); |
|
|
|
threads.emplace_back(peripheral_control_thread, peripheral_panda); |
|
|
|
threads.emplace_back(peripheral_control_thread, peripheral_panda); |
|
|
@ -685,9 +673,10 @@ int main(int argc, char* argv[]) { |
|
|
|
threads.emplace_back(can_recv_thread, pandas); |
|
|
|
threads.emplace_back(can_recv_thread, pandas); |
|
|
|
|
|
|
|
|
|
|
|
for (auto &t : threads) t.join(); |
|
|
|
for (auto &t : threads) t.join(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// we have exited, clean up pandas
|
|
|
|
// we have exited, clean up pandas
|
|
|
|
for (const auto& panda : pandas){ |
|
|
|
for (Panda *panda : pandas) { |
|
|
|
delete panda; |
|
|
|
delete panda; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|