#include "stdafx.h" #include "ConfigurationManager.h" using namespace DIOS::Dev::Detail::MachineryECOM; ConfigurationManager *ConfigurationManager::m_instance = nullptr; const std::string CONFIG_MANUFACTURE_CONFIG = "Config_Manufacturer.xml"; const std::string CONFIG_COMPONENT_CONTROLLER = "Config_ComponentController.xml"; const std::string CONFIG_POSITIONNUMBER = "Config_PositionNumber.xml"; const std::string CONFIG_CALIBRATION = "Config_MotionCalibration.xml"; const std::string CONFIG_MACHINERY = "Config_Machinery.xml"; const std::string CONFIG_TOMO = "Config_Tomo.xml"; const std::string CONFIG_SERVO_DRIVE = "Config_ServoDrive.xml"; const std::string CONFIG_EXPOSURE_DELAY = "Config_ExposureDelayTime.xml"; const std::string CONFIG_WORKSTATION = "Config_Workstaion.xml"; const std::string CONFIG_MOTION_VERTICAL = "Config_MotionTubeVertical.xml"; const std::string CONFIG_MOTION_HORIZONTAL = "Config_MotionTubeHorizontal.xml"; const std::string CONFIG_MOTION_ROTATION = "Config_MotionTubeRotation.xml"; const std::string CONFIG_TOMO_MOTION = "Config_TomoMotion.xml"; ConfigurationManager::ConfigurationManager() :m_workPath(""), m_configPath("") { } ConfigurationManager::~ConfigurationManager() { } ConfigurationManager *ConfigurationManager::Instance() { if (m_instance == nullptr) { m_instance = new ConfigurationManager(); } return m_instance; } void ConfigurationManager::Initialize(const std::string &workpath) { m_workPath = workpath; try { m_configPath = GetConfigPath(workpath); TPRINTA_DEBUG("WorkPath is %s,ConfigPath is %s", m_workPath.c_str(), m_configPath.c_str()); LoadComponentControllerConfig(); LoadPositionNumberConfig(); LoadCalibrationConfig(); LoadMachineryConfig(); LoadMotionConfigVertical(); LoadMotionConfigHorizontal(); LoadMotionConfigRotation(); LoadTomoConfig(); LoadServoDriveConfig(); LoadExposureDelayTimeConfig(); LoadWorkstationConfig(); LoadConfigTomoMotionLimitation(); } catch (ResDataObjectExption &e) { gdriverLog->Error("[ConfigurationManager][Initialize]->[Exception][{$}]", e.what()); } catch (...) { if(gdriverLog) gdriverLog->Error("[ConfigurationManager][Initialize]->[Exception][Unknown]"); } } BOOL ConfigurationManager::GetAllMachineryConfigs(ResDataObject &out) { out = m_machineryConfig; return TRUE; } BOOL ConfigurationManager::GetAllTomoConfigs(ResDataObject &out) { out = m_tomoConfig; return TRUE; } ResDataObject &ConfigurationManager::GetPositionNumberConfig(const std::string &key) { return m_positionNumber[key.c_str()]; } ResDataObject &ConfigurationManager::GetServoDriveConfig(const std::string &key) { return m_servoDrive[key.c_str()]; } ResDataObject &ConfigurationManager::GetExpousreDelayTimeConfig() { return m_exposureDelayTime; } ResDataObject &ConfigurationManager::GetCalibrationConfig(const std::string &key) { try { if (m_motionParamCalRoot.GetFirstOf("CONFIGURATION") >= 0) { auto motionParamCal = &(m_motionParamCalRoot)["CONFIGURATION"]; return (*motionParamCal)[key.c_str()]; } throw new exception("key not exist"); } catch (exception *e) { if(gdriverLog) gdriverLog->Error("[ConfigurationManager][GetCalibrationConfig]->[Exception][{$}][{$}]", key.c_str(), e->what()); } return m_motionParamCalRoot["CONFIGURATION"]; } ResDataObject &ConfigurationManager::GetTomoConfig(const std::string &key) { return m_tomoConfig[key.c_str()]; } ResDataObject &ConfigurationManager::GetMachineryConfig(const std::string &key) { if (m_machineryConfig.GetFirstOf(key.c_str()) >= 0) { return m_machineryConfig[key.c_str()]; } return (ResDataObject()); } ResDataObject& ConfigurationManager::GetConfigTubeVertical(const std::string& key) { if (m_motionConfigVertical.GetFirstOf(key.c_str()) >= 0) { return m_motionConfigVertical[key.c_str()]; } return (ResDataObject()); } ResDataObject& ConfigurationManager::GetConfigTubeHorizontal(const std::string& key) { if (m_motionConfigHorizontal.GetFirstOf(key.c_str()) >= 0) { return m_motionConfigHorizontal[key.c_str()]; } return (ResDataObject()); } ResDataObject& ConfigurationManager::GetConfigTubeRotation(const std::string& key) { if (m_motionConfigRotation.GetFirstOf(key.c_str()) >= 0) { return m_motionConfigRotation[key.c_str()]; } return (ResDataObject()); } ResDataObject& ConfigurationManager::GetWSConfig(const std::string& key) { if (m_wsConfig.GetFirstOf(key.c_str()) >= 0) { return m_wsConfig[key.c_str()]; } return (ResDataObject()); } ResDataObject& ConfigurationManager::GetConfigTomoMotionLimitation(const std::string& key) { if (m_TomoMotionConfig.GetFirstOf(key.c_str()) >= 0) { return m_TomoMotionConfig[key.c_str()]; } return (ResDataObject()); } std::string ConfigurationManager::GetControllerClassID(const std::string &key) { if (m_componentController.GetKeyCount(key.c_str()) <= 0) { return ""; } return string((const char *)m_componentController[key.c_str()]); } std::string ConfigurationManager::GetConfigPath(const std::string &workpath) { std::string ret = workpath; std::string filename = workpath + CONFIG_MANUFACTURE_CONFIG; try { HANDLE hFind = NULL; WIN32_FIND_DATA FindFileData; hFind = FindFirstFile(filename.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw new exception("Load file failed"); } FindClose(hFind); ResDataObject componnetConfig; if (componnetConfig.loadFile(filename.c_str())) { if (componnetConfig.GetFirstOf("CONFIGURATION") >= 0) { auto config = componnetConfig["CONFIGURATION"]; if (config.GetFirstOf("ManufacturerPath") >= 0) { ret = workpath + string((const char *)config["ManufacturerPath"]) + "\\"; } } } else { throw new exception("Load file failed"); } } catch (exception *e) { if (gdriverLog != nullptr) { gdriverLog->Error("[ConfigurationManager][GetConfigPath]->[Exception][{$}][{$}]", filename.c_str(), e->what()); } } return ret; } void ConfigurationManager::LoadComponentControllerConfig() { std::string filename = m_configPath + CONFIG_COMPONENT_CONTROLLER; try { HANDLE hFind = NULL; WIN32_FIND_DATA FindFileData; hFind = FindFirstFile(filename.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw new exception("Load file failed"); } FindClose(hFind); ResDataObject componnetConfig; if (componnetConfig.loadFile(filename.c_str())) { if (componnetConfig.GetFirstOf("CONFIGURATION") >= 0) { m_componentController = componnetConfig["CONFIGURATION"]; } } else { throw new exception("Load file failed"); } } catch (exception *e) { if(gdriverLog) gdriverLog->Error("[ConfigurationManager][LoadComponentControllerConfig]->[Exception][{$}][{$}]", filename.c_str(), e->what()); } } void ConfigurationManager::LoadMachineryConfig() { std::string filename = m_configPath + CONFIG_MACHINERY; try { HANDLE hFind = NULL; WIN32_FIND_DATA FindFileData; hFind = FindFirstFile(filename.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw new exception("Load file failed"); } FindClose(hFind); ResDataObject machineryConfig; if (machineryConfig.loadFile(filename.c_str())) { if (machineryConfig.GetFirstOf("CONFIGURATION") >= 0) { m_machineryConfig = machineryConfig["CONFIGURATION"]; } } else { throw new exception("Load file failed"); } } catch (exception *e) { if(gdriverLog) gdriverLog->Error("[ConfigurationManager][LoadMachineryConfig]->[Exception][{$}][{$}]", filename.c_str(), e->what()); } } void ConfigurationManager::LoadMotionConfigVertical() { std::string filename = m_configPath + CONFIG_MOTION_VERTICAL; try { HANDLE hFind = NULL; WIN32_FIND_DATA FindFileData; hFind = FindFirstFile(filename.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw new exception("Load file failed"); } FindClose(hFind); //ResDataObject motionConfigVertical; if (m_motionConfigVerticalRoot.loadFile(filename.c_str())) { if (m_motionConfigVerticalRoot.GetFirstOf("CONFIGURATION") >= 0) { m_motionConfigVertical = m_motionConfigVerticalRoot["CONFIGURATION"]; } } else { throw new exception("Load file failed"); } } catch (exception* e) { if (gdriverLog) gdriverLog->Error("[ConfigurationManager][LoadMotionConfigVertical]->[Exception][{$}][{$}]", filename.c_str(), e->what()); } } void ConfigurationManager::LoadMotionConfigHorizontal() { std::string filename = m_configPath + CONFIG_MOTION_HORIZONTAL; try { HANDLE hFind = NULL; WIN32_FIND_DATA FindFileData; hFind = FindFirstFile(filename.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw new exception("Load file failed"); } FindClose(hFind); //ResDataObject motionConfigHorizontal; if (m_motionConfigHorizontalRoot.loadFile(filename.c_str())) { if (m_motionConfigHorizontalRoot.GetFirstOf("CONFIGURATION") >= 0) { m_motionConfigHorizontal = m_motionConfigHorizontalRoot["CONFIGURATION"]; } } else { throw new exception("Load file failed"); } } catch (exception* e) { if (gdriverLog) gdriverLog->Error("[ConfigurationManager][LoadMotionConfigHorizontal]->[Exception][{$}][{$}]", filename.c_str(), e->what()); } } void ConfigurationManager::LoadMotionConfigRotation() { std::string filename = m_configPath + CONFIG_MOTION_ROTATION; try { HANDLE hFind = NULL; WIN32_FIND_DATA FindFileData; hFind = FindFirstFile(filename.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw new exception("Load file failed"); } FindClose(hFind); //ResDataObject motionConfigRotation; if (m_motionConfigRotationRoot.loadFile(filename.c_str())) { if (m_motionConfigRotationRoot.GetFirstOf("CONFIGURATION") >= 0) { m_motionConfigRotation = m_motionConfigRotationRoot["CONFIGURATION"]; } } else { throw new exception("Load file failed"); } } catch (exception* e) { if (gdriverLog) gdriverLog->Error("[ConfigurationManager][LoadMotionConfigRotation]->[Exception][{$}][{$}]", filename.c_str(), e->what()); } } void ConfigurationManager::LoadTomoConfig() { std::string filename = m_configPath + CONFIG_TOMO; try { HANDLE hFind = NULL; WIN32_FIND_DATA FindFileData; hFind = FindFirstFile(filename.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw new exception("Load file failed"); } FindClose(hFind); ResDataObject tomoConfig; if (tomoConfig.loadFile(filename.c_str())) { if (tomoConfig.GetFirstOf("CONFIGURATION") >= 0) { m_tomoConfig = tomoConfig["CONFIGURATION"]; } } else { throw new exception("Load file failed"); } } catch (exception *e) { if(gdriverLog) gdriverLog->Error("[ConfigurationManager][LoadTomoConfig]->[Exception][{$}][{$}]", filename.c_str(), e->what()); } } void ConfigurationManager::LoadPositionNumberConfig() { string filename = m_configPath + CONFIG_POSITIONNUMBER; try { WIN32_FIND_DATA FindFileData; HANDLE hFind = FindFirstFile(filename.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw new exception("Load file failed"); } FindClose(hFind); if (m_positionNumber.loadFile(filename.c_str())) { } else { throw new exception("Load file failed"); } } catch(exception *e) { if(gdriverLog) gdriverLog->Error("[ConfigurationManager][LoadPositionNumberConfig]->[Exception][{$}][{$}]", filename.c_str(), e->what()); } } void ConfigurationManager::LoadCalibrationConfig() { std::string filename = m_configPath + CONFIG_CALIBRATION; try { HANDLE hFind = NULL; WIN32_FIND_DATA FindFileData; hFind = FindFirstFile(filename.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw new exception("Load file failed"); } FindClose(hFind); if (!m_motionParamCalRoot.loadFile(filename.c_str())) { throw new exception("Load file failed"); } } catch (exception *e) { if(gdriverLog) gdriverLog->Error("[ConfigurationManager][LoadCalibrationConfig]->[Exception][{$}][{$}]", filename.c_str(), e->what()); } } void ConfigurationManager::LoadServoDriveConfig() { string filename = m_configPath + CONFIG_SERVO_DRIVE; try { WIN32_FIND_DATA FindFileData; HANDLE hFind = FindFirstFile(filename.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw new exception("Load file failed"); } FindClose(hFind); if (m_servoDrive.loadFile(filename.c_str())) { } else { throw new exception("Load file failed"); } } catch (exception *e) { if(gdriverLog) gdriverLog->Error("[ConfigurationManager][LoadServoDriveConfig]->[Exception][{$}][{$}]", filename.c_str(), e->what()); } } void ConfigurationManager::LoadExposureDelayTimeConfig() { string filename = m_configPath + CONFIG_EXPOSURE_DELAY; try { WIN32_FIND_DATA FindFileData; HANDLE hFind = FindFirstFile(filename.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw new exception("Load file failed"); } FindClose(hFind); ResDataObject root; if (root.loadFile(filename.c_str())) { if (root.GetFirstOf("CONFIGURATION") >= 0) { m_exposureDelayTime = root["CONFIGURATION"]; } } else { throw new exception("Load file failed"); } } catch (exception *e) { if(gdriverLog) gdriverLog->Error("[ConfigurationManager][LoadServoDriveConfig]->[Exception][{$}][{$}]", filename.c_str(), e->what()); } } void ConfigurationManager::LoadWorkstationConfig() { std::string filename = m_configPath + CONFIG_WORKSTATION; try { HANDLE hFind = NULL; WIN32_FIND_DATA FindFileData; hFind = FindFirstFile(filename.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw new exception("Load file failed"); } FindClose(hFind); ResDataObject wsConfig; if (wsConfig.loadFile(filename.c_str())) { if (wsConfig.GetFirstOf("CONFIGURATION") >= 0) { m_wsConfig = wsConfig["CONFIGURATION"]; } } else { throw new exception("Load file failed"); } } catch (exception* e) { if (gdriverLog) gdriverLog->Error("[ConfigurationManager][LoadWorkstationConfig]->[Exception][{$}][{$}]", filename.c_str(), e->what()); } } void ConfigurationManager::LoadConfigTomoMotionLimitation() { std::string filename = m_configPath + CONFIG_TOMO_MOTION; try { HANDLE hFind = NULL; WIN32_FIND_DATA FindFileData; hFind = FindFirstFile(filename.c_str(), &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { throw new exception("Load file failed"); } FindClose(hFind); ResDataObject motionConfig; if (motionConfig.loadFile(filename.c_str())) { if (motionConfig.GetFirstOf("CONFIGURATION") >= 0) { m_TomoMotionConfig = motionConfig["CONFIGURATION"]; } } else { throw new exception("Load file failed"); } } catch (exception* e) { if (gdriverLog) gdriverLog->Error("[ConfigurationManager][LoadConfigTomoMotionLimitation]->[Exception][{$}][{$}]", filename.c_str(), e->what()); } } BOOL ConfigurationManager::UpdateCalibrationConfig(const std::string &key, ResDataObject ¶ms) { if (m_motionParamCalRoot.GetFirstOf("CONFIGURATION") >= 0) { auto *motionParamCal = &(m_motionParamCalRoot)["CONFIGURATION"]; motionParamCal->update(key.c_str(), params[key.c_str()]); std::string filename = m_configPath + CONFIG_CALIBRATION; m_motionParamCalRoot.SaveFile(filename.c_str()); return TRUE; } return FALSE; } BOOL ConfigurationManager::UpdateMotionConfigTubeAngle(const std::string& key, ResDataObject& params) { if (m_motionConfigRotationRoot.GetFirstOf("CONFIGURATION") >= 0) { auto* motionParam = &(m_motionConfigRotationRoot)["CONFIGURATION"]; motionParam->update(key.c_str(), params[key.c_str()]); std::string filename = m_configPath + CONFIG_MOTION_ROTATION; m_motionConfigRotationRoot.SaveFile(filename.c_str()); return TRUE; } return FALSE; } BOOL ConfigurationManager::UpdateMotionConfigTubeHeight(const std::string& key, ResDataObject& params) { if (m_motionConfigVerticalRoot.GetFirstOf("CONFIGURATION") >= 0) { auto* motionParam = &(m_motionConfigVerticalRoot)["CONFIGURATION"]; motionParam->update(key.c_str(), params[key.c_str()]); std::string filename = m_configPath + CONFIG_MOTION_VERTICAL; m_motionConfigVerticalRoot.SaveFile(filename.c_str()); return TRUE; } return FALSE; } BOOL ConfigurationManager::UpdateMotionConfigTubeHorizontal(const std::string& key, ResDataObject& params) { if (m_motionConfigHorizontalRoot.GetFirstOf("CONFIGURATION") >= 0) { auto* motionParam = &(m_motionConfigHorizontalRoot)["CONFIGURATION"]; motionParam->update(key.c_str(), params[key.c_str()]); std::string filename = m_configPath + CONFIG_MOTION_HORIZONTAL; m_motionConfigHorizontalRoot.SaveFile(filename.c_str()); return TRUE; } return FALSE; }