From: Miro Richard Eklund Date: Wed, 12 Sep 2018 12:50:08 +0000 (+0300) Subject: Add atomic counter for instanceName and update README, fix loadFMU X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F64%2F2164%2F9;p=simantics%2Ffmil.git Add atomic counter for instanceName and update README, fix loadFMU Readme has been updated to have a more detailed build instruction on Windows. gitlab #6 gitlab #5 Change-Id: I86462b0a15e4adac0f4b8546811f6d2c3c18087a --- diff --git a/org.simantics.fmil.core/README.md b/org.simantics.fmil.core/README.md index 46d611b..0539e37 100644 --- a/org.simantics.fmil.core/README.md +++ b/org.simantics.fmil.core/README.md @@ -1,10 +1,40 @@ # How to build FMUSimulator and FMILibrary -CMake GUI for generating Visual Studio project files from FMILibrary sources +## Base FMILibrary + +To build the Visual Studio Solution files you need CMake. +CMake is also used to build the base native FMILibrary. + +Note: +This is not usually needed, you can use the existing build. Remember to manually delete CMakeCache and CMakeFiles from FMILibrary/build/expatex/-folder -NOTE: +Follow the instructions provided by the Linux Dockerfile and linuxbuild.sh. +In short: +1) Download the desired FMILibrary source .zip +2) Unzip in a location of your choosing +3) Open terminal +4) Change directory to where you want to build the output +5) Run cmake from command-line and provide as the first argument the path to where you unzipped sources in step 2 +Optional) To make a debug version, add -DFMILIB_ENABLE_LOG_LEVEL_DEBUG=ON before the path to source +6) In both debug and normal case, run "make" and "make install test" to verify the installation + +If the build succeeded, you should have .dll files which you can now copy to your win32 or win64 org.simantics.fmil.* projects. +Specifically: +fmu1_dll_cs.dll, fmu1_dll_me.dll, fmu2_dll_cs.dll, fmu2_dll_me.sll and fmilib_shared.dll +Copy the corresponding "Debug" build files to the sub-directoryn "Debug" in the projects. + +## FMUSimulator + +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" + +## Building on linux When building the libfmilib_shared.so, we need to replace fmi_util.c file under "/src/Util/src/FMI/fmi_util.c" with contents of fmi_util.c.txt, located under /native/FMUSimulator/fmi_util.c.txt. The Dockerfile already does this so if you build the libfmilib_shared.so with that, then you needn't worry about this. diff --git a/org.simantics.fmil.core/native/FMUSimulator/fmi_util.c.txt b/org.simantics.fmil.core/native/FMUSimulator/fmi_util.c.txt index 450910c..31ef175 100644 --- a/org.simantics.fmil.core/native/FMUSimulator/fmi_util.c.txt +++ b/org.simantics.fmil.core/native/FMUSimulator/fmi_util.c.txt @@ -231,6 +231,9 @@ int FMI_CS_LOAD(const char *zipFilePath, const char *unzipFolder, void **fmuPoin *fmuPointer = fmu2; *fmuVersion = 2; + } else { + *error = "Couldn't find version of FMU - possibly incorrect file!"; + return 1; } fmi_import_free_context(context); 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 285be84..bb8e076 100644 --- a/org.simantics.fmil.core/native/FMUSimulator/src/fmu_control.cpp +++ b/org.simantics.fmil.core/native/FMUSimulator/src/fmu_control.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include @@ -33,6 +34,12 @@ extern "C" { using namespace std; +static std::atomic instanceNameID; + +int create_id() { + return instanceNameID++; +} + struct FMI1 { void *fmu; @@ -472,14 +479,16 @@ JNIEXPORT jdoubleArray JNICALL Java_org_simantics_fmil_core_FMIL_getSubscribedRe JNIEXPORT jint JNICALL Java_org_simantics_fmil_core_FMIL_instantiateSimulation_1 (JNIEnv *env, jobject obj, jint id) { + int uniqueId = create_id(); + std::string instanceName = std::to_string(uniqueId); int returnValue; const char *error = ""; FMI1 &fmi = fmus[id]; if (fmi.version == 1) { - returnValue = FMI1_CS_INSTANTIATE(fmi.fmu, "", &error); + returnValue = FMI1_CS_INSTANTIATE(fmi.fmu, instanceName, &error); } else if (fmi.version == 2) { - returnValue = FMI2_CS_INSTANTIATE(fmi.fmu, "", &error); + returnValue = FMI2_CS_INSTANTIATE(fmi.fmu, instanceName, &error); } if(returnValue != 0) { string message = "No FMU loaded: "; 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 f4c7ca4..1f1e098 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 @@ -184,6 +184,11 @@ public class FMIL { private boolean fmuLoaded = false; public void loadFMUFile(String path) throws FMILException { + if (!Files.exists(Paths.get(path))) + throw new FMILException("File " + path + " does not exist"); + if (!Files.isRegularFile(Paths.get(path))) + throw new FMILException("Path " + path + " is not a file"); + synchronized(syncObject) { if(fmuN % 2 == 0) { @@ -232,7 +237,7 @@ public class FMIL { } } - private native int loadFMUFile_(String path, String toDir); + private native int loadFMUFile_(String path, String toDir) throws FMILException; /** * Set a step length for simulation