aboutsummaryrefslogtreecommitdiffstats
path: root/mock-server/MockServer.h
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-03-23 16:39:33 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-03-23 16:39:33 +0100
commit61debe99a269bf7e87f6ba2f8d2a376e619fcf12 (patch)
tree41cf942329760f8a5f16d98ea202124fcae8a0f3 /mock-server/MockServer.h
parent46e96b3318900b561928be304f4a9e252f2785a4 (diff)
downloadQtXpl2-61debe99a269bf7e87f6ba2f8d2a376e619fcf12.tar.gz
QtXpl2-61debe99a269bf7e87f6ba2f8d2a376e619fcf12.zip
Invert TCP connection model: client listens, server connects
The XPL2 protocol specifies that the JI2 controller initiates connections to the client, not the other way around. Xpl2Client now listens on 3 ports via QTcpServer and accepts inbound connections; MockServer connects out with auto-retry on the 1s KA_PING tick. QML API: startListening/stopListening, listening+connected properties, host property removed. Mock server gains --host CLI arg.
Diffstat (limited to 'mock-server/MockServer.h')
-rw-r--r--mock-server/MockServer.h77
1 files changed, 38 insertions, 39 deletions
diff --git a/mock-server/MockServer.h b/mock-server/MockServer.h
index 74b2731..242cb32 100644
--- a/mock-server/MockServer.h
+++ b/mock-server/MockServer.h
@@ -1,88 +1,87 @@
/**
* @file MockServer.h
- * @brief Mock XPL2 server — listens on all three protocol ports.
+ * @brief Mock XPL2 server — connects out to the client on three protocol
+ * ports.
*/
#pragma once
-#include <QList>
#include <QObject>
-#include <QTcpServer>
+#include <QTcpSocket>
#include <QTimer>
-class QTcpSocket;
-
class MockServer : public QObject
{
Q_OBJECT
public:
- explicit MockServer (QObject *parent = nullptr);
+ explicit MockServer (const QString &host, QObject *parent = nullptr);
static void enableWireDebug ();
private slots:
- void onNewConnection ();
- void onClientMessageReady ();
- void onClientDisconnected ();
- /* Send KA_PING keepalive to all connected clients. */
- void sendKaPing ();
+ void onSocketConnected ();
+ void onSocketDisconnected ();
+ void onSocketMessageReady ();
+ /* Send KA_PING on connected sockets, retry connection on disconnected. */
+ void tick ();
void sendJcStatusMsg ();
void sendPhStatusMsg ();
private:
struct Port
{
- QTcpServer server;
+ QTcpSocket socket;
const char *name = nullptr;
quint16 number = 0;
};
void setupPort (Port &port, const char *name, quint16 number);
+ void connectAll ();
/* Return a fixed-width "[Name:port]" tag for log lines. */
- QString logTag (quint16 localPort) const;
+ QString logTag (const QTcpSocket *socket) const;
/* Parse incoming line, log RX, and dispatch to the matching handler. */
- void handleCommand (QTcpSocket *client, const QByteArray &line);
- void sendReply (QTcpSocket *client, const QByteArray &data);
- void handleKaPing (QTcpSocket *client, const QByteArray &params);
- void handleGsJcVersion (QTcpSocket *client);
- void handleGsPhVersion (QTcpSocket *client, const QByteArray &params);
+ void handleCommand (Port &port, const QByteArray &line);
+ void sendReply (QTcpSocket &socket, const QByteArray &data);
+ void handleKaPing (Port &port, const QByteArray &params);
+ void handleGsJcVersion (QTcpSocket &socket);
+ void handleGsPhVersion (QTcpSocket &socket, const QByteArray &params);
/* CN_ control command handlers */
- void handleCnJcSuccess (QTcpSocket *client, const QByteArray &cmd);
- void handleCnPhSuccess (QTcpSocket *client, const QByteArray &cmd,
+ void handleCnJcSuccess (QTcpSocket &socket, const QByteArray &cmd);
+ void handleCnPhSuccess (QTcpSocket &socket, const QByteArray &cmd,
const QByteArray &params);
- void handleCnPhCalibrationData (QTcpSocket *client,
+ void handleCnPhCalibrationData (QTcpSocket &socket,
const QByteArray &params);
- void handleCnPhCalibrationRawData (QTcpSocket *client,
+ void handleCnPhCalibrationRawData (QTcpSocket &socket,
const QByteArray &params);
- void handleCnPhCalibratedBaseFrequency (QTcpSocket *client,
+ void handleCnPhCalibratedBaseFrequency (QTcpSocket &socket,
const QByteArray &params);
- void handleCnStatusMessagingStart (QTcpSocket *client, const QByteArray &cmd,
+ void handleCnStatusMessagingStart (QTcpSocket &socket, const QByteArray &cmd,
const QByteArray &params);
- void handleCnStatusMessagingStop (QTcpSocket *client, const QByteArray &cmd);
+ void handleCnStatusMessagingStop (QTcpSocket &socket, const QByteArray &cmd);
/* CF_ configuration command handlers */
- void handleCfJcSetPurgeSettings (QTcpSocket *client,
+ void handleCfJcSetPurgeSettings (QTcpSocket &socket,
const QByteArray &params);
- void handleCfJcSetJettingParams (QTcpSocket *client,
+ void handleCfJcSetJettingParams (QTcpSocket &socket,
const QByteArray &params);
- void handleCfPhJettingParams (QTcpSocket *client, const QByteArray &cmd,
+ void handleCfPhJettingParams (QTcpSocket &socket, const QByteArray &cmd,
const QByteArray &params);
- void handleCfJcSetter (QTcpSocket *client, const QByteArray &params);
- void handleCfPhSetter (QTcpSocket *client, const QByteArray &params);
- void handleCfJcGetter (QTcpSocket *client, const QByteArray &params);
- void handleCfPhGetter (QTcpSocket *client, const QByteArray &params);
+ void handleCfJcSetter (QTcpSocket &socket, const QByteArray &params);
+ void handleCfPhSetter (QTcpSocket &socket, const QByteArray &params);
+ void handleCfJcGetter (QTcpSocket &socket, const QByteArray &params);
+ void handleCfPhGetter (QTcpSocket &socket, const QByteArray &params);
/* Imaging command handlers */
- void handleImagingStart (QTcpSocket *client, const QByteArray &params);
- void handleImagingStop (QTcpSocket *client);
- void handleImagingMaskStart (QTcpSocket *client, const QByteArray &cmd,
+ void handleImagingStart (QTcpSocket &socket, const QByteArray &params);
+ void handleImagingStop (QTcpSocket &socket);
+ void handleImagingMaskStart (QTcpSocket &socket, const QByteArray &cmd,
const QByteArray &params);
- void handleImagingMaskEnd (QTcpSocket *client, const QByteArray &cmd,
+ void handleImagingMaskEnd (QTcpSocket &socket, const QByteArray &cmd,
const QByteArray &params);
- void handleImageCount (QTcpSocket *client);
+ void handleImageCount (QTcpSocket &socket);
+ QString m_host;
Port m_command;
Port m_imaging;
Port m_status;
- QList<QTcpSocket *> m_clients;
- QTimer m_pingTimer;
+ QTimer m_tickTimer;
QTimer m_jcStatusTimer;
QTimer m_phStatusTimer;
int m_jcStatusLevel = 1;