FMI Library: part of JModelica.org
fmi_total_test.c
Go to the documentation of this file.
1 /*
2  Copyright (C) 2012 Modelon AB
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the BSD style license.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  FMILIB_License.txt file for more details.
11 
12  You should have received a copy of the FMILIB_License.txt file
13  along with this program. If not, contact Modelon AB <http://www.modelon.com>.
14 */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include "fmi_dll_1_0_cs.h"
19 #include "fmi_dll_1_0_me.h"
20 #include "fmi_dll_common.h"
21 #include "jm_types.h"
22 #include "fmi_zip_unzip.h"
23 #include <FMI1/fmi1_xml_model_description.h>
24 #include "fmi_import_util.h"
25 
26 
27 #define PRINT_MY_DEBUG printf("Line: %d \t File: %s \n",__LINE__, __FILE__)
28 
29 void mylogger(fmiComponent c, fmiString instanceName, fmiStatus status, fmiString category, fmiString message, ...)
30 {
31  char msg[2024];
32  va_list argp;
33  va_start(argp, message);
34  vsprintf(msg, message, argp);
35  if (!instanceName) instanceName = "?";
36  if (!category) category = "?";
37  printf("fmiStatus = %d; %s (%s): %s\n", status, instanceName, category, msg);
38 }
39 
40 void do_pause()
41 {
42 #ifdef _MSC_VER
43  system("PAUSE");
44 #elif
45 #endif
46 }
47 
48 int main(int argc, char *argv[])
49 {
50  fmiCallbackFunctions callBackFunctions;
51  fmi_dll_t* fmu;
52  const char* FMUPath = "C:\\P510-JModelica\\FMIToolbox\\trunk\\src\\wrapperfolder\\Furuta.fmu";
53  const char* tmpPath = "C:\\Documents and Settings\\p418_baa\\Desktop\\XMLtest\\temporaryfolder";
54  const char* dllPath;
55  const char* modelIdentifier;
56  const char* modelName;
57  const char* model_description_path;
58  const char* instanceName;
59  const char* GUID;
60  fmi_dll_standard_enu_t standard = FMI_ME1; /* or FMI_CS1 */
61 
62 
63 
64  fmiBoolean loggingOn = fmiTrue;
65  fmi1_xml_model_description_t* md;
66  jm_status_enu_t status;
67 
69 
70  if (jm_status_error == fmi_zip_unzip(FMUPath, tmpPath)) {
71  printf("Failed to unzip the FMU file\n");
72  abort();
73  }
74 
75  callBackFunctions.logger = mylogger;
76  callBackFunctions.allocateMemory = calloc;
77  callBackFunctions.freeMemory = free;
78 
79  model_description_path = fmi_import_get_model_description_path(tmpPath, callBackFunctions);
80 
81  md = fmi1_xml_allocate_model_description(0);
82 
83  if(!md) abort();
84 
85  if(fmi1_xml_parse(md, model_description_path)) {
86  printf("Error parsing XML file %s:%s\n", FMUPath, fmi1_xml_get_last_error(md));
87  fmi1_xml_free_model_description(md);
88  abort();
89  }
90 
91 
92  printf("Model name: %s\n", fmi1_xml_get_model_name(md));
93  printf("Model identifier: %s\n", fmi1_xml_get_model_identifier(md));
94  printf("Model GUID: %s\n", fmi1_xml_get_GUID(md));
95 
96  modelIdentifier = fmi1_xml_get_model_identifier(md);
97  modelName = fmi1_xml_get_model_name(md);
98  GUID = fmi1_xml_get_GUID(md);
99 
100  modelIdentifier = fmi1_xml_get_model_identifier(md);
101 
102 
103 
104  dllPath = fmi_import_get_dll_path(tmpPath, modelIdentifier, callBackFunctions);
105 
106  fmu = fmi_dll_common_create_dllfmu(dllPath, modelIdentifier, callBackFunctions, standard);
107  if (fmu == NULL) {
108  printf("An error occured while fmi_dll_common_create_dllfmu was called, an error message should been printed.\n");
109  do_pause();
110  return 0;
111  }
112 
113  status = fmi_dll_common_load_dll(fmu);
114  if (status == jm_status_error) {
115  printf("Error in fmi_dll_common_load_dll: %s\n", fmi_dll_common_get_last_error(fmu));
116  do_pause();
117  return 0;
118  }
119 
120  status = fmi_dll_common_load_fcn(fmu);
121  if (status == jm_status_error) {
122  printf("Error in fmi_dll_common_load_fcn: %s\n", fmi_dll_common_get_last_error(fmu));
123  do_pause();
124  return 0;
125  }
126 
127  printf("fmi_dll_1_0_me_get_version: %s\n", fmi_dll_1_0_me_get_version(fmu));
128 
129  fmi_dll_common_free_dll(fmu);
130  fmi_dll_common_destroy_dllfmu(fmu);
131 
132  fmi1_xml_free_model_description(md);
133 
134  printf("Everything seems to be OK since you got this far=)!\n");
135 
136  do_pause();
137 }
138 
139 
size_t jm_callbacks * c
#define fmiBoolean
Definition: fmi1_types.h:37
FMILIB_EXPORT char * fmi_import_get_dll_path(const char *fmu_unzipped_path, const char *model_identifier, jm_callbacks *callBackFunctions)
#define fmiString
Definition: fmi1_types.h:38
#define PRINT_MY_DEBUG
fmi1_capi_t * fmu
FMILIB_EXPORT char * fmi_import_get_model_description_path(const char *fmu_unzipped_path, jm_callbacks *callBackFunctions)
void mylogger(fmiComponent c, fmiString instanceName, fmiStatus status, fmiString category, fmiString message,...)
jm_status_enu_t
Return status codes.
Definition: jm_types.h:44
int main(int argc, char *argv[])
void do_pause()
#define fmiComponent
Definition: fmi1_types.h:33