mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 01:18:36 +02:00
POSIX: STM32: Handle re-enumeration when changing modes
This commit is contained in:
@@ -40,6 +40,8 @@ public:
|
||||
bool isDisconnected();
|
||||
virtual void spawnThreads();
|
||||
virtual void joinThreads();
|
||||
void modeChangeIncoming() { driver->modeChangeIncoming(); }
|
||||
void awaitModeChangeComplete() { driver->awaitModeChangeComplete(); }
|
||||
bool rawWrite(const std::vector<uint8_t>& bytes) { return driver->write(bytes); }
|
||||
virtual bool sendPacket(std::vector<uint8_t>& bytes);
|
||||
bool redirectRead(std::function<void(std::vector<uint8_t>&&)> redirectTo);
|
||||
|
||||
@@ -20,6 +20,8 @@ public:
|
||||
virtual ~Driver() {}
|
||||
virtual bool open() = 0;
|
||||
virtual bool isOpen() = 0;
|
||||
virtual void modeChangeIncoming() {}
|
||||
virtual void awaitModeChangeComplete() {}
|
||||
virtual bool isDisconnected() { return disconnected; };
|
||||
virtual bool close() = 0;
|
||||
virtual bool read(std::vector<uint8_t>& bytes, size_t limit = 0);
|
||||
|
||||
@@ -24,21 +24,28 @@ 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(); }
|
||||
~STM32();
|
||||
static std::vector<neodevice_t> FindByProduct(int product);
|
||||
|
||||
bool open();
|
||||
bool isOpen();
|
||||
bool close();
|
||||
bool open() override;
|
||||
bool isOpen() override;
|
||||
bool close() override;
|
||||
|
||||
void modeChangeIncoming() override;
|
||||
void awaitModeChangeComplete() override;
|
||||
|
||||
private:
|
||||
neodevice_t& device;
|
||||
int fd = -1;
|
||||
std::atomic<bool> modeChanging{false};
|
||||
std::thread modeChangeThread;
|
||||
std::mutex modeChangeMutex;
|
||||
std::condition_variable modeChangeCV;
|
||||
|
||||
static std::string HandleToTTY(neodevice_handle_t handle);
|
||||
|
||||
void readTask();
|
||||
void writeTask();
|
||||
void readTask() override;
|
||||
void writeTask() override;
|
||||
bool fdIsValid();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user