Skip to content

Commit

Permalink
OPC-UA: Trigger an event when changing inputs
Browse files Browse the repository at this point in the history
This should make dassl and other solvers not discard changes as was
done previously.
  • Loading branch information
sjoelund authored and OpenModelica-Hudson committed May 5, 2017
1 parent 7abe645 commit ce11282
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions SimulationRuntime/c/simulation/solver/embedded_server.c
Expand Up @@ -42,7 +42,7 @@
#define DLL_EXT ".so"
#endif

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)
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, int *didEventStep)
{
return NULL;
}
Expand All @@ -55,7 +55,7 @@ void no_embedded_server_update(void *handle, double tout)
{
}

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;
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, int *didEventStep) = no_embedded_server_init;
void (*embedded_server_deinit)(void*) = no_embedded_server_deinit;
// Tells the embedded server that a simulation step has passed; the server
// can read/write values from/to the simulator
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/simulation/solver/embedded_server.h
Expand Up @@ -37,7 +37,7 @@
extern "C" {
#endif

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);
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, int *didEventStep);
extern void (*embedded_server_deinit)(void *handle);
/* Tells the embedded server that a simulation step has passed; the server
* can read/write values from/to the simulator
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/c/simulation/solver/solver_main.c
Expand Up @@ -705,7 +705,7 @@ int solver_main(DATA* data, threadData_t *threadData, const char* init_initMetho
}
}
}
data->embeddedServerState = embedded_server_init(data, data->localData[0]->timeValue, solverInfo.currentStepSize, argv_0, omc_real_time_sync_update, port);
data->embeddedServerState = embedded_server_init(data, data->localData[0]->timeValue, solverInfo.currentStepSize, argv_0, omc_real_time_sync_update, port, &solverInfo.didEventStep);
#endif
if(0 == retVal) {
retVal = -1;
Expand Down
7 changes: 5 additions & 2 deletions SimulationRuntime/opc/ua/omc_opc_ua.c
Expand Up @@ -58,6 +58,7 @@ typedef struct {
int *boolValsInputIndex;
int reinitStateFlag;
int *stateWasUpdatedFlag;
int *didEventStep;
double *updatedStates;
double real_time_sync_scaling;
void (*omc_real_time_sync_update)(DATA *data, double scaling);
Expand Down Expand Up @@ -448,7 +449,7 @@ static inline omc_opc_ua_state* addAliasVars(omc_opc_ua_state *state, var_kind_t
}
return state;
}
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)
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, int *didEventStep)
{
MODEL_DATA *modelData = data->modelData;
omc_opc_ua_state *state = (omc_opc_ua_state*) malloc(sizeof(omc_opc_ua_state));
Expand All @@ -466,6 +467,7 @@ void* omc_embedded_server_init(DATA *data, double t, double step, const char *ar
state->server_running = 1;
state->time = t;
state->omc_real_time_sync_update = omc_real_time_sync_update;
state->didEventStep = didEventStep;

pthread_cond_init(&state->cond_pause, NULL);
pthread_mutex_init(&state->mutex_pause, NULL);
Expand Down Expand Up @@ -637,11 +639,12 @@ void omc_embedded_server_update(void *state_vp, double t)
}

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

if (state->reinitStateFlag) {
// TODO: Trigger an event / restarting the numerical solver
*state->didEventStep = 1; /* Trigger an event in the solver, restarting it */
for (i = 0; i < modelData->nStates; i++) {
if (state->stateWasUpdatedFlag[i]) {
state->stateWasUpdatedFlag[i] = 0;
Expand Down
2 changes: 1 addition & 1 deletion SimulationRuntime/opc/ua/omc_opc_ua.h
Expand Up @@ -47,7 +47,7 @@
#endif
#endif

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);
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, int *didEventStep);
OPC_UA_EXPORT void omc_embedded_server_deinit(void*);
OPC_UA_EXPORT void omc_embedded_server_update(void*, double t);

Expand Down

0 comments on commit ce11282

Please sign in to comment.