diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index 0b40eac307..13b1e551fa 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -36,7 +36,7 @@ #define SATURATE_IL 1600 #define NIBBLE_TO_HEX(n) ((n) < 10 ? (n) + '0' : ((n) - 10) + 'a') -Panda * panda = NULL; +Panda * panda = nullptr; std::atomic safety_setter_thread_running(false); std::atomic ignition(false); @@ -121,7 +121,7 @@ bool usb_connect() { std::unique_ptr tmp_panda; try { - assert(panda == NULL); + assert(panda == nullptr); tmp_panda = std::make_unique(); } catch (std::exception &e) { return false; @@ -180,10 +180,13 @@ bool usb_connect() { } // must be called before threads or with mutex -void usb_retry_connect() { +static bool usb_retry_connect() { LOGW("attempting to connect"); - while (!usb_connect()) { util::sleep_for(100); } - LOGW("connected to board"); + while (!do_exit && !usb_connect()) { util::sleep_for(100); } + if (panda) { + LOGW("connected to board"); + } + return !do_exit; } void can_recv(PubMaster &pm) { @@ -523,16 +526,16 @@ int main() { threads.push_back(std::thread(can_health_thread, getenv("STARTED") != nullptr)); // connect to the board - usb_retry_connect(); - - threads.push_back(std::thread(can_send_thread, getenv("FAKESEND") != nullptr)); - threads.push_back(std::thread(can_recv_thread)); - threads.push_back(std::thread(hardware_control_thread)); - threads.push_back(std::thread(pigeon_thread)); + if (usb_retry_connect()) { + threads.push_back(std::thread(can_send_thread, getenv("FAKESEND") != nullptr)); + threads.push_back(std::thread(can_recv_thread)); + threads.push_back(std::thread(hardware_control_thread)); + threads.push_back(std::thread(pigeon_thread)); + } for (auto &t : threads) t.join(); delete panda; - panda = NULL; + panda = nullptr; } }