Allow disconnections to be signaled by drivers

This allows for disconnections to be detected quickly
where possible.

It also makes sure other driver errors aren't thrown
in the event of a disconnection.
This commit is contained in:
Kyle Schwarz
2020-10-08 17:38:10 -04:00
committed by Paul Hollinsky
parent dfe2d23d85
commit a5b27a15b0
10 changed files with 95 additions and 27 deletions
+6 -1
View File
@@ -238,7 +238,7 @@ bool Device::open() {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
// Check if we got a message, and if not, if settings are being applied
if(!receivedMessage && !settings->applyingSettings) {
if(!stopHeartbeatThread)
if(!stopHeartbeatThread && !isDisconnected())
report(APIEvent::Type::DeviceDisconnected, APIEvent::Severity::Error);
break;
}
@@ -316,6 +316,11 @@ bool Device::goOnline() {
bool Device::goOffline() {
forEachExtension([](const std::shared_ptr<DeviceExtension>& ext) { ext->onGoOffline(); return true; });
if(isDisconnected()) {
online = false;
return true;
}
if(!com->sendCommand(Command::EnableNetworkCommunication, false))
return false;