From 71176137caa6e966a1f0758383d7bccf7e4b3e40 Mon Sep 17 00:00:00 2001 From: EricLiu2000 Date: Mon, 5 Aug 2019 15:35:44 -0400 Subject: [PATCH] Added waits to ensure going online and offline succeed before returning --- device/device.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/device/device.cpp b/device/device.cpp index a6c1e92..f8f3b75 100644 --- a/device/device.cpp +++ b/device/device.cpp @@ -4,6 +4,7 @@ #include #include #include +#include using namespace icsneo; @@ -217,11 +218,19 @@ bool Device::goOnline() { if(!com->sendCommand(Command::EnableNetworkCommunication, true)) return false; + auto startTime = std::chrono::system_clock::now(); + ledState = LEDState::Online; online = true; updateLEDState(); + // wait until communication is enabled or 10 seconds, whichever comes first + while((std::chrono::system_clock::now() - startTime) < std::chrono::seconds::duration(10)) { + if(latestResetStatus && latestResetStatus->comEnabled) + break; + } + return true; } @@ -229,11 +238,19 @@ bool Device::goOffline() { if(!com->sendCommand(Command::EnableNetworkCommunication, false)) return false; + auto startTime = std::chrono::system_clock::now(); + ledState = (latestResetStatus && latestResetStatus->cmRunning) ? LEDState::CoreMiniRunning : LEDState::Offline; updateLEDState(); online = false; + // wait until communication is disabled or 10 seconds, whichever comes first + while((std::chrono::system_clock::now() - startTime) < std::chrono::seconds::duration(10)) { + if(latestResetStatus && !latestResetStatus->comEnabled) + break; + } + return true; }