Files
2024-02-27 15:29:15 +08:00

152 lines
6.5 KiB
C++

//int reParsing(int argc, char* argv[]) {
//QCoreApplication a(argc, argv);
#include <jsonParsing.h>
int jsonConfiguration::reParsing()
//jsonConfiguration::jsonConfiguration(QObject* parent)
{
clear();
QFile jsonFile(".//config//setting.json");
if (!jsonFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "Failed to open JSON file.";
return 1;
}
QByteArray jsonData = jsonFile.readAll();
jsonFile.close();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
if (!jsonDoc.isObject()) {
qDebug() << "Invalid JSON format.";
return 1;
}
QJsonObject jsonObj = jsonDoc.object();
imgSavePath = jsonObj.value("imgSavePath").toString();
stationName = jsonObj.value("stationName").toString();
////////////////////TABLE//LIST/////////////////////
QJsonArray tableListArray = jsonObj["tablelist"].toArray();
for (const QJsonValue& tableListValue : tableListArray) {
QJsonObject tableObj = tableListValue.toObject();
tableListCls::dataStruct data;
data.key = tableObj.value("key").toString();
data.cName = tableObj.value("cName").toString();
data.eName = tableObj.value("eName").toString();
data.value = tableObj.value("value").toString();
tableList.datas.append(data);
}
/////////////////////TCP////////////////////////////
QJsonObject tcpObj = jsonObj.value("Tcp").toObject();
tcp.key = tcpObj.value("key").toString();
tcp.writetype = tcpObj.value("writetype").toString();
tcp.finstcp_sleeptime = tcpObj.value("finstcp_sleeptime").toString();
tcp.finstcp_init = tcpObj.value("finstcp_init").toString();
tcp.heartCmd = tcpObj.value("heartCmd").toString();
tcp.finstcp_readAllCmd = tcpObj.value("finstcp_readAllCmd").toString();
tcp.moduleName = tcpObj.value("moduleName").toString();
tcp.startPos = tcp.finstcp_readAllCmd.split("_")[1].split("DM")[1].toInt();
//////////////PIXEL//ACC//////////////////////////
QJsonObject pixelAccuracyObj = jsonObj.value("PixelAccuracy").toObject();
QJsonObject::iterator itPixelAcc;
for (itPixelAcc = pixelAccuracyObj.begin();
itPixelAcc != pixelAccuracyObj.end();
++itPixelAcc) {
PixelAccuracyCls::dataStruct data;
data.key = itPixelAcc.key();
data.value = itPixelAcc.value().toDouble();
PixelAccuracy.datas.push_back(data);
}
/////////////////SHOW//////WIDGETS////////////
QJsonObject showWidgetsObj = jsonObj.value("ShowWidgets").toObject();
QJsonObject::iterator itShowWidget;
for (itShowWidget = showWidgetsObj.begin();
itShowWidget != showWidgetsObj.end();
++itShowWidget) {
QString key = itShowWidget.key();
if (key == "basicView")
{
showWidgets.basicView = itShowWidget.value().toString();
}
else
{
QJsonValue Array = itShowWidget.value();
QJsonArray cameraViewObj = Array.toArray();
QList<ShowWidgetsCls::widgets> list;
for (const QJsonValue& widgetValue : cameraViewObj) {
QJsonObject widgetObj = widgetValue.toObject();
ShowWidgetsCls::widgets widget;
widget.Key = widgetObj.value("key").toString();
widget.cName = widgetObj.value("cName").toString();
widget.eName = widgetObj.value("eName").toString();
list.append(widget);
}
showWidgets.viewList.insert({ key, list });
}
}
///////////////CAMERA//LIST/////////////////////
QJsonArray cameraSettingArray = jsonObj["CameraSetting"].toArray();
int cameraIndex = 0;
for (const QJsonValue& cameraValue : cameraSettingArray)
{
QJsonObject cameraObject = cameraValue.toObject();
CameraListCls::datastruct data;
data.cameraKeyName = cameraObject.value("keyName").toString();
data.connectionName = cameraObject.value("connectionName").toString();
data.serialNum = cameraObject.value("serialNum").toString();
data.triggermode = cameraObject.value("triggermodel").toString();
data.moduleName = cameraObject.value("moduleName").toString();
data.showIndex = cameraObject.value("showIndex").toInt();
data.cameraIndex = cameraIndex;
camera.cameraList.push_back(data);
camera.cameraMap.insert({ data.cameraKeyName ,data});
cameraIndex++;
}
///////////////LIGHT//SOURCE/////////////////////
QJsonArray lightSourceArray = jsonObj["LightSource"].toArray();
for (const QJsonValue& lightSourceValue : lightSourceArray) {
QJsonObject lightSourceObj = lightSourceValue.toObject();
LightSourceCls::LightSource data;
data.name = lightSourceObj.value("name").toString();
data.comPort = lightSourceObj.value("com").toString();
data.baudRate = lightSourceObj.value("baudRate").toString().toInt();
data.initStr = lightSourceObj.value("initial").toString();
LightSources.LightSourceList.push_back(data);
}
///////////////ALGOTHREAD//LIST/////////////////////
QJsonArray algoThreadArray = jsonObj["algoThread"].toArray();
int threadIndex = 0;
for (const QJsonValue& algoThreadValue : algoThreadArray)
{
QJsonObject algoThreadObject = algoThreadValue.toObject();
algoThreadCls::datastruct data;
data.threadKeyName = algoThreadObject.value("KeyName").toString();
data.showIndex = algoThreadObject.value("showIndex").toInt();
data.cameraKey = algoThreadObject.value("cameraKey").toString();
data.imgAmountMin= algoThreadObject.value("imgAmountMin").toInt();
data.threadIndex = threadIndex;
//algoThreads.algoThreadList.push_back(data);
algoThreads.algoDataMap.insert({ data.threadKeyName ,data });
threadIndex++;
}
///////////////SUMMARY//DATA////////////////////////
QJsonObject summaryDataObj = jsonObj.value("summaryData").toObject();
QJsonObject::iterator itSummary;
for (itSummary = summaryDataObj.begin();
itSummary != summaryDataObj.end();
++itSummary) {
summaryData.datas.insert({ itSummary.key() ,itSummary.value().toString() });
}
return 0;
}
void jsonConfiguration::clear()
{
camera.cameraList.clear();
camera.cameraMap.clear();
PixelAccuracy.datas.clear();
showWidgets.basicView.clear();
showWidgets.viewList.clear();
LightSources.LightSourceList.clear();
algoThreads.algoDataMap.clear();
tableList.datas.clear();
summaryData.datas.clear();
}