Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 7abe645

Browse files
chrjo5OpenModelica-Hudson
authored andcommitted
Added a new flag, -embeddedServerPort
1 parent deeabde commit 7abe645

File tree

7 files changed

+24
-7
lines changed

7 files changed

+24
-7
lines changed

SimulationRuntime/c/simulation/solver/embedded_server.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#define DLL_EXT ".so"
4343
#endif
4444

45-
void* no_embedded_server_init(DATA *data, double tout, double step, const char *argv_0, void (*omc_real_time_sync_update)(DATA *data, double scaling))
45+
void* no_embedded_server_init(DATA *data, double tout, double step, const char *argv_0, void (*omc_real_time_sync_update)(DATA *data, double scaling), int port)
4646
{
4747
return NULL;
4848
}
@@ -55,7 +55,7 @@ void no_embedded_server_update(void *handle, double tout)
5555
{
5656
}
5757

58-
void* (*embedded_server_init)(DATA *data, double tout, double step, const char *argv_0, void (*omc_real_time_sync_update)(DATA *data, double scaling)) = no_embedded_server_init;
58+
void* (*embedded_server_init)(DATA *data, double tout, double step, const char *argv_0, void (*omc_real_time_sync_update)(DATA *data, double scaling), int port) = no_embedded_server_init;
5959
void (*embedded_server_deinit)(void*) = no_embedded_server_deinit;
6060
// Tells the embedded server that a simulation step has passed; the server
6161
// can read/write values from/to the simulator

SimulationRuntime/c/simulation/solver/embedded_server.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
extern "C" {
3838
#endif
3939

40-
extern void* (*embedded_server_init)(DATA *data, double tout, double step, const char *argv_0, void (*omc_real_time_sync_update)(DATA *data, double scaling));
40+
extern void* (*embedded_server_init)(DATA *data, double tout, double step, const char *argv_0, void (*omc_real_time_sync_update)(DATA *data, double scaling), int port);
4141
extern void (*embedded_server_deinit)(void *handle);
4242
/* Tells the embedded server that a simulation step has passed; the server
4343
* can read/write values from/to the simulator

SimulationRuntime/c/simulation/solver/solver_main.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,18 @@ int solver_main(DATA* data, threadData_t *threadData, const char* init_initMetho
694694
#if !defined(OMC_MINIMAL_RUNTIME)
695695
dllHandle = embedded_server_load_functions(omc_flagValue[FLAG_EMBEDDED_SERVER]);
696696
omc_real_time_sync_init(threadData, data);
697-
data->embeddedServerState = embedded_server_init(data, data->localData[0]->timeValue, solverInfo.currentStepSize, argv_0, omc_real_time_sync_update);
697+
int port = 4841;
698+
/* If an embedded server is specified */
699+
if (dllHandle != NULL) {
700+
if (omc_flag[FLAG_EMBEDDED_SERVER_PORT]) {
701+
port = atoi(omc_flagValue[FLAG_EMBEDDED_SERVER_PORT]);
702+
/* In case of a bad conversion, don't spawn a server on port 0...*/
703+
if (port == 0) {
704+
port = 4841;
705+
}
706+
}
707+
}
708+
data->embeddedServerState = embedded_server_init(data, data->localData[0]->timeValue, solverInfo.currentStepSize, argv_0, omc_real_time_sync_update, port);
698709
#endif
699710
if(0 == retVal) {
700711
retVal = -1;

SimulationRuntime/c/util/simulation_options.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const char *FLAG_NAME[FLAG_MAX+1] = {
4242
/* FLAG_DELTA_X_LINEARIZE */ "deltaXLinearize",
4343
/* FLAG_DELTA_X_SOLVER */ "deltaXSolver",
4444
/* FLAG_EMBEDDED_SERVER */ "embeddedServer",
45+
/* FLAG_EMBEDDED_SERVER_PORT */ "embeddedServerPort",
4546
/* FLAG_EMIT_PROTECTED */ "emit_protected",
4647
/* FLAG_F */ "f",
4748
/* FLAG_HELP */ "help",
@@ -129,6 +130,7 @@ const char *FLAG_DESC[FLAG_MAX+1] = {
129130
/* FLAG_DELTA_X_LINEARIZE */ "value specifies the delta x value for numerical differentiation used by linearization. The default value is 1e-5.",
130131
/* FLAG_DELTA_X_SOLVER */ "value specifies the delta x value for numerical differentiation used by integrator. The default values is sqrt(DBL_EPSILON).",
131132
/* FLAG_EMBEDDED_SERVER */ "enables an embedded server. Valid values: none, opc-da [broken], opc-ua [experimental], or the path to a shared object.",
133+
/* FLAG_EMBEDDED_SERVER_PORT */ "[int (default 4841)] value specifies the port number used by the embedded server",
132134
/* FLAG_EMIT_PROTECTED */ "emits protected variables to the result-file",
133135
/* FLAG_F */ "value specifies a new setup XML file to the generated simulation code",
134136
/* FLAG_HELP */ "get detailed information that specifies the command-line flag",
@@ -231,6 +233,8 @@ const char *FLAG_DETAILED_DESC[FLAG_MAX+1] = {
231233
" * opc-da - [broken] run with embedded OPC DA server (WIN32 only, uses proprietary OPC SC interface)\n"
232234
" * opc-ua - [experimental] run with embedded OPC UA server (TCP port 4841 for now; will have its own configuration option later)\n"
233235
" * filename - path to a shared object implementing the embedded server interface (requires access to internal OMC data-structures if you want to read or write data)",
236+
/* FLAG_EMBEDDED_SERVER_PORT */
237+
" Value specifies the port number used by the embedded server. The default value is 4841.",
234238
/* FLAG_EMIT_PROTECTED */
235239
" Emits protected variables to the result-file.",
236240
/* FLAG_F */
@@ -444,6 +448,7 @@ const int FLAG_TYPE[FLAG_MAX] = {
444448
/* FLAG_DELTA_X_LINEARIZE */ FLAG_TYPE_OPTION,
445449
/* FLAG_DELTA_X_SOLVER */ FLAG_TYPE_OPTION,
446450
/* FLAG_EMBEDDED_SERVER */ FLAG_TYPE_OPTION,
451+
/* FLAG_EMBEDDED_SERVER_PORT */ FLAG_TYPE_OPTION,
447452
/* FLAG_EMIT_PROTECTED */ FLAG_TYPE_FLAG,
448453
/* FLAG_F */ FLAG_TYPE_OPTION,
449454
/* FLAG_HELP */ FLAG_TYPE_OPTION,

SimulationRuntime/c/util/simulation_options.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ enum _FLAG
5050
FLAG_DELTA_X_LINEARIZE,
5151
FLAG_DELTA_X_SOLVER,
5252
FLAG_EMBEDDED_SERVER,
53+
FLAG_EMBEDDED_SERVER_PORT,
5354
FLAG_EMIT_PROTECTED,
5455
FLAG_F,
5556
FLAG_HELP,

SimulationRuntime/opc/ua/omc_opc_ua.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,14 +448,14 @@ static inline omc_opc_ua_state* addAliasVars(omc_opc_ua_state *state, var_kind_t
448448
}
449449
return state;
450450
}
451-
void* omc_embedded_server_init(DATA *data, double t, double step, const char *argv_0, void (*omc_real_time_sync_update)(DATA *data, double scaling))
451+
void* omc_embedded_server_init(DATA *data, double t, double step, const char *argv_0, void (*omc_real_time_sync_update)(DATA *data, double scaling), int port)
452452
{
453453
MODEL_DATA *modelData = data->modelData;
454454
omc_opc_ua_state *state = (omc_opc_ua_state*) malloc(sizeof(omc_opc_ua_state));
455455
UA_ServerConfig config = UA_ServerConfig_standard;
456456
var_kind_t vk;
457457
state->logger = Logger_Stdout;
458-
state->nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 4841);
458+
state->nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, port);
459459
config.logger = Logger_Stdout;
460460
config.networkLayers = &state->nl;
461461
config.networkLayersSize = 1;

SimulationRuntime/opc/ua/omc_opc_ua.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#endif
4848
#endif
4949

50-
OPC_UA_EXPORT void* omc_embedded_server_init(DATA *data, double t, double step, const char *argv_0, void (*omc_real_time_sync_update)(DATA *data, double scaling));
50+
OPC_UA_EXPORT void* omc_embedded_server_init(DATA *data, double t, double step, const char *argv_0, void (*omc_real_time_sync_update)(DATA *data, double scaling), int port);
5151
OPC_UA_EXPORT void omc_embedded_server_deinit(void*);
5252
OPC_UA_EXPORT void omc_embedded_server_update(void*, double t);
5353

0 commit comments

Comments
 (0)