137 lines
5.5 KiB
C++
137 lines
5.5 KiB
C++
#include <appConfig.h>
|
|
#include <appCore.hpp>
|
|
void appConfig::parsingGlobalData()
|
|
{
|
|
nlohmann::json globalJson = readJsonFromPath("./config/setting.json");
|
|
softwareTile = globalJson["softwareTile"];
|
|
imgSavePath = globalJson["imgSavePath"];
|
|
oriImgSavePath = globalJson["oriImgSavePath"];
|
|
resImgSavePath = globalJson["resImgSavePath"];
|
|
handleAiModelPath = globalJson["handleAiModelPath"];
|
|
productDataPath = globalJson["productDataPath"];
|
|
|
|
//TRIGGER JSON
|
|
auto triggerJson = globalJson["Triggers"];
|
|
_triggerStruct.key = triggerJson["key"];
|
|
_triggerStruct.sleepTime = triggerJson["sleepTime"];
|
|
_triggerStruct.initStr = triggerJson["initStr"];
|
|
_triggerStruct.heartCmd = triggerJson["heartCmd"];
|
|
_triggerStruct.readAllCmd = triggerJson["readAllCmd"];
|
|
_triggerStruct.modelName = triggerJson["modelName"];
|
|
_triggerStruct.readNum = triggerJson["readNum"];
|
|
_triggerStruct.writeType = triggerJson["writeType"];
|
|
_triggerStruct.startPos = QString::fromStdString(_triggerStruct.readAllCmd).split("_")[2].toInt();
|
|
|
|
//CAMERA JSON
|
|
auto cameraJson = globalJson["CameraSetting"];
|
|
for (auto data : cameraJson)
|
|
{
|
|
cameraStruct _cameraStruct;
|
|
_cameraStruct.key = data["key"];
|
|
_cameraStruct.connectionName = data["connectionName"];
|
|
_cameraStruct.serialNum = data["serialNum"];
|
|
_cameraStruct.triggerMode = data["triggerMode"];
|
|
_cameraStruct.moduleName = data["moduleName"];
|
|
_cameraStructs.push_back(_cameraStruct);
|
|
}
|
|
|
|
//SQL
|
|
auto sqlJson = globalJson["SQL"];
|
|
for (auto data = sqlJson["initData"].begin(); data != sqlJson["initData"].end(); data++)
|
|
{
|
|
_sqlConfigStruct.datas.insert(std::make_pair(data.key(), data.value()));
|
|
}
|
|
}
|
|
void appConfig::parsingProductData(std::string path)
|
|
{
|
|
productDatasMutex.lock();
|
|
productDatas.clear();
|
|
std::vector<std::string>files;
|
|
fileManager::getAllFiles(path, files, ".json");
|
|
for (auto file : files)
|
|
{
|
|
nlohmann::json res = readJsonFromPath(file);
|
|
try
|
|
{
|
|
productDataStruct productData;
|
|
productData.name = res["productName"];
|
|
productData.customerPartNumber = res["customerPartNumber"];
|
|
productData.foxconnPartNumber = res["foxconnPartNumber"];
|
|
productData.indexOfArm = res["productIndex"];
|
|
productData.basePos = { res["baseX"],res["baseY"],res["baseZ"] };
|
|
productData.baseRad = { res["baseRx"],res["baseRy"],res["baseRz"] };
|
|
productData.halconAlgoIndex = res["halconAlgoIndex"];
|
|
productData.imgPosPath = res["imgPosPath"];
|
|
productData.disableHandleAiConfig = res["disableHandleAiConfig"];
|
|
productData.enableCodedAlgo = res["enableCodedAlgo"];
|
|
productData.codedAlgoIndex = res["codedAlgoIndex"];
|
|
productData.connectorAmout = res["connectorAmout"];
|
|
productData.isBackExist = res["isBackExist"];
|
|
productData.backArmIndex = res["backArmIndex"];
|
|
if (res["Correction"].empty() == false)
|
|
{
|
|
productData._correctionConfigStruct.correction_X = res["Correction"]["correction_X"];
|
|
productData._correctionConfigStruct.correction_Y = res["Correction"]["correction_Y"];
|
|
productData._correctionConfigStruct.correction_Z = res["Correction"]["correction_Z"];
|
|
|
|
productData._correctionConfigStruct.baseOffset_X = res["Correction"]["baseOffset_X"];
|
|
productData._correctionConfigStruct.baseOffset_Y = res["Correction"]["baseOffset_Y"];
|
|
productData._correctionConfigStruct.baseOffset_Z = res["Correction"]["baseOffset_Z"];
|
|
|
|
productData._correctionConfigStruct.offsetLimit_X = res["Correction"]["offsetLimit_X"];
|
|
productData._correctionConfigStruct.offsetLimit_Y = res["Correction"]["offsetLimit_Y"];
|
|
productData._correctionConfigStruct.offsetLimit_Z = res["Correction"]["offsetLimit_Z"];
|
|
}
|
|
|
|
for (auto it = res["partNumberList"].begin(); it != res["partNumberList"].end(); ++it)
|
|
{
|
|
productData.partNumberList.push_back(it.value());
|
|
}
|
|
for (auto it = res["cameraSetting"].begin(); it != res["cameraSetting"].end(); ++it)
|
|
{
|
|
std::vector<std::string> result = split(it.value(), '/');
|
|
productData.cameraSetting.insert(std::make_pair(std::stoi(it.key()), result));
|
|
}
|
|
for (auto it = res["lightSetting"].begin(); it != res["lightSetting"].end(); ++it)
|
|
{
|
|
productData.lightSetting.insert(std::make_pair(std::stoi(it.key()), it.value()));
|
|
}
|
|
if (res["productSign"].empty() == false)
|
|
{
|
|
for (auto it = res["productSign"].begin(); it != res["productSign"].end(); ++it)
|
|
{
|
|
productSignStruct _productSignStruct;
|
|
auto value = it.value();
|
|
_productSignStruct.sign = value["sign"];
|
|
_productSignStruct.posRect = cv::Rect(value["x"], value["y"], value["w"], value["h"]);
|
|
productData.productSign.insert(std::make_pair(std::stoi(it.key()), _productSignStruct));
|
|
}
|
|
}
|
|
productDatas.push_back(productData);
|
|
}
|
|
catch (const nlohmann::json::type_error& e)
|
|
{
|
|
if (e.id == 302)
|
|
fancyWarnWindow* warn = new fancyWarnWindow
|
|
(fancyWarnWindow::Warning, QString("%1损坏").arg(QString::fromStdString(fileManager::getFileName(file))),
|
|
"", true);
|
|
else
|
|
{
|
|
fancyWarnWindow* warn = new fancyWarnWindow
|
|
(fancyWarnWindow::Warning, QString("在读取%1中出现未知错误").arg(QString::fromStdString(fileManager::getFileName(file))),
|
|
e.what(), true);
|
|
std::cerr << "Exception: " << e.what() << std::endl;
|
|
qDebug() << "Exception: " << e.what();
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
fancyWarnWindow* warn = new fancyWarnWindow
|
|
(fancyWarnWindow::Warning, QString("在读取%1中出现严重错误").arg(QString::fromStdString(fileManager::getFileName(file))),
|
|
"请联系厂商处理", true);
|
|
}
|
|
}
|
|
_switchProductWidgetDataPtr.mutex = &productDatasMutex;
|
|
_switchProductWidgetDataPtr.productDatasPtr = &productDatas;
|
|
productDatasMutex.unlock();
|
|
} |