From: Tuukka Lehtonen Date: Fri, 21 Sep 2018 09:34:10 +0000 (+0000) Subject: Merge "Added getters and setters for all FMI data types." X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=4282c2e792b39be912e3db8226c342867c2dc065;hp=f5e59cf2a25d35424f2b85ea382f2db13bcadff7;p=simantics%2Ffmil.git Merge "Added getters and setters for all FMI data types." --- diff --git a/org.simantics.fmil.core/native/FMUSimulator/include/fmi1_cs.h b/org.simantics.fmil.core/native/FMUSimulator/include/fmi1_cs.h index 9704022..d3e6229 100644 --- a/org.simantics.fmil.core/native/FMUSimulator/include/fmi1_cs.h +++ b/org.simantics.fmil.core/native/FMUSimulator/include/fmi1_cs.h @@ -5,16 +5,10 @@ extern "C" { #endif -#ifdef _MSC_VER -#define DLLEXPORT __declspec(dllexport) -#else -#define DLLEXPORT -#endif - typedef struct { - char *name; - char *description; - char *declaredType; + const char *name; + const char *description; + const char *declaredType; long vr; // 0 = real // 1 = integer @@ -37,33 +31,56 @@ typedef struct { } FMIL_Variable; typedef struct { - char *name; - char *description; - char *quantity; - char *unit; + const char *name; + const char *description; + const char *quantity; + const char *unit; } FMIL_DeclaredType; -DLLEXPORT int FMI_CS_LOAD(const char *zipFilePath, const char *unzipFolder, void **fmuPointer, int *fmuVersion, const char **error); +int FMI_CS_LOAD(const char *zipFilePath, const char *unzipFolder, void **fmuPointer, int *fmuVersion, const char **error); + +int FMI1_CS_UNLOAD(void* fmu, const char **error); +FMIL_Variable *FMI1_CS_GET_VARIABLES(void* fmu, int *count, const char **error); +FMIL_DeclaredType *FMI1_CS_GET_DECLARED_TYPES(void* fmu, int *count, const char **error); +int FMI1_CS_INSTANTIATE(void* fmu, const char *instanceName, const char **error); +int FMI1_CS_INITIALIZE(void* fmu, const char **error); +int FMI1_CS_STEP(void* fmu, double masterTime, double stepSize, const char **error); + +int FMI1_CS_SET_REAL(void *fmu, int valueId, double value, const char **error); +int FMI1_CS_SET_INTEGER(void *fmu, int valueId, int value, const char **error); +int FMI1_CS_SET_BOOLEAN(void *fmu, int valueId, int value, const char **error); +int FMI1_CS_SET_STRING(void *fmu, int valueId, const char *value, const char **error); + +double FMI1_CS_GET_REAL(void *fmu, int valueReference, const char **error); +int FMI1_CS_GET_INTEGER(void *fmu, int valueReference, const char **error); +int FMI1_CS_GET_BOOLEAN(void *fmu, int valueReference, const char **error); +const char *FMI1_CS_GET_STRING(void *fmu, int valueReference, const char **error); + +int FMI1_CS_GET_REALS(void *fmu, int *valueReferences, double *result, int count, const char **error); +int FMI1_CS_GET_INTEGERS(void *fmu, int *valueReferences, int *result, int count, const char **error); +int FMI1_CS_GET_BOOLEANS(void *fmu, int *valueReferences, char *result, int count, const char **error); +int FMI1_CS_GET_STRINGS(void *fmu, int *valueReferences, const char **result, int count, const char **error); + +int FMI2_CS_UNLOAD(void* fmu, const char **error); +FMIL_Variable *FMI2_CS_GET_VARIABLES(void* fmu, int *count, const char **error); +FMIL_DeclaredType *FMI2_CS_GET_DECLARED_TYPES(void* fmu, int *count, const char **error); +int FMI2_CS_INSTANTIATE(void* fmu, const char *instanceName, const char **error); +int FMI2_CS_INITIALIZE(void* fmu, const char **error); +int FMI2_CS_STEP(void* fmu, double masterTime, double stepSize, const char **error); +int FMI2_CS_SET_REAL(void *fmu, int valueId, double value, const char **error); +int FMI2_CS_SET_INTEGER(void *fmu, int valueId, int value, const char **error); +int FMI2_CS_SET_BOOLEAN(void *fmu, int valueId, int value, const char **error); +int FMI2_CS_SET_STRING(void *fmu, int valueId, const char *value, const char **error); -DLLEXPORT int FMI1_CS_UNLOAD(void* fmu, const char **error); -DLLEXPORT FMIL_Variable *FMI1_CS_GET_VARIABLES(void* fmu, int *count, const char **error); -DLLEXPORT FMIL_DeclaredType *FMI1_CS_GET_DECLARED_TYPES(void* fmu, int *count, const char **error); -DLLEXPORT int FMI1_CS_INSTANTIATE(void* fmu, const char *instanceName, const char **error); -DLLEXPORT int FMI1_CS_INITIALIZE(void* fmu, const char **error); -DLLEXPORT int FMI1_CS_STEP(void* fmu, double masterTime, double stepSize, const char **error); -DLLEXPORT int FMI1_CS_SET_REAL(void* fmu, int vr, double value, const char **error); -DLLEXPORT double FMI1_CS_GET_REAL(void* fmu, int vr, const char **error); -DLLEXPORT int FMI1_CS_GET_REALS(void* fmu, int *vrs, double *values, int count, const char **error); +double FMI2_CS_GET_REAL(void *fmu, int valueReference, const char **error); +int FMI2_CS_GET_INTEGER(void *fmu, int valueReference, const char **error); +int FMI2_CS_GET_BOOLEAN(void *fmu, int valueReference, const char **error); +const char *FMI2_CS_GET_STRING(void *fmu, int valueReference, const char **error); -DLLEXPORT int FMI2_CS_UNLOAD(void* fmu, const char **error); -DLLEXPORT FMIL_Variable *FMI2_CS_GET_VARIABLES(void* fmu, int *count, const char **error); -DLLEXPORT FMIL_DeclaredType *FMI2_CS_GET_DECLARED_TYPES(void* fmu, int *count, const char **error); -DLLEXPORT int FMI2_CS_INSTANTIATE(void* fmu, const char *instanceName, const char **error); -DLLEXPORT int FMI2_CS_INITIALIZE(void* fmu, const char **error); -DLLEXPORT int FMI2_CS_STEP(void* fmu, double masterTime, double stepSize, const char **error); -DLLEXPORT int FMI2_CS_SET_REAL(void* fmu, int vr, double value, const char **error); -DLLEXPORT double FMI2_CS_GET_REAL(void* fmu, int vr, const char **error); -DLLEXPORT int FMI2_CS_GET_REALS(void* fmu, int *vrs, double *values, int count, const char **error); +int FMI2_CS_GET_REALS(void *fmu, int *valueReferences, double *result, int count, const char **error); +int FMI2_CS_GET_INTEGERS(void *fmu, int *valueReferences, int *result, int count, const char **error); +int FMI2_CS_GET_BOOLEANS(void *fmu, int *valueReferences, int *result, int count, const char **error); +int FMI2_CS_GET_STRINGS(void *fmu, int *valueReferences, const char **result, int count, const char **error); #ifdef __cplusplus } 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 32bf32f..5341d95 100644 --- a/org.simantics.fmil.core/native/FMUSimulator/src/fmi_util.c +++ b/org.simantics.fmil.core/native/FMUSimulator/src/fmi_util.c @@ -7,67 +7,7 @@ #include -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - const char *name; - const char *description; - const char *declaredType; - long vr; - /* 0 = real - // 1 = integer - // 2 = boolean - // 3 = string - // 4 = enumeration */ - int type; - /* 0 = constant - // 1 = parameter - // 2 = discrete - // 3 = continuous - // 4 = unknown */ - int variability; - /* 0 = input - // 1 = output - // 2 = internal - // 3 = none - // 4 = unknown */ - int causality; -} FMIL_Variable; - -typedef struct { - const char *name; - const char *description; - const char *quantity; - const char *unit; -} FMIL_DeclaredType; - -int FMI_CS_LOAD(const char *zipFilePath, const char *unzipFolder, void **fmuPointer, int *fmuVersion, const char **error); - -int FMI1_CS_UNLOAD(void* fmu, const char **error); -FMIL_Variable *FMI1_CS_GET_VARIABLES(void* fmu, int *count, const char **error); -FMIL_DeclaredType *FMI1_CS_GET_DECLARED_TYPES(void* fmu, int *count, const char **error); -int FMI1_CS_INSTANTIATE(void* fmu, const char *instanceName, const char **error); -int FMI1_CS_INITIALIZE(void* fmu, const char **error); -int FMI1_CS_STEP(void* fmu, double masterTime, double stepSize, const char **error); -int FMI1_CS_SET_REAL(void* fmu, int vr, double value, const char **error); -double FMI1_CS_GET_REAL(void* fmu, int vr, const char **error); -int FMI1_CS_GET_REALS(void* fmu, int *vrs, double *values, int count, const char **error); - -int FMI2_CS_UNLOAD(void* fmu, const char **error); -FMIL_Variable *FMI2_CS_GET_VARIABLES(void* fmu, int *count, const char **error); -FMIL_DeclaredType *FMI2_CS_GET_DECLARED_TYPES(void* fmu, int *count, const char **error); -int FMI2_CS_INSTANTIATE(void* fmu, const char *instanceName, const char **error); -int FMI2_CS_INITIALIZE(void* fmu, const char **error); -int FMI2_CS_STEP(void* fmu, double masterTime, double stepSize, const char **error); -int FMI2_CS_SET_REAL(void* fmu, int vr, double value, const char **error); -double FMI2_CS_GET_REAL(void* fmu, int vr, const char **error); -int FMI2_CS_GET_REALS(void* fmu, int *vrs, double *values, int count, const char **error); - -#ifdef __cplusplus -} -#endif +#include #define BUFFER 4096 @@ -84,11 +24,11 @@ void fmilogger(fmi1_component_t c, fmi1_string_t instanceName, fmi1_status_t sta int len; va_list argp; va_start(argp, message); - /*len=jm_vsnprintf(msg, BUFFER, message, argp); + len = vsnprintf(msg, BUFFER, message, argp); printf("fmiStatus = %d; %s (%s): %s\n", status, instanceName, category, msg); if(len > BUFFER) { - printf("Warning: message was trancated"); - }*/ + printf("Warning: Message was truncated.\n"); + } } int FMI_CS_LOAD(const char *zipFilePath, const char *unzipFolder, void **fmuPointer, int *fmuVersion, const char **error) { @@ -268,7 +208,7 @@ FMIL_Variable *FMI1_CS_GET_VARIABLES(void *fmu, int *count, const char **error) fmi1_import_variable_list_t* vl = fmi1_import_get_variable_list((fmi1_import_t *)fmu); fmi1_import_variable_typedef_t* type; - count[0] = fmi1_import_get_variable_list_size(vl); + count[0] = (int)fmi1_import_get_variable_list_size(vl); result = (FMIL_Variable *)malloc(count[0]*sizeof(FMIL_Variable)); @@ -365,7 +305,7 @@ FMIL_Variable *FMI2_CS_GET_VARIABLES(void *fmu, int *count, const char **error) fmi2_import_variable_list_t* vl = fmi2_import_get_variable_list((fmi2_import_t *)fmu, 0); fmi2_import_variable_typedef_t* type; - count[0] = fmi2_import_get_variable_list_size(vl); + count[0] = (int)fmi2_import_get_variable_list_size(vl); result = (FMIL_Variable *)malloc(count[0]*sizeof(FMIL_Variable)); @@ -552,14 +492,13 @@ int FMI2_CS_INSTANTIATE(void *fmu, const char *instanceName, const char **error) fmi2_string_t mimeType; fmi2_real_t timeout; fmi2_boolean_t visible; - fmi2_boolean_t interactive; - fmi2_boolean_t loggingOn; jm_status_enu_t jmstatus; fmuLocation = ""; mimeType = ""; timeout = 0; visible = fmi2_false; + // With NULL value for resourceLocation, its value is taken from the `fmu` argument jmstatus = fmi2_import_instantiate((fmi2_import_t*)fmu, instanceName, fmi2_cosimulation, NULL, visible); if (jmstatus == jm_status_error) { *error = fmi2_import_get_last_error((fmi2_import_t*)fmu); @@ -648,12 +587,15 @@ int FMI2_CS_STEP(void *fmu, double masterTime, double stepSize, const char **err return 0; } +// FMI1 setters + int FMI1_CS_SET_REAL(void *fmu, int valueId, double value, const char **error) { fmi1_status_t status; + fmi1_real_t valueTmp = value; fmi1_value_reference_t vr = valueId; - status = fmi1_import_set_real((fmi1_import_t *)fmu, &vr, 1, &value); + status = fmi1_import_set_real((fmi1_import_t *)fmu, &vr, 1, &valueTmp); if (status == fmi1_status_error || status == fmi1_status_fatal) { *error = "Error happened during setting real value!"; return 1; @@ -661,12 +603,57 @@ int FMI1_CS_SET_REAL(void *fmu, int valueId, double value, const char **error) { return 0; } +int FMI1_CS_SET_INTEGER(void *fmu, int valueId, int value, const char **error) { + + fmi1_status_t status; + fmi1_integer_t valueTmp = value; + + fmi1_value_reference_t vr = valueId; + status = fmi1_import_set_integer((fmi1_import_t *)fmu, &vr, 1, &valueTmp); + if (status == fmi1_status_error || status == fmi1_status_fatal) { + *error = "Error happened during setting integer value!"; + return 1; + } + return 0; +} + +int FMI1_CS_SET_BOOLEAN(void *fmu, int valueId, int value, const char **error) { + + fmi1_status_t status; + fmi1_boolean_t valueTmp = value != 0; + + fmi1_value_reference_t vr = valueId; + status = fmi1_import_set_boolean((fmi1_import_t *)fmu, &vr, 1, &valueTmp); + if (status == fmi1_status_error || status == fmi1_status_fatal) { + *error = "Error happened during setting boolean value!"; + return 1; + } + return 0; +} + +int FMI1_CS_SET_STRING(void *fmu, int valueId, const char *value, const char **error) { + + fmi1_status_t status; + fmi1_string_t valueTmp = value; + + fmi1_value_reference_t vr = valueId; + status = fmi1_import_set_string((fmi1_import_t *)fmu, &vr, 1, &valueTmp); + if (status == fmi1_status_error || status == fmi1_status_fatal) { + *error = "Error happened during setting string value!"; + return 1; + } + return 0; +} + +// FMI2 setters + int FMI2_CS_SET_REAL(void *fmu, int valueId, double value, const char **error) { fmi2_status_t status; + fmi2_real_t valueTmp = value; fmi2_value_reference_t vr = valueId; - status = fmi2_import_set_real((fmi2_import_t *)fmu, &vr, 1, &value); + status = fmi2_import_set_real((fmi2_import_t *)fmu, &vr, 1, &valueTmp); if (status == fmi2_status_error || status == fmi2_status_fatal) { *error = "Error happened during setting real value!"; return 1; @@ -674,6 +661,50 @@ int FMI2_CS_SET_REAL(void *fmu, int valueId, double value, const char **error) { return 0; } +int FMI2_CS_SET_INTEGER(void *fmu, int valueId, int value, const char **error) { + + fmi2_status_t status; + fmi2_integer_t valueTmp = value; + + fmi2_value_reference_t vr = valueId; + status = fmi2_import_set_integer((fmi2_import_t *)fmu, &vr, 1, &valueTmp); + if (status == fmi2_status_error || status == fmi2_status_fatal) { + *error = "Error happened during setting integer value!"; + return 1; + } + return 0; +} + +int FMI2_CS_SET_BOOLEAN(void *fmu, int valueId, int value, const char **error) { + + fmi2_status_t status; + fmi2_boolean_t valueTmp = value != 0; + + fmi2_value_reference_t vr = valueId; + status = fmi2_import_set_boolean((fmi2_import_t *)fmu, &vr, 1, &valueTmp); + if (status == fmi2_status_error || status == fmi2_status_fatal) { + *error = "Error happened during setting boolean value!"; + return 1; + } + return 0; +} + +int FMI2_CS_SET_STRING(void *fmu, int valueId, const char *value, const char **error) { + + fmi2_status_t status; + fmi2_string_t valueTmp = value; + + fmi2_value_reference_t vr = valueId; + status = fmi2_import_set_string((fmi2_import_t *)fmu, &vr, 1, &valueTmp); + if (status == fmi2_status_error || status == fmi2_status_fatal) { + *error = "Error happened during setting string value!"; + return 1; + } + return 0; +} + +// FMI1 getters + double FMI1_CS_GET_REAL(void *fmu, int valueReference, const char **error) { fmi1_value_reference_t vr = valueReference; @@ -688,6 +719,50 @@ double FMI1_CS_GET_REAL(void *fmu, int valueReference, const char **error) { return value; } +int FMI1_CS_GET_INTEGER(void *fmu, int valueReference, const char **error) { + + fmi1_value_reference_t vr = valueReference; + fmi1_integer_t value; + + fmi1_status_t status; + + status = fmi1_import_get_integer((fmi1_import_t *)fmu, &vr, 1, &value); + if (status == fmi1_status_error || status == fmi1_status_fatal) { + *error = "Error happened during getting integer value!"; + } + return value; +} + +int FMI1_CS_GET_BOOLEAN(void *fmu, int valueReference, const char **error) { + + fmi1_value_reference_t vr = valueReference; + fmi1_boolean_t value; + + fmi1_status_t status; + + status = fmi1_import_get_boolean((fmi1_import_t *)fmu, &vr, 1, &value); + if (status == fmi1_status_error || status == fmi1_status_fatal) { + *error = "Error happened during getting boolean value!"; + } + return value; +} + +const char *FMI1_CS_GET_STRING(void *fmu, int valueReference, const char **error) { + + fmi1_value_reference_t vr = valueReference; + fmi1_string_t value; + + fmi1_status_t status; + + status = fmi1_import_get_string((fmi1_import_t *)fmu, &vr, 1, &value); + if (status == fmi1_status_error || status == fmi1_status_fatal) { + *error = "Error happened during getting string value!"; + } + return value; +} + +// FMI2 getters + double FMI2_CS_GET_REAL(void *fmu, int valueReference, const char **error) { fmi2_value_reference_t vr = valueReference; @@ -697,35 +772,152 @@ double FMI2_CS_GET_REAL(void *fmu, int valueReference, const char **error) { status = fmi2_import_get_real((fmi2_import_t *)fmu, &vr, 1, &value); if (status == fmi2_status_error || status == fmi2_status_fatal) { - *error = "Error happened during setting real value!"; + *error = "Error happened during getting real value!"; } return value; } -int FMI1_CS_GET_REALS(void *fmu, int *valueReferences, double *result, int count, const char **error) { +int FMI2_CS_GET_INTEGER(void *fmu, int valueReference, const char **error) { - fmi1_value_reference_t *vrs = (fmi1_value_reference_t*) valueReferences; - fmi1_real_t value; + fmi2_value_reference_t vr = valueReference; + fmi2_integer_t value; + + fmi2_status_t status; + + status = fmi2_import_get_integer((fmi2_import_t *)fmu, &vr, 1, &value); + if (status == fmi2_status_error || status == fmi2_status_fatal) { + *error = "Error happened during getting integer value!"; + } + return value; +} + +int FMI2_CS_GET_BOOLEAN(void *fmu, int valueReference, const char **error) { + + fmi2_value_reference_t vr = valueReference; + fmi2_boolean_t value; + + fmi2_status_t status; + status = fmi2_import_get_boolean((fmi2_import_t *)fmu, &vr, 1, &value); + if (status == fmi2_status_error || status == fmi2_status_fatal) { + *error = "Error happened during getting boolean value!"; + } + return value; +} + +const char *FMI2_CS_GET_STRING(void *fmu, int valueReference, const char **error) { + + fmi2_value_reference_t vr = valueReference; + fmi2_string_t value; + + fmi2_status_t status; + + status = fmi2_import_get_string((fmi2_import_t *)fmu, &vr, 1, &value); + if (status == fmi2_status_error || status == fmi2_status_fatal) { + *error = "Error happened during getting string value!"; + } + return value; +} + +// FMI1 array getters + +int FMI1_CS_GET_REALS(void *fmu, int *valueReferences, double *result, int count, const char **error) { + + fmi1_value_reference_t *vrs = (fmi1_value_reference_t*)valueReferences; fmi1_status_t status; status = fmi1_import_get_real((fmi1_import_t *)fmu, vrs, count, result); if (status == fmi1_status_error || status == fmi1_status_fatal) { - *error = "Error happened during getting reals value!"; + *error = "Error happened during getting real values!"; + } + return 0; +} + +int FMI1_CS_GET_INTEGERS(void *fmu, int *valueReferences, int *result, int count, const char **error) { + + fmi1_value_reference_t *vrs = (fmi1_value_reference_t*)valueReferences; + fmi1_status_t status; + + status = fmi1_import_get_integer((fmi1_import_t *)fmu, vrs, count, result); + if (status == fmi1_status_error || status == fmi1_status_fatal) { + *error = "Error happened during getting integer values!"; } return 0; } +int FMI1_CS_GET_BOOLEANS(void *fmu, int *valueReferences, char *result, int count, const char **error) { + + fmi1_value_reference_t *vrs = (fmi1_value_reference_t*)valueReferences; + fmi1_status_t status; + + status = fmi1_import_get_boolean((fmi1_import_t *)fmu, vrs, count, result); + if (status == fmi1_status_error || status == fmi1_status_fatal) { + *error = "Error happened during getting boolean values!"; + } + return 0; +} + +int FMI1_CS_GET_STRINGS(void *fmu, int *valueReferences, const char **result, int count, const char **error) { + + fmi1_value_reference_t *vrs = (fmi1_value_reference_t*)valueReferences; + fmi1_status_t status; + + status = fmi1_import_get_string((fmi1_import_t *)fmu, vrs, count, result); + if (status == fmi1_status_error || status == fmi1_status_fatal) { + *error = "Error happened during getting string values!"; + } + return 0; +} + +// FMI2 array getters + int FMI2_CS_GET_REALS(void *fmu, int *valueReferences, double *result, int count, const char **error) { fmi2_value_reference_t *vrs = (fmi2_value_reference_t*) valueReferences; - fmi2_real_t value; - fmi2_status_t status; status = fmi2_import_get_real((fmi2_import_t *)fmu, vrs, count, result); if (status == fmi2_status_error || status == fmi2_status_fatal) { - *error = "Error happened during getting reals value!"; + *error = "Error happened during getting real values!"; + } + return 0; + +} + +int FMI2_CS_GET_INTEGERS(void *fmu, int *valueReferences, int *result, int count, const char **error) { + + fmi2_value_reference_t *vrs = (fmi2_value_reference_t*)valueReferences; + fmi2_status_t status; + + status = fmi2_import_get_integer((fmi2_import_t *)fmu, vrs, count, result); + if (status == fmi2_status_error || status == fmi2_status_fatal) { + *error = "Error happened during getting integer values!"; + } + return 0; + +} + +int FMI2_CS_GET_BOOLEANS(void *fmu, int *valueReferences, int *result, int count, const char **error) { + + fmi2_value_reference_t *vrs = (fmi2_value_reference_t*)valueReferences; + fmi2_status_t status; + + status = fmi2_import_get_boolean((fmi2_import_t *)fmu, vrs, count, result); + if (status == fmi2_status_error || status == fmi2_status_fatal) { + *error = "Error happened during getting boolean values!"; + } + return 0; + +} + +int FMI2_CS_GET_STRINGS(void *fmu, int *valueReferences, const char **result, int count, const char **error) { + + fmi2_value_reference_t *vrs = (fmi2_value_reference_t*) valueReferences; + fmi2_status_t status; + + status = fmi2_import_get_string((fmi2_import_t *)fmu, vrs, count, result); + if (status == fmi2_status_error || status == fmi2_status_fatal) { + *error = "Error happened during getting string values!"; } 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 13272f1..dba9da2 100644 --- a/org.simantics.fmil.core/native/FMUSimulator/src/fmu_control.cpp +++ b/org.simantics.fmil.core/native/FMUSimulator/src/fmu_control.cpp @@ -233,7 +233,7 @@ JNIEXPORT jint JNICALL Java_org_simantics_fmil_core_FMIL_loadFMUFile_1 env->ReleaseStringUTFChars(path, fmuPath); env->ReleaseStringUTFChars(tempDir, fmuTempDir); - return fmus.size() - 1; + return (jint)fmus.size() - 1; } @@ -296,109 +296,75 @@ string getTypeString(ScalarVariable* sv) { JNIEXPORT jint JNICALL Java_org_simantics_fmil_core_FMIL_setRealValue_1 (JNIEnv *env, jobject obj, jint id, jint vr, jdouble value) { - const char *error = ""; - FMI1 fmi = fmus[id]; - if (fmi.version == 1) { + const char *error = ""; + FMI1 &fmi = fmus[id]; + if (fmi.version == 1) { FMI1_CS_SET_REAL(fmi.fmu, vr, value, &error); - } else if (fmi.version == 2) { - FMI2_CS_SET_REAL(fmi.fmu, vr, value, &error); - } - if (!isEmpty(error)) { - string message = "Could not set real value "; - return throwFMILException(env, message += error); - } - return 0; + } + else if (fmi.version == 2) { + FMI2_CS_SET_REAL(fmi.fmu, vr, value, &error); + } + if (!isEmpty(error)) { + string message = "Could not set real value: "; + return throwFMILException(env, message += error); + } + return 0; } JNIEXPORT jint JNICALL Java_org_simantics_fmil_core_FMIL_setIntegerValue_1 - (JNIEnv *env, jobject obj, jstring id, jstring parameter, jint value) { - /* - const char *fmuId = env->GetStringUTFChars(id, 0); - if(exists(fmuId)) { - FMUControlStruct& fmuStruct = fmus[fmuId]; - const char *name = env->GetStringUTFChars(parameter, 0); - string nameString = name; - string modelId = fmuId; - if(!referenceExists(fmuStruct, name)) { - string errorMessage = "setIntegerValue: Model (id " + modelId + ") does not contain variable: " + nameString; - env->ReleaseStringUTFChars(parameter, name); - env->ReleaseStringUTFChars(id, fmuId); - return throwException(env, errorMessage); - } else { - // Check variable type - ScalarVariable* sv = fmuStruct.vars[fmuStruct.indexes[name]]; - switch (sv->typeSpec->type){ - case elm_Integer: - break; // ok - default: { - string errorMessage = "setIntegerValue: " + nameString + " is not of type Integer. (type: + " + getTypeString(sv) + ")"; - env->ReleaseStringUTFChars(parameter, name); - env->ReleaseStringUTFChars(id, fmuId); - return throwException(env, errorMessage); - } - } - - // Change value - fmiValueReference vr = getReference(fmuStruct, name); - const int intValue = (int) value; - fmuStruct.fmu.setInteger(fmuStruct.c, &vr, 1, &intValue); - env->ReleaseStringUTFChars(parameter, name); - env->ReleaseStringUTFChars(id, fmuId); - return 1; - } - } else { - string message = fmuId; - env->ReleaseStringUTFChars(id, fmuId); - return throwException(env, "setIntegerValue: Model id " + message + " not found"); + (JNIEnv *env, jobject obj, jint id, jint vr, jint value) { + + const char *error = ""; + FMI1 fmi = fmus[id]; + if (fmi.version == 1) { + FMI1_CS_SET_INTEGER(fmi.fmu, vr, value, &error); } - */ - return 1; + else if (fmi.version == 2) { + FMI2_CS_SET_INTEGER(fmi.fmu, vr, value, &error); + } + if (!isEmpty(error)) { + string message = "Could not set integer value: "; + return throwFMILException(env, message += error); + } + return 0; } JNIEXPORT jint JNICALL Java_org_simantics_fmil_core_FMIL_setBooleanValue_1 - (JNIEnv *env, jobject obj, jstring id, jstring parameter, jboolean value) { - /* - const char *fmuId = env->GetStringUTFChars(id, 0); - if(exists(fmuId)) { - FMUControlStruct& fmuStruct = fmus[fmuId]; - const char *name = env->GetStringUTFChars(parameter, 0); - string nameString = name; - string modelId = fmuId; - if(!referenceExists(fmuStruct, name)) { - string errorMessage = "setBooleanValue: Model (id " + modelId + ") does not contain variable: " + nameString; - env->ReleaseStringUTFChars(parameter, name); - env->ReleaseStringUTFChars(id, fmuId); - return throwException(env, errorMessage); - } else { - // Check variable type - ScalarVariable* sv = fmuStruct.vars[fmuStruct.indexes[name]]; - switch (sv->typeSpec->type){ - case elm_Boolean: - break; // ok - default: { - string errorMessage = "setBooleanValue: " + nameString + " is not of type Boolean. (type: + " + getTypeString(sv) + ")"; - env->ReleaseStringUTFChars(parameter, name); - env->ReleaseStringUTFChars(id, fmuId); - return throwException(env, errorMessage); - } - } + (JNIEnv *env, jobject obj, jint id, jint vr, jboolean value) { - // Change value - fmiValueReference vr = getReference(fmuStruct, name); - fmiBoolean result = 1; - if(value == 0) - result = 0; - fmuStruct.fmu.setBoolean(fmuStruct.c, &vr, 1, &result); - env->ReleaseStringUTFChars(parameter, name); - env->ReleaseStringUTFChars(id, fmuId); - return 1; - } - } else { - string message = fmuId; - env->ReleaseStringUTFChars(id, fmuId); - return throwException(env, "setBooleanValue: Model id " + message + " not found"); - }*/ - return 1; + const char *error = ""; + FMI1 fmi = fmus[id]; + if (fmi.version == 1) { + FMI1_CS_SET_BOOLEAN(fmi.fmu, vr, value != 0, &error); + } + else if (fmi.version == 2) { + FMI2_CS_SET_BOOLEAN(fmi.fmu, vr, value != 0, &error); + } + if (!isEmpty(error)) { + string message = "Could not set boolean value: "; + return throwFMILException(env, message += error); + } + return 0; +} + +JNIEXPORT jint JNICALL Java_org_simantics_fmil_core_FMIL_setStringValue_1 +(JNIEnv *env, jobject obj, jint id, jint vr, jstring value) { + + const char *error = ""; + const char *valueChars = env->GetStringUTFChars(value, 0); + FMI1 fmi = fmus[id]; + if (fmi.version == 1) { + FMI1_CS_SET_INTEGER(fmi.fmu, vr, value != 0, &error); + } + else if (fmi.version == 2) { + FMI2_CS_SET_INTEGER(fmi.fmu, vr, value != 0, &error); + } + env->ReleaseStringUTFChars(value, valueChars); + if (!isEmpty(error)) { + string message = "Could not set string value: "; + return throwFMILException(env, message += error); + } + return 0; } JNIEXPORT jboolean JNICALL Java_org_simantics_fmil_core_FMIL_isInitialized_1 @@ -525,7 +491,7 @@ JNIEXPORT jint JNICALL Java_org_simantics_fmil_core_FMIL_setTime_1 JNIEXPORT jobjectArray JNICALL Java_org_simantics_fmil_core_FMIL_getAllVariables_1 (JNIEnv *env, jobject obj, jint id) { - jobjectArray ret= (jobjectArray)env->NewObjectArray(fmus[id].variables.size(), + jobjectArray ret= (jobjectArray)env->NewObjectArray((jsize)fmus[id].variables.size(), env->FindClass("java/lang/String"), env->NewStringUTF("")); @@ -540,7 +506,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simantics_fmil_core_FMIL_getAllVariables JNIEXPORT jobjectArray JNICALL Java_org_simantics_fmil_core_FMIL_getAllVariableDescriptions_1 (JNIEnv *env, jobject obj, jint id) { - jobjectArray ret= (jobjectArray)env->NewObjectArray(fmus[id].descriptions.size(), + jobjectArray ret= (jobjectArray)env->NewObjectArray((jsize)fmus[id].descriptions.size(), env->FindClass("java/lang/String"), env->NewStringUTF("")); @@ -555,7 +521,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simantics_fmil_core_FMIL_getAllVariableD JNIEXPORT jobjectArray JNICALL Java_org_simantics_fmil_core_FMIL_getAllVariableDeclaredTypes_1 (JNIEnv *env, jobject obj, jint id) { - jobjectArray ret= (jobjectArray)env->NewObjectArray(fmus[id].declaredTypes.size(), + jobjectArray ret= (jobjectArray)env->NewObjectArray((jsize)fmus[id].declaredTypes.size(), env->FindClass("java/lang/String"), env->NewStringUTF("")); @@ -648,7 +614,7 @@ JNIEXPORT jintArray JNICALL Java_org_simantics_fmil_core_FMIL_getAllVariableCaus JNIEXPORT jobjectArray JNICALL Java_org_simantics_fmil_core_FMIL_getAllDeclaredTypes_1 (JNIEnv *env, jobject obj, jint id) { - jobjectArray ret= (jobjectArray)env->NewObjectArray(fmus[id].declaredTypeNames.size(), + jobjectArray ret= (jobjectArray)env->NewObjectArray((jsize)fmus[id].declaredTypeNames.size(), env->FindClass("java/lang/String"), env->NewStringUTF("")); @@ -663,7 +629,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simantics_fmil_core_FMIL_getAllDeclaredT JNIEXPORT jobjectArray JNICALL Java_org_simantics_fmil_core_FMIL_getAllDeclaredTypeDescriptions_1 (JNIEnv *env, jobject obj, jint id) { - jobjectArray ret= (jobjectArray)env->NewObjectArray(fmus[id].typeDescriptions.size(), + jobjectArray ret= (jobjectArray)env->NewObjectArray((jsize)fmus[id].typeDescriptions.size(), env->FindClass("java/lang/String"), env->NewStringUTF("")); @@ -678,7 +644,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simantics_fmil_core_FMIL_getAllDeclaredT JNIEXPORT jobjectArray JNICALL Java_org_simantics_fmil_core_FMIL_getAllDeclaredTypeQuantities_1 (JNIEnv *env, jobject obj, jint id) { - jobjectArray ret= (jobjectArray)env->NewObjectArray(fmus[id].quantities.size(), + jobjectArray ret= (jobjectArray)env->NewObjectArray((jsize)fmus[id].quantities.size(), env->FindClass("java/lang/String"), env->NewStringUTF("")); @@ -693,7 +659,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_simantics_fmil_core_FMIL_getAllDeclaredT JNIEXPORT jobjectArray JNICALL Java_org_simantics_fmil_core_FMIL_getAllDeclaredTypeUnits_1 (JNIEnv *env, jobject obj, jint id) { - jobjectArray ret= (jobjectArray)env->NewObjectArray(fmus[id].units.size(), + jobjectArray ret= (jobjectArray)env->NewObjectArray((jsize)fmus[id].units.size(), env->FindClass("java/lang/String"), env->NewStringUTF("")); @@ -882,105 +848,73 @@ JNIEXPORT jdouble JNICALL Java_org_simantics_fmil_core_FMIL_getRealValue_1 } if (!isEmpty(error)) { string message = "Could not get real value: "; - return throwFMILException(env, message += error); + throwFMILException(env, message += error); + return 0.0; } return value; } JNIEXPORT jint JNICALL Java_org_simantics_fmil_core_FMIL_getIntegerValue_1 - (JNIEnv *env, jobject obj, jstring id, jstring variable) { - /* - const char *fmuId = env->GetStringUTFChars(id, 0); - if(exists(fmuId)) { - FMUControlStruct fmuStruct = fmus[fmuId]; - env->ReleaseStringUTFChars(id, fmuId); - const char *name = env->GetStringUTFChars(variable, 0); - - if(referenceExists(fmuStruct, name)) { - fmiValueReference vr = getReference(fmuStruct, name); - int result; - fmuStruct.fmu.getInteger(fmuStruct.c, &vr, 1, &result); - env->ReleaseStringUTFChars(variable, name); - return result; - - } else { - string nameString = name; - string message = "Variable " + nameString + " not found"; - env->ReleaseStringUTFChars(variable, name); - return throwException(env, message); - } + (JNIEnv *env, jobject obj, jint id, jint vr) { - } else { - string message = fmuId; - env->ReleaseStringUTFChars(id, fmuId); - return throwException(env, "unloadFMU: Model id " + message + " not found"); - } - */ - return 1; + int value; + const char *error = ""; + FMI1 fmi = fmus[id]; + if (fmi.version == 1) { + value = FMI1_CS_GET_INTEGER(fmi.fmu, vr, &error); + } + else if (fmi.version == 2) { + value = FMI2_CS_GET_INTEGER(fmi.fmu, vr, &error); + } + if (!isEmpty(error)) { + string message = "Could not get integer value: "; + throwFMILException(env, message += error); + return 0; + } + return value; } JNIEXPORT jboolean JNICALL Java_org_simantics_fmil_core_FMIL_getBooleanValue_1 - (JNIEnv *env, jobject obj, jstring id, jstring variable) { - /* - const char *fmuId = env->GetStringUTFChars(id, 0); - if(exists(fmuId)) { - FMUControlStruct fmuStruct = fmus[fmuId]; - env->ReleaseStringUTFChars(id, fmuId); - const char *name = env->GetStringUTFChars(variable, 0); - - if(referenceExists(fmuStruct, name)) { - fmiValueReference vr = getReference(fmuStruct, name); - fmiBoolean result; - fmuStruct.fmu.getBoolean(fmuStruct.c, &vr, 1, &result); - env->ReleaseStringUTFChars(variable, name); - return result; - - } else { - string nameString = name; - string message = "Variable " + nameString + " not found"; - env->ReleaseStringUTFChars(variable, name); - return throwException(env, message); - } + (JNIEnv *env, jobject obj, jint id, jint vr) { - } else { - string message = fmuId; - env->ReleaseStringUTFChars(id, fmuId); - return throwException(env, "unloadFMU: Model id " + message + " not found"); - }*/ - return 1; + int value; + const char *error = ""; + + FMI1 fmi = fmus[id]; + if (fmi.version == 1) { + value = FMI1_CS_GET_BOOLEAN(fmi.fmu, vr, &error); + } + else if (fmi.version == 2) { + value = FMI2_CS_GET_BOOLEAN(fmi.fmu, vr, &error); + } + if (!isEmpty(error)) { + string message = "Could not get boolean value: "; + throwFMILException(env, message += error); + return 0; + } + return value != 0; } JNIEXPORT jstring JNICALL Java_org_simantics_fmil_core_FMIL_getStringValue_1 - (JNIEnv *env, jobject obj, jstring id, jstring variable) { - /* - const char *fmuId = env->GetStringUTFChars(id, 0); - if(exists(fmuId)) { - FMUControlStruct fmuStruct = fmus[fmuId]; - env->ReleaseStringUTFChars(id, fmuId); - const char *name = env->GetStringUTFChars(variable, 0); - - if(referenceExists(fmuStruct, name)) { - fmiValueReference vr = getReference(fmuStruct, name); - fmiString result; - fmuStruct.fmu.getString(fmuStruct.c, &vr, 1, &result); - env->ReleaseStringUTFChars(variable, name); - return env->NewStringUTF(result); - - } else { - string nameString = name; - string message = "Variable " + nameString + " not found"; - env->ReleaseStringUTFChars(variable, name); - return 0; //throwException(env, message); - } + (JNIEnv *env, jobject obj, jint id, jint vr) { - } else { - string message = fmuId; - env->ReleaseStringUTFChars(id, fmuId); - return 0; //throwException(env, "unloadFMU: Model id " + message + " not found"); + const char *value; + const char *error = ""; + + FMI1 fmi = fmus[id]; + if (fmi.version == 1) { + value = FMI1_CS_GET_STRING(fmi.fmu, vr, &error); + } + else if (fmi.version == 2) { + value = FMI2_CS_GET_STRING(fmi.fmu, vr, &error); + } + if (!isEmpty(error)) { + string message = "Could not get string value: "; + throwFMILException(env, message += error); + return nullptr; } - */ - return 0; + return env->NewStringUTF(value); } 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 1f1e098..06d1fd2 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 @@ -32,6 +32,8 @@ public class FMIL { private static final Logger LOGGER = LoggerFactory.getLogger(FMIL.class); + private static final boolean DEBUG = false; + /** * Static variables */ @@ -345,23 +347,31 @@ public class FMIL { private native int subscribe_(int id, int[] variables); /** - * Set a new (Real, double) value for a variable. If the variable is a + * Set value of a real variable. If the variable is a * parameter, the change is effective immediately. * - * @param name Variable - * @param value New (Real, double) value + * @param name Variable name + * @param value New value * @throws FMILException */ public void setRealValue(String name, double value) throws FMILException { - - synchronized(syncObject) { + setRealValue(variableMap.get(name), value); + } + /** + * Set value of a real variable. If the variable is a + * parameter, the change is effective immediately. + * + * @param name Variable id + * @param value New value + * @throws FMILException + */ + public void setRealValue(int variableReference, double value) throws FMILException { + synchronized(syncObject) { try { - - int ret = setRealValue_(getModelIDNew(), variableMap.get(name), value); + int ret = setRealValue_(getModelIDNew(), variableReference, value); 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) { @@ -369,21 +379,77 @@ public class FMIL { } catch (Exception e) { throw new FMILException(e.getMessage()); } - } - } - public void setRealValue(int variableReference, double value) throws FMILException { - - synchronized(syncObject) { + private native int setRealValue_(int id, int variableReference, double value) throws FMILException; - try { + + /** + * Set value of an integer variable. If the variable is a + * parameter, the change is effective immediately. + * + * @param name Variable name + * @param value New value + * @throws FMILException + */ + public void setIntegerValue(String name, int value) throws FMILException { + setIntegerValue(variableMap.get(name), value); + } - int ret = setRealValue_(getModelIDNew(), variableReference, value); + /** + * Set value of an integer variable. If the variable is a + * parameter, the change is effective immediately. + * + * @param name Variable id + * @param value New value + * @throws FMILException + */ + public void setIntegerValue(int variableReference, int value) throws FMILException { + synchronized(syncObject) { + try { + int ret = setIntegerValue_(getModelIDNew(), variableReference, value); 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) { + throw new FMILException(UNSATISFIED_LINK); + } catch (Exception e) { + throw new FMILException(e.getMessage()); + } + } + } + + private native int setIntegerValue_(int id, int variableReference, int value) throws FMILException; + + /** + * Set value of a boolean variable. If the variable is a + * parameter, the change is effective immediately. + * + * @param name Variable name + * @param value New value + * @throws FMILException + */ + public void setBooleanValue(String name, boolean value) throws FMILException { + setBooleanValue(variableMap.get(name), value); + } + + /** + * Set value of a boolean variable. If the variable is a + * parameter, the change is effective immediately. + * + * @param name Variable id + * @param value New value + * @throws FMILException + */ + public void setBooleanValue(int variableReference, boolean value) throws FMILException { + synchronized(syncObject) { + try { + int ret = setBooleanValue_(getModelIDNew(), variableReference, value); + 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) { @@ -391,82 +457,50 @@ public class FMIL { } catch (Exception e) { throw new FMILException(e.getMessage()); } - } - } - private native int setRealValue_(int id, int variableReference, double value) throws FMILException; + private native int setBooleanValue_(int id, int variableReference, boolean value) throws FMILException; -// /** -// * Set a new (integer) value for a variable. If the variable is a -// * parameter, the change is effective immediately. -// * -// * @param name Variable -// * @param value New (integer) value -// * @throws FMILException -// */ -// public void setIntegerValue(String name, int value) throws FMILException { -// synchronized(syncObject) { -// -// try { -// -// int ret = setIntegerValue_(getModelID(), name, value); -// if(ret == ERROR) -// throw new FMILException(getLastErrorMessage()); -// -// } catch (UnsatisfiedLinkError err) { -// throw new FMILException(UNSATISFIED_LINK); -// } catch (Exception e) { -// throw new FMILException(e.getMessage()); -// } -// } -// } -// private native int setIntegerValue_(String id, String name, int value); -// -// /** -// * Set a new (boolean) value for a variable. If the variable is a -// * parameter, the change is effective immediately. -// * -// * @param name Variable -// * @param value New (boolean) value -// * @throws FMILException -// */ -// public void setBooleanValue(String name, boolean value) throws FMILException { -// synchronized(syncObject) { -// -// try { -// -// int ret = setBooleanValue_(getModelID(), name, value); -// if(ret == ERROR) -// throw new FMILException(getLastErrorMessage()); -// -// } catch (UnsatisfiedLinkError err) { -// throw new FMILException(UNSATISFIED_LINK); -// } catch (Exception e) { -// throw new FMILException(e.getMessage()); -// } -// } -// } -// private native int setBooleanValue_(String id, String name, boolean value); -// -// public void setTime(double time) throws FMILException { -// synchronized(syncObject) { -// -// try { -// -// int ret = setTime_(getModelID(), time); -// if(ret == ERROR) -// throw new FMILException(getLastErrorMessage()); -// -// } catch (UnsatisfiedLinkError err) { -// throw new FMILException(UNSATISFIED_LINK); -// } catch (Exception e) { -// throw new FMILException(e.getMessage()); -// } -// } -// } -// private native int setTime_(String id, double time); + + /** + * Set value of a string variable. If the variable is a + * parameter, the change is effective immediately. + * + * @param name Variable name + * @param value New value + * @throws FMILException + */ + public void setStringValue(String name, String value) throws FMILException { + setStringValue(variableMap.get(name), value); + } + + /** + * Set value of a string variable. If the variable is a + * parameter, the change is effective immediately. + * + * @param name Variable id + * @param value New value + * @throws FMILException + */ + public void setStringValue(int variableReference, String value) throws FMILException { + synchronized(syncObject) { + try { + int ret = setStringValue_(getModelIDNew(), variableReference, value); + 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) { + throw new FMILException(UNSATISFIED_LINK); + } catch (Exception e) { + throw new FMILException(e.getMessage()); + } + } + } + + private native int setStringValue_(int id, int variableReference, String value) throws FMILException; + /** * Simulate one step forward. The step length can be set with @@ -870,19 +904,60 @@ public class FMIL { // private native String getLastErrorMessage_(String id); /** - * Get a real (double) value for variable + * Get a value (double) for real variable * @param name Name of the variable * @return value * @throws FMILException */ public double getRealValue(String name) throws FMILException { + double result = getRealValue(variableMap.get(name)); + if (DEBUG) System.err.println("getRealValue " + name + " = " + result); + return result; + } + + /** + * Get a value (double) for real variable + * @param variableReference Numeric id of the variable + * @return value + * @throws FMILException + */ + public double getRealValue(int variableReference) throws FMILException { synchronized(syncObject) { + try { + return getRealValue_(getModelIDNew(), variableReference); + } catch (UnsatisfiedLinkError err) { + throw new FMILException(UNSATISFIED_LINK); + } catch (Exception e) { + throw new FMILException(e.getMessage()); + } + } + } + + private native double getRealValue_(int id, int variableReference) throws FMILException; + + + /** + * Get value of integer variable + * @param name Name of the variable + * @return value + * @throws FMILException + */ + public int getIntegerValue(String name) throws FMILException { + int result = getIntegerValue(variableMap.get(name)); + if (DEBUG) System.err.println("getIntegerValue " + name + " = " + result); + return result; + } + /** + * Get a real (double) value for variable + * @param variableReference Numeric id of the variable + * @return value + * @throws FMILException + */ + public int getIntegerValue(int variableReference) throws FMILException { + synchronized(syncObject) { try { - // TODO: printtaa id ja name, jotta saadaan virheessä kiinni - double result = getRealValue_(getModelIDNew(), variableMap.get(name)); - System.err.println("getRealValue " + name + " = " + result); - return result; + return getIntegerValue_(getModelIDNew(), variableReference); } catch (UnsatisfiedLinkError err) { throw new FMILException(UNSATISFIED_LINK); } catch (Exception e) { @@ -890,71 +965,75 @@ public class FMIL { } } } + + private native int getIntegerValue_(int id, int variableReference) throws FMILException; + + + /** + * Get value of boolean variable + * @param name Name of the variable + * @return value + * @throws FMILException + */ + public boolean getBooleanValue(String name) throws FMILException { + boolean result = getBooleanValue(variableMap.get(name)); + if (DEBUG) System.err.println("getBooleanValue " + name + " = " + result); + return result; + } - private native double getRealValue_(int id, int variableReference); + /** + * Get value of boolean variable + * @param variableReference Numeric id of the variable + * @return value + * @throws FMILException + */ + public boolean getBooleanValue(int variableReference) throws FMILException { + synchronized(syncObject) { + try { + return getBooleanValue_(getModelIDNew(), variableReference); + } catch (UnsatisfiedLinkError err) { + throw new FMILException(UNSATISFIED_LINK); + } catch (Exception e) { + throw new FMILException(e.getMessage()); + } + } + } + + private native boolean getBooleanValue_(int id, int variableReference) throws FMILException; + + + /** + * Get value of string variable + * @param name Name of the variable + * @return value + * @throws FMILException + */ + public String getStringValue(String name) throws FMILException { + String result = getStringValue(variableMap.get(name)); + if (DEBUG) System.err.println("getIntegerValue " + name + " = " + result); + return result; + } -// /** -// * Get a string value for variable -// * @param name Name of the variable -// * @return value -// * @throws FMILException -// */ -// public String getStringValue(String name) throws FMILException { -// synchronized(syncObject) { -// -// try { -// return getStringValue_(getModelID(), name); -// } catch (UnsatisfiedLinkError err) { -// throw new FMILException(UNSATISFIED_LINK); -// } catch (Exception e) { -// throw new FMILException(e.getMessage()); -// } -// } -// } -// -// private native String getStringValue_(String id, String name); -// -// /** -// * Get an integer value for variable -// * @param name Name of the variable -// * @return value -// * @throws FMILException -// */ -// public int getIntegerValue(String name) throws FMILException { -// synchronized(syncObject) { -// -// try { -// return getIntegerValue_(getModelID(), name); -// } catch (UnsatisfiedLinkError err) { -// throw new FMILException(UNSATISFIED_LINK); -// } catch (Exception e) { -// throw new FMILException(e.getMessage()); -// } -// } -// } -// -// private native int getIntegerValue_(String id, String name); -// -// /** -// * Get a real (double) value for variable -// * @param name Name of the variable -// * @return value -// * @throws FMILException -// */ -// public boolean getBooleanValue(String name) throws FMILException { -// synchronized(syncObject) { -// -// try { -// return getBooleanValue_(getModelID(), name); -// } catch (UnsatisfiedLinkError err) { -// throw new FMILException(UNSATISFIED_LINK); -// } catch (Exception e) { -// throw new FMILException(e.getMessage()); -// } -// } -// } -// -// private native boolean getBooleanValue_(String id, String name); + /** + * Get value of string variable + * @param variableReference Numeric id of the variable + * @return value + * @throws FMILException + */ + public String getStringValue(int variableReference) throws FMILException { + synchronized(syncObject) { + try { + return getStringValue_(getModelIDNew(), variableReference); + } catch (UnsatisfiedLinkError err) { + throw new FMILException(UNSATISFIED_LINK); + } catch (Exception e) { + throw new FMILException(e.getMessage()); + } + } + } + + private native String getStringValue_(int id, int variableReference) throws FMILException; + private FileChannel channel; private FileLock lock; diff --git a/org.simantics.fmil.linux64/libraries/debug/fmildebug.log b/org.simantics.fmil.linux64/libraries/debug/fmildebug.log index 29fd816..0032725 100644 --- a/org.simantics.fmil.linux64/libraries/debug/fmildebug.log +++ b/org.simantics.fmil.linux64/libraries/debug/fmildebug.log @@ -865,7 +865,7 @@ Install the project... Running tests... Test project /builds/fmildebug Start 1: ctest_build_all - 1/26 Test #1: ctest_build_all .................... Passed 0.83 sec + 1/26 Test #1: ctest_build_all .................... Passed 0.73 sec Start 2: ctest_fmi_zip_unzip_test 2/26 Test #2: ctest_fmi_zip_unzip_test ........... Passed 0.00 sec Start 3: ctest_fmi_zip_zip_test @@ -873,7 +873,7 @@ Test project /builds/fmildebug Start 4: ctest_fmi1_xml_parsing_test 4/26 Test #4: ctest_fmi1_xml_parsing_test ........ Passed 0.02 sec Start 5: ctest_fmi_import_me_test - 5/26 Test #5: ctest_fmi_import_me_test ........... Passed 0.18 sec + 5/26 Test #5: ctest_fmi_import_me_test ........... Passed 0.14 sec Start 6: ctest_fmi_import_cs_test 6/26 Test #6: ctest_fmi_import_cs_test ........... Passed 0.00 sec Start 7: ctest_fmi_import_cs_tc_test @@ -885,7 +885,7 @@ Test project /builds/fmildebug Start 10: ctest_fmi_import_xml_test_mf 10/26 Test #10: ctest_fmi_import_xml_test_mf ....... Passed 0.00 sec Start 11: ctest_fmi1_capi_cs_test -11/26 Test #11: ctest_fmi1_capi_cs_test ............ Passed 0.01 sec +11/26 Test #11: ctest_fmi1_capi_cs_test ............ Passed 0.00 sec Start 12: ctest_fmi1_capi_me_test 12/26 Test #12: ctest_fmi1_capi_me_test ............ Passed 0.00 sec Start 13: ctest_fmi1_logger_test_run @@ -913,10 +913,10 @@ Test project /builds/fmildebug Start 24: ctest_fmi_import_test_cs_1 24/26 Test #24: ctest_fmi_import_test_cs_1 ......... Passed 0.00 sec Start 25: ctest_fmi_import_test_me_2 -25/26 Test #25: ctest_fmi_import_test_me_2 ......... Passed 0.01 sec +25/26 Test #25: ctest_fmi_import_test_me_2 ......... Passed 0.00 sec Start 26: ctest_fmi_import_test_cs_2 -26/26 Test #26: ctest_fmi_import_test_cs_2 ......... Passed 0.01 sec +26/26 Test #26: ctest_fmi_import_test_cs_2 ......... Passed 0.00 sec 100% tests passed, 0 tests failed out of 26 -Total Test time (real) = 1.14 sec +Total Test time (real) = 0.98 sec diff --git a/org.simantics.fmil.linux64/libraries/debug/fmusimulatordebug.log b/org.simantics.fmil.linux64/libraries/debug/fmusimulatordebug.log index a09165c..61b60fd 100644 --- a/org.simantics.fmil.linux64/libraries/debug/fmusimulatordebug.log +++ b/org.simantics.fmil.linux64/libraries/debug/fmusimulatordebug.log @@ -1,54 +1,33 @@ -src/fmi_util.c: In function 'void fmilogger(fmi1_component_t, fmi1_string_t, fmi1_status_t, fmi1_string_t, fmi1_string_t, ...)': -src/fmi_util.c:83:7: warning: unused variable 'msg' [-Wunused-variable] - char msg[BUFFER]; - ^ -src/fmi_util.c:84:9: warning: unused variable 'len' [-Wunused-variable] - int len; - ^ src/fmi_util.c: In function 'int FMI_CS_LOAD(const char*, const char*, void**, int*, const char**)': -src/fmi_util.c:145:41: warning: comparison between 'fmi2_fmu_kind_enu_t {aka enum fmi2_fmu_kind_enu_t}' and 'enum fmi1_fmu_kind_enu_t' [-Wenum-compare] +src/fmi_util.c:85:41: warning: comparison between 'fmi2_fmu_kind_enu_t {aka enum fmi2_fmu_kind_enu_t}' and 'enum fmi1_fmu_kind_enu_t' [-Wenum-compare] if (fmi2_import_get_fmu_kind(fmu2) != fmi1_fmu_kind_enu_cs_standalone && fmi2_import_get_fmu_kind(fmu2) != fmi1_fmu_kind_enu_cs_tool) { ^ -src/fmi_util.c:145:110: warning: comparison between 'fmi2_fmu_kind_enu_t {aka enum fmi2_fmu_kind_enu_t}' and 'enum fmi1_fmu_kind_enu_t' [-Wenum-compare] +src/fmi_util.c:85:110: warning: comparison between 'fmi2_fmu_kind_enu_t {aka enum fmi2_fmu_kind_enu_t}' and 'enum fmi1_fmu_kind_enu_t' [-Wenum-compare] if (fmi2_import_get_fmu_kind(fmu2) != fmi1_fmu_kind_enu_cs_standalone && fmi2_import_get_fmu_kind(fmu2) != fmi1_fmu_kind_enu_cs_tool) { ^ src/fmi_util.c: In function 'int FMI1_CS_INSTANTIATE(void*, const char*, const char**)': -src/fmi_util.c:525:16: warning: variable 'fmuLocation' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:465:16: warning: variable 'fmuLocation' set but not used [-Wunused-but-set-variable] fmi1_string_t fmuLocation; ^ -src/fmi_util.c:526:16: warning: variable 'mimeType' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:466:16: warning: variable 'mimeType' set but not used [-Wunused-but-set-variable] fmi1_string_t mimeType; ^ -src/fmi_util.c:528:17: warning: variable 'visible' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:468:17: warning: variable 'visible' set but not used [-Wunused-but-set-variable] fmi1_boolean_t visible; ^ -src/fmi_util.c:529:17: warning: variable 'interactive' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:469:17: warning: variable 'interactive' set but not used [-Wunused-but-set-variable] fmi1_boolean_t interactive; ^ -src/fmi_util.c:530:17: warning: variable 'loggingOn' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:470:17: warning: variable 'loggingOn' set but not used [-Wunused-but-set-variable] fmi1_boolean_t loggingOn; ^ src/fmi_util.c: In function 'int FMI2_CS_INSTANTIATE(void*, const char*, const char**)': -src/fmi_util.c:551:16: warning: variable 'fmuLocation' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:491:16: warning: variable 'fmuLocation' set but not used [-Wunused-but-set-variable] fmi2_string_t fmuLocation; ^ -src/fmi_util.c:552:16: warning: variable 'mimeType' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:492:16: warning: variable 'mimeType' set but not used [-Wunused-but-set-variable] fmi2_string_t mimeType; ^ -src/fmi_util.c:553:14: warning: variable 'timeout' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:493:14: warning: variable 'timeout' set but not used [-Wunused-but-set-variable] fmi2_real_t timeout; ^ -src/fmi_util.c:555:17: warning: unused variable 'interactive' [-Wunused-variable] - fmi2_boolean_t interactive; - ^ -src/fmi_util.c:556:17: warning: unused variable 'loggingOn' [-Wunused-variable] - fmi2_boolean_t loggingOn; - ^ -src/fmi_util.c: In function 'int FMI1_CS_GET_REALS(void*, int*, double*, int, const char**)': -src/fmi_util.c:708:14: warning: unused variable 'value' [-Wunused-variable] - fmi1_real_t value; - ^ -src/fmi_util.c: In function 'int FMI2_CS_GET_REALS(void*, int*, double*, int, const char**)': -src/fmi_util.c:722:14: warning: unused variable 'value' [-Wunused-variable] - fmi2_real_t value; - ^ diff --git a/org.simantics.fmil.linux64/libraries/debug/libFMUSimulator.so b/org.simantics.fmil.linux64/libraries/debug/libFMUSimulator.so index 0bc0103..d3a9097 100644 Binary files a/org.simantics.fmil.linux64/libraries/debug/libFMUSimulator.so and b/org.simantics.fmil.linux64/libraries/debug/libFMUSimulator.so differ diff --git a/org.simantics.fmil.linux64/libraries/fmil.log b/org.simantics.fmil.linux64/libraries/fmil.log index 8271905..4d799e8 100644 --- a/org.simantics.fmil.linux64/libraries/fmil.log +++ b/org.simantics.fmil.linux64/libraries/fmil.log @@ -865,15 +865,15 @@ Install the project... Running tests... Test project /builds/fmil Start 1: ctest_build_all - 1/26 Test #1: ctest_build_all .................... Passed 0.78 sec + 1/26 Test #1: ctest_build_all .................... Passed 0.65 sec Start 2: ctest_fmi_zip_unzip_test 2/26 Test #2: ctest_fmi_zip_unzip_test ........... Passed 0.00 sec Start 3: ctest_fmi_zip_zip_test 3/26 Test #3: ctest_fmi_zip_zip_test ............. Passed 0.00 sec Start 4: ctest_fmi1_xml_parsing_test - 4/26 Test #4: ctest_fmi1_xml_parsing_test ........ Passed 0.01 sec + 4/26 Test #4: ctest_fmi1_xml_parsing_test ........ Passed 0.02 sec Start 5: ctest_fmi_import_me_test - 5/26 Test #5: ctest_fmi_import_me_test ........... Passed 0.13 sec + 5/26 Test #5: ctest_fmi_import_me_test ........... Passed 0.09 sec Start 6: ctest_fmi_import_cs_test 6/26 Test #6: ctest_fmi_import_cs_test ........... Passed 0.00 sec Start 7: ctest_fmi_import_cs_tc_test @@ -891,11 +891,11 @@ Test project /builds/fmil Start 13: ctest_fmi1_logger_test_run 13/26 Test #13: ctest_fmi1_logger_test_run ......... Passed 0.00 sec Start 14: ctest_fmi1_logger_test_check -14/26 Test #14: ctest_fmi1_logger_test_check ....... Passed 0.01 sec +14/26 Test #14: ctest_fmi1_logger_test_check ....... Passed 0.02 sec Start 15: ctest_fmi2_xml_parsing_test 15/26 Test #15: ctest_fmi2_xml_parsing_test ........ Passed 0.02 sec Start 16: ctest_fmi2_import_xml_test_empty -16/26 Test #16: ctest_fmi2_import_xml_test_empty ... Passed 0.01 sec +16/26 Test #16: ctest_fmi2_import_xml_test_empty ... Passed 0.00 sec Start 17: ctest_fmi2_import_xml_test_me 17/26 Test #17: ctest_fmi2_import_xml_test_me ...... Passed 0.00 sec Start 18: ctest_fmi2_import_xml_test_cs @@ -911,12 +911,12 @@ Test project /builds/fmil Start 23: ctest_fmi_import_test_me_1 23/26 Test #23: ctest_fmi_import_test_me_1 ......... Passed 0.00 sec Start 24: ctest_fmi_import_test_cs_1 -24/26 Test #24: ctest_fmi_import_test_cs_1 ......... Passed 0.00 sec +24/26 Test #24: ctest_fmi_import_test_cs_1 ......... Passed 0.01 sec Start 25: ctest_fmi_import_test_me_2 -25/26 Test #25: ctest_fmi_import_test_me_2 ......... Passed 0.01 sec +25/26 Test #25: ctest_fmi_import_test_me_2 ......... Passed 0.00 sec Start 26: ctest_fmi_import_test_cs_2 26/26 Test #26: ctest_fmi_import_test_cs_2 ......... Passed 0.00 sec 100% tests passed, 0 tests failed out of 26 -Total Test time (real) = 1.02 sec +Total Test time (real) = 0.85 sec diff --git a/org.simantics.fmil.linux64/libraries/fmusimulator.log b/org.simantics.fmil.linux64/libraries/fmusimulator.log index a09165c..61b60fd 100644 --- a/org.simantics.fmil.linux64/libraries/fmusimulator.log +++ b/org.simantics.fmil.linux64/libraries/fmusimulator.log @@ -1,54 +1,33 @@ -src/fmi_util.c: In function 'void fmilogger(fmi1_component_t, fmi1_string_t, fmi1_status_t, fmi1_string_t, fmi1_string_t, ...)': -src/fmi_util.c:83:7: warning: unused variable 'msg' [-Wunused-variable] - char msg[BUFFER]; - ^ -src/fmi_util.c:84:9: warning: unused variable 'len' [-Wunused-variable] - int len; - ^ src/fmi_util.c: In function 'int FMI_CS_LOAD(const char*, const char*, void**, int*, const char**)': -src/fmi_util.c:145:41: warning: comparison between 'fmi2_fmu_kind_enu_t {aka enum fmi2_fmu_kind_enu_t}' and 'enum fmi1_fmu_kind_enu_t' [-Wenum-compare] +src/fmi_util.c:85:41: warning: comparison between 'fmi2_fmu_kind_enu_t {aka enum fmi2_fmu_kind_enu_t}' and 'enum fmi1_fmu_kind_enu_t' [-Wenum-compare] if (fmi2_import_get_fmu_kind(fmu2) != fmi1_fmu_kind_enu_cs_standalone && fmi2_import_get_fmu_kind(fmu2) != fmi1_fmu_kind_enu_cs_tool) { ^ -src/fmi_util.c:145:110: warning: comparison between 'fmi2_fmu_kind_enu_t {aka enum fmi2_fmu_kind_enu_t}' and 'enum fmi1_fmu_kind_enu_t' [-Wenum-compare] +src/fmi_util.c:85:110: warning: comparison between 'fmi2_fmu_kind_enu_t {aka enum fmi2_fmu_kind_enu_t}' and 'enum fmi1_fmu_kind_enu_t' [-Wenum-compare] if (fmi2_import_get_fmu_kind(fmu2) != fmi1_fmu_kind_enu_cs_standalone && fmi2_import_get_fmu_kind(fmu2) != fmi1_fmu_kind_enu_cs_tool) { ^ src/fmi_util.c: In function 'int FMI1_CS_INSTANTIATE(void*, const char*, const char**)': -src/fmi_util.c:525:16: warning: variable 'fmuLocation' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:465:16: warning: variable 'fmuLocation' set but not used [-Wunused-but-set-variable] fmi1_string_t fmuLocation; ^ -src/fmi_util.c:526:16: warning: variable 'mimeType' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:466:16: warning: variable 'mimeType' set but not used [-Wunused-but-set-variable] fmi1_string_t mimeType; ^ -src/fmi_util.c:528:17: warning: variable 'visible' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:468:17: warning: variable 'visible' set but not used [-Wunused-but-set-variable] fmi1_boolean_t visible; ^ -src/fmi_util.c:529:17: warning: variable 'interactive' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:469:17: warning: variable 'interactive' set but not used [-Wunused-but-set-variable] fmi1_boolean_t interactive; ^ -src/fmi_util.c:530:17: warning: variable 'loggingOn' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:470:17: warning: variable 'loggingOn' set but not used [-Wunused-but-set-variable] fmi1_boolean_t loggingOn; ^ src/fmi_util.c: In function 'int FMI2_CS_INSTANTIATE(void*, const char*, const char**)': -src/fmi_util.c:551:16: warning: variable 'fmuLocation' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:491:16: warning: variable 'fmuLocation' set but not used [-Wunused-but-set-variable] fmi2_string_t fmuLocation; ^ -src/fmi_util.c:552:16: warning: variable 'mimeType' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:492:16: warning: variable 'mimeType' set but not used [-Wunused-but-set-variable] fmi2_string_t mimeType; ^ -src/fmi_util.c:553:14: warning: variable 'timeout' set but not used [-Wunused-but-set-variable] +src/fmi_util.c:493:14: warning: variable 'timeout' set but not used [-Wunused-but-set-variable] fmi2_real_t timeout; ^ -src/fmi_util.c:555:17: warning: unused variable 'interactive' [-Wunused-variable] - fmi2_boolean_t interactive; - ^ -src/fmi_util.c:556:17: warning: unused variable 'loggingOn' [-Wunused-variable] - fmi2_boolean_t loggingOn; - ^ -src/fmi_util.c: In function 'int FMI1_CS_GET_REALS(void*, int*, double*, int, const char**)': -src/fmi_util.c:708:14: warning: unused variable 'value' [-Wunused-variable] - fmi1_real_t value; - ^ -src/fmi_util.c: In function 'int FMI2_CS_GET_REALS(void*, int*, double*, int, const char**)': -src/fmi_util.c:722:14: warning: unused variable 'value' [-Wunused-variable] - fmi2_real_t value; - ^ diff --git a/org.simantics.fmil.linux64/libraries/libFMUSimulator.so b/org.simantics.fmil.linux64/libraries/libFMUSimulator.so index 6fd7340..2ad0e96 100644 Binary files a/org.simantics.fmil.linux64/libraries/libFMUSimulator.so and b/org.simantics.fmil.linux64/libraries/libFMUSimulator.so differ diff --git a/org.simantics.fmil.win32/libraries/FMUSimulator.dll b/org.simantics.fmil.win32/libraries/FMUSimulator.dll index b1e603f..6a4486e 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 7c1b95f..e369002 100644 Binary files a/org.simantics.fmil.win64/libraries/FMUSimulator.dll and b/org.simantics.fmil.win64/libraries/FMUSimulator.dll differ