Detect device disconnects

When a device is sending any traffic, the device is considered to be connected. If no traffic if being received from the device, a status is requested. If the device fails to report the status back in a timely manner, it is considered to be disconnected.

If the device fails to reply to the status request, it is important to confirm that the device is not applying settings. While the device is applying settings, it will not be sending heartbeats or able to process a status request.
This commit is contained in:
Kyle Schwarz
2020-08-27 13:20:48 -04:00
parent 5db07102aa
commit 044c2bb86f
6 changed files with 53 additions and 0 deletions
+1
View File
@@ -70,6 +70,7 @@ public:
MessageFormattingError = 0x2019,
CANFDNotSupported = 0x2020,
RTRNotSupported = 0x2021,
DeviceDisconnected = 0x2022,
// Transport Events
FailedToRead = 0x3000,
+7
View File
@@ -7,6 +7,7 @@
#include <memory>
#include <utility>
#include <cstring>
#include <atomic>
#include "icsneo/api/eventmanager.h"
#include "icsneo/device/neodevice.h"
#include "icsneo/device/idevicesettings.h"
@@ -30,6 +31,8 @@ public:
if(isMessagePollingEnabled())
disableMessagePolling();
close();
if(heartbeatThread.joinable())
heartbeatThread.join();
}
static std::string SerialNumToString(uint32_t serial);
@@ -100,6 +103,7 @@ protected:
bool online = false;
int messagePollingCallbackID = 0;
int internalHandlerCallbackID = 0;
int messageReceivedCallbackID = 0;
device_eventhandler_t report;
// START Initialization Functions
@@ -211,6 +215,9 @@ private:
size_t pollingMessageLimit = 20000;
moodycamel::BlockingConcurrentQueue<std::shared_ptr<Message>> pollingContainer;
void enforcePollingMessageLimit();
std::atomic<bool> stopHeartbeatThread{false};
std::thread heartbeatThread;
};
}
+3
View File
@@ -324,6 +324,7 @@ static_assert(sizeof(UART_SETTINGS) == UART_SETTINGS_SIZE, "UART_SETTINGS is the
#ifdef __cplusplus
#include "icsneo/communication/communication.h"
#include <iostream>
#include <atomic>
namespace icsneo {
@@ -404,6 +405,8 @@ public:
bool readonly = false;
bool disableGSChecksumming = false;
std::atomic<bool> applyingSettings{false};
protected:
std::shared_ptr<Communication> com;
device_eventhandler_t report;