blob: d339bc3c3d501dcd3e3230d656e4fea8c49c157d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
/**
* @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 commandPort READ commandPort WRITE setCommandPort NOTIFY
commandPortChanged)
Q_PROPERTY (quint16 imagingPort READ imagingPort WRITE setImagingPort NOTIFY
imagingPortChanged)
Q_PROPERTY (quint16 statusPort READ statusPort WRITE setStatusPort NOTIFY
statusPortChanged)
Q_PROPERTY (bool connected READ isConnected NOTIFY connectedChanged)
public:
explicit Xpl2Client (QObject *parent = nullptr);
QString host () const;
void setHost (const QString &host);
quint16 commandPort () const;
void setCommandPort (quint16 port);
quint16 imagingPort () const;
void setImagingPort (quint16 port);
quint16 statusPort () const;
void setStatusPort (quint16 port);
bool isConnected () const;
Q_INVOKABLE void connectToServer ();
Q_INVOKABLE void disconnectFromServer ();
Q_INVOKABLE void sendCommand (const QString &command);
signals:
void hostChanged ();
void commandPortChanged ();
void imagingPortChanged ();
void statusPortChanged ();
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_commandPort = 9110;
quint16 m_imagingPort = 9111;
quint16 m_statusPort = 9112;
};
|