mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 09:28:40 +02:00
Added waits to ensure going online and offline succeed before returning
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
using namespace icsneo;
|
using namespace icsneo;
|
||||||
|
|
||||||
@@ -217,11 +218,19 @@ bool Device::goOnline() {
|
|||||||
if(!com->sendCommand(Command::EnableNetworkCommunication, true))
|
if(!com->sendCommand(Command::EnableNetworkCommunication, true))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
auto startTime = std::chrono::system_clock::now();
|
||||||
|
|
||||||
ledState = LEDState::Online;
|
ledState = LEDState::Online;
|
||||||
|
|
||||||
online = true;
|
online = true;
|
||||||
updateLEDState();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,11 +238,19 @@ bool Device::goOffline() {
|
|||||||
if(!com->sendCommand(Command::EnableNetworkCommunication, false))
|
if(!com->sendCommand(Command::EnableNetworkCommunication, false))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
auto startTime = std::chrono::system_clock::now();
|
||||||
|
|
||||||
ledState = (latestResetStatus && latestResetStatus->cmRunning) ? LEDState::CoreMiniRunning : LEDState::Offline;
|
ledState = (latestResetStatus && latestResetStatus->cmRunning) ? LEDState::CoreMiniRunning : LEDState::Offline;
|
||||||
|
|
||||||
updateLEDState();
|
updateLEDState();
|
||||||
online = false;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user