Skip to content

Commit bc4f0bc

Browse files
committed
- Start TLM co-simulation by reading the hostname.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@25743 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 1c319f6 commit bc4f0bc

File tree

4 files changed

+54
-10
lines changed

4 files changed

+54
-10
lines changed

OMEdit/OMEditGUI/OMEditGUI.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ win32 {
198198
LIBS += -L../../build/lib/omc -lOMPlot -lomqwt \
199199
-L../OMEditGUI/Debugger/Parser -lGDBMIParser \
200200
-L../../Parser -lantlr3 \
201-
-lOpenModelicaCompiler -lOpenModelicaRuntimeC -lfmilib -lModelicaExternalC -lomcgc -lpthread
201+
-lOpenModelicaCompiler -lOpenModelicaRuntimeC -lfmilib -lModelicaExternalC -lomcgc -lpthread \
202+
-lws2_32
202203
INCLUDEPATH += $$(OMDEV)/lib/omniORB-4.1.6-mingw/include \
203204
../../3rdParty/qwt/build/include \
204205
../../OMPlot/OMPlotGUI \

OMEdit/OMEditGUI/Simulation/TLMCoSimulationDialog.cpp

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@
3535
*
3636
*/
3737

38+
#ifdef WIN32
39+
#include <winsock2.h>
40+
#else
41+
#include <sys/socket.h>
42+
#include <netinet/in.h>
43+
#include <arpa/inet.h>
44+
#include <unistd.h>
45+
#endif
46+
3847
#include "TLMCoSimulationDialog.h"
3948
#include "TLMCoSimulationOutputWidget.h"
4049
#include "VariablesWidget.h"
@@ -60,7 +69,7 @@ TLMCoSimulationDialog::TLMCoSimulationDialog(MainWindow *pMainWindow)
6069
// manager monitor port
6170
mpMonitorPortLabel = new Label(tr("Monitor Port:"));
6271
mpMonitorPortLabel->setToolTip(tr("Set the port for monitoring connections"));
63-
mpMonitorPortTextBox = new QLineEdit("5010");
72+
mpMonitorPortTextBox = new QLineEdit("12111");
6473
// interface request mode
6574
mpInterfaceRequestModeCheckBox = new QCheckBox(tr("Interface Request Mode"));
6675
mpInterfaceRequestModeCheckBox->setToolTip(tr("Run manager in interface request mode, get information about interface locations"));
@@ -177,6 +186,10 @@ bool TLMCoSimulationDialog::validate()
177186
return true;
178187
}
179188

189+
/*!
190+
* \brief TLMCoSimulationDialog::createTLMCoSimulationOptions
191+
* \return
192+
*/
180193
TLMCoSimulationOptions TLMCoSimulationDialog::createTLMCoSimulationOptions()
181194
{
182195
TLMCoSimulationOptions tlmCoSimulationOptions;
@@ -200,8 +213,26 @@ TLMCoSimulationOptions TLMCoSimulationDialog::createTLMCoSimulationOptions()
200213
managerArgs.append("-m");
201214
managerArgs.append(mpMonitorPortTextBox->text());
202215
// set monitor server:port for monitor process
203-
QString monitorPort = "130.236.182.49:";
204-
monitorPort.append(mpMonitorPortTextBox->text());
216+
#define MAXHOSTNAME 1024
217+
char myname[MAXHOSTNAME+1];
218+
struct hostent *hp;
219+
#ifdef WIN32
220+
WSADATA ws;
221+
int d;
222+
d = WSAStartup(0x0101,&ws);
223+
#endif
224+
gethostname(myname, MAXHOSTNAME);
225+
hp = gethostbyname((const char*) myname);
226+
if (hp == NULL) {
227+
MessageItem messageItem(MessageItem::TLM, "", false, 0, 0, 0, 0,
228+
tr("Failed to get my hostname, check that name resolves, e.g. /etc/hosts has %1")
229+
.arg(QString(myname)), Helper::scriptingKind, Helper::errorLevel);
230+
mpMainWindow->getMessagesWidget()->addGUIMessage(messageItem);
231+
tlmCoSimulationOptions.setIsValid(false);
232+
return tlmCoSimulationOptions;
233+
}
234+
char* localIP = inet_ntoa (*(struct in_addr *)*hp->h_addr_list);
235+
QString monitorPort = QString(localIP) + ":" + mpMonitorPortTextBox->text();
205236
monitorArgs.append(monitorPort);
206237
}
207238
if (!mpServerPortTextBox->text().isEmpty()) {
@@ -227,15 +258,21 @@ TLMCoSimulationOptions TLMCoSimulationDialog::createTLMCoSimulationOptions()
227258
return tlmCoSimulationOptions;
228259
}
229260

261+
/*!
262+
* \brief TLMCoSimulationDialog::simulate
263+
* Starts the TLM co-simulation
264+
*/
230265
void TLMCoSimulationDialog::simulate()
231266
{
232267
if (validate()) {
233268
TLMCoSimulationOptions tlmCoSimulationOptions = createTLMCoSimulationOptions();
234-
TLMCoSimulationOutputWidget *pTLMCoSimulationOutputWidget = new TLMCoSimulationOutputWidget(tlmCoSimulationOptions, mpMainWindow);
235-
int xPos = QApplication::desktop()->availableGeometry().width() - pTLMCoSimulationOutputWidget->frameSize().width() - 20;
236-
int yPos = QApplication::desktop()->availableGeometry().height() - pTLMCoSimulationOutputWidget->frameSize().height() - 20;
237-
pTLMCoSimulationOutputWidget->setGeometry(xPos, yPos, pTLMCoSimulationOutputWidget->width(), pTLMCoSimulationOutputWidget->height());
238-
pTLMCoSimulationOutputWidget->show();
239-
accept();
269+
if (tlmCoSimulationOptions.isValid()) {
270+
TLMCoSimulationOutputWidget *pTLMCoSimulationOutputWidget = new TLMCoSimulationOutputWidget(tlmCoSimulationOptions, mpMainWindow);
271+
int xPos = QApplication::desktop()->availableGeometry().width() - pTLMCoSimulationOutputWidget->frameSize().width() - 20;
272+
int yPos = QApplication::desktop()->availableGeometry().height() - pTLMCoSimulationOutputWidget->frameSize().height() - 20;
273+
pTLMCoSimulationOutputWidget->setGeometry(xPos, yPos, pTLMCoSimulationOutputWidget->width(), pTLMCoSimulationOutputWidget->height());
274+
pTLMCoSimulationOutputWidget->show();
275+
accept();
276+
}
240277
}
241278
}

OMEdit/OMEditGUI/Simulation/TLMCoSimulationOptions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class TLMCoSimulationOptions
4444
{
4545
public:
4646
TLMCoSimulationOptions() {
47+
setIsValid(true);
4748
setClassName("");
4849
setFileName("");
4950
setServerPort("11111");
@@ -55,6 +56,8 @@ class TLMCoSimulationOptions
5556
setMonitorDebugMode(false);
5657
}
5758

59+
void setIsValid(bool isValid) {mValid = isValid;}
60+
bool isValid() {return mValid;}
5861
void setClassName(QString className) {mClassName = className;}
5962
QString getClassName() {return mClassName;}
6063
void setFileName(QString fileName) {mFileName = fileName;}
@@ -78,6 +81,7 @@ class TLMCoSimulationOptions
7881
void setMonitorArgs(QStringList monitorArgs) {mMonitorArgs = monitorArgs;}
7982
QStringList getMonitorArgs() {return mMonitorArgs;}
8083
private:
84+
bool mValid;
8185
QString mClassName;
8286
QString mFileName;
8387
QString mServerPort;

OMEdit/OMEditGUI/Simulation/TLMCoSimulationOutputWidget.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ TLMCoSimulationOutputWidget::TLMCoSimulationOutputWidget(TLMCoSimulationOptions
6363
// open manager log button
6464
mpOpenManagerLogFileButton = new QPushButton(tr("Open Manager Log File"));
6565
connect(mpOpenManagerLogFileButton, SIGNAL(clicked()), SLOT(openManagerLogFile()));
66+
mpOpenManagerLogFileButton->setEnabled(tlmCoSimulationOptions.getManagerArgs().contains("-d"));
6667
// manager buttons layout
6768
QHBoxLayout *pManagerButtonsHorizontalLayout = new QHBoxLayout;
6869
pManagerButtonsHorizontalLayout->addWidget(mpStopManagerButton);
@@ -79,6 +80,7 @@ TLMCoSimulationOutputWidget::TLMCoSimulationOutputWidget(TLMCoSimulationOptions
7980
// open monitor log button
8081
mpOpenMonitorLogFileButton = new QPushButton(tr("Open Monitor Log File"));
8182
connect(mpOpenMonitorLogFileButton, SIGNAL(clicked()), SLOT(openMonitorLogFile()));
83+
mpOpenMonitorLogFileButton->setEnabled(tlmCoSimulationOptions.getMonitorArgs().contains("-d"));
8284
// monitor buttons layout
8385
QHBoxLayout *pMonitorButtonsHorizontalLayout = new QHBoxLayout;
8486
pMonitorButtonsHorizontalLayout->addWidget(mpStopMonitorButton);

0 commit comments

Comments
 (0)