diff --git a/silecs-communication-cpp/.settings/language.settings.xml b/silecs-communication-cpp/.settings/language.settings.xml index 3c4fe0fc48b61ea9de4753e075d75d6c336e0510..2dca687776054ecd78adf76672ad4b3444eba097 100644 --- a/silecs-communication-cpp/.settings/language.settings.xml +++ b/silecs-communication-cpp/.settings/language.settings.xml @@ -5,7 +5,7 @@ <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> - <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-226963044723472530" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true"> + <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1822403455252202220" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true"> <language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.g++"/> </provider> @@ -16,7 +16,7 @@ <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> - <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-226963044723472530" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true"> + <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1822403455252202220" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true"> <language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.g++"/> </provider> diff --git a/silecs-communication-cpp/Makefile b/silecs-communication-cpp/Makefile index b6f166c75132a6913b75555b26a148870c4115d8..186f2ec67212190fc4d9982a485c3f27894f4d4a 100644 --- a/silecs-communication-cpp/Makefile +++ b/silecs-communication-cpp/Makefile @@ -17,13 +17,16 @@ PROJECT = silecs PRODUCT = communication VERSION = 1.0.4 -COMMON_MAKE_PATH ?= /opt/cern/buildsystem/generic/2.8.20 +SKIP_MANIFEST = TRUE +COMMON_MAKE_PATH ?= /common/home/bel/schwinn/lnx/workspace-silecs-neon/generic-makefiles +#COMMON_MAKE_PATH ?= /opt/cern/buildsystem/generic/2.8.20 # product configuration LIB_NAME = comm DBG = true -COMPILER_FLAGS = -Os -fno-strict-aliasing -fexceptions -DLINUX -DARM_FIX -DDAVE_LITTLE_ENDIAN -D_GNU_SOURCE -DMAJOR=$(MAJOR) -DMINOR=$(MINOR) -DPATCH=$(PATCH) +#COMPILER_FLAGS = -Os -fno-strict-aliasing -fexceptions -DLINUX -DARM_FIX -DDAVE_LITTLE_ENDIAN -D_GNU_SOURCE -DMAJOR=$(MAJOR) -DMINOR=$(MINOR) -DPATCH=$(PATCH) +COMPILER_FLAGS = -DMAJOR=$(MAJOR) -DMINOR=$(MINOR) -DPATCH=$(PATCH) # Comment IN/Out to enable NI-Support #COMPILER_FLAGS += -DNI_SUPPORT_ENABLED=TRUE diff --git a/silecs-communication-cpp/Makefile.dep b/silecs-communication-cpp/Makefile.dep index 09e84717b392f028ac6e1bf451cb307e82caa7ee..1cf11595b77d9147920869e190b384262cafc13b 100644 --- a/silecs-communication-cpp/Makefile.dep +++ b/silecs-communication-cpp/Makefile.dep @@ -2,7 +2,7 @@ BOOST_VERSION ?= 1.54.0 LIBXML_PATH = /usr/include/libxml2/ SNAP7_BASE = ../snap7/snap7-full -BOOST_HOME ?= /acc/local/$(CPU)/3rdparty/boost/$(BOOST_VERSION) +BOOST_HOME ?= /opt/gsi/3rdparty/boost/$(BOOST_VERSION) DEPENDENT_COMPILER_OPTIONS += -I$(LIBXML_PATH) DEPENDENT_COMPILER_OPTIONS += -I$(SNAP7_BASE)/release/Wrappers/c-cpp diff --git a/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.cpp b/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.cpp index fc9c8036630b5ffe6ec1292e798f9bc216b25d6f..419e0e3a7ee2d11004cb14597a86f452ebb134b8 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/communication/SilecsConnection.cpp @@ -118,17 +118,6 @@ namespace Silecs if (isTimeToReconnect()) { LOG((COMM|DIAG)) << "It's time to reconnect"; - if ((thePLC->synchroMode_ == FULL_SYNCHRO) || (thePLC->synchroMode_ == SLAVE_SYNCHRO)) - { - //Retentive registers synchronization is requested: - //connection is not allowed if Slave Registers are not all initialized - std::string registerNotInitialized; - if (thePLC->checkSlaveRegistersInit(registerNotInitialized) == false) - { - logError(thePLC); - throw SilecsException(__FILE__, __LINE__, DIAG_SLAVE_REGISTER_NOT_INITIALIZED, registerNotInitialized); - } - } // It's time to open the connection according to the (re)connection timing // Let's try several times with limited delay (some ms). @@ -181,15 +170,7 @@ namespace Silecs if (justConnected) { LOG((COMM|DIAG)) << "First connection - performing registers synchronization"; - if ((thePLC->synchroMode_ == FULL_SYNCHRO) || (thePLC->synchroMode_ == MASTER_SYNCHRO)) - { - thePLC->downloadMasterRegisters(); - } - - if ((thePLC->synchroMode_ == FULL_SYNCHRO) || (thePLC->synchroMode_ == SLAVE_SYNCHRO)) - { - thePLC->uploadSlaveRegisters(); - } + thePLC->updateLocalData(); } LOG((COMM|DIAG)) << "isConnected_:" << isConnected_; return isConnected_; diff --git a/silecs-communication-cpp/src/silecs-communication/interface/core/PLCRecvAction.cpp b/silecs-communication-cpp/src/silecs-communication/interface/core/PLCRecvAction.cpp index 84f0a9bd149a59aafe0e165c1b6372280cae091a..1171ae927fd4971db96f2851703b6951a95b5b7b 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/core/PLCRecvAction.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/core/PLCRecvAction.cpp @@ -229,6 +229,10 @@ namespace Silecs for(pDeviceIter = deviceCol.begin(); pDeviceIter != deviceCol.end(); ++pDeviceIter) { Device* pDev = pDeviceIter->second; + if ( !pDev->hasBlock(theBlock_->getName()) ) + { + return 0; + } if (RECV & Log::topics_) { if (pConn->isEnabled()) diff --git a/silecs-communication-cpp/src/silecs-communication/interface/core/SilecsService.h b/silecs-communication-cpp/src/silecs-communication/interface/core/SilecsService.h index 3eb7c8b4ad8718aacb943d589fd9d9dbd36845c8..d6ade6bb5b1f5217a2880314d89839cbd6aedf14 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/core/SilecsService.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/core/SilecsService.h @@ -34,9 +34,11 @@ namespace Silecs // Register and Block access types typedef enum { - Output, Input, InOut + Output, + Input, + InOut } AccessType; - /// @endcond + /// @endcond READ-ONLY / WRITE-ONLY / READ-WRITE /*! * \brief Defines the category of the SILECS Exception. diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsCluster.cpp b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsCluster.cpp index 843649fbe94e791c6f923558929c0f26960dd911..fee499ed166a0ab87f5ff5658de31865ed0c6cda 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsCluster.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsCluster.cpp @@ -116,20 +116,15 @@ namespace Silecs //At first, check this class/version is already deployed (one PLC in the Cluster at least) if (plcMap_.size() > 0) { // Retrieve the block-map from the first PLC (same for each of them) - blockMapType blockMap = plcMap_.begin()->second->getBlockMap(); - - blockMapType::iterator blockMapIter; - //Retrieve the name of each Block object of the Map that has selected access-type - for(blockMapIter = blockMap.begin(); blockMapIter != blockMap.end(); ++blockMapIter) - { Block* pBlock = blockMapIter->second; - if (pBlock->getAccessType() == accessType) - { std::string blockName = pBlock->getName(); - //Do not append the same name twice (read-write Block has two instances) - if (blockList.find(blockName) == std::string::npos) - { //Do not insert blank before the first name - if (!blockList.empty()) blockList.append(" "); - blockList.append(blockName); - } + blockVectorType blockCol = plcMap_.begin()->second->getBlockCol(); + + blockVectorType::iterator block; + for(block = blockCol.begin(); block != blockCol.end(); ++block) + { + if ((*block)->getAccessType() == accessType) + { + std::string blockName = (*block)->getName(); + blockList.append(blockName + " "); } } } @@ -229,12 +224,14 @@ namespace Silecs // Schedule task on each PLC using asynchronous call for parallelism for(plcMapIter = plcMap_.begin(); plcMapIter != plcMap_.end(); ++plcMapIter) - { plcMapIter->second->sendAsync(blockName); + { + plcMapIter->second->sendAsync(blockName); } // then wait for the completion of each PLC thread (finally, maximum delay will be the longest one). for(plcMapIter = plcMap_.begin(); plcMapIter != plcMap_.end(); ++plcMapIter) - { plcMapIter->second->waitAsync(); + { + plcMapIter->second->waitAsync(); } } diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsDevice.cpp b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsDevice.cpp index e609f60d681c1e6ad4851f71bcf05c60523226d8..c38082c78b399aa08365f950ade05f667163a048 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsDevice.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsDevice.cpp @@ -29,6 +29,8 @@ #include <silecs-communication/interface/equipment/CNVRegister.h> +#include <sstream> + namespace Silecs { Device::Device(PLC* thePLC, std::string deviceName, std::string deviceAddress, boost::ptr_vector<ElementXML>& blockNodes) : thePLC_ (thePLC) @@ -37,12 +39,13 @@ namespace Silecs label_ = deviceName; StringUtilities::fromString(address_,deviceAddress ); - LOG(ALLOC) << "Device (create): " << label_; + LOG(ALLOC) << "Creating SilecsDevice: " << label_; boost::ptr_vector<ElementXML>::const_iterator blockIter; for(blockIter = blockNodes.begin(); blockIter != blockNodes.end(); blockIter++) { std::string blockName = blockIter->getAttribute("name"); + LOG(ALLOC) << "Adding Block to Device: " << blockName; AccessType accessType = Block::whichAccessType(blockIter->getAttribute("mode")); std::vector< boost::shared_ptr<ElementXML> > registerNodes = blockIter->childList_; instantiateRegisters(blockName, accessType, registerNodes); @@ -190,10 +193,14 @@ namespace Silecs void Device::keepMasterRegisters(std::string blockName) { - blockRegisterMapType::iterator iter = blockRegisterMap_.find(blockName); - if (iter == blockRegisterMap_.end()) - { throw SilecsException(__FILE__, __LINE__, PARAM_UNKNOWN_BLOCK_NAME, blockName); - } + blockRegisterMapType::iterator iter; + iter = blockRegisterMap_.find(blockName); + if( iter == blockRegisterMap_.end() ) + { + std::ostringstream errorMessage; + errorMessage << "Block not found! The block '" << blockName << "' does not exist on the device '" << label_ << "'."; + throw SilecsException(__FILE__, __LINE__,errorMessage.str()); + } for (unsigned int i=0; i<iter->second.size(); i++) { Register* pReg = iter->second[i]; @@ -202,7 +209,21 @@ namespace Silecs } Block* Device::getBlock(const std::string blockName, AccessType accessType) - { return thePLC_->getBlock(blockName, accessType); + { + if( ! hasBlock(blockName) ) + { + std::ostringstream errorMessage; + errorMessage << "Block not found! The block '" << blockName << "' does not exist on the device '" << label_ << "'."; + throw SilecsException(__FILE__, __LINE__,errorMessage.str()); + } + return thePLC_->getBlock(blockName, accessType); + } + + bool Device::hasBlock(const std::string blockName) + { + blockRegisterMapType::iterator iter; + iter = blockRegisterMap_.find(blockName); + return ( iter != blockRegisterMap_.end() ); } diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsDevice.h b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsDevice.h index 11014b115680cb7e2f49ad7cd9259cb2d52e177d..1e130c03146e9e253e5708777b6528cc8886462f 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsDevice.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsDevice.h @@ -147,6 +147,8 @@ namespace Silecs */ Block* getBlock(const std::string blockName, AccessType accessType = InOut); + bool hasBlock(const std::string blockName); + /*! * \fn importRegisters * \brief Extract all the concerned registers data of that device from a given block and set the registers value. diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp index 9f9f1ad82eae8e6b55d732ad67ef34d06ea51953..7b8f12431356267aaebb4cf2fb388cd4932678fe 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp @@ -92,16 +92,10 @@ namespace Silecs deviceCol_.clear(); // Remove the Block instances related to this PLC - blockMapType::iterator pBlockIter; - for(pBlockIter = blockMap_.begin(); pBlockIter != blockMap_.end(); ++pBlockIter) - { delete pBlockIter->second; - pBlockIter->second = NULL; + blockVectorType::iterator pBlockIter; + for(pBlockIter = blockCol_.begin(); pBlockIter != blockCol_.end(); ++pBlockIter) + { delete *pBlockIter; } - blockMap_.clear(); - - // Clear Blocks collection used for retentive registers synchronization - masterInputBlockCol_.clear(); - slaveOutputBlockCol_.clear(); } void PLC::connect(SynchroMode synchroMode, bool connectNow, bool compareChecksums) @@ -234,76 +228,27 @@ namespace Silecs std::string PLC::getLocalDate() { return localDate_; } unsigned long PLC::getLocalChecksum() { return localChecksum_; } - - void PLC::downloadMasterRegisters() + void PLC::updateLocalData() { - if (masterInputBlockCol_.size()) - { - if (DEBUG & Log::topics_) LOG(COMM) << "Download Master registers of " << name_ << ":" << theCluster_->getClassName() << "/v" << theCluster_->getClassVersion(); - } - - // Read all the Master Blocks (containing 1 MASTER register at least) - // to update retentive values on client side. - for (unsigned int i=0; i<masterInputBlockCol_.size(); i++) + blockVectorType::iterator blockIter; + for (blockIter = blockCol_.begin();blockIter!= blockCol_.end(); blockIter ++) { - Block* pBlock = masterInputBlockCol_[i]; - LOG(COMM) << "Attempt to download Block: " << pBlock->getName(); - pBlock->getTask()->execute(allDevicesSynchronization_); - - // Then update local RW Master registers with values coming from PLC source - if (pBlock->hasOutputAccess()) - { // Perform keepMasterRegisters for each device of the Cluster. + if ((*blockIter)->hasInputAccess()) + { deviceVectorType::iterator pDeviceIter; for(pDeviceIter = deviceCol_.begin(); pDeviceIter != deviceCol_.end(); ++pDeviceIter) { - pDeviceIter->second->keepMasterRegisters(pBlock->getName()); - } - } - } - } - - - bool PLC::checkSlaveRegistersInit(std::string& registerNotInitialized) - { - //We should not allow update Slave Registers if only one of them has never been setted (not initialized) - //for each Block that contains Slave register(s) - for (unsigned int i=0; i<slaveOutputBlockCol_.size(); i++) - { //for each Device of the collection - for(deviceVectorType::iterator pDeviceIter = deviceCol_.begin(); pDeviceIter != deviceCol_.end(); ++pDeviceIter) - { //for each register of this block - std::vector<Register*>& registerCol = pDeviceIter->second->getRegisterCollection(slaveOutputBlockCol_[i]->getName()); - for (unsigned int i=0; i<registerCol.size(); i++) - { //check that Slave register is initialized and stop the connection process if needed - Register* pReg = registerCol[i]; - if ((pReg->getSynchroType() == Slave) && (pReg->isInitialized() == false)) - { //Slave registers synchronization is not allowed - registerNotInitialized = pDeviceIter->first + "/" + pReg->getName(); - return false; - } + if( pDeviceIter->second->hasBlock((*blockIter)->getName())) + { + LOG(COMM) << "Updating block '" << (*blockIter)->getName() << "' for device '" << pDeviceIter->second->getLabel()<< "'"; + //pDeviceIter->second->keepMasterRegisters(pBlock->getName()); + pDeviceIter->second->recv((*blockIter)->getName()); + } } } } - return true; } - - void PLC::uploadSlaveRegisters() - { - if (slaveOutputBlockCol_.size()) - { // There are Slave registers and they are all well-initialized, PLC memory can be updated with their local values - LOG((COMM|DIAG)) << "Upload Slave registers to " << name_ << ":" << theCluster_->getClassName() << "/v" << theCluster_->getClassVersion(); - } - - // Write all the Slave Blocks (containing 1 SLAVE register at least) - // to update retentive values on PLC side. - for (unsigned int i=0; i<slaveOutputBlockCol_.size(); i++) - { - LOG(COMM) << "Attempt to upload Block: " << slaveOutputBlockCol_[i]->getName(); - slaveOutputBlockCol_[i]->getTask()->execute(allDevicesSynchronization_); - } - } - - int PLC::recvUnitCode(UnitCodeType& dataStruct) { return getConnection()->readUnitCode(this, dataStruct); @@ -433,9 +378,9 @@ namespace Silecs for(blockIter = blockNodes.begin(); blockIter != blockNodes.end(); blockIter++) { - std::string blockNameFull; //"block-name" + "access-type" std::string blockName = (*blockIter).getAttribute("name"); AccessType accessType = Block::whichAccessType((*blockIter).getAttribute("mode")); + LOG((DIAG)) << "The block '" << blockName << " will be created with access-type: '" << accessType << "'."; Block* pBlock = 0; // Instantiate Input blocks ------------------------------------------------------ @@ -444,18 +389,15 @@ namespace Silecs if(whichPLCBrand(brand_)==Ni) #ifdef NI_SUPPORT_ENABLED - pBlock = new CNVInputBlock(this, (*pBlockElCol)[i], accessType, pCurrentBlockElCol); + pBlock = new CNVInputBlock(this, (*pBlockElCol)[i], accessType); #else throw SilecsException(__FILE__, __LINE__, "Support for NI-Devices is disabled"); #endif else - pBlock = new InputBlock(this,*blockIter, accessType); - blockNameFull = blockName + Block::whichAccessType(Input); + pBlock = new InputBlock(this,*blockIter, Input); + blockCol_.push_back(pBlock); // FIXME: Currently a block is instatiated twice if it is READ+WRITE - //Store references of Input Master blocks for retentive registers synchronization - if (pBlock->hasMasterRegister()) masterInputBlockCol_.push_back(pBlock); } - // Instantiate Output blocks ------------------------------------------------------ if (Service::withOutputAccess(accessType)) //Output or InOut accessprotocol { //Instantiate the block, forcing it to Output access for InOut case @@ -463,21 +405,17 @@ namespace Silecs if(whichPLCBrand(brand_)==Ni) #ifdef NI_SUPPORT_ENABLED - pBlock = new CNVOutputBlock(this, (*pBlockElCol)[i], accessType, pCurrentBlockElCol); + pBlock = new CNVOutputBlock(this, (*pBlockElCol)[i], accessType); #else throw SilecsException(__FILE__, __LINE__, "Support for NI-Devices is disabled"); #endif else - pBlock = new OutputBlock(this, *blockIter, accessType); + pBlock = new OutputBlock(this, *blockIter, Output); + blockCol_.push_back(pBlock); // FIXME: Currently a block is instatiated twice if it is READ+WRITE + } - blockNameFull = blockName + Block::whichAccessType(Output); - //Store references of Ouput Slave blocks for retentive registers synchronization - if (pBlock->hasSlaveRegister()) slaveOutputBlockCol_.push_back(pBlock); - } - //Store reference of the block for general communication purpose - blockMap_.insert(std::make_pair(blockNameFull, pBlock)); } //for blocks } //for classes } @@ -565,50 +503,19 @@ namespace Silecs Block* PLC::getBlock(const std::string blockName, AccessType accessType) { - blockMapType::iterator pBlockMapIter; - - switch(accessType) - { case Input: - //Doest the block exist with the Input access-type? - pBlockMapIter = blockMap_.find(blockName + Block::whichAccessType(Input)); - if (pBlockMapIter == blockMap_.end()) - { - //No! then check if it exists with other access-type - pBlockMapIter = blockMap_.find(blockName + Block::whichAccessType(Output)); - if (pBlockMapIter == blockMap_.end()) - //This block does not exist at all? - throw SilecsException(__FILE__, __LINE__, PARAM_UNKNOWN_BLOCK_NAME, blockName); - else - //This block exists but with the opposite access-type - throw SilecsException(__FILE__, __LINE__, PARAM_ACCESS_TYPE_MISMATCH, blockName); - } - break; - case Output: - //Doest the block exist with the Output access-type? - pBlockMapIter = blockMap_.find(blockName + Block::whichAccessType(Output)); - if (pBlockMapIter == blockMap_.end()) - { - //No! then check if it exists with other access-type - pBlockMapIter = blockMap_.find(blockName + Block::whichAccessType(Input)); - if (pBlockMapIter == blockMap_.end()) - //This block does not exist at all? - throw SilecsException(__FILE__, __LINE__, PARAM_UNKNOWN_BLOCK_NAME, blockName); - else - //This block exists but with the opposite access-type - throw SilecsException(__FILE__, __LINE__, PARAM_ACCESS_TYPE_MISMATCH, blockName); - } - break; - default: - //should never occure! - throw SilecsException(__FILE__, __LINE__, (int)UNEXPECTED_ERROR, "Input or Output argument is required!"); - } - - //block with expected access-type has been found - return pBlockMapIter->second; + blockVectorType::iterator block; + for( block = blockCol_.begin(); block != blockCol_.end(); block++) + { + if( (*block)->getName() == blockName && (*block)->getAccessType() == accessType) + return *block; + } + std::ostringstream error; + error << "The block '" << blockName << "' was not found for the access type: '" << Block::whichAccessType(accessType) << "'"; + throw SilecsException(__FILE__, __LINE__, error.str()); } - blockMapType& PLC::getBlockMap() { return blockMap_; } + blockVectorType& PLC::getBlockCol() { return blockCol_; } PLCBrand PLC::whichPLCBrand(std::string brand) diff --git a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h index d969a79a973656154803e26ab58e864614aca28e..9f0b73d6f6555c285e024f1feb97a847b4901957 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h @@ -33,7 +33,6 @@ namespace Silecs /// @cond typedef std::vector<std::pair<std::string, Device*> > deviceVectorType; - typedef std::map<std::string, Block*> blockMapType; typedef std::vector<Block*> blockVectorType; typedef std::map<std::string, Connection*> connMapType; @@ -386,27 +385,7 @@ namespace Silecs inline PLCSystem& getSystemID() { return systemID_; } inline ProtocolMode& getProtocolID() { return protocolModeID_; } - /*! - * \fn downloadMasterRegisters - * \brief This method is used for Retentive registers synchronization on each PLC (re)connection. - * Connects PLC and acquires all Input blocks which contain at least one MASTER retentive register. - */ - void downloadMasterRegisters(); - - /*! - * \fn checkSlaveRegistersInit - * \brief This method checks that all of the retentive Slave Registers are initialized and return - * false if not. For obvious security reason, immediate connection of the PLC is not allowed in this case. - * \param registerNotInitialized receive first name of the register that is not initialized yet. - */ - bool checkSlaveRegistersInit(std::string& registerNotInitialized); - - /*! - * \fn uploadSlaveRegisters - * \brief This method is used for Retentive registers synchronization on each PLC (re)connection. - * Connects PLC and transmits all Output blocks which contain at least one SLAVE retentive register. - */ - void uploadSlaveRegisters(); + void updateLocalData(); /*! * \fn updateHeader @@ -461,7 +440,7 @@ namespace Silecs * \brief Provides the map of the Block objects attached to the underlying PLC(s) * \return Block object map */ - blockMapType& getBlockMap(); + blockVectorType& getBlockCol(); /*! * \fn updateStatus @@ -521,11 +500,7 @@ namespace Silecs deviceVectorType deviceCol_; /// Block collection of the PLC listed by name. - blockMapType blockMap_; - - /// Store references of Slave and Master Blocks for retentive registers synchronization - blockVectorType masterInputBlockCol_; - blockVectorType slaveOutputBlockCol_; + blockVectorType blockCol_; /// Object to manage the plc communication /* By default, we instantiate 1 connection (2 channels: r/w) per PLC/Cluster diff --git a/silecs-diagnostic-cpp/.settings/language.settings.xml b/silecs-diagnostic-cpp/.settings/language.settings.xml index 1d5ad43cdb798e5d5376058ed49bf392988ac736..d9feb0808fea34b7dfb77fa150accb2b3fc1ff0c 100644 --- a/silecs-diagnostic-cpp/.settings/language.settings.xml +++ b/silecs-diagnostic-cpp/.settings/language.settings.xml @@ -5,7 +5,7 @@ <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> - <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-226963044723472530" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true"> + <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1822403455252202220" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true"> <language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.g++"/> </provider> @@ -16,7 +16,7 @@ <provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/> <provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/> <provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/> - <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-226963044723472530" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true"> + <provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1822403455252202220" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true"> <language-scope id="org.eclipse.cdt.core.gcc"/> <language-scope id="org.eclipse.cdt.core.g++"/> </provider> diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp index f006dadee3f0396a0376b4b0613b0dfb2cdddec5..142acd2701653acb4f862b44df556a5ce513fe74 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.cpp @@ -117,11 +117,11 @@ void diagnosticToolMainView::resetGUI() } catch(std::string *str) { - Utils::logError(ui->console,QString::fromStdString(*str)); + Utils::logError(ui->console,*str); } catch(std::exception& ex) { - Utils::logError(ui->console,QString::fromStdString(ex.what())); + Utils::logError(ui->console,ex.what()); } catch(...) { @@ -139,7 +139,7 @@ void diagnosticToolMainView::loadFiles() mysilecs = new silecsModule(generateLogTopics(), ui->console); ui->treeWidget->clear(); - Item * root = mysilecs->generateTree(designName.toStdString(),deployFile.toStdString()); + Item * root = mysilecs->generateTree(designName,deployFile); if(root == NULL) { @@ -157,7 +157,7 @@ void diagnosticToolMainView::loadFiles() std::string writeBlockList = cluster->getBlockList(Output)+" "+cluster->getBlockList(InOut); istringstream blockListSplitted(writeBlockList); - Utils::logInfo(ui->console,"[Info:] - " + QString::fromStdString(writeBlockList)); + Utils::logInfo(ui->console, writeBlockList); do { std::string blockName; @@ -171,7 +171,7 @@ void diagnosticToolMainView::loadFiles() // Receive combo box std::string readBlockList = cluster->getBlockList(Input)+" "+cluster->getBlockList(InOut); istringstream blockListSplitted2(readBlockList); - Utils::logInfo(ui->console,QString::fromStdString(readBlockList)); + Utils::logInfo(ui->console,readBlockList); do { std::string blockName; @@ -185,7 +185,7 @@ void diagnosticToolMainView::loadFiles() // Send combo box std::string copyBlockList = cluster->getBlockList(InOut); istringstream blockListSplitted3(copyBlockList); - Utils::logInfo(ui->console, QString::fromStdString(copyBlockList)); + Utils::logInfo(ui->console, copyBlockList); do { std::string blockName; @@ -195,24 +195,15 @@ void diagnosticToolMainView::loadFiles() ui->copyComboBox->addItem(QString::fromStdString(blockName)); }while(blockListSplitted3); - - // Disable opening button - // close must be pressed before opening again - //GSI-Hack - file dialog - //ui->openButton->setEnabled(false); - - - //ui->closeButton->setEnabled(true); - } } catch(std::string *str) { - Utils::logError(ui->console,QString::fromStdString(*str)); + Utils::logError(ui->console,*str); } catch(std::exception& ex) { - Utils::logError(ui->console,QString::fromStdString(ex.what())); + Utils::logError(ui->console,ex.what()); } catch (...) //catch any exception { @@ -222,6 +213,8 @@ void diagnosticToolMainView::loadFiles() void diagnosticToolMainView::on_connectButton_clicked() { + ui->console->clear(); + // Connect button // Get current Item @@ -265,11 +258,11 @@ void diagnosticToolMainView::on_connectButton_clicked() } catch(std::string *str) { - Utils::logError(ui->console,QString::fromStdString(*str)); + Utils::logError(ui->console,*str); } catch(std::exception& ex) { - Utils::logError(ui->console,QString::fromStdString(ex.what())); + Utils::logError(ui->console,ex.what()); } catch(...) { @@ -280,6 +273,8 @@ void diagnosticToolMainView::on_connectButton_clicked() void diagnosticToolMainView::on_disconnectButton_clicked() { + ui->console->clear(); + // Disconnect button try { @@ -321,11 +316,11 @@ void diagnosticToolMainView::on_disconnectButton_clicked() } catch(std::string *str) { - Utils::logError(ui->console,QString::fromStdString(*str)); + Utils::logError(ui->console,*str); } catch(std::exception& ex) { - Utils::logError(ui->console,QString::fromStdString(ex.what())); + Utils::logError(ui->console,ex.what()); } catch(...) { @@ -335,6 +330,7 @@ void diagnosticToolMainView::on_disconnectButton_clicked() void diagnosticToolMainView::on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous) { + ui->console->clear(); (void)current; // to suppress unused warning (void)previous; // to suppress unused warning try @@ -382,7 +378,8 @@ void diagnosticToolMainView::on_treeWidget_currentItemChanged(QTreeWidgetItem *c if(!currentItem->whatsThis(0).compare(QString::fromStdString(DEVICE_TYPE))) { qDebug() << "Device selected"; - Utils::displayDeviceInformation(((Silecs::Device*)(currentItem->getLinkedObject())),ui->InformationMessage); + Silecs::Device* device = (Silecs::Device*)(currentItem->getLinkedObject()); + Utils::displayDeviceInformation(device,ui->InformationMessage); bool connected = ((Silecs::PLC*)dynamic_cast<Item*>(currentItem->parent())->getLinkedObject())->isConnected(); @@ -432,11 +429,11 @@ void diagnosticToolMainView::on_treeWidget_currentItemChanged(QTreeWidgetItem *c } catch(std::string *str) { - Utils::logError(ui->console,QString::fromStdString(*str)); + Utils::logError(ui->console,*str); } catch(std::exception& ex) { - Utils::logError(ui->console,QString::fromStdString(ex.what())); + Utils::logError(ui->console,ex.what()); } catch(...) { @@ -495,6 +492,7 @@ void diagnosticToolMainView::markItemNotEdiable(QTreeWidgetItem *item) void diagnosticToolMainView::on_treeWidget_doubleClicked(const QModelIndex &index) { + ui->console->clear(); (void)index; // to suppress unused warning try { @@ -553,11 +551,11 @@ void diagnosticToolMainView::on_treeWidget_doubleClicked(const QModelIndex &inde } catch(std::string *str) { - Utils::logError(ui->console,QString::fromStdString(*str)); + Utils::logError(ui->console,*str); } catch(std::exception& ex) { - Utils::logError(ui->console,QString::fromStdString(ex.what())); + Utils::logError(ui->console,ex.what()); } catch(...) { @@ -567,6 +565,7 @@ void diagnosticToolMainView::on_treeWidget_doubleClicked(const QModelIndex &inde void diagnosticToolMainView::on_sendButton_clicked() { + ui->console->clear(); try{ Item *currentItem = dynamic_cast<Item*>(ui->treeWidget->currentItem()); @@ -625,7 +624,7 @@ void diagnosticToolMainView::on_sendButton_clicked() int ret = plc->send(ui->sendComboBox->currentText().toStdString()); if(ret != 0) { - Utils::logError(ui->console,QString::fromStdString("Error while receiving the block to the selected device")); + Utils::logError(ui->console,"Error while receiving the block to the selected device"); return; } logCommunicationSuccess(mytimer.elapsed()); @@ -649,10 +648,11 @@ void diagnosticToolMainView::on_sendButton_clicked() //send and mesure sending time QTime mytimer; mytimer.start(); + Utils::logInfo(ui->console,"Sending data to device: '" + device->getLabel() + "', block: '" + ui->sendComboBox->currentText().toStdString() + "'"); int ret = device->send(ui->sendComboBox->currentText().toStdString()); if(ret != 0) { - Utils::logError(ui->console,QString::fromStdString("Error while receiving the block to the selected device")); + Utils::logError(ui->console,"Error while receiving the block to the selected device"); return; } logCommunicationSuccess( mytimer.elapsed()); @@ -666,11 +666,11 @@ void diagnosticToolMainView::on_sendButton_clicked() } catch(std::string *str) { - Utils::logError(ui->console,QString::fromStdString(*str)); + Utils::logError(ui->console,*str); } catch(std::exception& ex) { - Utils::logError(ui->console,QString::fromStdString(ex.what())); + Utils::logError(ui->console,ex.what()); } catch(...) { @@ -680,6 +680,7 @@ void diagnosticToolMainView::on_sendButton_clicked() void diagnosticToolMainView::on_receiveButton_clicked() { + ui->console->clear(); // Receive Button try{ Item *currentItem = dynamic_cast<Item*>(ui->treeWidget->currentItem()); @@ -692,16 +693,15 @@ void diagnosticToolMainView::on_receiveButton_clicked() Utils::logError(ui->console,"Please select a device"); return; } - this->receiveDevice(blockName,currentItem); } catch(std::string *str) { - Utils::logError(ui->console,QString::fromStdString(*str)); + Utils::logError(ui->console,*str); } catch(std::exception& ex) { - Utils::logError(ui->console,QString::fromStdString(ex.what())); + Utils::logError(ui->console,ex.what()); } catch(...) { @@ -712,10 +712,11 @@ void diagnosticToolMainView::on_receiveButton_clicked() void diagnosticToolMainView::on_classNameComboBox_currentIndexChanged(const QString &arg1) { - if( !deployFile.isEmpty() ) + ui->console->clear(); + if( !deployFile.empty() ) { ui->DesignName->setText(""); - designName = ui->classNameComboBox->currentText(); + designName = ui->classNameComboBox->currentText().toStdString(); loadFiles(); } return; @@ -723,20 +724,21 @@ void diagnosticToolMainView::on_classNameComboBox_currentIndexChanged(const QStr void diagnosticToolMainView::on_loadDeployButton_clicked() { - deployFile = QFileDialog::getOpenFileName(this, tr("Deploy to Open"), "" ,tr("Silecs Deploy Files (*.silecsdeploy)")); - if( !deployFile.isEmpty() ) + ui->console->clear(); + deployFile = QFileDialog::getOpenFileName(this, tr("Deploy to Open"), "" ,tr("Silecs Deploy Files (*.silecsdeploy)")).toStdString(); + if( !deployFile.empty() ) { - ui->DeployName->setText(deployFile); + ui->DeployName->setText(QString::fromStdString(deployFile)); ui->DesignName->setText("pick a design"); fillClassNameComboBox(); } return; } -void diagnosticToolMainView::setDeployFile(QString file) +void diagnosticToolMainView::setDeployFile(std::string file) { deployFile = file; - ui->DeployName->setText(deployFile); + ui->DeployName->setText(QString::fromStdString(deployFile)); ui->DesignName->setText("pick a design"); fillClassNameComboBox(); } @@ -744,7 +746,7 @@ void diagnosticToolMainView::setDeployFile(QString file) void diagnosticToolMainView::fillClassNameComboBox() { Utils::logInfo(ui->console,"Loading deploy file: " + deployFile); - XMLParser parserDeploy(deployFile.toStdString(),true); + XMLParser parserDeploy(deployFile,true); boost::ptr_vector<ElementXML> classNodes = parserDeploy.getElementsFromXPath_throwIfEmpty("/SILECS-Deploy/Controller/SilecsDesign"); if(classNodes.size() == 0) { @@ -806,22 +808,23 @@ void diagnosticToolMainView::receiveDevice(std::string blockName, Item* deviceIt //receive device and mesure sending time QTime mytimer; mytimer.start(); + Utils::logInfo(ui->console,"Receiving data from device: '" + device->getLabel() + "', block: '" + blockName + "'"); int ret = device->recv(blockName); int elapsedTime = mytimer.elapsed(); if(ret != 0) { - Utils::logError(ui->console,QString::fromStdString("Error while receiving the block to the selected device")); + Utils::logError(ui->console,"Error while receiving the block to the selected device"); return; } logBlockReceived(blockName, elapsedTime); } catch(std::string *str) { - Utils::logError(ui->console,QString::fromStdString(*str)); + Utils::logError(ui->console,*str); } catch(std::exception& ex) { - Utils::logError(ui->console,QString::fromStdString(ex.what())); + Utils::logError(ui->console,ex.what()); } catch (...) { @@ -844,17 +847,17 @@ void diagnosticToolMainView::periodicReceiveDevice() } catch(std::string *str) { - Utils::logError(ui->console,"error while receiving block: " + QString::fromStdString(blockNameForPeriodicReceive)); - Utils::logError(ui->console,QString::fromStdString(*str)); + Utils::logError(ui->console,"error while receiving block: " + blockNameForPeriodicReceive); + Utils::logError(ui->console,*str); } catch(std::exception& ex) { - Utils::logError(ui->console,"error while receiving block: " + QString::fromStdString(blockNameForPeriodicReceive)); - Utils::logError(ui->console,QString::fromStdString(ex.what())); + Utils::logError(ui->console,"error while receiving block: " + blockNameForPeriodicReceive); + Utils::logError(ui->console,ex.what()); } catch (...) { - Utils::logError(ui->console,"error while receiving block: " + QString::fromStdString(blockNameForPeriodicReceive)); + Utils::logError(ui->console,"error while receiving block: " + blockNameForPeriodicReceive); Utils::logError(ui->console,"unknown error in diagnosticToolMainView::periodicReceiveDevice"); } mysilecs->updateDeviceItem(currentItemForPeriodicReceive,true); @@ -862,6 +865,7 @@ void diagnosticToolMainView::periodicReceiveDevice() void diagnosticToolMainView::on_periodicReceiveButton_toggled(bool checked) { + ui->console->clear(); if(checked) { // receive periodic Button @@ -928,6 +932,7 @@ void diagnosticToolMainView::on_periodicReceiveButton_toggled(bool checked) void diagnosticToolMainView::on_copyButton_clicked() { + ui->console->clear(); // copy input value to output Button try{ diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.h b/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.h index a96ef5239bdcccc9db49b7f883ae1e29eb29a01a..eaf4f2391ef465546c4259de7a89ae185e092c58 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.h +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/diagnostictoolmainview.h @@ -43,7 +43,7 @@ public: explicit diagnosticToolMainView(QWidget *parent = 0); ~diagnosticToolMainView(); - void setDeployFile(QString file); + void setDeployFile(std::string file); private slots: @@ -91,8 +91,8 @@ private slots: private: // GSI-Hack - load directly from file - QString designName; - QString deployFile; + std::string designName; + std::string deployFile; void resetGUI(); void loadFiles(); diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/main.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/main.cpp index 1ac7fa0fe457aa0954e090fd5b579e5a8dc16516..f9b9106cbc3787e0b5a2efc9094875160124eb78 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/main.cpp +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/main.cpp @@ -63,7 +63,7 @@ std::string UserName; if (argc >= 3) // an argument was passed { if (strcmp(argv[1],"-d") == 0) - mainWin.setDeployFile(QString::fromStdString(argv[2])); + mainWin.setDeployFile(argv[2]); } I::sleep(SPLASH_SCREEN_TIME); diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp index 5567b14f5f03183b2cbc34332713e6a09826f5f6..a716747c3f9534079994c7f72a5982a4c350e4c6 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/silecsmodule.cpp @@ -43,7 +43,7 @@ silecsModule::silecsModule(std::string logTopics, QTextBrowser *messageConsole): } else { - Utils::logInfo(messageConsole_,"the following log topics will be used: " + QString::fromStdString(logTopics)); + Utils::logInfo(messageConsole_,"the following log topics will be used: " + logTopics); char *a = new char[logTopics.size()+1]; a[logTopics.size()]=0; memcpy(a,logTopics.c_str(),logTopics.size()); @@ -84,7 +84,7 @@ Item *silecsModule::generateTree(string className, string deployFile) Item *root = NULL; try{ - Utils::logInfo(messageConsole_,"Loading deploy file: " + QString::fromStdString(deployFile)); + Utils::logInfo(messageConsole_,"Loading deploy file: " + deployFile); XMLParser parserDeploy(deployFile,true); ElementXML silecsDesign = parserDeploy.getFirstElementFromXPath("/SILECS-Deploy/Controller/SilecsDesign[@silecs-design-name='" + className + "']"); @@ -120,12 +120,12 @@ Item *silecsModule::generateTree(string className, string deployFile) string deployProject = deployFile.substr(0,deployFolderPos) + deployName; string parameterFile = deployProject + "/generated/client/" + plcName + ".silecsparam"; - Utils::logInfo(messageConsole_,"Loading parameter file: " + QString::fromStdString(parameterFile)); + Utils::logInfo(messageConsole_,"Loading parameter file: " + parameterFile); plc = silecsCluster->getPLC(plcName,parameterFile); } catch(const Silecs::SilecsException& ex2) { - Utils::logError(messageConsole_,"Error while loading "+QString::fromStdString(plcName)+". "+QString::fromStdString(ex2.what())); + Utils::logError(messageConsole_,"Error while loading "+ plcName+". "+ ex2.what()); continue; } @@ -142,7 +142,7 @@ Item *silecsModule::generateTree(string className, string deployFile) std::string deviceName = pDeviceIter->first; Silecs::Device *device = pDeviceIter->second; - Utils::logInfo(messageConsole_,"found device: '" + QString::fromStdString(deviceName) + "' in parameter-file"); + Utils::logInfo(messageConsole_,"found device: '" + deviceName + "' in parameter-file"); // add device on the tree Item *deviceItem = Utils::addTreeItem(plcItem,QString::fromStdString(deviceName),"",QString::fromStdString(DEVICE_TYPE),device,":/Images/DEV.png"); @@ -155,10 +155,11 @@ Item *silecsModule::generateTree(string className, string deployFile) { std::string registerName; registerListSplitted >> registerName; - Utils::logInfo(messageConsole_,"found Register: '" + QString::fromStdString(registerName) + "' in parameter file"); + //avoid last empty register if(registerName.compare("")==0) break; + 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" ); @@ -176,7 +177,8 @@ Item *silecsModule::generateTree(string className, string deployFile) } catch (const Silecs::SilecsException& ex) { - Utils::logError(messageConsole_,"getTreeroot - '" + QString::fromStdString(ex.what())); + std::string message = "getTreeroot - '"; + Utils::logError(messageConsole_, message + ex.what()); return NULL; } catch(...) @@ -900,6 +902,8 @@ void silecsModule::updateClusterItem(Item *Cluster,bool updateInputBufferOnly) void silecsModule::updatePLCItem(Item *PLCItem,bool updateInputBufferOnly) { + Silecs::PLC* plc = (Silecs::PLC*)(PLCItem->getLinkedObject()); + Utils::logInfo(messageConsole_,std::string("updating controller: '") + plc->getName() + "'"); int numberOfdevice = PLCItem->childCount(); for(int deviceIndex=0; deviceIndex<numberOfdevice;deviceIndex++) { @@ -911,6 +915,7 @@ void silecsModule::updatePLCItem(Item *PLCItem,bool updateInputBufferOnly) void silecsModule::updateDeviceItem(Item *deviceItem,bool updateInputBufferOnly) { Silecs::Device *device = (Silecs::Device*)deviceItem->getLinkedObject(); + Utils::logInfo(messageConsole_,std::string("updating device: '") + device-> getLabel() + "'"); int numberOfRegisters = deviceItem->childCount(); for(int regIndex=0;regIndex<numberOfRegisters;regIndex++) @@ -918,6 +923,7 @@ void silecsModule::updateDeviceItem(Item *deviceItem,bool updateInputBufferOnly) // Get the register Item in the tree view Item *regItem = dynamic_cast<Item*>(deviceItem->child(regIndex)); Silecs::Register *reg = device->getRegister(regItem->text(0).toStdString()); + Utils::logInfo(messageConsole_,"updating register: '" + reg->getName() + "'of device: '" + device-> getLabel() + "'" ); // PLC values try @@ -945,7 +951,7 @@ void silecsModule::updateDeviceItem(Item *deviceItem,bool updateInputBufferOnly) regItem->setText(2 , "?"); std::ostringstream message; message << "Impossible to read the input buffer value of - '" << regItem->text(0).toStdString() << "'"; - Utils::logError(messageConsole_,QString::fromStdString(message.str())); + Utils::logError(messageConsole_,message.str()); } if(!updateInputBufferOnly) @@ -981,7 +987,7 @@ void silecsModule::updateDeviceItem(Item *deviceItem,bool updateInputBufferOnly) regItem->setText(3 , "?"); std::ostringstream message; message << "Impossible to read the output buffer value of - '" << regItem->text(0).toStdString() << "'"; - Utils::logError(messageConsole_,QString::fromStdString(message.str())); + Utils::logError(messageConsole_, message.str()); } } } diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/utils.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/utils.cpp index 2e736481216641175a4f3b2e79cde44488e0c895..85d3dc1691ffd0717abb9c2d72d88e1ac5b842bb 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/utils.cpp +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/utils.cpp @@ -18,23 +18,23 @@ extern silecsModule *mysilecs; -void Utils::logError(QTextBrowser* errorConsole, QString message) +void Utils::logError(QTextBrowser* errorConsole, std::string message) { - errorConsole->insertHtml("<font color='red'>DIAG-TOOL [ERROR] " + message + "</font><br>"); + errorConsole->insertHtml(QString::fromStdString("<font color='red'>DIAG-TOOL [ERROR] " + message + "</font><br>")); errorConsole->verticalScrollBar()->setValue(errorConsole->verticalScrollBar()->maximum()); } -void Utils::logInfo(QTextBrowser* errorConsole, QString message) +void Utils::logInfo(QTextBrowser* errorConsole, std::string message) { - errorConsole->insertHtml("<font color='black'>DIAG-TOOL [INFO] " + message + "</font><br>"); + errorConsole->insertHtml(QString::fromStdString("<font color='black'>DIAG-TOOL [INFO] " + message + "</font><br>")); errorConsole->verticalScrollBar()->setValue(errorConsole->verticalScrollBar()->maximum()); } -void Utils::logDebugIf(QTextBrowser* errorConsole, QString message) +void Utils::logDebugIf(QTextBrowser* errorConsole, std::string message) { if( mysilecs->isDebugLogEnabled()) { - errorConsole->insertHtml("<font color='black'>DIAG-TOOL [DEBUG] " + message + "</font><br>"); + errorConsole->insertHtml(QString::fromStdString("<font color='black'>DIAG-TOOL [DEBUG] " + message + "</font><br>")); errorConsole->verticalScrollBar()->setValue(errorConsole->verticalScrollBar()->maximum()); } } diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/utils.h b/silecs-diagnostic-cpp/src/silecs-diagnostic/utils.h index 2b6f5d72462e3975acf1efbb8abeda4a2618e3fc..13666ee36a6061549418b4c1c65bdff2e59cfe25 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/utils.h +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/utils.h @@ -39,11 +39,11 @@ namespace Silecs namespace Utils { - void logError(QTextBrowser* errorConsole, QString message); + void logError(QTextBrowser* errorConsole, std::string message); - void logInfo(QTextBrowser* errorConsole, QString message); + void logInfo(QTextBrowser* errorConsole, std::string message); - void logDebugIf(QTextBrowser* errorConsole, QString message); + void logDebugIf(QTextBrowser* errorConsole, std::string message); /** * Convert a integer number in the equivalent string