1 | ;;************************************************ STATIC LIBRARY CASE FILE LOCATION *************************************************
|
---|
2 | ;;************************************************ LIBRARY LOADING IT IS WORKING ****************************************
|
---|
3 | ;;************************************************ BUT THE FMU INSTANTIATION FAILS ****************************************
|
---|
4 | ;;************************************************* SOMETIMES WE POINT TO THE NULL POINTER *******************************************
|
---|
5 | ;;******************************** DETAIL : WE ACCESS THE LIBRARY AND FUNCTIONS POINTERS BUT NO INSTANTIATION OF THE ME FMU ***************
|
---|
6 | ;;**************************************** WE EVEN CAN PARAMETRIZE THE CALL BACK FUNCTIONS ***********************************
|
---|
7 | ;; ************************** BUT THE FMU OBJECT INSTANTIATION IS FROZEN ******************************
|
---|
8 |
|
---|
9 |
|
---|
10 | I have tried to decompose the model exchange instantiation method into its intermediate stages.
|
---|
11 | Starting from the point where I already have the fmu-information data from the access path to the
|
---|
12 | binary location.
|
---|
13 | Notice that here this is a static compilation.
|
---|
14 |
|
---|
15 | At this point the object f-i is the fmu-info object.
|
---|
16 | FMI> (defparameter f-i fmu-info)
|
---|
17 | F-I
|
---|
18 |
|
---|
19 | ;;************************************************ STATIC LIBRARY CASE FILE LOCATION *************************************************
|
---|
20 | We then try to load the library by first the location of the library .... here static format
|
---|
21 |
|
---|
22 | FMI> (defparameter lib-dir-content (directory
|
---|
23 | (concatenate
|
---|
24 | 'string
|
---|
25 | (namestring (ldp f-i))
|
---|
26 | "*"
|
---|
27 | *PROBE-EXT*)))
|
---|
28 | LIB-DIR-CONTENT
|
---|
29 | FMI> lib-dir-content
|
---|
30 | (#P"/home/frederic/quicklisp/local-projects/cl-fmi/test/FirstOrderStat/unzip-3763847132/binaries/linux64/Modelica_Blocks_Continuous_FirstOrder.so")
|
---|
31 |
|
---|
32 |
|
---|
33 | ;;************************************************ LIBRARY LOADING IT IS WORKING ****************************************
|
---|
34 | We then create the model exchange object instance.
|
---|
35 | Here is the common lisp cffi way of doing it ... notice that the last two parameters of the fmi2Instantiate function are set to 0 0.
|
---|
36 | The old fmu working case accepts this restriction.
|
---|
37 |
|
---|
38 | In our test here
|
---|
39 |
|
---|
40 | ;;************************************************ BUT THE FMU INSTANTIATION FAILS ****************************************
|
---|
41 | FMI> (mapcar #'cffi:load-foreign-library
|
---|
42 | lib-dir-content)
|
---|
43 | (#<CFFI:FOREIGN-LIBRARY MODELICA_BLOCKS_CONTINUOUS_FIRSTORDER.SO-1056 "Modelica_Blocks_Continuous_FirstOrder.so">)
|
---|
44 | FMI> (cffi:with-foreign-object (cbf 'fmi2CallbackFunctions)
|
---|
45 | (setf (cffi:foreign-slot-value cbf
|
---|
46 | 'fmi2CallbackFunctions
|
---|
47 | 'allocateMemory)
|
---|
48 | calloc-function-pointer)
|
---|
49 | (setf (cffi:foreign-slot-value cbf
|
---|
50 | 'fmi2CallbackFunctions
|
---|
51 | 'freeMemory)
|
---|
52 | free-function-pointer)
|
---|
53 | (setf (cffi:foreign-slot-value cbf 'fmi2CallbackFunctions
|
---|
54 | 'stepFinished)
|
---|
55 | (cffi:null-pointer))
|
---|
56 | (setf (cffi:foreign-slot-value cbf
|
---|
57 | 'fmi2CallbackFunctions
|
---|
58 | 'componentEnvironment)
|
---|
59 | (cffi:null-pointer))
|
---|
60 | (make-instance 'instance-me
|
---|
61 | :p (fmi2Instantiate
|
---|
62 | (mn (md f-i))
|
---|
63 | :fmi2ModelExchange
|
---|
64 | (g (md f-i))
|
---|
65 | (string-right-trim "/"
|
---|
66 | (namestring (car (directory (ldp f-i)))))
|
---|
67 | cbf
|
---|
68 | 0
|
---|
69 | 0 )
|
---|
70 | :i f-i))
|
---|
71 | #<INSTANCE-ME {10025F25A3}>
|
---|
72 |
|
---|
73 | WE HAVE A POINTER !!!!!
|
---|
74 | ;;************************************************* SOMETIMES WE POINT TO THE NULL POINTER *******************************************
|
---|
75 | I then can assign a symbol to it and try the process of talking to it.
|
---|
76 | But in fact the pointer to the callback function is null !!!
|
---|
77 | FMI> (defparameter fmu-test #<INSTANCE-ME {10025F25A3}>)
|
---|
78 | FMU-TEST
|
---|
79 | FMI> (fmi2reset (p fmu-test))
|
---|
80 | :FMI2ERROR
|
---|
81 | FMI> (p fmu-test)
|
---|
82 | #.(SB-SYS:INT-SAP #X00000000)
|
---|
83 |
|
---|
84 | ;;***********************************************************************************************************************************************
|
---|
85 | ;;******************************** DETAIL : WE ACCESS THE LIBRARY AND FUNCTIONS POINTERS BUT NO INSTANTIATION OF THE ME FMU ***************
|
---|
86 | ;;***********************************************************************************************************************************************
|
---|
87 | DO I REALLY ACCESS THE LIBRARY ?
|
---|
88 | Here is a detailed step by step definition of the fmu callback function object.
|
---|
89 | And you can see that I managed to get a non-null pointer for each function.
|
---|
90 | The callback functions pointer is cbf-fmu
|
---|
91 |
|
---|
92 | FMI> (defparameter cbam-fmu (cffi:foreign-alloc 'fmi2CallbackAllocateMemory))
|
---|
93 | CBAM-FMU
|
---|
94 | FMI> CBAM-FMU
|
---|
95 | #.(SB-SYS:INT-SAP #X7FFFE80008E0)
|
---|
96 | FMI> (defparameter cbfm-fmu (cffi:foreign-alloc 'fmi2CallbackFreeMemory))
|
---|
97 | CBFM-FMU
|
---|
98 | FMI> CBFM-FMU
|
---|
99 | #.(SB-SYS:INT-SAP #X7FFFE80065C0)
|
---|
100 | FMI> (defparameter cbl-fmu (cffi:foreign-alloc 'fmi2CallbackLogger))
|
---|
101 | CBL-FMU
|
---|
102 | FMI> CBL-FMU
|
---|
103 | #.(SB-SYS:INT-SAP #X7FFFE80065E0)
|
---|
104 | FMI> (defparameter cbf-fmu (cffi:foreign-alloc 'fmi2CallbackFunctions) )
|
---|
105 | CBF-FMU
|
---|
106 | FMI> CBF-FMU
|
---|
107 | #.(SB-SYS:INT-SAP #X7FFFE8006600)
|
---|
108 |
|
---|
109 | ;;**************************************** WE EVEN CAN PARAMETRIZE THE CALL BACK FUNCTIONS ***********************************
|
---|
110 | If we move on we can access the loggerstatus
|
---|
111 | At the end the fmi2Instantiate function call doesn't work ... in this case the REPL is frozen with no warning messages.
|
---|
112 |
|
---|
113 |
|
---|
114 | FMI> (defparameter loggerStatus (cffi:foreign-alloc 'fmi2Status))
|
---|
115 | LOGGERSTATUS
|
---|
116 | FMI> LOGGERSTATUS
|
---|
117 | #.(SB-SYS:INT-SAP #X7FFFE8006630)
|
---|
118 |
|
---|
119 | ;; some variables are defined so we can use either 0 or fmi2False
|
---|
120 | FMI> (string-right-trim "/" (namestring (car (directory (ldp f-i)))))
|
---|
121 | "/home/frederic/quicklisp/local-projects/cl-fmi/test/FirstOrderStat/unzip-3763847132/binaries/linux64"
|
---|
122 | FMI> fmi2True
|
---|
123 | 1
|
---|
124 | FMI> calloc-function-pointer
|
---|
125 | #.(SB-SYS:INT-SAP #X7FFFF7176900)
|
---|
126 | FMI> (setf (cffi:foreign-slot-value cbf-fmu
|
---|
127 | 'fmi2CallbackFunctions
|
---|
128 | 'allocateMemory)
|
---|
129 | calloc-function-pointer)
|
---|
130 | #.(SB-SYS:INT-SAP #X7FFFF7176900)
|
---|
131 |
|
---|
132 | FMI> free-function-pointer
|
---|
133 | #.(SB-SYS:INT-SAP #X0042D230)
|
---|
134 |
|
---|
135 | FMI> (setf (cffi:foreign-slot-value cbf-fmu
|
---|
136 | 'fmi2CallbackFunctions
|
---|
137 | 'freeMemory)
|
---|
138 | free-function-pointer)
|
---|
139 | #.(SB-SYS:INT-SAP #X0042D230)
|
---|
140 |
|
---|
141 | FMI> (setf (cffi:foreign-slot-value cbf-fmu 'fmi2CallbackFunctions
|
---|
142 | 'stepFinished)
|
---|
143 | (cffi:null-pointer))
|
---|
144 | #.(SB-SYS:INT-SAP #X00000000)
|
---|
145 |
|
---|
146 | FMI> (cffi:null-pointer)
|
---|
147 | #.(SB-SYS:INT-SAP #X00000000)
|
---|
148 |
|
---|
149 | FMI> (mn (md f-i))
|
---|
150 | "Modelica.Blocks.Continuous.FirstOrder"
|
---|
151 |
|
---|
152 | FMI> (g (md f-i))
|
---|
153 | "{15786be9-7df2-4916-bf0b-f46d83152302}"
|
---|
154 |
|
---|
155 | FMI> (string-right-trim "/" (namestring (car (directory (ldp f-i)))))
|
---|
156 | "/home/frederic/quicklisp/local-projects/cl-fmi/test/FirstOrderStat/unzip-3763847132/binaries/linux64"
|
---|
157 |
|
---|
158 | ;; ************************** BUT THE FMU OBJECT INSTANTIATION IS FROZEN ******************************
|
---|
159 | FMI> (fmi2Instantiate
|
---|
160 | (mn (md f-i))
|
---|
161 | :fmi2ModelExchange
|
---|
162 | (g (md f-i))
|
---|
163 | (string-right-trim "/"
|
---|
164 | (namestring (car (directory (ldp f-i)))))
|
---|
165 | cbf-fmu
|
---|
166 | 0
|
---|
167 | 0 )
|
---|
168 | FROZEN
|
---|
169 |
|
---|