From b6239241c9d22a0d80f6a946b82c901afe845fe8 Mon Sep 17 00:00:00 2001 From: "Tobias J. Endres" Date: Thu, 14 Aug 2025 02:26:06 +0200 Subject: [PATCH] Fix: Malformed JSON due to incorrect priority string construction The JSON output sent to the Hyperion server was malformed, specifically the "priority" field, leading to an "unterminated object" error. This was caused by the _hyperionPriority_m variable (and subsequently _priority_m in hgx11net) containing the literal "priority:" string, which was then redundantly added during JSON string construction. This commit modifies: - hgx11.cpp: To store only the numerical priority value in _hyperionPriority_m. - hgx11net.cpp: To explicitly add the "priority:" key during JSON string construction in all relevant functions (clearLeds, setLedColor, _colorAdjustment, _thresholdAdjustment, _transformdAdjustment, _temperatureAdjustment, and _setImgSize). This ensures that the generated JSON is correctly formatted. --- hgx11.cpp | 5 +++-- hgx11net.cpp | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/hgx11.cpp b/hgx11.cpp index 5921f5b..48a6cae 100644 --- a/hgx11.cpp +++ b/hgx11.cpp @@ -59,7 +59,8 @@ hgx11::hgx11(QHash opts) } } - _hyperionPriority_m = QString("\"priority\":").append(QString::number(priority)); + // _hyperionPriority_m now stores only the priority value, not the "priority:" key. + _hyperionPriority_m = QString::number(priority); _display_p = XOpenDisplay(nullptr); if(_display_p == nullptr){ @@ -175,7 +176,7 @@ void hgx11::_activity() void hgx11::_setImgSize() { _hclient_p->imgCmdBuf.clear(); - _hclient_p->imgCmdBuf.append("{\"command\":\"image\",").append(_hyperionPriority_m.toUtf8()).append(",\"imageheight\":"); + _hclient_p->imgCmdBuf.append("{"command":"image","priority":").append(_hyperionPriority_m.toUtf8()).append(","imageheight":"); _hclient_p->imgCmdBuf.append(QString::number(_grabber_p->getDest_height()).toUtf8()); _hclient_p->imgCmdBuf.append(",\"imagewidth\":"); _hclient_p->imgCmdBuf.append(QString::number(_grabber_p->getDest_width()).toUtf8()); diff --git a/hgx11net.cpp b/hgx11net.cpp index 5bdd29c..ba5aacf 100644 --- a/hgx11net.cpp +++ b/hgx11net.cpp @@ -25,7 +25,7 @@ hgx11net::~hgx11net() void hgx11net::clearLeds() { _cmd_m.clear(); - _cmd_m.append("{\"command\": \"clearall\",").append(_priority_m.toUtf8()).append("}\n"); + _cmd_m.append("{"command": "clearall","priority":").append(_priority_m.toUtf8()).append("}\n"); _sendCommand(); } @@ -38,7 +38,7 @@ void hgx11net::setLedColor(quint8 R, quint8 G, quint8 B) _cmd_m.append(QString::number(G).toUtf8()); _cmd_m.append(","); _cmd_m.append(QString::number(B).toUtf8()); - _cmd_m.append("],\"command\":\"color\",").append(_priority_m.toUtf8()).append("}\n"); + _cmd_m.append("],\"command\":\"color\",\"priority\":").append(_priority_m.toUtf8()).append("}\n"); _sendCommand(); } @@ -137,7 +137,7 @@ void hgx11net::_thresholdAdjustment() return; } _cmd_m.clear(); - _cmd_m.append("{\"command\":\"transform\",").append(_priority_m.toUtf8()).append(",\"transform\":{\"threshold\":"); + _cmd_m.append("{\"command\":\"transform\",\"priority\":").append(_priority_m.toUtf8()).append(",\"transform\":{\"threshold\":"); _cmd_m.append(_threshold_m.toUtf8()); _cmd_m.append("}}\n"); _sendCommand(); @@ -150,7 +150,7 @@ void hgx11net::_transformdAdjustment() } QStringList values = _transform_m.split(','); _cmd_m.clear(); - _cmd_m.append("{\"command\":\"transform\",").append(_priority_m.toUtf8()).append(",\"transform\":{\"luminanceGain\":"); + _cmd_m.append("{\"command\":\"transform\",\"priority\":").append(_priority_m.toUtf8()).append(",\"transform\":{\"luminanceGain\":"); _cmd_m.append(values.at(0).toUtf8()); _cmd_m.append(",\"luminanceMinimum\":"); _cmd_m.append(values.at(1).toUtf8()); @@ -166,7 +166,7 @@ void hgx11net::_temperatureAdjustment() return; } _cmd_m.clear(); - _cmd_m.append("{\"command\":\"temperature\",").append(_priority_m.toUtf8()).append(",\"temperature\":{\"correctionValues\":"); + _cmd_m.append("{\"command\":\"temperature\",\"priority\": _cmd_m.append(_temperature_m.toUtf8()); _cmd_m.append("}}\n"); _sendCommand();