123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715 |
- #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;
- }
|