aboutsummaryrefslogtreecommitdiffstats
path: root/src/Xpl2Client.cpp
diff options
context:
space:
mode:
authorThomas Vanbesien <tvanbesi@proton.me>2026-03-16 15:14:13 +0100
committerThomas Vanbesien <tvanbesi@proton.me>2026-03-16 15:14:13 +0100
commit50034b142dc851da7118032f7218cb1d25ea98e4 (patch)
treeb506a4dec9c10ee0510bcbb570c6c06433252960 /src/Xpl2Client.cpp
parent9ac64169720fb2b9852589b74f7300bcfebcaf62 (diff)
downloadQtXpl2-50034b142dc851da7118032f7218cb1d25ea98e4.tar.gz
QtXpl2-50034b142dc851da7118032f7218cb1d25ea98e4.zip
CN_ control commands: typed API, dispatch, mock responses, demo UI
Diffstat (limited to 'src/Xpl2Client.cpp')
-rw-r--r--src/Xpl2Client.cpp406
1 files changed, 406 insertions, 0 deletions
diff --git a/src/Xpl2Client.cpp b/src/Xpl2Client.cpp
index 54346e0..8276577 100644
--- a/src/Xpl2Client.cpp
+++ b/src/Xpl2Client.cpp
@@ -117,6 +117,141 @@ Xpl2Client::getPhVersion (int printheadId)
}
/* ------------------------------------------------------------------ */
+/* CN_ Control commands */
+/* ------------------------------------------------------------------ */
+
+void
+Xpl2Client::jettingAllOn ()
+{
+ sendCommand (m_commandSocket, "CN_JETTING_ALL_ON");
+}
+
+void
+Xpl2Client::jettingOn (const QString &jettingMask)
+{
+ sendCommand (m_commandSocket, "CN_JETTING_ON", { jettingMask });
+}
+
+void
+Xpl2Client::jettingOff ()
+{
+ sendCommand (m_commandSocket, "CN_JETTING_OFF");
+}
+
+void
+Xpl2Client::phJettingOn (int printheadId, const QString &jettingMask)
+{
+ sendCommand (m_commandSocket, "CN_PH_JETTING_ON",
+ { printheadId, jettingMask });
+}
+
+void
+Xpl2Client::phJettingOff (int printheadId)
+{
+ sendCommand (m_commandSocket, "CN_PH_JETTING_OFF", { printheadId });
+}
+
+void
+Xpl2Client::jcIdLedOn ()
+{
+ sendCommand (m_commandSocket, "CN_JC_ID_LED_ON");
+}
+
+void
+Xpl2Client::jcIdLedOff ()
+{
+ sendCommand (m_commandSocket, "CN_JC_ID_LED_OFF");
+}
+
+void
+Xpl2Client::phIdLedOn (int printheadId)
+{
+ sendCommand (m_commandSocket, "CN_PH_ID_LED_ON", { printheadId });
+}
+
+void
+Xpl2Client::phIdLedOff (int printheadId)
+{
+ sendCommand (m_commandSocket, "CN_PH_ID_LED_OFF", { printheadId });
+}
+
+void
+Xpl2Client::jcCalibration ()
+{
+ sendCommand (m_commandSocket, "CN_JC_CALIBRATION");
+}
+
+void
+Xpl2Client::phCalibration (int printheadId)
+{
+ sendCommand (m_commandSocket, "CN_PH_CALIBRATION", { printheadId });
+}
+
+void
+Xpl2Client::phCalibrationData (int printheadId)
+{
+ sendCommand (m_commandSocket, "CN_PH_CALIBRATION_DATA", { printheadId });
+}
+
+void
+Xpl2Client::phCalibrationRawData (int printheadId)
+{
+ sendCommand (m_commandSocket, "CN_PH_CALIBRATION_RAW_DATA", { printheadId });
+}
+
+void
+Xpl2Client::phCalibratedBaseFrequency (int printheadId)
+{
+ sendCommand (m_commandSocket, "CN_PH_CALIBRATED_BASE_FREQUENCY",
+ { printheadId });
+}
+
+void
+Xpl2Client::jcStatusMessagingStart (int statusLevel, int sendIntervalMs)
+{
+ sendCommand (m_statusSocket, "CN_JC_STATUS_MESSAGING_START",
+ { statusLevel, sendIntervalMs });
+}
+
+void
+Xpl2Client::jcStatusMessagingStop ()
+{
+ sendCommand (m_statusSocket, "CN_JC_STATUS_MESSAGING_STOP");
+}
+
+void
+Xpl2Client::phStatusMessagingStart (int statusLevel, int sendIntervalMs)
+{
+ sendCommand (m_statusSocket, "CN_PH_STATUS_MESSAGING_START",
+ { statusLevel, sendIntervalMs });
+}
+
+void
+Xpl2Client::phStatusMessagingStop ()
+{
+ sendCommand (m_statusSocket, "CN_PH_STATUS_MESSAGING_STOP");
+}
+
+void
+Xpl2Client::jcResetFaultCodes ()
+{
+ sendCommand (m_commandSocket, "CN_JC_RESET_FAULT_CODES");
+}
+
+void
+Xpl2Client::phResetFaultCodes (int printheadId)
+{
+ sendCommand (m_commandSocket, "CN_PH_RESET_FAULT_CODES", { printheadId });
+}
+
+void
+Xpl2Client::phNozzlesDisabled (int printheadId, const QString &mask)
+{
+ sendCommand (m_commandSocket, "CN_PH_NOZZLES_DISABLED",
+ { printheadId, mask });
+}
+
+/* ------------------------------------------------------------------ */
/* Send / dispatch */
/* ------------------------------------------------------------------ */
@@ -149,6 +284,30 @@ Xpl2Client::dispatchCommandMessage (const Xpl2Protocol::ParsedMessage &msg)
handleGsJcVersion (msg.params);
else if (msg.command == "GS_PH_VERSION")
handleGsPhVersion (msg.params);
+ /* CN_ commands — JC success shape (controllerId, success) */
+ else if (msg.command == "CN_JETTING_ALL_ON" || msg.command == "CN_JETTING_ON"
+ || msg.command == "CN_JETTING_OFF"
+ || msg.command == "CN_JC_ID_LED_ON"
+ || msg.command == "CN_JC_ID_LED_OFF"
+ || msg.command == "CN_JC_CALIBRATION"
+ || msg.command == "CN_JC_RESET_FAULT_CODES")
+ handleJcSuccessResponse (msg.command, msg.params);
+ /* CN_ commands — PH success shape (controllerId, phId, success) */
+ else if (msg.command == "CN_PH_JETTING_ON"
+ || msg.command == "CN_PH_JETTING_OFF"
+ || msg.command == "CN_PH_ID_LED_ON"
+ || msg.command == "CN_PH_ID_LED_OFF"
+ || msg.command == "CN_PH_CALIBRATION"
+ || msg.command == "CN_PH_RESET_FAULT_CODES"
+ || msg.command == "CN_PH_NOZZLES_DISABLED")
+ handlePhSuccessResponse (msg.command, msg.params);
+ /* CN_ commands — custom shapes */
+ else if (msg.command == "CN_PH_CALIBRATION_DATA")
+ handleCnPhCalibrationData (msg.params);
+ else if (msg.command == "CN_PH_CALIBRATION_RAW_DATA")
+ handleCnPhCalibrationRawData (msg.params);
+ else if (msg.command == "CN_PH_CALIBRATED_BASE_FREQUENCY")
+ handleCnPhCalibratedBaseFrequency (msg.params);
else
qWarning ("%s Unknown command: %s", qPrintable (logTag (&m_commandSocket)),
msg.command.constData ());
@@ -169,6 +328,14 @@ Xpl2Client::dispatchStatusMessage (const Xpl2Protocol::ParsedMessage &msg)
{
if (msg.command == "KA_PING")
handleKaPing (m_statusSocket);
+ else if (msg.command == "CN_JC_STATUS_MESSAGING_START")
+ handleCnJcStatusMessagingStart (msg.params);
+ else if (msg.command == "CN_JC_STATUS_MESSAGING_STOP")
+ handleCnJcStatusMessagingStop (msg.params);
+ else if (msg.command == "CN_PH_STATUS_MESSAGING_START")
+ handleCnPhStatusMessagingStart (msg.params);
+ else if (msg.command == "CN_PH_STATUS_MESSAGING_STOP")
+ handleCnPhStatusMessagingStop (msg.params);
else
qWarning ("%s Unknown command: %s", qPrintable (logTag (&m_statusSocket)),
msg.command.constData ());
@@ -239,6 +406,245 @@ Xpl2Client::handleGsPhVersion (const QVariantList &params)
bootVer);
}
+void
+Xpl2Client::handleJcSuccessResponse (const QByteArray &command,
+ const QVariantList &params)
+{
+ if (params.size () < 2)
+ {
+ qWarning () << command << ": expected 2 params, got" << params.size ();
+ return;
+ }
+ int cid = params[0].toInt ();
+ bool ok = params[1].toInt () == 1;
+
+ qDebug ("%s %s controller=%d success=%d",
+ qPrintable (logTag (&m_commandSocket)), command.constData (), cid,
+ ok);
+ emit statusMessage (QStringLiteral ("RX %1: controller=%2 success=%3")
+ .arg (QString::fromUtf8 (command))
+ .arg (cid)
+ .arg (ok));
+
+ if (command == "CN_JETTING_ALL_ON")
+ emit jettingAllOnResult (cid, ok);
+ else if (command == "CN_JETTING_ON")
+ emit jettingOnResult (cid, ok);
+ else if (command == "CN_JETTING_OFF")
+ emit jettingOffResult (cid, ok);
+ else if (command == "CN_JC_ID_LED_ON")
+ emit jcIdLedOnResult (cid, ok);
+ else if (command == "CN_JC_ID_LED_OFF")
+ emit jcIdLedOffResult (cid, ok);
+ else if (command == "CN_JC_CALIBRATION")
+ emit jcCalibrationResult (cid, ok);
+ else if (command == "CN_JC_RESET_FAULT_CODES")
+ emit jcResetFaultCodesResult (cid, ok);
+}
+
+void
+Xpl2Client::handlePhSuccessResponse (const QByteArray &command,
+ const QVariantList &params)
+{
+ if (params.size () < 3)
+ {
+ qWarning () << command << ": expected 3 params, got" << params.size ();
+ return;
+ }
+ int cid = params[0].toInt ();
+ int phId = params[1].toInt ();
+ bool ok = params[2].toInt () == 1;
+
+ qDebug ("%s %s controller=%d ph=%d success=%d",
+ qPrintable (logTag (&m_commandSocket)), command.constData (), cid,
+ phId, ok);
+ emit statusMessage (QStringLiteral ("RX %1: controller=%2 ph=%3 success=%4")
+ .arg (QString::fromUtf8 (command))
+ .arg (cid)
+ .arg (phId)
+ .arg (ok));
+
+ if (command == "CN_PH_JETTING_ON")
+ emit phJettingOnResult (cid, phId, ok);
+ else if (command == "CN_PH_JETTING_OFF")
+ emit phJettingOffResult (cid, phId, ok);
+ else if (command == "CN_PH_ID_LED_ON")
+ emit phIdLedOnResult (cid, phId, ok);
+ else if (command == "CN_PH_ID_LED_OFF")
+ emit phIdLedOffResult (cid, phId, ok);
+ else if (command == "CN_PH_CALIBRATION")
+ emit phCalibrationResult (cid, phId, ok);
+ else if (command == "CN_PH_RESET_FAULT_CODES")
+ emit phResetFaultCodesResult (cid, phId, ok);
+ else if (command == "CN_PH_NOZZLES_DISABLED")
+ emit phNozzlesDisabledResult (cid, phId, ok);
+}
+
+void
+Xpl2Client::handleCnPhCalibrationData (const QVariantList &params)
+{
+ if (params.size () < 50)
+ {
+ qWarning () << "CN_PH_CALIBRATION_DATA: expected 50 params, got"
+ << params.size ();
+ return;
+ }
+ int cid = params[0].toInt ();
+ int phId = params[1].toInt ();
+ QVariantList frequencies = params.mid (2, 48);
+ qDebug ("%s CN_PH_CALIBRATION_DATA controller=%d ph=%d (%lld freqs)",
+ qPrintable (logTag (&m_commandSocket)), cid, phId,
+ static_cast<long long> (frequencies.size ()));
+ emit statusMessage (
+ QStringLiteral ("RX CN_PH_CALIBRATION_DATA: controller=%1 ph=%2")
+ .arg (cid)
+ .arg (phId));
+ emit phCalibrationDataReceived (cid, phId, frequencies);
+}
+
+void
+Xpl2Client::handleCnPhCalibrationRawData (const QVariantList &params)
+{
+ if (params.size () < 50)
+ {
+ qWarning () << "CN_PH_CALIBRATION_RAW_DATA: expected 50 params, got"
+ << params.size ();
+ return;
+ }
+ int cid = params[0].toInt ();
+ int phId = params[1].toInt ();
+ QVariantList frequencies = params.mid (2, 48);
+ qDebug ("%s CN_PH_CALIBRATION_RAW_DATA controller=%d ph=%d (%lld freqs)",
+ qPrintable (logTag (&m_commandSocket)), cid, phId,
+ static_cast<long long> (frequencies.size ()));
+ emit statusMessage (
+ QStringLiteral ("RX CN_PH_CALIBRATION_RAW_DATA: controller=%1 ph=%2")
+ .arg (cid)
+ .arg (phId));
+ emit phCalibrationRawDataReceived (cid, phId, frequencies);
+}
+
+void
+Xpl2Client::handleCnPhCalibratedBaseFrequency (const QVariantList &params)
+{
+ if (params.size () < 4)
+ {
+ qWarning () << "CN_PH_CALIBRATED_BASE_FREQUENCY: expected 4 params, got"
+ << params.size ();
+ return;
+ }
+ int cid = params[0].toInt ();
+ int phId = params[1].toInt ();
+ double baseFreq = params[2].toDouble ();
+ double activeBaseFreq = params[3].toDouble ();
+ qDebug ("%s CN_PH_CALIBRATED_BASE_FREQUENCY controller=%d ph=%d "
+ "base=%.2f active=%.2f",
+ qPrintable (logTag (&m_commandSocket)), cid, phId, baseFreq,
+ activeBaseFreq);
+ emit statusMessage (
+ QStringLiteral ("RX CN_PH_CALIBRATED_BASE_FREQUENCY: controller=%1 "
+ "ph=%2 base=%3 active=%4")
+ .arg (cid)
+ .arg (phId)
+ .arg (baseFreq)
+ .arg (activeBaseFreq));
+ emit phCalibratedBaseFrequencyReceived (cid, phId, baseFreq, activeBaseFreq);
+}
+
+void
+Xpl2Client::handleCnJcStatusMessagingStart (const QVariantList &params)
+{
+ if (params.size () < 4)
+ {
+ qWarning () << "CN_JC_STATUS_MESSAGING_START: expected 4 params, got"
+ << params.size ();
+ return;
+ }
+ int cid = params[0].toInt ();
+ int level = params[1].toInt ();
+ int interval = params[2].toInt ();
+ bool ok = params[3].toInt () == 1;
+ qDebug ("%s CN_JC_STATUS_MESSAGING_START controller=%d level=%d "
+ "interval=%d success=%d",
+ qPrintable (logTag (&m_statusSocket)), cid, level, interval, ok);
+ emit statusMessage (
+ QStringLiteral ("RX CN_JC_STATUS_MESSAGING_START: controller=%1 "
+ "level=%2 interval=%3 success=%4")
+ .arg (cid)
+ .arg (level)
+ .arg (interval)
+ .arg (ok));
+ emit jcStatusMessagingStartResult (cid, level, interval, ok);
+}
+
+void
+Xpl2Client::handleCnJcStatusMessagingStop (const QVariantList &params)
+{
+ if (params.size () < 2)
+ {
+ qWarning () << "CN_JC_STATUS_MESSAGING_STOP: expected 2 params, got"
+ << params.size ();
+ return;
+ }
+ int cid = params[0].toInt ();
+ bool ok = params[1].toInt () == 1;
+ qDebug ("%s CN_JC_STATUS_MESSAGING_STOP controller=%d success=%d",
+ qPrintable (logTag (&m_statusSocket)), cid, ok);
+ emit statusMessage (
+ QStringLiteral ("RX CN_JC_STATUS_MESSAGING_STOP: controller=%1 "
+ "success=%2")
+ .arg (cid)
+ .arg (ok));
+ emit jcStatusMessagingStopResult (cid, ok);
+}
+
+void
+Xpl2Client::handleCnPhStatusMessagingStart (const QVariantList &params)
+{
+ if (params.size () < 4)
+ {
+ qWarning () << "CN_PH_STATUS_MESSAGING_START: expected 4 params, got"
+ << params.size ();
+ return;
+ }
+ int cid = params[0].toInt ();
+ int level = params[1].toInt ();
+ int interval = params[2].toInt ();
+ bool ok = params[3].toInt () == 1;
+ qDebug ("%s CN_PH_STATUS_MESSAGING_START controller=%d level=%d "
+ "interval=%d success=%d",
+ qPrintable (logTag (&m_statusSocket)), cid, level, interval, ok);
+ emit statusMessage (
+ QStringLiteral ("RX CN_PH_STATUS_MESSAGING_START: controller=%1 "
+ "level=%2 interval=%3 success=%4")
+ .arg (cid)
+ .arg (level)
+ .arg (interval)
+ .arg (ok));
+ emit phStatusMessagingStartResult (cid, level, interval, ok);
+}
+
+void
+Xpl2Client::handleCnPhStatusMessagingStop (const QVariantList &params)
+{
+ if (params.size () < 2)
+ {
+ qWarning () << "CN_PH_STATUS_MESSAGING_STOP: expected 2 params, got"
+ << params.size ();
+ return;
+ }
+ int cid = params[0].toInt ();
+ bool ok = params[1].toInt () == 1;
+ qDebug ("%s CN_PH_STATUS_MESSAGING_STOP controller=%d success=%d",
+ qPrintable (logTag (&m_statusSocket)), cid, ok);
+ emit statusMessage (
+ QStringLiteral ("RX CN_PH_STATUS_MESSAGING_STOP: controller=%1 "
+ "success=%2")
+ .arg (cid)
+ .arg (ok));
+ emit phStatusMessagingStopResult (cid, ok);
+}
+
/* ------------------------------------------------------------------ */
/* Internal */
/* ------------------------------------------------------------------ */