/* * @Author: your name * @Date: 2022-04-20 15:50:00 * @LastEditTime: 2025-09-11 22:03:50 * @LastEditors: xiewenji 527774126@qq.com * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE * @FilePath: /ZCXD_MonitorPlatform/src/CoreLogicModule/src/CamDeal.cpp */ #include "ConfigManager.h" #include #include "ConfigBase.h" #include "../../AlgorithmModule/include/ImgCheckConfig.h" ConfigManager::ConfigManager() { m_strConfigRootPath = ""; } ConfigManager::~ConfigManager() { } std::vector m_FlawCodeList; std::vector QX_Result_Names = { "OK", "aotudian", "other", "line", "zangwu", "edge", "ymhs", "dianzhuang", "posun", "xianwei", "shuizi", "danban", "fuchen", "tag", }; std::vector QX_Result_Code = { "P0000", "MA507", "MA508", "MA506", "MA504", "MA503", "MA502", "MA505", "MA501", "P0001", "P0002", "P0003", "P0004", "P0005", }; int ReadFlawCodeConfig(std::string json_path) { m_FlawCodeList.erase(m_FlawCodeList.begin(), m_FlawCodeList.end()); std::string strPath = json_path; printf("ReadFlawCodeConfig path %s\n", strPath.c_str()); Json::CharReaderBuilder builder; builder["collectComments"] = true; Json::Value root; std::string err; std::ifstream ifs(strPath); if (!ifs.is_open()) { printf("error:file is open\n"); return 0; } if (!Json::parseFromStream(builder, ifs, &root, &err)) { printf("error:parseFromStream\n"); return 0; } for (int i = 0; i < root.size(); i++) { // printf("Node idx %d /%d \n", i, root.size()); ReadFlawCode tem; tem.flaw_name = root[i]["zh_name"].asString(); tem.flaw_code = root[i]["en_name"].asString(); string desc = root[i]["desc"].asString(); { std::istringstream stream(desc); std::string token; // 使用 getline 按照分号分割 while (std::getline(stream, token, ';')) { tem.config_flaw_name.push_back(token); } } m_FlawCodeList.push_back(tem); } for(int i = 0; i < m_FlawCodeList.size(); i++) { if(i >= QX_Result_Names.size()) { QX_Result_Names.push_back(m_FlawCodeList.at(i).flaw_name); QX_Result_Code.push_back(m_FlawCodeList.at(i).flaw_code); } else { QX_Result_Names.at(i) = m_FlawCodeList.at(i).flaw_name; QX_Result_Code.at(i) = m_FlawCodeList.at(i).flaw_code; } } return 0; } int ConfigManager::LoadParamConfig(std::shared_ptr &Config, std::string strConfigPath) { Json::CharReaderBuilder builder; Json::Value json_value; std::string errs; std::ifstream infile(strConfigPath, ios::binary); printf("Analysis_Config_path========== %s \n", strConfigPath.c_str()); // getchar(); if (infile.is_open()) { if (Json::parseFromStream(builder, infile, &json_value, &errs)) { Config->UpdateJSONConfig((void *)&json_value, ConfigType_Analysisy_Common_XL); // printf("m_pConfig ConfigType_Analysisy_Common_XL %s\n", Config->GetErrorInfo().c_str()); } else { printf("****%s fail \n", strConfigPath.c_str()); } } else { printf("****%s fail \n", strConfigPath.c_str()); infile.close(); return 1; } infile.close(); return 0; } int ConfigManager::LoadAnalysisConfig(std::string strConfigPath) { m_strConfigRootPath = strConfigPath; int re = UpdateConfig(); return re; } std::string ConfigManager::GetJsonPath() { return m_strConfigRootPath; } int ConfigManager::UpdateConfig() { string defect_list_file = GetJsonPath(); if (defect_list_file == "") { defect_list_file = "/var/aidlux/efs/model/defect_list.json"; } else{ defect_list_file += "/defect_list.json"; } ReadFlawCodeConfig(defect_list_file); bool bFileName = false; // std::regex pattern(R"(param_[0-9]\.json)"); std::regex pattern(R"(param_(\d+|left|right)\.json)"); if (!fs::exists(m_strConfigRootPath)) { std::cerr << "目录不存在: " << m_strConfigRootPath << std::endl; return 1; } // Config_instances_.clear(); for (const auto &entry : fs::directory_iterator(m_strConfigRootPath)) { if (entry.is_regular_file()) { std::string filename = entry.path().filename().string(); if (std::regex_match(filename, pattern)) { bFileName = true; std::cout << "匹配文件: " << entry.path() << std::endl; std::shared_ptr temConfig = ConfigBase::GetInstance(); int re = LoadParamConfig(temConfig, entry.path()); if (re != 0) { continue; } AnalysisyConfigST p; temConfig->GetConfig(ConfigType_Analysisy_Common_XL, &p); printf("********* CamearName %s\n", p.commonCheckConfig.baseConfig.strCamearName.c_str()); if (p.commonCheckConfig.baseConfig.strCamearName == "") { printf("Error >>>> camear Name is empty \n"); continue; } auto it = Config_instances_.find(p.commonCheckConfig.baseConfig.strCamearName); if (it != Config_instances_.end() && it->second) { LoadParamConfig(it->second, entry.path()); } else { Config_instances_[p.commonCheckConfig.baseConfig.strCamearName] = temConfig; } } } else { std::cerr << "config error 2: " << m_strConfigRootPath << std::endl; } } if(!bFileName){ cout << "Error >>>> no param_x.json file !!!!!!!!!!!!\n"; return 2; } return 0; } int ConfigManager::GetConfig(int nConfigType, void *pconfig) { return 0; }