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 b924e1a49aeaf03e4560fbf7b4078c2709d06b1c..cbe74b5eb8dd8c887bde9f7d98dabe7675ee0585 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp +++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.cpp @@ -255,7 +255,10 @@ std::string PLC::getModel() { return model_; } - +PLCType PLC::getPLCType() +{ + return typeID_; +} std::string PLC::getProtocolType() { return protocolType_; 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 bda5960c8821e8c6a2ef66e47792174ca1ba866e..e7cbd7a7b4a43074bf6cc284e12c2a03e81917d1 100644 --- a/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h +++ b/silecs-communication-cpp/src/silecs-communication/interface/equipment/SilecsPLC.h @@ -191,6 +191,12 @@ public: */ std::string getModel(); + /*! + * \brief Returns PLC type: bus coupler or bus controller + * \return PLC type + */ + PLCType getPLCType(); + /*! * \brief Returns the protocol type used for the PLC communication: MODBUS-TCP, S7-TCP, CNV-TCP * \return PLC protocol type diff --git a/silecs-diagnostic-cpp/src/silecs-diagnostic/utils.cpp b/silecs-diagnostic-cpp/src/silecs-diagnostic/utils.cpp index ef5fa67810f1ea2d58e1a0d989c33d426f224688..31097bdb30c021dbf48ee0041feedd04882a92ee 100755 --- a/silecs-diagnostic-cpp/src/silecs-diagnostic/utils.cpp +++ b/silecs-diagnostic-cpp/src/silecs-diagnostic/utils.cpp @@ -21,23 +21,23 @@ extern silecsModule *mysilecs; void Utils::logError(QTextBrowser* errorConsole, std::string message) { - errorConsole->insertHtml(QString::fromStdString("<font color='red'>DIAG-TOOL [ERROR] " + message + "</font><br>")); - errorConsole->verticalScrollBar()->setValue(errorConsole->verticalScrollBar()->maximum()); + errorConsole->insertHtml(QString::fromStdString("<font color='red'>DIAG-TOOL [ERROR] " + message + "</font><br>")); + errorConsole->verticalScrollBar()->setValue(errorConsole->verticalScrollBar()->maximum()); } void Utils::logInfo(QTextBrowser* errorConsole, std::string message) { - errorConsole->insertHtml(QString::fromStdString("<font color='black'>DIAG-TOOL [INFO] " + message + "</font><br>")); - errorConsole->verticalScrollBar()->setValue(errorConsole->verticalScrollBar()->maximum()); + errorConsole->insertHtml(QString::fromStdString("<font color='black'>DIAG-TOOL [INFO] " + message + "</font><br>")); + errorConsole->verticalScrollBar()->setValue(errorConsole->verticalScrollBar()->maximum()); } void Utils::logDebugIf(QTextBrowser* errorConsole, std::string message) { - if( mysilecs->isDebugLogEnabled()) - { - errorConsole->insertHtml(QString::fromStdString("<font color='black'>DIAG-TOOL [DEBUG] " + message + "</font><br>")); - errorConsole->verticalScrollBar()->setValue(errorConsole->verticalScrollBar()->maximum()); - } + if (mysilecs->isDebugLogEnabled()) + { + errorConsole->insertHtml(QString::fromStdString("<font color='black'>DIAG-TOOL [DEBUG] " + message + "</font><br>")); + errorConsole->verticalScrollBar()->setValue(errorConsole->verticalScrollBar()->maximum()); + } } //convert int to string @@ -80,16 +80,16 @@ std::string Utils::toString(long number, int base) return stream.str(); } -Item* Utils::addTreeItem(Item *parent,QString name ,QString description, QString type, void* linkedObject,QString icon) +Item* Utils::addTreeItem(Item *parent, QString name, QString description, QString type, void* linkedObject, QString icon) { Item *itm = new Item(linkedObject); - itm->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled ); - itm->setText(0,name); - itm->setText(2,description); - itm->setWhatsThis(0,type); + itm->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled); + itm->setText(0, name); + itm->setText(2, description); + itm->setWhatsThis(0, type); - if(icon.compare("")!=0) - itm->setIcon(0,QIcon(QPixmap(icon))); + if (icon.compare("") != 0) + itm->setIcon(0, QIcon(QPixmap(icon))); parent->addChild(itm); return itm; @@ -101,7 +101,7 @@ char* Utils::chop(char *string) len = strlen(string); char *newstring; newstring = (char *)malloc(len); - for(i = 0; i < strlen(string)-1; i++) + for (i = 0; i < strlen(string) - 1; i++) { newstring[i] = string[i]; } @@ -110,87 +110,97 @@ char* Utils::chop(char *string) return newstring; } -template <class T>bool from_string(T& t,const std::string& s, std::ios_base& (*f)(std::ios_base&)) +template<class T> bool from_string(T& t, const std::string& s, std::ios_base& (*f)(std::ios_base&)) { std::istringstream iss(s); - return !(iss >> f >> t).fail(); + return ! (iss >> f >> t).fail(); } -void Utils::displayClusterInformation(Silecs::Cluster *cluster,QTextEdit *console) +void Utils::displayClusterInformation(Silecs::Cluster *cluster, QTextEdit *console) { std::string text = ""; text.append("<h3>Cluster general information</h3>"); text.append("<ul>"); - text.append("<li>Class name: "+cluster->getClassName()+"</li>"); - text.append("<li>Class version: "+cluster->getClassVersion()+"</li>"); - text.append("<li>Host name: "+cluster->getHostName()+"</li>"); + text.append("<li>Class name: " + cluster->getClassName() + "</li>"); + text.append("<li>Class version: " + cluster->getClassVersion() + "</li>"); + text.append("<li>Host name: " + cluster->getHostName() + "</li>"); text.append("</ul>"); console->setText(QString::fromStdString(text)); } - -void Utils::displayPLCInformation(Silecs::PLC *plc,QTextEdit *console) +void Utils::displayPLCInformation(Silecs::PLC *plc, QTextEdit *console) { std::string text = ""; - if(plc->isConnected(false)) + if (plc->isConnected(false)) { text.append("<h3><font color ='green'>This PLC is currently connected</font></h3><hr/>"); - HeaderInformations *headerInfo = mysilecs->getHeaderInformations(plc->getName()); - text.append("<h3><font color ='green'>PLC Runtime information</font></h3>"); - text.append("<ul>"); - text.append("<li>PLC HEADER DATA uploaded from: "+plc->getName()+"</li>"); - text.append("<li>Software Release: "+headerInfo->getheaderRelease()+"</li>"); - text.append("<li>Mapping Owner: "+headerInfo->getheaderOwner()+"</li>"); - text.append("<li>Mapping Checksum: "+headerInfo->getHeaderChecksum()+"</li>"); - text.append("<li>Generation Date: "+headerInfo->getheaderDate()+"</li>"); - text.append("</ul><hr/>"); - - delete headerInfo; + if (plc->getPLCType() == BusCoupler) + { + text.append("<h3><font color ='green'>PLC Runtime information</font></h3>"); + text.append("<ul>"); + text.append("<li>No runtime information available: Bus controller (no memory)</li>"); + text.append("</ul><hr/>"); + + } + else + { + HeaderInformations *headerInfo = mysilecs->getHeaderInformations(plc->getName()); + text.append("<h3><font color ='green'>PLC Runtime information</font></h3>"); + text.append("<ul>"); + text.append("<li>PLC HEADER DATA uploaded from: " + plc->getName() + "</li>"); + text.append("<li>Software Release: " + headerInfo->getheaderRelease() + "</li>"); + text.append("<li>Mapping Owner: " + headerInfo->getheaderOwner() + "</li>"); + text.append("<li>Mapping Checksum: " + headerInfo->getHeaderChecksum() + "</li>"); + text.append("<li>Generation Date: " + headerInfo->getheaderDate() + "</li>"); + text.append("</ul><hr/>"); + + delete headerInfo; + } } else text.append("<h3>This PLC is currently disconnected</h3><hr/>"); text.append("<h3>PLC general information</h3>"); text.append("<ul>"); - text.append("<li>Name: "+plc->getName()+"</li>"); - text.append("<li>Address: "+plc->getIPAddress()+"</li>"); - text.append("<li>Brand: "+plc->getBrand()+"</li>"); - text.append("<li>Model: "+plc->getModel()+"</li>"); - text.append("<li>Owner: "+plc->getLocalOwner()+"</li>"); + text.append("<li>Name: " + plc->getName() + "</li>"); + text.append("<li>Address: " + plc->getIPAddress() + "</li>"); + text.append("<li>Brand: " + plc->getBrand() + "</li>"); + text.append("<li>Model: " + plc->getModel() + "</li>"); + text.append("<li>Owner: " + plc->getLocalOwner() + "</li>"); text.append("</ul><hr/>"); text.append("<h3>PLC configuration information</h3>"); text.append("<ul>"); - text.append("<li>Protocol type: "+plc->getProtocolType()+"</li>"); - text.append("<li>Protocol mode: "+plc->getProtocolMode()+"</li>"); + text.append("<li>Protocol type: " + plc->getProtocolType() + "</li>"); + text.append("<li>Protocol mode: " + plc->getProtocolMode() + "</li>"); if (plc->getMemBaseAddress() > -1) - text.append("<li>Memory Base address: "+toString(plc->getMemBaseAddress())+" (0x"+toString(plc->getMemBaseAddress(), 16)+")"+ "</li>"); + text.append("<li>Memory Base address: " + toString(plc->getMemBaseAddress()) + " (0x" + toString(plc->getMemBaseAddress(), 16) + ")" + "</li>"); else text.append("<li>Memory Base address: Not applicable</li>"); if (plc->getDIBaseAddress() > -1) - text.append("<li>DI Base address: "+toString(plc->getDIBaseAddress())+" (0x"+toString(plc->getDIBaseAddress(), 16)+")"+ "</li>"); + text.append("<li>DI Base address: " + toString(plc->getDIBaseAddress()) + " (0x" + toString(plc->getDIBaseAddress(), 16) + ")" + "</li>"); else text.append("<li>DI Base address: Not applicable</li>"); if (plc->getDOBaseAddress() > -1) - text.append("<li>DO Base address: "+toString(plc->getDOBaseAddress())+" (0x"+toString(plc->getDOBaseAddress(), 16)+")"+ "</li>"); + text.append("<li>DO Base address: " + toString(plc->getDOBaseAddress()) + " (0x" + toString(plc->getDOBaseAddress(), 16) + ")" + "</li>"); else text.append("<li>DO Base address: Not applicable</li>"); if (plc->getAIBaseAddress() > -1) - text.append("<li>AI Base address: "+toString(plc->getAIBaseAddress())+" (0x"+toString(plc->getAIBaseAddress(), 16)+")"+ "</li>"); + text.append("<li>AI Base address: " + toString(plc->getAIBaseAddress()) + " (0x" + toString(plc->getAIBaseAddress(), 16) + ")" + "</li>"); else text.append("<li>AI Base address: Not applicable</li>"); if (plc->getAOBaseAddress() > -1) - text.append("<li>AO Base address: "+toString(plc->getAOBaseAddress())+" (0x"+toString(plc->getAOBaseAddress(), 16)+")"+ "</li>"); + text.append("<li>AO Base address: " + toString(plc->getAOBaseAddress()) + " (0x" + toString(plc->getAOBaseAddress(), 16) + ")" + "</li>"); else text.append("<li>AO Base address: Not applicable</li>"); @@ -198,54 +208,56 @@ void Utils::displayPLCInformation(Silecs::PLC *plc,QTextEdit *console) text.append("<h3>PLC generation information</h3>"); text.append("<ul>"); - text.append("<li>Release: "+plc->getLocalRelease()+"</li>"); - text.append("<li>Date: "+plc->getLocalDate()+"</li>"); - text.append("<li>Checksum: "+toString(plc->getLocalChecksum())+"</li>"); + text.append("<li>Release: " + plc->getLocalRelease() + "</li>"); + text.append("<li>Date: " + plc->getLocalDate() + "</li>"); + text.append("<li>Checksum: " + toString(plc->getLocalChecksum()) + "</li>"); text.append("</ul><hr/>"); console->setText(QString::fromStdString(text)); } -void Utils::displayDeviceInformation(Silecs::Device *device,QTextEdit *console) +void Utils::displayDeviceInformation(Silecs::Device *device, QTextEdit *console) { std::string text = ""; text.append("<h3>Device general information</h3>"); text.append("<ul>"); - text.append("<li>Name: "+device->getLabel()+"</li>"); + text.append("<li>Name: " + device->getLabel() + "</li>"); text.append("</ul>"); console->setText(QString::fromStdString(text)); } -void Utils::displayRegisterInformation(Silecs::Register *reg,QTextEdit *console) +void Utils::displayRegisterInformation(Silecs::Register *reg, QTextEdit *console) { std::string text = ""; text.append("<h3>Register general information</h3>"); text.append("<ul>"); - text.append("<li>Name: "+reg->getName()+"</li>"); - text.append("<li>Format: "+reg->getFormatAsString()+"</li>"); - if(reg->getFormat() == String) - text.append("<li>String length: "+toString(reg->getLength())+"</li>"); - text.append("<li>Dimension1: "+toString(reg->getDimension1())+"</li>"); - text.append("<li>Dimension2: "+toString(reg->getDimension2())+"</li>"); - text.append("<li>Block name: "+reg->getBlockName()+"</li>"); - text.append("<li>Last update: "+reg->getTimeStampAsString()+"</li>"); + text.append("<li>Name: " + reg->getName() + "</li>"); + text.append("<li>Format: " + reg->getFormatAsString() + "</li>"); + if (reg->getFormat() == String) + text.append("<li>String length: " + toString(reg->getLength()) + "</li>"); + text.append("<li>Dimension1: " + toString(reg->getDimension1()) + "</li>"); + text.append("<li>Dimension2: " + toString(reg->getDimension2()) + "</li>"); + text.append("<li>Block name: " + reg->getBlockName() + "</li>"); + text.append("<li>Last update: " + reg->getTimeStampAsString() + "</li>"); // Access method - if(reg->hasInputAccess() && reg->hasOutputAccess()) + if (reg->hasInputAccess() && reg->hasOutputAccess()) text.append("<li>Access method: Read / Write </li>"); else { - if(reg->hasInputAccess()) text.append("<li>Access method: Read only </li>"); - else text.append("<li>Access method: Write only </li>"); + if (reg->hasInputAccess()) + text.append("<li>Access method: Read only </li>"); + else + text.append("<li>Access method: Write only </li>"); } - text.append("<li>Access area: "+reg->whichAccessArea(reg->getAccessArea())+"</li>"); + text.append("<li>Access area: " + reg->whichAccessArea(reg->getAccessArea()) + "</li>"); // Retentive volatile - if(reg->isRetentive()) + if (reg->isRetentive()) text.append("<li>Storage method: Retentive</li>"); else text.append("<li>Storage method: Volatile</li>"); @@ -255,15 +267,11 @@ void Utils::displayRegisterInformation(Silecs::Register *reg,QTextEdit *console) console->setText(QString::fromStdString(text)); } -void Utils::displayRegisterValue(Silecs::Register *reg, - QLabel *binValueLabel, - QLabel *hexValueLabel, - QLabel *decValueLabel, - QLabel *asciiValueLabel - ) +void Utils::displayRegisterValue(Silecs::Register *reg, QLabel *binValueLabel, QLabel *hexValueLabel, QLabel *decValueLabel, QLabel *asciiValueLabel) { - if(!reg->isReadable()){ + if (!reg->isReadable()) + { binValueLabel->setText("--Write only register--"); hexValueLabel->setText("--Write only register--"); decValueLabel->setText("--Write only register--"); @@ -272,16 +280,17 @@ void Utils::displayRegisterValue(Silecs::Register *reg, else { // The register has input access - if(reg->getDimension1()>1 || reg->getDimension2()>1) + if (reg->getDimension1() > 1 || reg->getDimension2() > 1) { binValueLabel->setText("--Vector--"); hexValueLabel->setText("--Vector--"); decValueLabel->setText("--Vector--"); asciiValueLabel->setText("--Vector--"); } - else{ + else + { //Scalar with input access - switch(reg->getFormat()) + switch (reg->getFormat()) { case uInt8: { @@ -295,7 +304,7 @@ void Utils::displayRegisterValue(Silecs::Register *reg, //if(!c.isPrint()) // c='?'; //asciiValueLabel->setText(QObject::tr("%1").arg(c)); - asciiValueLabel->setText(c.isPrint() ? QObject::tr("%1").arg(c):"--Not printable--"); + asciiValueLabel->setText(c.isPrint() ? QObject::tr("%1").arg(c) : "--Not printable--"); break; } @@ -305,7 +314,7 @@ void Utils::displayRegisterValue(Silecs::Register *reg, hexValueLabel->setText(QObject::tr("%1").arg(reg->getValInt8(), 0, 16)); decValueLabel->setText(QObject::tr("%1").arg(reg->getValInt8(), 0, 10)); QChar c = reg->getValInt8(); - asciiValueLabel->setText(c.isPrint() ? QObject::tr("%1").arg(c):"--Not printable--"); + asciiValueLabel->setText(c.isPrint() ? QObject::tr("%1").arg(c) : "--Not printable--"); break; } case uInt16: @@ -371,7 +380,7 @@ void Utils::displayRegisterValue(Silecs::Register *reg, break; } - default:// Float32,Float64,Date + default: // Float32,Float64,Date { binValueLabel->setText("--Not relevant--"); hexValueLabel->setText("--Not relevant--");