Ticket #5421: STRANGE-OCCURENCE-LOAD.txt

File STRANGE-OCCURENCE-LOAD.txt, 6.7 KB (added by FBXon2ROX, 6 years ago)

Detailed steps fo the callbackfunctions fmu instantiation (static not working case)

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