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.
This commit is contained in:
Tobias J. Endres 2025-08-14 02:26:06 +02:00
parent 53d90d0f91
commit b6239241c9
2 changed files with 8 additions and 7 deletions

View File

@ -59,7 +59,8 @@ hgx11::hgx11(QHash<QString, QString> 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());

View File

@ -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();