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
@@ -37,6 +37,7 @@ public:
bool open();
bool close();
bool isOpen();
bool isDisconnected();
virtual void spawnThreads();
virtual void joinThreads();
bool rawWrite(const std::vector<uint8_t>& bytes) { return driver->write(bytes); }
+2
View File
@@ -20,6 +20,7 @@ public:
virtual ~Driver() {}
virtual bool open() = 0;
virtual bool isOpen() = 0;
virtual bool isDisconnected() { return disconnected; };
virtual bool close() = 0;
virtual bool read(std::vector<uint8_t>& bytes, size_t limit = 0);
virtual bool readWait(std::vector<uint8_t>& bytes, std::chrono::milliseconds timeout = std::chrono::milliseconds(100), size_t limit = 0);
@@ -47,6 +48,7 @@ protected:
moodycamel::BlockingConcurrentQueue<WriteOperation> writeQueue;
std::thread readThread, writeThread;
std::atomic<bool> closing{false};
std::atomic<bool> disconnected{false};
};
}
+1
View File
@@ -49,6 +49,7 @@ public:
virtual bool close();
virtual bool isOnline() const { return online; }
virtual bool isOpen() const { return com->isOpen(); }
virtual bool isDisconnected() const { return com->isDisconnected(); }
virtual bool goOnline();
virtual bool goOffline();
+1 -1
View File
@@ -19,7 +19,7 @@ public:
static std::vector<neodevice_t> FindByProduct(int product);
FTDI(const device_eventhandler_t& err, neodevice_t& forDevice);
~FTDI() { close(); }
~FTDI() { if(isOpen()) close(); }
bool open();
bool close();
bool isOpen() { return ftdi.isOpen(); }
+2
View File
@@ -24,6 +24,7 @@ public:
* Other POSIX systems (BSDs, QNX, etc) will need bespoke code written in the future
*/
STM32(const device_eventhandler_t& err, neodevice_t& forDevice) : Driver(err), device(forDevice) {}
~STM32() { if(isOpen()) close(); }
static std::vector<neodevice_t> FindByProduct(int product);
bool open();
@@ -38,6 +39,7 @@ private:
void readTask();
void writeTask();
bool fdIsValid();
};
}