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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
|
/**
* @file Xpl2Client.h
* @brief TCP client for the Alchemie XPL2 printhead protocol.
*/
#pragma once
#include "Xpl2Protocol.h"
#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 (bool connected READ isConnected NOTIFY connectedChanged)
Q_PROPERTY (int controllerId READ controllerId NOTIFY jcVersionReceived)
Q_PROPERTY (
QString firmwareVersion READ firmwareVersion NOTIFY jcVersionReceived)
Q_PROPERTY (
QString hardwareVersion READ hardwareVersion NOTIFY jcVersionReceived)
Q_PROPERTY (int printheadCount READ printheadCount NOTIFY jcVersionReceived)
public:
explicit Xpl2Client (QObject *parent = nullptr);
QString host () const;
void setHost (const QString &host);
bool isConnected () const;
int controllerId () const;
QString firmwareVersion () const;
QString hardwareVersion () const;
int printheadCount () const;
static void enableWireDebug ();
Q_INVOKABLE void connectToServer ();
Q_INVOKABLE void disconnectFromServer ();
/** Get the just connected Jetting Controller ID and Software Version. */
Q_INVOKABLE void getJcVersion ();
/** Query the specified printhead's version info. */
Q_INVOKABLE void getPhVersion (int printheadId);
/* -- CN_ Control commands ----------------------------------------- */
/** Switch jetting on for all printheads. */
Q_INVOKABLE void jettingAllOn ();
/** Switch jetting on for all printheads with a per-nozzle mask (180 chars).
*/
Q_INVOKABLE void jettingOn (const QString &jettingMask);
/** Switch jetting off for all printheads. */
Q_INVOKABLE void jettingOff ();
/** Switch jetting on for one printhead with a per-nozzle mask (12 chars). */
Q_INVOKABLE void phJettingOn (int printheadId, const QString &jettingMask);
/** Switch jetting off for one printhead. */
Q_INVOKABLE void phJettingOff (int printheadId);
/** Switch the JC identification LED on. */
Q_INVOKABLE void jcIdLedOn ();
/** Switch the JC identification LED off. */
Q_INVOKABLE void jcIdLedOff ();
/** Switch a printhead's identification LED on. */
Q_INVOKABLE void phIdLedOn (int printheadId);
/** Switch a printhead's identification LED off. */
Q_INVOKABLE void phIdLedOff (int printheadId);
/** Run calibration on all printheads. */
Q_INVOKABLE void jcCalibration ();
/** Run calibration on one printhead. */
Q_INVOKABLE void phCalibration (int printheadId);
/** Get nozzle calibration data for one printhead (48 floats). */
Q_INVOKABLE void phCalibrationData (int printheadId);
/** Get raw nozzle calibration data for one printhead (48 floats). */
Q_INVOKABLE void phCalibrationRawData (int printheadId);
/** Get the calibrated base frequency and active base frequency. */
Q_INVOKABLE void phCalibratedBaseFrequency (int printheadId);
/** Start sending JC status messages at the given level and interval. */
Q_INVOKABLE void jcStatusMessagingStart (int statusLevel,
int sendIntervalMs);
/** Stop sending JC status messages. */
Q_INVOKABLE void jcStatusMessagingStop ();
/** Start sending PH status messages at the given level and interval. */
Q_INVOKABLE void phStatusMessagingStart (int statusLevel,
int sendIntervalMs);
/** Stop sending PH status messages. */
Q_INVOKABLE void phStatusMessagingStop ();
/** Reset fault codes for all printheads on the controller. */
Q_INVOKABLE void jcResetFaultCodes ();
/** Reset fault codes for one printhead. */
Q_INVOKABLE void phResetFaultCodes (int printheadId);
/** Disable nozzles on one printhead using a 12-char mask. */
Q_INVOKABLE void phNozzlesDisabled (int printheadId, const QString &mask);
signals:
void hostChanged ();
void connectedChanged ();
void errorOccurred (const QString &error);
void statusMessage (const QString &message);
void jcVersionReceived ();
void phVersionReceived (int controllerId, int printheadId,
const QString &mcuFirmwareVersion,
const QString &mcuHardwareVersion,
const QString &mcuFirmwareVariant,
const QString &fpgaFirmwareVersion,
const QString &fpgaHardwareVersion,
const QString &bootloaderVersion);
/* CN_ response signals */
void jettingAllOnResult (int controllerId, bool success);
void jettingOnResult (int controllerId, bool success);
void jettingOffResult (int controllerId, bool success);
void phJettingOnResult (int controllerId, int printheadId, bool success);
void phJettingOffResult (int controllerId, int printheadId, bool success);
void jcIdLedOnResult (int controllerId, bool success);
void jcIdLedOffResult (int controllerId, bool success);
void phIdLedOnResult (int controllerId, int printheadId, bool success);
void phIdLedOffResult (int controllerId, int printheadId, bool success);
void jcCalibrationResult (int controllerId, bool success);
void phCalibrationResult (int controllerId, int printheadId, bool success);
void phCalibrationDataReceived (int controllerId, int printheadId,
const QVariantList &frequencies);
void phCalibrationRawDataReceived (int controllerId, int printheadId,
const QVariantList &frequencies);
void phCalibratedBaseFrequencyReceived (int controllerId, int printheadId,
double baseFrequency,
double activeBaseFrequency);
void jcStatusMessagingStartResult (int controllerId, int statusLevel,
int sendIntervalMs, bool success);
void jcStatusMessagingStopResult (int controllerId, bool success);
void phStatusMessagingStartResult (int controllerId, int statusLevel,
int sendIntervalMs, bool success);
void phStatusMessagingStopResult (int controllerId, bool success);
void jcResetFaultCodesResult (int controllerId, bool success);
void phResetFaultCodesResult (int controllerId, int printheadId,
bool success);
void phNozzlesDisabledResult (int controllerId, int printheadId,
bool success);
private slots:
void onSocketConnected ();
void onSocketDisconnected ();
void onSocketMessageReady ();
void onSocketError (QAbstractSocket::SocketError error);
private:
void sendCommand (QTcpSocket &socket, const QByteArray &command,
const QVariantList ¶ms = {});
void dispatchCommandMessage (const Xpl2Protocol::ParsedMessage &msg);
void dispatchImagingMessage (const Xpl2Protocol::ParsedMessage &msg);
void dispatchStatusMessage (const Xpl2Protocol::ParsedMessage &msg);
void handleKaPing (QTcpSocket &socket);
void handleGsJcVersion (const QVariantList ¶ms);
void handleGsPhVersion (const QVariantList ¶ms);
void handleJcSuccessResponse (const QByteArray &command,
const QVariantList ¶ms);
void handlePhSuccessResponse (const QByteArray &command,
const QVariantList ¶ms);
void handleCnPhCalibrationData (const QVariantList ¶ms);
void handleCnPhCalibrationRawData (const QVariantList ¶ms);
void handleCnPhCalibratedBaseFrequency (const QVariantList ¶ms);
void handleCnJcStatusMessagingStart (const QVariantList ¶ms);
void handleCnJcStatusMessagingStop (const QVariantList ¶ms);
void handleCnPhStatusMessagingStart (const QVariantList ¶ms);
void handleCnPhStatusMessagingStop (const QVariantList ¶ms);
void updateConnectedState ();
QString logTag (const QTcpSocket *socket) const;
QTcpSocket m_commandSocket;
QTcpSocket m_imagingSocket;
QTcpSocket m_statusSocket;
QString m_host = QStringLiteral ("127.0.0.1");
quint16 m_commandPort = 9110;
quint16 m_imagingPort = 9111;
quint16 m_statusPort = 9112;
bool m_connected = false;
static bool s_wireDebug;
int m_controllerId = 0;
QString m_firmwareVersion;
QString m_hardwareVersion;
int m_printheadCount = 0;
};
|