Skip to content

Commit

Permalink
added new example with periodic clocks
Browse files Browse the repository at this point in the history
  • Loading branch information
lausdahl committed Sep 12, 2024
1 parent 84fe32b commit 5bceacc
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public class Fmi3Interpreter {
static final ExternalReflectCallHelper.ArgMapping intArrayOutArgMapper = new ExternalReflectCallHelper.ArgMapping(TP.Int, 2,
ExternalReflectCallHelper.ArgMapping.InOut.Output, null);

static final ExternalReflectCallHelper.ArgMapping boolOutArgMapper = new ExternalReflectCallHelper.ArgMapping(TP.Bool, 1,
ExternalReflectCallHelper.ArgMapping.InOut.Output, null);
static final ExternalReflectCallHelper.ArgMapping doubleOutArgMapper = new ExternalReflectCallHelper.ArgMapping(TP.Real, 1,
ExternalReflectCallHelper.ArgMapping.InOut.Output, null);

final static Logger logger = LoggerFactory.getLogger(Interpreter.class);
private final File workingDirectory;
Expand Down Expand Up @@ -529,18 +533,19 @@ private static Value getFmuInstanceValue(BufferedOutputStream fmuLogOutputStream
}));

functions.put("updateDiscreteStates", new FunctionValue.ExternalFunctionValue(fcargs -> {
// int updateDiscreteStates(out bool[] discreteStatesNeedUpdate, out bool[] terminateSimulation,
// out bool[] nominalsOfContinuousStatesChanged, out bool[] valuesOfContinuousStatesChanged, out bool[] nextEventTimeDefined,
// out real[] nextEventTime);
// int updateDiscreteStates(out bool discreteStatesNeedUpdate, out bool terminateSimulation,
// out bool nominalsOfContinuousStatesChanged, out bool valuesOfContinuousStatesChanged, out bool nextEventTimeDefined,
// out real nextEventTime);
checkArgLength(fcargs, 6);
try {
FmuResult<IFmi3Instance.UpdateDiscreteStates> res = instance.updateDiscreteStates();
boolArrayOutArgMapper.mapOut(fcargs.get(0), new boolean[]{res.result.isDiscreteStatesNeedUpdate()});
boolArrayOutArgMapper.mapOut(fcargs.get(1), new boolean[]{res.result.isTerminateSimulation()});
boolArrayOutArgMapper.mapOut(fcargs.get(2), new boolean[]{res.result.isNominalsOfContinuousStatesChanged()});
boolArrayOutArgMapper.mapOut(fcargs.get(3), new boolean[]{res.result.isValuesOfContinuousStatesChanged()});
boolArrayOutArgMapper.mapOut(fcargs.get(4), new boolean[]{res.result.isNextEventTimeDefined()});
doubleArrayOutArgMapper.mapOut(fcargs.get(5), new double[]{res.result.getNextEventTime()});

boolOutArgMapper.mapOut(fcargs.get(0), res.result.isDiscreteStatesNeedUpdate());
boolOutArgMapper.mapOut(fcargs.get(1), res.result.isTerminateSimulation());
boolOutArgMapper.mapOut(fcargs.get(2), res.result.isNominalsOfContinuousStatesChanged());
boolOutArgMapper.mapOut(fcargs.get(3), res.result.isValuesOfContinuousStatesChanged());
boolOutArgMapper.mapOut(fcargs.get(4), res.result.isNextEventTimeDefined());
doubleOutArgMapper.mapOut(fcargs.get(5), res.result.getNextEventTime());
return status2IntValue(res.status);
} catch (FmuInvocationException e) {
throw new InterpreterException(e);
Expand Down Expand Up @@ -691,7 +696,11 @@ private static Value getFmuInstanceValue(BufferedOutputStream fmuLogOutputStream
checkArgLength(fcargs, 1);
try {
FmuResult<Long> res = instance.getNumberOfEventIndicators();
intArrayOutArgMapper.mapOut(fcargs.get(0), res.result);
final ExternalReflectCallHelper.ArgMapping uintOutArgMapper = new ExternalReflectCallHelper.ArgMapping(TP.Long, 1,
ExternalReflectCallHelper.ArgMapping.InOut.Output, null);
uintOutArgMapper.mapOut(fcargs.get(0), res.result);
UpdatableValue v= (UpdatableValue) fcargs.get(0);
v.setValue(new UnsignedIntegerValue(((LongValue)v.deref()).getValue()));
return status2IntValue(res.status);
} catch (FmuInvocationException e) {
throw new InterpreterException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,36 @@ public void mapOut(Value original, Object value) {
break;
}
ref.setValue(new ArrayValue<>(values));
}else if(dimension==1)
{
Value mappedValue = null;
switch (type){
case Bool:
mappedValue=new BooleanValue(value.getClass().isPrimitive()?(boolean)value:(Boolean)value);
break;
case Byte:
mappedValue=new ByteValue(value.getClass().isPrimitive()?(byte)value:(Byte)value);
break;
case Float:
mappedValue=new FloatValue(value.getClass().isPrimitive()?(float)value:(Float)value);
break;
case Int:
mappedValue=new IntegerValue(value.getClass().isPrimitive()?(int)value:(Integer)value);
break;
case Long:
mappedValue=new LongValue(value.getClass().isPrimitive()?(long)value:(Long)value);
break;
case Real:
mappedValue=new RealValue(value.getClass().isPrimitive()?(double)value:(Double)value);
break;
case Short:
mappedValue=new ShortValue(value.getClass().isPrimitive()?(short)value:(Short)value);
break;
case String:
mappedValue=new StringValue((String)value);
break;
}
ref.setValue(mappedValue);
}

}
Expand Down
Loading

0 comments on commit 5bceacc

Please sign in to comment.