diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp index b5adda80fc9611acd8d4095e5fb4b1d69806dc39..055a86ff51c09351bfa462cf345a96dec445c4c2 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp @@ -18,6 +18,7 @@ #include <silecs-diagnostic/utils.h> #include <silecs-communication/interface/utility/XMLParser.h> +#include <silecs-communication/interface/utility/SilecsException.h> #include <exception> extern silecsModule *mysilecs; @@ -197,6 +198,11 @@ void diagnosticToolMainView::loadFiles() }while(blockListSplitted3); } } + catch (const Silecs::SilecsException& ex) + { + std::cout << "Test"<< std::endl; + Utils::logError(ui->console, ex.what()); + } catch(std::string *str) { Utils::logError(ui->console,*str); diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp index 41b1e810f83d5ba65bf199f4d900454b4896acef..e65d1e905d02546ef0bb96eefc3170181525fd11 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp @@ -114,121 +114,106 @@ void silecsModule::updatePLCRunState(Item *plcItem) Item *silecsModule::generateTree(string className, string deployFile) { - Item *root = NULL; - try{ + Utils::logInfo(messageConsole_,"Loading deploy file: " + deployFile); + XMLParser parserDeploy(deployFile,true); - Utils::logInfo(messageConsole_,"Loading deploy file: " + deployFile); - XMLParser parserDeploy(deployFile,true); - - root = new Item(silecsCluster); - if( className == HEADER_NAME ) - { - silecsCluster = silecsService->getCluster(HEADER_NAME,HEADER_VERSION); - root->setText(0,QString::fromStdString(HEADER_NAME+" v"+HEADER_VERSION)); - } - else - { - ElementXML silecsDesign = parserDeploy.getFirstElementFromXPath("/SILECS-Deploy/Controller/SilecsDesign[@silecs-design-name='" + className + "']"); - string classVersion = silecsDesign.getAttribute("silecs-design-version"); - silecsCluster = silecsService->getCluster(className,classVersion); - root->setText(0,QString::fromStdString(className+" v"+classVersion)); - } - root->setWhatsThis(0,QString::fromStdString(CLUSTER_TYPE)); - root->setLinkedObject(silecsCluster); + Item *root = new Item(silecsCluster); + if( className == HEADER_NAME ) + { + silecsCluster = silecsService->getCluster(HEADER_NAME,HEADER_VERSION); + root->setText(0,QString::fromStdString(HEADER_NAME+" v"+HEADER_VERSION)); + } + else + { + ElementXML silecsDesign = parserDeploy.getFirstElementFromXPath("/SILECS-Deploy/Controller/SilecsDesign[@silecs-design-name='" + className + "']"); + string classVersion = silecsDesign.getAttribute("silecs-design-version"); + silecsCluster = silecsService->getCluster(className,classVersion); + root->setText(0,QString::fromStdString(className+" v"+classVersion)); + } + root->setWhatsThis(0,QString::fromStdString(CLUSTER_TYPE)); + root->setLinkedObject(silecsCluster); - boost::ptr_vector<ElementXML> controllerNodes = parserDeploy.getElementsFromXPath_throwIfEmpty("/SILECS-Deploy/Controller"); - boost::ptr_vector<ElementXML>::const_iterator controllerIter; - for(controllerIter = controllerNodes.begin(); controllerIter != controllerNodes.end(); controllerIter++) + boost::ptr_vector<ElementXML> controllerNodes = parserDeploy.getElementsFromXPath_throwIfEmpty("/SILECS-Deploy/Controller"); + boost::ptr_vector<ElementXML>::const_iterator controllerIter; + for(controllerIter = controllerNodes.begin(); controllerIter != controllerNodes.end(); controllerIter++) + { + std::string plcName = controllerIter->getAttribute("host-name"); + if(plcName.compare("")==true) { - std::string plcName = controllerIter->getAttribute("host-name"); - if(plcName.compare("")==true) - { - Utils::logError(messageConsole_,"PLC name empty - will be skipped"); - break; - } - Silecs::PLC *plc; - string parameterFile = ""; - try - { - ElementXML deployUnitNode = parserDeploy.getFirstElementFromXPath("/SILECS-Deploy/Deploy-Unit"); - string deployName = deployUnitNode.getAttribute("name"); - std::size_t deployFolderPos = deployFile.find(deployName); - string deployProject = deployFile.substr(0,deployFolderPos) + deployName; - parameterFile = deployProject + "/generated/client/" + plcName + ".silecsparam"; - - Utils::logInfo(messageConsole_,"Loading parameter file: " + parameterFile); - plc = silecsCluster->getPLC(plcName,parameterFile); - } - catch(const Silecs::SilecsException& ex2) - { - Utils::logError(messageConsole_,"Error while loading "+ plcName+". "+ ex2.what()); - continue; - } + Utils::logError(messageConsole_,"PLC name empty - will be skipped"); + break; + } + Silecs::PLC *plc; + string parameterFile = ""; + try + { + ElementXML deployUnitNode = parserDeploy.getFirstElementFromXPath("/SILECS-Deploy/Deploy-Unit"); + string deployName = deployUnitNode.getAttribute("name"); + std::size_t deployFolderPos = deployFile.find(deployName); + string deployProject = deployFile.substr(0,deployFolderPos) + deployName; + parameterFile = deployProject + "/generated/client/" + plcName + ".silecsparam"; + + Utils::logInfo(messageConsole_,"Loading parameter file: " + parameterFile); + plc = silecsCluster->getPLC(plcName,parameterFile); + } + catch(const Silecs::SilecsException& ex2) + { + Utils::logError(messageConsole_,"Error while loading "+ plcName+". "+ ex2.what()); + continue; + } - // add plc on the tree - Item *plcItem = Utils::addTreeItem(root,QString::fromStdString(plcName),"",QString::fromStdString(PLC_TYPE),plc,":/Images/PLC.png"); + // add plc on the tree + Item *plcItem = Utils::addTreeItem(root,QString::fromStdString(plcName),"",QString::fromStdString(PLC_TYPE),plc,":/Images/PLC.png"); - boost::ptr_vector<ElementXML> instances; - XMLParser parseParam(parameterFile,true); - try - { - instances = parseParam.getElementsFromXPath_throwIfEmpty("/SILECS-Param/SILECS-Mapping/SILECS-Class[@name='" + className + "']/Instance"); - } - catch(const Silecs::SilecsException& ex2) - { - Utils::logError(messageConsole_,"Failed to fetch instances for class '" + className + "' from parameter-file '" + parameterFile + "':" + ex2.what()); - break; - } + boost::ptr_vector<ElementXML> instances; + XMLParser parseParam(parameterFile,true); + try + { + instances = parseParam.getElementsFromXPath_throwIfEmpty("/SILECS-Param/SILECS-Mapping/SILECS-Class[@name='" + className + "']/Instance"); + } + catch(const Silecs::SilecsException& ex2) + { + Utils::logError(messageConsole_,"Failed to fetch instances for class '" + className + "' from parameter-file '" + parameterFile + "':" + ex2.what()); + break; + } - boost::ptr_vector<ElementXML>::iterator pInstanceIter; - for(pInstanceIter = instances.begin(); pInstanceIter != instances.end(); ++pInstanceIter) - { - std::string deviceName = pInstanceIter->getAttribute("label"); - Utils::logInfo(messageConsole_,"found device: '" + deviceName + "' in parameter-file"); - Silecs::Device *device = plc->getDevice(deviceName); + boost::ptr_vector<ElementXML>::iterator pInstanceIter; + for(pInstanceIter = instances.begin(); pInstanceIter != instances.end(); ++pInstanceIter) + { + std::string deviceName = pInstanceIter->getAttribute("label"); + Utils::logInfo(messageConsole_,"found device: '" + deviceName + "' in parameter-file"); + Silecs::Device *device = plc->getDevice(deviceName); - // add device on the tree - Item *deviceItem = Utils::addTreeItem(plcItem,QString::fromStdString(deviceName),"",QString::fromStdString(DEVICE_TYPE),device,":/Images/DEV.png"); + // add device on the tree + Item *deviceItem = Utils::addTreeItem(plcItem,QString::fromStdString(deviceName),"",QString::fromStdString(DEVICE_TYPE),device,":/Images/DEV.png"); - // get register List for the current device - std::string registerList = device->getRegisterList(); - istringstream registerListSplitted(registerList); + // get register List for the current device + std::string registerList = device->getRegisterList(); + istringstream registerListSplitted(registerList); - do - { - std::string registerName; - registerListSplitted >> registerName; + do + { + std::string registerName; + registerListSplitted >> registerName; - //avoid last empty register - if(registerName.compare("")==0) break; + //avoid last empty register + if(registerName.compare("")==0) break; - Utils::logInfo(messageConsole_,"found Register: '" + registerName + "' in parameter file"); - Silecs::Register *reg = device->getRegister(registerName); + Utils::logInfo(messageConsole_,"found Register: '" + registerName + "' in parameter file"); + Silecs::Register *reg = device->getRegister(registerName); - Item *registerItem = Utils::addTreeItem(deviceItem,QString::fromStdString(registerName),"",QString::fromStdString(REGISTER_TYPE),reg,":/Images/REG.png" ); + Item *registerItem = Utils::addTreeItem(deviceItem,QString::fromStdString(registerName),"",QString::fromStdString(REGISTER_TYPE),reg,":/Images/REG.png" ); - // Set the block name - registerItem->setText(1 , QString::fromStdString(reg->getBlockName())); + // Set the block name + registerItem->setText(1 , QString::fromStdString(reg->getBlockName())); - // Color background of input and output buffer - registerItem->setBackgroundColor(2,QColor(255,255,204));//light yellow - registerItem->setBackgroundColor(3,QColor(204,255,255));//light blue + // Color background of input and output buffer + registerItem->setBackgroundColor(2,QColor(255,255,204));//light yellow + registerItem->setBackgroundColor(3,QColor(204,255,255));//light blue - }while(registerListSplitted); - } - } // END OF PLC LOOP - } - catch (const Silecs::SilecsException& ex) - { - std::string message = "getTreeroot - '"; - Utils::logError(messageConsole_, message + ex.what()); - return NULL; - } - catch(...) - { - Utils::logError(messageConsole_,"getTreeroot - Unknown Error '"); - return NULL; - } + }while(registerListSplitted); + } + } // END OF PLC LOOP // Reset the number of connected PLC this->counterConnectedPLC =0;