diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-01-07 14:43:03 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-01-07 14:43:03 +0100 |
commit | adb70d5ee1987cfb1680114d2db9786923aad1f1 (patch) | |
tree | a15de82808f40153cd285994cab7534ed9a10538 /confui/serial.h | |
parent | 46ede2c109fe2aa390936ec4f0a30321fb7b5d86 (diff) | |
parent | b083c8e08d610a4e74f39f66f3daa191301893b1 (diff) |
Merge branch 'qt-gui-meshconnector-serial' into dev
Diffstat (limited to 'confui/serial.h')
-rw-r--r-- | confui/serial.h | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/confui/serial.h b/confui/serial.h new file mode 100644 index 0000000..aa0508f --- /dev/null +++ b/confui/serial.h @@ -0,0 +1,42 @@ +#pragma once + +#include <QSerialPort> +#include <QString> +#include <vector> + +using std::string; +using std::vector; + +/** @brief manage asynchronous serial connection */ +class CDSerialConnector { +public: + CDSerialConnector(); + virtual ~CDSerialConnector(); + + /** @brief get list of available serial ports */ + static vector<string> get_ports(); + + /** @brief open serial port */ + virtual void connect(string port); + /** @brief close serial port */ + virtual void disconnect(); + + /** @brief write to serial port */ + virtual void write(QByteArray msg); + /** @brief get last message */ + virtual QByteArray get_data(); + + /** @brief get current port name */ + virtual string get_port(); + +private: + /** @brief executed when new data is received */ + virtual void action(); + + QSerialPort *_serial = nullptr; + QByteArray _msg; +}; + +/** @brief global pointer to serial connector, initialized in CDMainWindow */ +extern CDSerialConnector *g_cd_serial; + |