Skip to content

Commit

Permalink
revert the last OPC UA commit as it breaks the Windows builds (#8358)
Browse files Browse the repository at this point in the history
- we will put it back after we check that it builds on Windows
  • Loading branch information
adrpo committed Dec 23, 2021
1 parent 8713a81 commit 602775e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 64 deletions.
Expand Up @@ -311,11 +311,8 @@ static void checkSimulationTerminated(DATA* data, SOLVER_INFO* solverInfo)
{
if(terminationTerminate)
{
if (TermInfo.filename != NULL && TermInfo.filename[0] != '\0') {
printInfo(stdout, TermInfo);
fputc('\n', stdout);
}

printInfo(stdout, TermInfo);
fputc('\n', stdout);
infoStreamPrint(LOG_STDOUT, 0, "Simulation call terminate() at time %f\nMessage : %s", data->localData[0]->timeValue, TermMsg);
data->simulationInfo->stopTime = solverInfo->currentTime;
}
Expand Down
65 changes: 7 additions & 58 deletions OMCompiler/SimulationRuntime/opc/ua/omc_opc_ua.c
Expand Up @@ -46,8 +46,6 @@ typedef struct {
UA_Boolean server_running;
UA_Boolean run;
UA_Boolean step;
UA_Boolean terminate;
UA_Boolean oldUseStopTime;
pthread_mutex_t mutex_pause;
pthread_cond_t cond_pause;
double time[2];
Expand Down Expand Up @@ -128,8 +126,6 @@ readBoolean(void *handle, const UA_NodeId nodeid, UA_Boolean sourceTimeStamp, co
val = state->run;
} else if (nodeid.identifier.numeric == OMC_OPC_NODEID_ENABLE_STOP_TIME) {
val = state->data->simulationInfo->useStopTime;
} else if (nodeid.identifier.numeric == OMC_OPC_NODEID_TERMINATE) {
val = state->terminate;
} else if (nodeid.identifier.numeric >= VARKIND_BOOL*MAX_VARS_KIND && nodeid.identifier.numeric < (1+VARKIND_BOOL)*MAX_VARS_KIND) {
int index1 = nodeid.identifier.numeric-VARKIND_BOOL*MAX_VARS_KIND;
int index = index1 >= ALIAS_START_ID ? modelData->booleanAlias[index1-ALIAS_START_ID].nameID : index1;
Expand Down Expand Up @@ -174,27 +170,10 @@ writeBoolean(void *handle, const UA_NodeId nodeid, const UA_Variant *data, const
pthread_mutex_unlock(&state->mutex_pause);
pthread_cond_signal(&state->cond_pause);
} else if (nodeid.identifier.numeric==OMC_OPC_NODEID_ENABLE_STOP_TIME) {
if (!(state->terminate)) { /* prevent writes to useStopTime if terminate flag is set */
pthread_mutex_lock(&state->mutex_pause);
state->data->simulationInfo->useStopTime = newVal;
pthread_mutex_unlock(&state->mutex_pause);
} else {
statusCode = UA_STATUSCODE_BADREQUESTNOTALLOWED;
}
} else if (nodeid.identifier.numeric==OMC_OPC_NODEID_TERMINATE) {
pthread_mutex_lock(&state->mutex_pause);

if (newVal) {
/* Store prev. useStopTime state in case terminate flag is reset in same step */
state->oldUseStopTime = state->data->simulationInfo->useStopTime;
state->data->simulationInfo->useStopTime = newVal; /* enable stop time for termination */
}
else if (state->terminate) /* Falling edge of this flag occurred in the same step, restore prev. val of useStopTime */
state->data->simulationInfo->useStopTime = state->oldUseStopTime;

state->terminate = newVal;

state->data->simulationInfo->useStopTime = newVal;
pthread_mutex_unlock(&state->mutex_pause);
pthread_cond_signal(&state->cond_pause);
} else if (nodeid.identifier.numeric >= VARKIND_BOOL*MAX_VARS_KIND && nodeid.identifier.numeric < (1+VARKIND_BOOL)*MAX_VARS_KIND) {
int index1 = nodeid.identifier.numeric-VARKIND_BOOL*MAX_VARS_KIND;
int index = index1 >= ALIAS_START_ID ? modelData->booleanAlias[index1-ALIAS_START_ID].nameID : index1;
Expand Down Expand Up @@ -525,12 +504,10 @@ void* omc_embedded_server_init(DATA *data, double t, double step, const char *ar

state->run = 0;
state->step = 0;
state->terminate = 0;
state->oldUseStopTime = data->simulationInfo->useStopTime;

pthread_create(&state->thread, NULL, (void*) &threadWork, state);

/* add variable for a simulation step */
/* add a variable node to the address space */
UA_NodeId stepNodeId = UA_NODEID_NUMERIC(0, OMC_OPC_NODEID_STEP);
UA_QualifiedName stepName = UA_QUALIFIEDNAME(1, "OpenModelica.step");
UA_DataSource stepDataSource = (UA_DataSource) {
Expand All @@ -546,7 +523,7 @@ void* omc_embedded_server_init(DATA *data, double t, double step, const char *ar
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
stepName, UA_NODEID_NULL, attr, stepDataSource, NULL);

/* add variable for simulation run */
/* Run variable */
UA_NodeId runNodeId = UA_NODEID_NUMERIC(0, OMC_OPC_NODEID_RUN);
UA_QualifiedName runName = UA_QUALIFIEDNAME(1, "OpenModelica.run");
UA_VariableAttributes runAttr;
Expand Down Expand Up @@ -594,7 +571,7 @@ void* omc_embedded_server_init(DATA *data, double t, double step, const char *ar
name, UA_NODEID_NULL, attr, dataSource, NULL);
}

/* add variable for current simulation time */
/* add a variable node to the address space */
UA_NodeId timeNodeId = UA_NODEID_NUMERIC(0, OMC_OPC_NODEID_TIME);
UA_QualifiedName timeName = UA_QUALIFIEDNAME(1, "time");
UA_DataSource timeDataSource = (UA_DataSource) {
Expand All @@ -608,24 +585,6 @@ void* omc_embedded_server_init(DATA *data, double t, double step, const char *ar
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
timeName, UA_NODEID_NULL, timeAttr, timeDataSource, NULL);

{
/* add variable for graceful termination of the simulation */
UA_NodeId terminateNodeId = UA_NODEID_NUMERIC(0, OMC_OPC_NODEID_TERMINATE);
UA_QualifiedName terminateName = UA_QUALIFIEDNAME(1, "OpenModelica.terminate");
UA_DataSource dataSource = (UA_DataSource) {
.handle = state, .read = readBoolean, .write = writeBoolean};
UA_VariableAttributes attr;
UA_VariableAttributes_init(&attr);
attr.description = UA_LOCALIZEDTEXT("en_US", "When set to true, the simulation is terminated gracefully");
attr.displayName = UA_LOCALIZEDTEXT("en_US", "terminate");
attr.writeMask = 1;
attr.userWriteMask = 1;
UA_Server_addDataSourceVariableNode(state->server, terminateNodeId,
UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES),
terminateName, UA_NODEID_NULL, attr, dataSource, NULL);
}

state->gotNewInput = 0;
state->inputVarsBackup = malloc(modelData->nInputVars * sizeof(double));
memcpy(state->inputVarsBackup, data->simulationInfo->inputVars, modelData->nInputVars * sizeof(double));
Expand Down Expand Up @@ -689,6 +648,8 @@ int omc_embedded_server_update(void *state_vp, double t)
MODEL_DATA *modelData = data->modelData;
int latestValues;

waitForStep(state);

latestValues = state->latestValues ? 0 : 1;

state->time[latestValues] = t;
Expand All @@ -703,17 +664,11 @@ int omc_embedded_server_update(void *state_vp, double t)
state->latestValues = latestValues;
pthread_mutex_unlock(&state->mutex_values);


waitForStep(state);


pthread_mutex_lock(&state->write_values);

if (state->gotNewInput) {
res = 1; /* Trigger an event in the solver, restarting it */
memcpy(data->simulationInfo->inputVars, state->inputVarsBackup, modelData->nInputVars * sizeof(double));

state->gotNewInput = 0;
}

if (state->reinitStateFlag) {
Expand All @@ -724,13 +679,7 @@ int omc_embedded_server_update(void *state_vp, double t)
(data->localData[0])->realVars[i] = state->updatedStates[i];
}
}

state->reinitStateFlag = 0;
}

if (state->terminate)
omc_terminate((FILE_INFO) omc_dummyFileInfo, "The embedded server received command to terminate.");

pthread_mutex_unlock(&state->write_values);

return res;
Expand Down
1 change: 0 additions & 1 deletion OMCompiler/SimulationRuntime/opc/ua/omc_opc_ua.h
Expand Up @@ -57,7 +57,6 @@ OPC_UA_EXPORT int omc_embedded_server_update(void*, double t);
#define OMC_OPC_NODEID_REAL_TIME_SCALING_FACTOR 10002
#define OMC_OPC_NODEID_ENABLE_STOP_TIME 10003
#define OMC_OPC_NODEID_TIME 10004
#define OMC_OPC_NODEID_TERMINATE 10005

#define MAX_VARS_KIND 100000000
#define ALIAS_START_ID (MAX_VARS_KIND/2)
Expand Down

0 comments on commit 602775e

Please sign in to comment.