]> gerrit.simantics Code Review - simantics/fmil.git/commitdiff
Pending status can be returns from FMU to Native C to Java 93/2293/3
authorMiro Richard Eklund <miro.eklund@semantum.fi>
Wed, 10 Oct 2018 11:49:08 +0000 (14:49 +0300)
committerMiro Richard Eklund <miro.eklund@semantum.fi>
Wed, 10 Oct 2018 11:53:37 +0000 (14:53 +0300)
Previous doStep only returned status OK or ERROR. Now pending status is
possible for asyncronous FMUs.

gitlab #10

Change-Id: I5d2ff07e98fe0137fcc9ed3500b3b0986bf1dbe0

org.simantics.fmil.core/README.md
org.simantics.fmil.core/native/FMUSimulator/src/fmi_util.c
org.simantics.fmil.core/native/FMUSimulator/src/fmu_control.cpp
org.simantics.fmil.core/src/org/simantics/fmil/core/FMIL.java
org.simantics.fmil.win32/libraries/FMUSimulator.dll
org.simantics.fmil.win64/libraries/FMUSimulator.dll

index d5ef5ef3e96eb7fe124f73e8874115e644322618..e1036be3e198b05f256c4365de8de790859e4559 100644 (file)
@@ -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"
index 5341d952018f8a3583d75c44b8bde706f2560b99..e91a6c4f70c133dbe2797b3a6b49cc5ba1961a76 100644 (file)
@@ -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;
 }
index ae86d2b047c387e8698a3f6037a1cf4db42fd66c..28e75f74c2b3a4c7dde14119cea95a1be1885902 100644 (file)
@@ -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);
index 06d1fd2b2b97acf142db5532f2c547337b2f4966..4b1eeaca132386d9e1071b4e6bac3569d25d8325 100644 (file)
@@ -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) {
index 23d5a23caa8a1b51d550ccd3f00acab73da61047..fddcb48658fb1b8794b5ab66caeb08316a084716 100644 (file)
Binary files a/org.simantics.fmil.win32/libraries/FMUSimulator.dll and b/org.simantics.fmil.win32/libraries/FMUSimulator.dll differ
index 9e12f65c50f93b4e83c89abfd48e108ebcac6c80..8c7dc44fa059e6e8d27d88ea56a97bfcbae2a88a 100644 (file)
Binary files a/org.simantics.fmil.win64/libraries/FMUSimulator.dll and b/org.simantics.fmil.win64/libraries/FMUSimulator.dll differ