Skip to content

Commit

Permalink
fixed get binary for fmi3
Browse files Browse the repository at this point in the history
  • Loading branch information
lausdahl committed Nov 9, 2023
1 parent 27627a1 commit 3bd84c1
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,6 @@ private static Value getFmuInstanceValue(BufferedOutputStream fmuLogOutputStream


functions.put("setBinary", new FunctionValue.ExternalFunctionValue(fcargs -> {
// int setShiftDecimal(uint valueReferences[], int nValueReferences, real shifts[]);
checkArgLength(fcargs, 3);

long elementsToUse = getUint(fcargs.get(1));
Expand Down Expand Up @@ -832,6 +831,38 @@ private static Value getFmuInstanceValue(BufferedOutputStream fmuLogOutputStream

}));

functions.put("getBinary", new FunctionValue.ExternalFunctionValue(fcargs -> {
checkArgLength(fcargs, 3);

long elementsToUse = getUint(fcargs.get(1));

long[] scalarValueIndices =
getArrayValue(fcargs.get(0), Optional.of(elementsToUse), NumericValue.class).stream().mapToLong(NumericValue::longValue)
.toArray();

ByteArrayArrayValue buffer = (ByteArrayArrayValue) fcargs.get(2).deref();


try {
FmuResult<byte[][]> res = instance.getBinary(scalarValueIndices);

buffer.getModule().clear();
for (int i = 0; i < res.result.length; i++) {
int[] values = new int[res.result[i].length];
for (int j = 0; j < values.length; j++) {
values[j] = res.result[i][j];
}

buffer.getModule().add(
Arrays.stream(values).mapToObj(ByteValue::new).collect(Collectors.toList()));
}
return new IntegerValue(res.status.value);
} catch (FmiInvalidNativeStateException e) {
throw new InterpreterException(e);
}

}));


checkRequiredFunctions(module, functions);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,28 @@ import ArrayUtil;



ByteArrayArray var_201=arrayUtil.createByteArrayArray(0);
uint vref_201[1]={30};

int status_201= instance.getBinary(vref_201,1,ref var_201);
if( status_201 != 0)
error "An error occurred during setBinary";
else
logger.log(3,"getBinary status %d for variable 'Binary_input'",status_201);



ByteArrayArray var_202=arrayUtil.createByteArrayArray(0);
uint vref_202[1]={31};

int status_202= instance.getBinary(vref_202,1,ref var_202);
if( status_202 != 0)
error "An error occurred during setBinary";
else
logger.log(3,"getBinary status %d for variable 'Binary_output'",status_202);



int var_203[1000];
uint vref_203[1]={32};

Expand Down Expand Up @@ -696,7 +718,7 @@ import ArrayUtil;
bool earlyReturn=false;
real lastSuccessfulTime=0.0;


while(time < end-step)
{
res = instance.doStep(time,
Expand Down Expand Up @@ -1103,6 +1125,28 @@ import ArrayUtil;



ByteArrayArray var_235=arrayUtil.createByteArrayArray(0);
uint vref_235[1]={30};

int status_235= instance.getBinary(vref_235,1,ref var_235);
if( status_235 != 0)
error "An error occurred during setBinary";
else
logger.log(3,"getBinary status %d for variable 'Binary_input'",status_235);



ByteArrayArray var_236=arrayUtil.createByteArrayArray(0);
uint vref_236[1]={31};

int status_236= instance.getBinary(vref_236,1,ref var_236);
if( status_236 != 0)
error "An error occurred during setBinary";
else
logger.log(3,"getBinary status %d for variable 'Binary_output'",status_236);



int var_237[1000];
uint vref_237[1]={32};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ module FMI3Instance

int getString(uint valueReferences[],out string values[]);

int getBinary(uint valueReferences[], out ByteArrayArray data);
int getBinary(uint valueReferences[],int nvr, out ByteArrayArray data);
/* end::getters[] */

/* tag::setters[] */
Expand Down

0 comments on commit 3bd84c1

Please sign in to comment.