aboutsummaryrefslogtreecommitdiffstats
path: root/src/Xpl2Client.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/Xpl2Client.h')
-rw-r--r--src/Xpl2Client.h53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/Xpl2Client.h b/src/Xpl2Client.h
new file mode 100644
index 0000000..f052962
--- /dev/null
+++ b/src/Xpl2Client.h
@@ -0,0 +1,53 @@
+/**
+ * @file Xpl2Client.h
+ * @brief TCP client for the Alchemie XPL2 printhead protocol.
+ */
+#pragma once
+
+#include <QObject>
+#include <QQmlEngine>
+#include <QTcpSocket>
+
+class Xpl2Client : public QObject {
+ Q_OBJECT
+ QML_ELEMENT
+ QML_SINGLETON
+
+ Q_PROPERTY(QString host READ host WRITE setHost NOTIFY hostChanged)
+ Q_PROPERTY(quint16 port READ port WRITE setPort NOTIFY portChanged)
+ Q_PROPERTY(bool connected READ isConnected NOTIFY connectedChanged)
+
+public:
+ explicit Xpl2Client(QObject *parent = nullptr);
+
+ QString host() const;
+ void setHost(const QString &host);
+
+ quint16 port() const;
+ void setPort(quint16 port);
+
+ bool isConnected() const;
+
+ Q_INVOKABLE void connectToServer();
+ Q_INVOKABLE void disconnectFromServer();
+ Q_INVOKABLE void sendCommand(const QString &command);
+
+signals:
+ void hostChanged();
+ void portChanged();
+ void connectedChanged();
+ void responseReceived(const QString &response);
+ void errorOccurred(const QString &error);
+ void statusMessage(const QString &message);
+
+private slots:
+ void onConnected();
+ void onDisconnected();
+ void onReadyRead();
+ void onErrorOccurred(QAbstractSocket::SocketError error);
+
+private:
+ QTcpSocket m_socket;
+ QString m_host = QStringLiteral("127.0.0.1");
+ quint16 m_port = 5000;
+};