From: Miro Richard Eklund Date: Wed, 10 Oct 2018 11:49:08 +0000 (+0300) Subject: Pending status can be returns from FMU to Native C to Java X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=f6f05cb36bc0b849af8090efac1d549779e2076f;p=simantics%2Ffmil.git Pending status can be returns from FMU to Native C to Java Previous doStep only returned status OK or ERROR. Now pending status is possible for asyncronous FMUs. gitlab #10 Change-Id: I5d2ff07e98fe0137fcc9ed3500b3b0986bf1dbe0 --- diff --git a/org.simantics.fmil.core/README.md b/org.simantics.fmil.core/README.md index d5ef5ef..e1036be 100644 --- a/org.simantics.fmil.core/README.md +++ b/org.simantics.fmil.core/README.md @@ -56,6 +56,6 @@ under /native/FMUSimulator/fmi_util.c.txt. The Dockerfile already does this so i When you have the Visual Studio files: Build from command-line our FMUSimulator.dll -1) Open a terminal -2) Navigate to org.simantics.fmil.core/native/FMUSimulator -3) Run "msbuild.exe" +1) Open a VS development terminal +2) Navigate to org.simantics.fmil.core/native +3) Run "windowsbuildsim.bat" diff --git a/org.simantics.fmil.core/native/FMUSimulator/src/fmi_util.c b/org.simantics.fmil.core/native/FMUSimulator/src/fmi_util.c index 5341d95..e91a6c4 100644 --- a/org.simantics.fmil.core/native/FMUSimulator/src/fmi_util.c +++ b/org.simantics.fmil.core/native/FMUSimulator/src/fmi_util.c @@ -571,6 +571,8 @@ int FMI1_CS_STEP(void *fmu, double masterTime, double stepSize, const char **err if (status == fmi1_status_error || status == fmi1_status_fatal) { *error = "Error happened during stepping!"; return 1; + } else if (status == fmi1_status_pending) { + return 2; } return 0; } @@ -583,6 +585,8 @@ int FMI2_CS_STEP(void *fmu, double masterTime, double stepSize, const char **err if (status == fmi2_status_error || status == fmi2_status_fatal) { *error = "Error happened during stepping!"; return 1; + } else if (status == fmi2_status_pending) { + return 2; } return 0; } diff --git a/org.simantics.fmil.core/native/FMUSimulator/src/fmu_control.cpp b/org.simantics.fmil.core/native/FMUSimulator/src/fmu_control.cpp index ae86d2b..28e75f7 100644 --- a/org.simantics.fmil.core/native/FMUSimulator/src/fmu_control.cpp +++ b/org.simantics.fmil.core/native/FMUSimulator/src/fmu_control.cpp @@ -693,14 +693,14 @@ JNIEXPORT jint JNICALL Java_org_simantics_fmil_core_FMIL_simulateStep_1 } else if (fmi.version == 2) { returnValue = FMI2_CS_STEP(fmi.fmu, fmi.currentTime, fmi.timeStep, &error); } - if(returnValue != 0) { + if(returnValue == 1) { string message = "Could not simulate step: "; return throwException(env, message += error); } fmi.currentTime += fmi.timeStep; - return 0; + return returnValue; //Pass return value up. 0 is OK, 1 is error, 2 is pending /* const char *fmuId = env->GetStringUTFChars(id, 0); diff --git a/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java b/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java index 06d1fd2..4b1eeac 100644 --- a/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java +++ b/org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java @@ -39,6 +39,7 @@ public class FMIL { */ private static int OK = 0; private static int ERROR = 1; + private static int PENDING = 2; private static String UNSATISFIED_LINK = "Method not found. DLL might not be loaded properly."; public static final String TEMP_FMU_DIRECTORY_NAME = "fmil"; public static String TEMP_FMU_COMMON_DIRECTORY; @@ -513,10 +514,11 @@ public class FMIL { try { - int ret = simulateStep_(getModelIDNew()); - if(ret != OK) + int ret = simulateStep_(getModelIDNew()); //0 is ok, 1 is error, 2 is pending + if(ret == PENDING) + LOGGER.warn("Pending status return from FMU. This is not implemented in our Simulator yet!"); + else if(ret != OK) LOGGER.warn("Function return value != OK, an exception should have been thrown from native code!"); - } catch (FMILException e) { throw e; } catch (UnsatisfiedLinkError err) { diff --git a/org.simantics.fmil.win32/libraries/FMUSimulator.dll b/org.simantics.fmil.win32/libraries/FMUSimulator.dll index 23d5a23..fddcb48 100644 Binary files a/org.simantics.fmil.win32/libraries/FMUSimulator.dll and b/org.simantics.fmil.win32/libraries/FMUSimulator.dll differ diff --git a/org.simantics.fmil.win64/libraries/FMUSimulator.dll b/org.simantics.fmil.win64/libraries/FMUSimulator.dll index 9e12f65..8c7dc44 100644 Binary files a/org.simantics.fmil.win64/libraries/FMUSimulator.dll and b/org.simantics.fmil.win64/libraries/FMUSimulator.dll differ