From fa095de6cc8ec5a5b5c14091f2b3179ad7071876 Mon Sep 17 00:00:00 2001 From: Thomas Vanbesien Date: Mon, 16 Mar 2026 16:19:49 +0100 Subject: EV_ events with Q_GADGET status types, mock periodic emission, tabbed demo UI --- mock-server/MockServer.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++++- mock-server/MockServer.h | 6 +++ 2 files changed, 111 insertions(+), 1 deletion(-) (limited to 'mock-server') diff --git a/mock-server/MockServer.cpp b/mock-server/MockServer.cpp index f2431d9..f8831da 100644 --- a/mock-server/MockServer.cpp +++ b/mock-server/MockServer.cpp @@ -22,6 +22,11 @@ MockServer::MockServer (QObject *parent) : QObject (parent) connect (&m_pingTimer, &QTimer::timeout, this, &MockServer::sendKaPing); m_pingTimer.start (1000); + + connect (&m_jcStatusTimer, &QTimer::timeout, this, + &MockServer::sendJcStatusMsg); + connect (&m_phStatusTimer, &QTimer::timeout, this, + &MockServer::sendPhStatusMsg); } void @@ -291,7 +296,23 @@ MockServer::handleCnStatusMessagingStart (QTcpSocket *client, { qDebug ("%s RX %s,%s", qPrintable (logTag (client->localPort ())), cmd.constData (), params.constData ()); - /* Echo back: controllerId, level, interval, success. */ + + /* Parse level and interval from params: "level,interval" */ + QList parts = params.split (','); + int level = parts.size () > 0 ? parts[0].toInt () : 1; + int interval = parts.size () > 1 ? parts[1].toInt () : 1000; + + if (cmd == "CN_JC_STATUS_MESSAGING_START") + { + m_jcStatusLevel = level; + m_jcStatusTimer.start (interval); + } + else + { + m_phStatusLevel = level; + m_phStatusTimer.start (interval); + } + sendReply (client, cmd + ",1," + params + ",1\n"); } @@ -301,6 +322,12 @@ MockServer::handleCnStatusMessagingStop (QTcpSocket *client, { qDebug ("%s RX %s", qPrintable (logTag (client->localPort ())), cmd.constData ()); + + if (cmd == "CN_JC_STATUS_MESSAGING_STOP") + m_jcStatusTimer.stop (); + else + m_phStatusTimer.stop (); + sendReply (client, cmd + ",1,1\n"); } @@ -365,3 +392,80 @@ MockServer::handleCfPhGetter (QTcpSocket *client, const QByteArray ¶ms) params.constData ()); sendReply (client, "CF_PH_GETTER,1," + params + ",\"0\",1\n"); } + +void +MockServer::sendJcStatusMsg () +{ + static int tick = 0; + ++tick; + bool odd = (tick % 2) != 0; + + /* Alternate between two value sets so the demo visually updates. + Level 1: cid, level, cpu, rail5v, canBus8v, temp, humidity, busCurrent, + onTimeSeconds */ + QByteArray level = QByteArray::number (m_jcStatusLevel); + QByteArray base = "EV_STATUS_MSG_JC,1," + level; + if (odd) + base += ",42.5,4.98,7.95,35.2,55.0,0.12,3600"; + else + base += ",58.3,5.02,8.05,37.8,48.5,0.15,3660"; + + if (m_jcStatusLevel >= 2) + { + if (odd) + base += ",\"192.168.1.100\",23.5,1,1,1,3,\"1.05\",\"2.00\"" + ",0,0,0,0,0,0"; + else + base += ",\"192.168.1.100\",24.1,1,1,1,3,\"1.05\",\"2.00\"" + ",1,0,1,0,1,0"; + } + base += '\n'; + + for (auto *client : m_clients) + if (client->state () == QAbstractSocket::ConnectedState + && client->localPort () == m_status.number) + sendReply (client, base); +} + +void +MockServer::sendPhStatusMsg () +{ + static int tick = 0; + ++tick; + bool odd = (tick % 2) != 0; + + /* Alternate between two value sets. + Level 1: cid, level, phId, temp, humidity, mcuTemp, pdsV, mdsV, sysV, + eFuseI, nozzleI, vdd, 13×trip bools, dutyCycle, pwmFreq, drive, + nozzleDriveFreq, nozzleDriveDutyCycle, onTimeSeconds */ + QByteArray level = QByteArray::number (m_phStatusLevel); + QByteArray base = "EV_STATUS_MSG_PH,1," + level + ",1"; + if (odd) + base += ",38.5,45.0,40.2,36.0,24.0,3.3,0.05,0.02,3.3" + ",0,0,0,0,0,0,0,0,0,0,0,0,0" + ",50.0,10000.0,3,8000.0,50.0,1800"; + else + base += ",41.2,42.0,43.1,35.5,23.8,3.28,0.06,0.03,3.31" + ",0,0,0,0,0,0,0,0,0,0,0,0,0" + ",55.0,10500.0,4,8200.0,52.0,1860"; + + if (m_phStatusLevel >= 2) + { + if (odd) + base += ",0,\"MCU001\",\"FLASH001\",12345" + ",\"1.00\",\"3.10\",\"Standard\",\"1.00\",\"2.05\",\"0.9.1\"" + ",100.0,45.0,20.0,36.0,30.0,18.0,2.0,\"1.00\"" + ",0,0,0,0,0,0,0,0,0,0,0,0,0,0"; + else + base += ",0,\"MCU001\",\"FLASH001\",12345" + ",\"1.00\",\"3.10\",\"Standard\",\"1.00\",\"2.05\",\"0.9.1\"" + ",100.0,45.0,20.0,35.5,30.0,18.0,2.0,\"1.00\"" + ",1,-1,2,0,0,0,0,0,0,0,0,0,0,0"; + } + base += '\n'; + + for (auto *client : m_clients) + if (client->state () == QAbstractSocket::ConnectedState + && client->localPort () == m_status.number) + sendReply (client, base); +} diff --git a/mock-server/MockServer.h b/mock-server/MockServer.h index b14dda5..3086057 100644 --- a/mock-server/MockServer.h +++ b/mock-server/MockServer.h @@ -25,6 +25,8 @@ private slots: void onClientDisconnected (); /* Send KA_PING keepalive to all connected clients. */ void sendKaPing (); + void sendJcStatusMsg (); + void sendPhStatusMsg (); private: struct Port @@ -73,5 +75,9 @@ private: Port m_status; QList m_clients; QTimer m_pingTimer; + QTimer m_jcStatusTimer; + QTimer m_phStatusTimer; + int m_jcStatusLevel = 1; + int m_phStatusLevel = 1; static bool s_wireDebug; }; -- cgit v1.2.3