Skip to content

Commit

Permalink
Allow set counter in Instantiated and Initialization Mode (#471)
Browse files Browse the repository at this point in the history
fixes #470
  • Loading branch information
t-sommer authored Feb 26, 2024
1 parent 12960ef commit 223d398
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Stair/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#define MODEL_EXCHANGE

#define GET_INT32
#define SET_INT32

#define EVENT_UPDATE

#define FIXED_SOLVER_STEP 0.2
Expand Down
25 changes: 25 additions & 0 deletions Stair/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ Status getInt32(ModelInstance* comp, ValueReference vr, int32_t values[], size_t
}
}

Status setInt32(ModelInstance* comp, ValueReference vr, const int32_t values[], size_t nValues, size_t* index) {

ASSERT_NVALUES(1);

switch (vr) {
case vr_counter:
#if FMI_VERSION == 1
if (comp->state != Instantiated) {
logError(comp, "Variable \"counter\" can only be set after instantiation.");
return Error;
}
#else
if (comp->state != Instantiated && comp->state != InitializationMode) {
logError(comp, "Variable \"counter\" can only be set in Instantiated and Intialization Mode.");
return Error;
}
#endif
M(counter) = values[(*index)++];
return OK;
default:
logError(comp, "Set Int32 is not allowed for value reference %u.", vr);
return Error;
}
}

Status eventUpdate(ModelInstance *comp) {

const double epsilon = (1.0 + fabs(comp->time)) * DBL_EPSILON;
Expand Down

0 comments on commit 223d398

Please sign in to comment.