@@ -8,7 +8,11 @@ FILE *createOutputFile(const char *filename) {
88 FILE * file = fopen (filename , "w" );
99
1010 if (file ) {
11- fputs ("time,Float32_continuous_output,Float32_discrete_output,Float64_continuous_output,Float64_discrete_output,Int8_output,UInt8_output,Int16_output,UInt16_output,Int32_output,UInt32_output,Int64_output,UInt64_output,Boolean_output,Binary_output\n" , file );
11+ #if FMI_VERSION == 3
12+ fputs ("time,Float32_continuous_output,Float32_discrete_output,Float64_continuous_output,Float64_discrete_output,Int8_output,UInt8_output,Int16_output,UInt16_output,Int32_output,UInt32_output,Int64_output,UInt64_output,Boolean_output,String_output,Binary_output\n" , file );
13+ #else
14+ fputs ("time,Float64_continuous_output,Float64_discrete_output,Int32_output,Boolean_output,String_output\n" , file );
15+ #endif
1216 }
1317
1418 return file ;
@@ -34,26 +38,14 @@ FMIStatus applyStartValues(FMIInstance *S) {
3438 const fmi1ValueReference float64ValueReferences [1 ] = { vr_Float64_fixed_parameter };
3539 const fmi1Real realValues [1 ] = { 1.0 };
3640 CALL (FMI1SetReal (S , float64ValueReferences , 1 , realValues ));
37-
38- const fmi1ValueReference stringValueReferences [1 ] = { vr_String_parameter };
39- const fmi1String stringValues [1 ] = { "FMI is awesome!" };
40- CALL (FMI1SetString (S , stringValueReferences , 1 , stringValues ));
4141#elif FMI_VERSION == 2
4242 const fmi2ValueReference float64ValueReferences [1 ] = { vr_Float64_fixed_parameter };
4343 const fmi2Real realValues [1 ] = { 1.0 };
4444 CALL (FMI2SetReal (S , float64ValueReferences , 1 , realValues ));
45-
46- const fmi2ValueReference stringValueReferences [1 ] = { vr_String_parameter };
47- const fmi2String stringValues [1 ] = { "FMI is awesome!" };
48- CALL (FMI2SetString (S , stringValueReferences , 1 , stringValues ));
4945#elif FMI_VERSION == 3
5046 const fmi3ValueReference float64ValueReferences [1 ] = { vr_Float64_fixed_parameter };
5147 const fmi3Float64 float64Values [1 ] = { 1.0 };
5248 CALL (FMI3SetFloat64 (S , float64ValueReferences , 1 , float64Values , 1 ));
53-
54- const fmi3ValueReference stringValueReferences [1 ] = { vr_String_parameter };
55- const fmi3String stringValues [1 ] = { "FMI is awesome!" };
56- CALL (FMI3SetString (S , stringValueReferences , 1 , stringValues , 1 ));
5749#endif
5850
5951TERMINATE :
@@ -106,28 +98,36 @@ FMIStatus applyDiscreteInputs(FMIInstance *S, double time) {
10698
10799#if FMI_VERSION == 1
108100 const fmi1ValueReference float64ValueReferences [2 ] = { vr_Float64_tunable_parameter , vr_Float64_discrete_input };
109- const fmi1Real float64Values [2 ] = { time < 1.5 ? 0.0 : -1.0 , time < 1.0 ? 0 : 1.0 };
101+ const fmi1Real float64Values [2 ] = { time < 1.5 ? 0.0 : -1.0 , before_step ? 0 : 1.0 };
110102 CALL (FMI1SetReal (S , float64ValueReferences , 1 , float64Values ));
111103
112104 const fmi1ValueReference int32ValueReferences [1 ] = { vr_Int32_input };
113105 const fmi1Integer int32Values [1 ] = { before_step ? INT32_MIN : INT32_MAX };
114106 CALL (FMI1SetInteger (S , int32ValueReferences , 1 , int32Values ));
115107
116108 const fmi1ValueReference booleanValueReferences [1 ] = { vr_Boolean_input };
117- const fmi1Boolean booleanValues [1 ] = { time < 1.0 ? false : true };
109+ const fmi1Boolean booleanValues [1 ] = { before_step ? false : true };
118110 CALL (FMI1SetBoolean (S , booleanValueReferences , 1 , booleanValues ));
111+
112+ const fmi1ValueReference stringValueReferences [1 ] = { vr_String_input };
113+ const fmi1String stringValues [1 ] = { before_step ? "FMI is awesome!" : "FMI is still awesome!" };
114+ CALL (FMI1SetString (S , stringValueReferences , 1 , stringValues ));
119115#elif FMI_VERSION == 2
120116 const fmi2ValueReference float64ValueReferences [2 ] = { vr_Float64_tunable_parameter , vr_Float64_discrete_input };
121- const fmi2Real float64Values [2 ] = { time < 1.5 ? 0.0 : -1.0 , time < 1.0 ? 0 : 1.0 };
117+ const fmi2Real float64Values [2 ] = { time < 1.5 ? 0.0 : -1.0 , before_step ? 0 : 1.0 };
122118 CALL (FMI2SetReal (S , float64ValueReferences , 1 , float64Values ));
123119
124120 const fmi2ValueReference int32ValueReferences [1 ] = { vr_Int32_input };
125121 const fmi2Integer int32Values [1 ] = { before_step ? INT32_MIN : INT32_MAX };
126122 CALL (FMI2SetInteger (S , int32ValueReferences , 1 , int32Values ));
127123
128124 const fmi2ValueReference booleanValueReferences [1 ] = { vr_Boolean_input };
129- const fmi2Boolean booleanValues [1 ] = { time < 1.0 ? false : true };
125+ const fmi2Boolean booleanValues [1 ] = { before_step ? false : true };
130126 CALL (FMI2SetBoolean (S , booleanValueReferences , 1 , booleanValues ));
127+
128+ const fmi2ValueReference stringValueReferences [1 ] = { vr_String_input };
129+ const fmi2String stringValues [1 ] = { before_step ? "FMI is awesome!" : "FMI is still awesome!" };
130+ CALL (FMI2SetString (S , stringValueReferences , 1 , stringValues ));
131131#elif FMI_VERSION == 3
132132 const fmi3ValueReference Float32_vr [1 ] = { vr_Float32_discrete_input };
133133 const fmi3Float32 Float32_values [1 ] = { before_step ? 0 : 1.0f };
@@ -173,8 +173,12 @@ FMIStatus applyDiscreteInputs(FMIInstance *S, double time) {
173173 const fmi3Boolean booleanValues [1 ] = { before_step ? false : true };
174174 CALL (FMI3SetBoolean (S , booleanValueReferences , 1 , booleanValues , 1 ));
175175
176+ const fmi3ValueReference stringValueReferences [1 ] = { vr_String_input };
177+ const fmi3String stringValues [1 ] = { before_step ? "FMI is awesome!" : "FMI is still awesome!" };
178+ CALL (FMI3SetString (S , stringValueReferences , 1 , stringValues , 1 ));
179+
176180 const fmi3ValueReference binaryValueReferences [1 ] = { vr_Binary_input };
177- const fmi3Binary binaryValues [1 ] = { (void * )"bar" };
181+ const fmi3Binary binaryValues [1 ] = { before_step ? ( void * ) "foo" : (void * )"bar" };
178182 const size_t binarySizes [1 ] = { 3 };
179183 CALL (FMI3SetBinary (S , binaryValueReferences , 1 , binarySizes , binaryValues , 1 ));
180184#endif
@@ -201,7 +205,12 @@ FMIStatus recordVariables(FMIInstance *S, double time, FILE *outputFile) {
201205 fmi1Boolean Boolean_values [1 ] = { 0 };
202206 CALL (FMI1GetBoolean (S , Boolean_vr , 1 , Boolean_values ));
203207
204- fprintf (outputFile , "%g,%.16g,%.16g,%" PRIu32 ",%d\n" , time , Float64_values [0 ], Float64_values [1 ], Int32_values [0 ], Boolean_values [0 ]);
208+ const fmi1ValueReference String_vr [1 ] = { vr_String_output };
209+ fmi1String String_values [1 ] = { NULL };
210+ CALL (FMI1GetString ((FMIInstance * )S , String_vr , 1 , String_values ));
211+
212+ fprintf (outputFile , "%g,%.16g,%.16g,%" PRIu32 ",%d,\"%s\"\n" ,
213+ time , Float64_values [0 ], Float64_values [1 ], Int32_values [0 ], Boolean_values [0 ], String_values [0 ]);
205214
206215#elif FMI_VERSION == 2
207216
@@ -217,7 +226,12 @@ FMIStatus recordVariables(FMIInstance *S, double time, FILE *outputFile) {
217226 fmi2Boolean Boolean_values [1 ] = { 0 };
218227 CALL (FMI2GetBoolean (S , Boolean_vr , 1 , Boolean_values ));
219228
220- fprintf (outputFile , "%g,%.16g,%.16g,%" PRIu32 ",%d\n" , time , Float64_values [0 ], Float64_values [1 ], Int32_values [0 ], Boolean_values [0 ]);
229+ const fmi2ValueReference String_vr [1 ] = { vr_String_output };
230+ fmi2String String_values [1 ] = { NULL };
231+ CALL (FMI2GetString ((FMIInstance * )S , String_vr , 1 , String_values ));
232+
233+ fprintf (outputFile , "%g,%.16g,%.16g,%" PRIu32 ",%d,\"%s\"\n" ,
234+ time , Float64_values [0 ], Float64_values [1 ], Int32_values [0 ], Boolean_values [0 ], String_values [0 ]);
221235
222236#elif FMI_VERSION == 3
223237
@@ -265,12 +279,32 @@ FMIStatus recordVariables(FMIInstance *S, double time, FILE *outputFile) {
265279 fmi3Boolean Boolean_values [1 ] = { 0 };
266280 CALL (FMI3GetBoolean ((FMIInstance * )S , Boolean_vr , 1 , Boolean_values , 1 ));
267281
282+ const fmi3ValueReference String_vr [1 ] = { vr_String_output };
283+ fmi3String String_values [1 ] = { NULL };
284+ CALL (FMI3GetString ((FMIInstance * )S , String_vr , 1 , String_values , 1 ));
285+
268286 const fmi3ValueReference Binary_vr [1 ] = { vr_Binary_output };
269287 size_t Binary_sizes [1 ] = { 0 };
270288 fmi3Binary Binary_values [1 ] = { NULL };
271- CALL (FMI3GetBinary ((FMIInstance * )S , Binary_vr , 1 , Binary_sizes , Binary_values , 1 ));
289+ CALL (FMI3GetBinary ((FMIInstance * )S , Binary_vr , 1 , Binary_sizes , Binary_values , 1 ));
290+
291+ fprintf (outputFile , "%g,%.7g,%.7g,%.16g,%.16g,%" PRId8 ",%" PRIu8 ",%" PRId16 ",%" PRIu16 ",%" PRId32 ",%" PRIu32 ",%" PRId64 ",%" PRIu64 ",%d,\"%s\"," ,
292+ time , Float32_values [0 ], Float32_values [1 ], Float64_values [0 ], Float64_values [1 ], Int8_values [0 ], UInt8_values [0 ], Int16_values [0 ], UInt16_values [0 ], Int32_values [0 ], UInt32_values [0 ], Int64_values [0 ], UInt64_values [0 ], Boolean_values [0 ], String_values [0 ]);
293+
294+ for (size_t i = 0 ; i < Binary_sizes [0 ]; i ++ ) {
295+
296+ const fmi3Byte b = Binary_values [0 ][i ];
297+
298+ const char hex [3 ] = {
299+ "0123456789abcdef" [b >> 4 ],
300+ "0123456789abcdef" [b & 0x0F ],
301+ '\0'
302+ };
303+
304+ fputs (hex , outputFile );
305+ }
272306
273- fprintf ( outputFile , "%g,%.7g,%.7g,%.16g,%.16g,%" PRId8 ",%" PRIu8 ",%" PRId16 ",%" PRIu16 ",%" PRId32 ",%" PRIu32 ",%" PRId64 ",%" PRIu64 ",%d,%.*s\n" , time , Float32_values [ 0 ], Float32_values [ 1 ], Float64_values [ 0 ], Float64_values [ 1 ], Int8_values [ 0 ], UInt8_values [ 0 ], Int16_values [ 0 ], UInt16_values [ 0 ], Int32_values [ 0 ], UInt32_values [ 0 ], Int64_values [ 0 ], UInt64_values [ 0 ], Boolean_values [ 0 ], ( int ) Binary_sizes [ 0 ], Binary_values [ 0 ] );
307+ fputc ( '\n' , outputFile );
274308
275309#endif
276310
0 commit comments