bzr branch
http://suren.me/webbzr/alps/pcitool
346.1.16
by Vasilii Chernov
1. Add cmake BUILD_PYTHON_MODULES option. |
1 |
#include "pcipywrap.h" |
346.1.22
by Vasilii Chernov
1. Http server add tree view |
2 |
#include "locking.h" |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
3 |
|
346.1.11
by Vasilii Chernov
Move python module init code to transfom view constructor |
4 |
char* full_log = NULL; |
5 |
||
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
6 |
/*!
|
7 |
* \brief Wraping for vsnprintf function, that saves string to char*
|
|
8 |
* \return saved from vsnprintf string
|
|
9 |
*/
|
|
10 |
char* vmake_str(const char* msg, va_list vl) |
|
11 |
{
|
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
12 |
char *buf; |
13 |
size_t sz; |
|
14 |
||
15 |
va_list vl_copy; |
|
16 |
va_copy(vl_copy, vl); |
|
17 |
||
18 |
sz = vsnprintf(NULL, 0, msg, vl); |
|
19 |
buf = (char *)malloc(sz + 1); |
|
20 |
||
21 |
if(!buf) |
|
22 |
{
|
|
23 |
return NULL; |
|
24 |
}
|
|
25 |
||
26 |
vsnprintf(buf, sz+1, msg, vl_copy); |
|
27 |
va_end(vl_copy); |
|
28 |
||
29 |
return buf; |
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
30 |
}
|
31 |
||
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
32 |
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
33 |
/*!
|
34 |
* \brief Wraping for vsnprintf function, that saves string to char*
|
|
35 |
* \return saved from vsnprintf string
|
|
36 |
*/
|
|
37 |
char* make_str(const char* msg, ...) |
|
38 |
{
|
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
39 |
va_list vl; |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
40 |
va_start(vl, msg); |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
41 |
char *buf = vmake_str(msg, vl); |
42 |
va_end(vl); |
|
43 |
return buf; |
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
44 |
}
|
45 |
||
46 |
/*!
|
|
47 |
* \brief Version of pcilib_logger_t, that saves error text to Python exeption
|
|
48 |
*/
|
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
49 |
void pcilib_print_error_to_py(void *arg, const char *file, int line, |
50 |
pcilib_log_priority_t prio, const char *msg, |
|
51 |
va_list va) { |
|
52 |
//wrap error message with file and line number
|
|
53 |
char* buf_raw_msg = vmake_str(msg, va); |
|
54 |
char* buf_wrapped_message = make_str("%s [%s:%d]\n", buf_raw_msg, file, line); |
|
55 |
||
56 |
if(prio == PCILIB_LOG_ERROR) |
|
57 |
{
|
|
58 |
if(!full_log) |
|
59 |
full_log = make_str(""); |
|
60 |
||
61 |
//copy received message to log
|
|
62 |
char* buf = full_log; |
|
63 |
full_log = make_str("%s%s", buf, buf_wrapped_message); |
|
64 |
free(buf); |
|
65 |
}
|
|
66 |
else
|
|
67 |
printf("%s", buf_wrapped_message); |
|
68 |
||
69 |
free(buf_wrapped_message); |
|
70 |
free(buf_raw_msg); |
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
71 |
}
|
72 |
||
346.1.16
by Vasilii Chernov
1. Add cmake BUILD_PYTHON_MODULES option. |
73 |
void set_python_exception(const char* msg, ...) |
74 |
{
|
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
75 |
va_list vl; |
346.1.16
by Vasilii Chernov
1. Add cmake BUILD_PYTHON_MODULES option. |
76 |
va_start(vl, msg); |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
77 |
char *buf = vmake_str(msg, vl); |
78 |
||
79 |
char* wrapped_exeption; |
|
80 |
if(full_log) |
|
81 |
wrapped_exeption = make_str("%s\nprogramm error log:\n%s", buf, full_log); |
|
82 |
else
|
|
83 |
wrapped_exeption = buf; |
|
84 |
||
85 |
free(full_log); |
|
86 |
full_log = NULL; |
|
87 |
||
88 |
PyErr_SetString(PyExc_Exception, wrapped_exeption); |
|
89 |
||
90 |
free(buf); |
|
91 |
if(full_log) |
|
92 |
free(wrapped_exeption); |
|
93 |
va_end(vl); |
|
346.1.16
by Vasilii Chernov
1. Add cmake BUILD_PYTHON_MODULES option. |
94 |
}
|
95 |
||
96 |
||
346.1.30
by Vasilii Chernov
1. api-serer: |
97 |
void redirect_logs_to_exeption() |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
98 |
{
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
99 |
pcilib_set_logger(pcilib_get_log_level(), |
100 |
pcilib_print_error_to_py, |
|
101 |
pcilib_get_logger_context()); |
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
102 |
}
|
103 |
||
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
104 |
/*!
|
105 |
* \brief Wrap for PyDict_SetItem, with decrease reference counting after set.
|
|
106 |
*/
|
|
107 |
void pcilib_pydict_set_item(PyObject* dict, PyObject* name, PyObject* value) |
|
108 |
{
|
|
109 |
PyDict_SetItem(dict, |
|
110 |
name, |
|
111 |
value); |
|
112 |
Py_XDECREF(name); |
|
113 |
Py_XDECREF(value); |
|
114 |
}
|
|
115 |
||
116 |
/*!
|
|
117 |
* \brief Wrap for PyList_Append, with decrease reference counting after append.
|
|
118 |
*/
|
|
119 |
void pcilib_pylist_append(PyObject* list, PyObject* value) |
|
120 |
{
|
|
121 |
PyList_Append(list, value); |
|
122 |
Py_XDECREF(value); |
|
123 |
}
|
|
124 |
||
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
125 |
void add_pcilib_value_to_dict(pcilib_t* ctx, PyObject* dict, pcilib_value_t* val, const char *name) |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
126 |
{
|
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
127 |
PyObject *py_val = (PyObject*)pcilib_get_value_as_pyobject(ctx, val, NULL); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
128 |
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
129 |
if(py_val) |
130 |
pcilib_pydict_set_item(dict, |
|
346.1.35
by Vasilii Chernov
Add Python3 support |
131 |
PyUnicode_FromString(name), |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
132 |
py_val); |
133 |
else
|
|
134 |
pcilib_pydict_set_item(dict, |
|
346.1.35
by Vasilii Chernov
Add Python3 support |
135 |
PyUnicode_FromString("defvalue"), |
136 |
PyUnicode_FromString("invalid")); |
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
137 |
}
|
138 |
||
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
139 |
PyObject * pcilib_convert_property_info_to_pyobject(pcilib_t* ctx, pcilib_property_info_t listItem) |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
140 |
{
|
141 |
PyObject* pylistItem = PyDict_New(); |
|
142 |
||
143 |
if(listItem.name) |
|
346.1.13
by Vasilii Chernov
Fix memory leaks |
144 |
pcilib_pydict_set_item(pylistItem, |
346.1.35
by Vasilii Chernov
Add Python3 support |
145 |
PyUnicode_FromString("name"), |
146 |
PyUnicode_FromString(listItem.name)); |
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
147 |
|
148 |
if(listItem.description) |
|
346.1.13
by Vasilii Chernov
Fix memory leaks |
149 |
pcilib_pydict_set_item(pylistItem, |
346.1.35
by Vasilii Chernov
Add Python3 support |
150 |
PyUnicode_FromString("description"), |
151 |
PyUnicode_FromString(listItem.description)); |
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
152 |
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
153 |
if(listItem.path) |
346.1.13
by Vasilii Chernov
Fix memory leaks |
154 |
pcilib_pydict_set_item(pylistItem, |
346.1.35
by Vasilii Chernov
Add Python3 support |
155 |
PyUnicode_FromString("path"), |
156 |
PyUnicode_FromString(listItem.path)); |
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
157 |
|
158 |
//serialize types
|
|
159 |
const char* type = "invalid"; |
|
160 |
switch(listItem.type) |
|
161 |
{
|
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
162 |
case PCILIB_TYPE_INVALID: |
163 |
type = "invalid"; |
|
164 |
break; |
|
165 |
case PCILIB_TYPE_STRING: |
|
166 |
type = "string"; |
|
167 |
break; |
|
168 |
case PCILIB_TYPE_DOUBLE: |
|
169 |
type = "double"; |
|
170 |
break; |
|
171 |
case PCILIB_TYPE_LONG : |
|
172 |
type = "long"; |
|
173 |
break; |
|
174 |
default: |
|
175 |
break; |
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
176 |
}
|
346.1.13
by Vasilii Chernov
Fix memory leaks |
177 |
pcilib_pydict_set_item(pylistItem, |
346.1.35
by Vasilii Chernov
Add Python3 support |
178 |
PyUnicode_FromString("type"), |
179 |
PyUnicode_FromString(type)); |
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
180 |
|
181 |
||
182 |
//serialize modes
|
|
183 |
PyObject* modes = PyList_New(0); |
|
184 |
||
185 |
if((listItem.mode & PCILIB_ACCESS_R ) == PCILIB_REGISTER_R) |
|
346.1.35
by Vasilii Chernov
Add Python3 support |
186 |
pcilib_pylist_append(modes, PyUnicode_FromString("R")); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
187 |
if((listItem.mode & PCILIB_ACCESS_W ) == PCILIB_REGISTER_W) |
346.1.35
by Vasilii Chernov
Add Python3 support |
188 |
pcilib_pylist_append(modes, PyUnicode_FromString("W")); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
189 |
if((listItem.mode & PCILIB_ACCESS_RW ) == PCILIB_REGISTER_RW) |
346.1.35
by Vasilii Chernov
Add Python3 support |
190 |
pcilib_pylist_append(modes, PyUnicode_FromString("RW")); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
191 |
if((listItem.mode & PCILIB_REGISTER_INCONSISTENT) == PCILIB_REGISTER_INCONSISTENT) |
346.1.35
by Vasilii Chernov
Add Python3 support |
192 |
pcilib_pylist_append(modes, PyUnicode_FromString("NO_CHK")); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
193 |
|
346.1.13
by Vasilii Chernov
Fix memory leaks |
194 |
pcilib_pydict_set_item(pylistItem, |
346.1.35
by Vasilii Chernov
Add Python3 support |
195 |
PyUnicode_FromString("mode"), |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
196 |
modes); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
197 |
|
198 |
//serialize flags
|
|
199 |
PyObject* flags = PyList_New(0); |
|
200 |
||
201 |
if((listItem.flags & PCILIB_LIST_FLAG_CHILDS ) == PCILIB_LIST_FLAG_CHILDS) |
|
346.1.35
by Vasilii Chernov
Add Python3 support |
202 |
pcilib_pylist_append(flags, PyUnicode_FromString("childs")); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
203 |
|
346.1.13
by Vasilii Chernov
Fix memory leaks |
204 |
pcilib_pydict_set_item(pylistItem, |
346.1.35
by Vasilii Chernov
Add Python3 support |
205 |
PyUnicode_FromString("flags"), |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
206 |
flags); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
207 |
|
208 |
if(listItem.unit) |
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
209 |
pcilib_pydict_set_item(pylistItem, |
346.1.35
by Vasilii Chernov
Add Python3 support |
210 |
PyUnicode_FromString("unit"), |
211 |
PyUnicode_FromString(listItem.unit)); |
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
212 |
|
213 |
return pylistItem; |
|
214 |
}
|
|
215 |
||
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
216 |
PyObject * pcilib_convert_register_info_to_pyobject(pcilib_t* ctx, pcilib_register_info_t listItem) |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
217 |
{
|
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
218 |
PyObject* pylistItem = PyDict_New(); |
219 |
||
220 |
if(listItem.name) |
|
221 |
pcilib_pydict_set_item(pylistItem, |
|
346.1.35
by Vasilii Chernov
Add Python3 support |
222 |
PyUnicode_FromString("name"), |
223 |
PyUnicode_FromString(listItem.name)); |
|
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
224 |
|
225 |
if(listItem.description) |
|
226 |
pcilib_pydict_set_item(pylistItem, |
|
346.1.35
by Vasilii Chernov
Add Python3 support |
227 |
PyUnicode_FromString("description"), |
228 |
PyUnicode_FromString(listItem.description)); |
|
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
229 |
|
230 |
if(listItem.bank) |
|
231 |
pcilib_pydict_set_item(pylistItem, |
|
346.1.35
by Vasilii Chernov
Add Python3 support |
232 |
PyUnicode_FromString("bank"), |
233 |
PyUnicode_FromString(listItem.bank)); |
|
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
234 |
|
235 |
||
236 |
//serialize modes
|
|
237 |
PyObject* modes = PyList_New(0); |
|
238 |
||
239 |
if((listItem.mode & PCILIB_REGISTER_R) == PCILIB_REGISTER_R) |
|
346.1.35
by Vasilii Chernov
Add Python3 support |
240 |
pcilib_pylist_append(modes, PyUnicode_FromString("R")); |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
241 |
if((listItem.mode & PCILIB_REGISTER_W) == PCILIB_REGISTER_W) |
346.1.35
by Vasilii Chernov
Add Python3 support |
242 |
pcilib_pylist_append(modes, PyUnicode_FromString("W")); |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
243 |
if((listItem.mode & PCILIB_REGISTER_RW) == PCILIB_REGISTER_RW) |
346.1.35
by Vasilii Chernov
Add Python3 support |
244 |
pcilib_pylist_append(modes, PyUnicode_FromString("RW")); |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
245 |
if((listItem.mode & PCILIB_REGISTER_W1C) == PCILIB_REGISTER_W1C) |
346.1.35
by Vasilii Chernov
Add Python3 support |
246 |
pcilib_pylist_append(modes, PyUnicode_FromString("W1C")); |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
247 |
if((listItem.mode & PCILIB_REGISTER_RW1C) == PCILIB_REGISTER_RW1C) |
346.1.35
by Vasilii Chernov
Add Python3 support |
248 |
pcilib_pylist_append(modes, PyUnicode_FromString("RW1C")); |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
249 |
if((listItem.mode & PCILIB_REGISTER_W1I) == PCILIB_REGISTER_W1I) |
346.1.35
by Vasilii Chernov
Add Python3 support |
250 |
pcilib_pylist_append(modes, PyUnicode_FromString("W1I")); |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
251 |
if((listItem.mode & PCILIB_REGISTER_RW1I) == PCILIB_REGISTER_RW1I) |
346.1.35
by Vasilii Chernov
Add Python3 support |
252 |
pcilib_pylist_append(modes, PyUnicode_FromString("RW1I")); |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
253 |
if((listItem.mode & PCILIB_REGISTER_INCONSISTENT) == PCILIB_REGISTER_INCONSISTENT) |
346.1.35
by Vasilii Chernov
Add Python3 support |
254 |
pcilib_pylist_append(modes, PyUnicode_FromString("NO_CHK")); |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
255 |
|
256 |
pcilib_pydict_set_item(pylistItem, |
|
346.1.35
by Vasilii Chernov
Add Python3 support |
257 |
PyUnicode_FromString("mode"), |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
258 |
modes); |
259 |
||
260 |
pcilib_value_t defval = {0}; |
|
261 |
pcilib_set_value_from_register_value(ctx, &defval, listItem.defvalue); |
|
262 |
add_pcilib_value_to_dict(ctx, pylistItem, &defval, "defvalue"); |
|
263 |
||
264 |
if(listItem.range) |
|
265 |
{
|
|
266 |
pcilib_value_t minval = {0}; |
|
267 |
pcilib_set_value_from_register_value(ctx, &minval, listItem.range->min); |
|
268 |
||
269 |
pcilib_value_t maxval = {0}; |
|
270 |
pcilib_set_value_from_register_value(ctx, &maxval, listItem.range->max); |
|
271 |
||
272 |
PyObject* range = PyDict_New(); |
|
273 |
add_pcilib_value_to_dict(ctx, range, &minval, "min"); |
|
274 |
add_pcilib_value_to_dict(ctx, range, &maxval, "max"); |
|
275 |
pcilib_pydict_set_item(pylistItem, |
|
346.1.35
by Vasilii Chernov
Add Python3 support |
276 |
PyUnicode_FromString("range"), |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
277 |
range); |
278 |
}
|
|
279 |
||
280 |
if(listItem.values) |
|
281 |
{
|
|
282 |
||
283 |
PyObject* values = PyList_New(0); |
|
284 |
||
285 |
for (int j = 0; listItem.values[j].name; j++) |
|
286 |
{
|
|
287 |
PyObject* valuesItem = PyDict_New(); |
|
288 |
||
289 |
pcilib_value_t val = {0}; |
|
290 |
pcilib_set_value_from_register_value(ctx, &val, listItem.values[j].value); |
|
291 |
||
292 |
pcilib_value_t min = {0}; |
|
293 |
pcilib_set_value_from_register_value(ctx, &min, listItem.values[j].min); |
|
294 |
||
295 |
pcilib_value_t max = {0}; |
|
296 |
pcilib_set_value_from_register_value(ctx, &max, listItem.values[j].max); |
|
297 |
||
298 |
add_pcilib_value_to_dict(ctx, valuesItem, &val, "value"); |
|
299 |
add_pcilib_value_to_dict(ctx, valuesItem, &min, "min"); |
|
300 |
add_pcilib_value_to_dict(ctx, valuesItem, &max, "max"); |
|
301 |
||
302 |
if(listItem.values[j].name) |
|
303 |
pcilib_pydict_set_item(valuesItem, |
|
346.1.35
by Vasilii Chernov
Add Python3 support |
304 |
PyUnicode_FromString("name"), |
305 |
PyUnicode_FromString(listItem.values[j].name)); |
|
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
306 |
if(listItem.values[j].description) |
307 |
{
|
|
308 |
pcilib_pydict_set_item(valuesItem, |
|
346.1.35
by Vasilii Chernov
Add Python3 support |
309 |
PyUnicode_FromString("description"), |
310 |
PyUnicode_FromString(listItem.values[j].description)); |
|
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
311 |
|
312 |
}
|
|
313 |
pcilib_pylist_append(values, valuesItem); |
|
314 |
}
|
|
315 |
||
316 |
pcilib_pydict_set_item(pylistItem, |
|
346.1.35
by Vasilii Chernov
Add Python3 support |
317 |
PyUnicode_FromString("values"), |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
318 |
values); |
319 |
}
|
|
320 |
||
321 |
return pylistItem; |
|
322 |
||
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
323 |
}
|
324 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
325 |
pcipywrap *new_pcipywrap(const char* fpga_device, const char* model) |
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
326 |
{
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
327 |
//opening device
|
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
328 |
pcilib_t* ctx = pcilib_open(fpga_device, model); |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
329 |
if(!ctx) |
330 |
{
|
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
331 |
set_python_exception("Failed pcilib_open(%s, %s)", fpga_device, model); |
332 |
return NULL; |
|
333 |
}
|
|
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
334 |
pcipywrap *self; |
335 |
self = (pcipywrap *) malloc(sizeof(pcipywrap)); |
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
336 |
self->shared = 0; |
337 |
self->ctx = ctx; |
|
338 |
return self; |
|
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
339 |
}
|
340 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
341 |
pcipywrap *create_pcipywrap(PyObject* ctx) |
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
342 |
{
|
346.1.35
by Vasilii Chernov
Add Python3 support |
343 |
if(!PyCapsule_CheckExact(ctx)) |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
344 |
{
|
346.1.35
by Vasilii Chernov
Add Python3 support |
345 |
set_python_exception("Incorrect ctx type. Only PyCapsule is allowed"); |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
346 |
return NULL; |
347 |
}
|
|
348 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
349 |
pcipywrap *self; |
350 |
self = (pcipywrap *) malloc(sizeof(pcipywrap)); |
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
351 |
self->shared = 1; |
346.1.35
by Vasilii Chernov
Add Python3 support |
352 |
self->ctx = PyCapsule_GetPointer(ctx, PyCapsule_GetName(ctx)); |
353 |
||
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
354 |
return self; |
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
355 |
}
|
356 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
357 |
void delete_pcipywrap(pcipywrap *self) { |
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
358 |
if(!self->shared) |
359 |
pcilib_close(self->ctx); |
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
360 |
|
346.1.33
by Vasilii Chernov
Move scripts handing code from py.c to Python wrap |
361 |
free(self); |
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
362 |
}
|
363 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
364 |
PyObject* pcipywrap_read_register(pcipywrap *self, const char *regname, const char *bank) |
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
365 |
{
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
366 |
pcilib_value_t val = {0}; |
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
367 |
pcilib_register_value_t reg_value; |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
368 |
|
369 |
int err; |
|
370 |
||
371 |
err = pcilib_read_register(self->ctx, bank, regname, ®_value); |
|
372 |
if(err) |
|
373 |
{
|
|
374 |
set_python_exception("Failed pcilib_read_register"); |
|
375 |
return NULL; |
|
376 |
}
|
|
377 |
||
378 |
err = pcilib_set_value_from_register_value(self->ctx, &val, reg_value); |
|
379 |
if(err) |
|
380 |
{
|
|
381 |
set_python_exception("Failed pcilib_set_value_from_register_value"); |
|
382 |
return NULL; |
|
383 |
}
|
|
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
384 |
|
385 |
return pcilib_get_value_as_pyobject(self->ctx, &val, NULL); |
|
386 |
}
|
|
387 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
388 |
PyObject* pcipywrap_write_register(pcipywrap *self, PyObject* val, const char *regname, const char *bank) |
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
389 |
{
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
390 |
pcilib_value_t val_internal = {0}; |
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
391 |
pcilib_register_value_t reg_value; |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
392 |
|
393 |
int err; |
|
394 |
||
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
395 |
err = pcilib_set_value_from_pyobject(self->ctx, &val_internal, val); |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
396 |
|
397 |
if(err) |
|
398 |
{
|
|
399 |
set_python_exception("Failed pcilib_set_value_from_pyobject"); |
|
400 |
return NULL; |
|
401 |
}
|
|
402 |
||
403 |
||
404 |
reg_value = pcilib_get_value_as_register_value(self->ctx, &val_internal, &err); |
|
405 |
if(err) |
|
406 |
{
|
|
407 |
set_python_exception("Failed pcilib_set_value_from_pyobject, (error %i)", err); |
|
408 |
return NULL; |
|
409 |
}
|
|
410 |
||
411 |
err = pcilib_write_register(self->ctx, bank, regname, reg_value); |
|
412 |
||
413 |
if(err) |
|
414 |
{
|
|
415 |
set_python_exception("Failed pcilib_set_value_from_pyobject, (error %i)", err); |
|
416 |
return NULL; |
|
417 |
}
|
|
418 |
||
346.1.35
by Vasilii Chernov
Add Python3 support |
419 |
return PyLong_FromLong((long)1); |
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
420 |
}
|
421 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
422 |
PyObject* pcipywrap_get_property(pcipywrap *self, const char *prop) |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
423 |
{
|
424 |
int err; |
|
425 |
pcilib_value_t val = {0}; |
|
426 |
||
427 |
err = pcilib_get_property(self->ctx, prop, &val); |
|
428 |
||
429 |
if(err) |
|
430 |
{
|
|
431 |
set_python_exception("Failed pcilib_get_property, (error %i)", err); |
|
432 |
return NULL; |
|
433 |
}
|
|
434 |
||
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
435 |
return pcilib_get_value_as_pyobject(self->ctx, &val, NULL); |
436 |
}
|
|
437 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
438 |
PyObject* pcipywrap_set_property(pcipywrap *self, PyObject* val, const char *prop) |
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
439 |
{
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
440 |
int err; |
441 |
||
442 |
pcilib_value_t val_internal = {0}; |
|
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
443 |
err = pcilib_set_value_from_pyobject(self->ctx, &val_internal, val); |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
444 |
if(err) |
445 |
{
|
|
446 |
set_python_exception("pcilib_set_value_from_pyobject, (error %i)", err); |
|
447 |
return NULL; |
|
448 |
}
|
|
449 |
||
450 |
err = pcilib_set_property(self->ctx, prop, &val_internal); |
|
451 |
if(err) |
|
452 |
{
|
|
453 |
set_python_exception("pcilib_set_property, (error %i)", err); |
|
454 |
return NULL; |
|
455 |
}
|
|
456 |
||
346.1.35
by Vasilii Chernov
Add Python3 support |
457 |
return PyLong_FromLong((long)1); |
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
458 |
}
|
459 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
460 |
PyObject* pcipywrap_get_registers_list(pcipywrap *self, const char *bank) |
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
461 |
{
|
374
by Suren A. Chilingaryan
Handle build.h in releases |
462 |
pcilib_register_info_t *list = pcilib_get_register_list(self->ctx, bank, PCILIB_LIST_FLAGS_DEFAULT); |
463 |
||
464 |
if(!list) { |
|
465 |
set_python_exception("pcilib_get_register_list return NULL"); |
|
466 |
return NULL; |
|
467 |
}
|
|
468 |
||
469 |
PyObject* pyList = PyList_New(0); |
|
470 |
for(int i = 0; list[i].name; i++) |
|
471 |
{
|
|
472 |
//serialize item attributes
|
|
473 |
PyObject* pylistItem = pcilib_convert_register_info_to_pyobject(self->ctx, list[i]); |
|
474 |
pcilib_pylist_append(pyList, pylistItem); |
|
475 |
}
|
|
476 |
pcilib_free_register_info(self->ctx, list); |
|
477 |
return pyList; |
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
478 |
}
|
479 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
480 |
PyObject* pcipywrap_get_register_info(pcipywrap *self, const char* reg,const char *bank) |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
481 |
{
|
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
482 |
pcilib_register_info_t *info = pcilib_get_register_info(self->ctx, bank, reg, PCILIB_LIST_FLAGS_DEFAULT); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
483 |
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
484 |
if(!info) |
485 |
{
|
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
486 |
return NULL; |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
487 |
}
|
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
488 |
|
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
489 |
PyObject* py_info = pcilib_convert_register_info_to_pyobject(self->ctx, info[0]); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
490 |
|
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
491 |
pcilib_free_register_info(self->ctx, info); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
492 |
|
493 |
return py_info; |
|
494 |
}
|
|
495 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
496 |
PyObject* pcipywrap_get_property_list(pcipywrap *self, const char* branch) |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
497 |
{
|
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
498 |
pcilib_property_info_t *list = pcilib_get_property_list(self->ctx, branch, PCILIB_LIST_FLAGS_DEFAULT); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
499 |
|
500 |
PyObject* pyList = PyList_New(0); |
|
501 |
||
502 |
for(int i = 0; list[i].path; i++) |
|
503 |
{
|
|
504 |
//serialize item attributes
|
|
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
505 |
PyObject* pylistItem = pcilib_convert_property_info_to_pyobject(self->ctx, list[i]); |
346.1.13
by Vasilii Chernov
Fix memory leaks |
506 |
pcilib_pylist_append(pyList, pylistItem); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
507 |
}
|
508 |
||
346.1.17
by Vasilii Chernov
Refactor pcipywrap to object |
509 |
pcilib_free_property_info(self->ctx, list); |
346.1.9
by Vasilii Chernov
Change no_set_check parameter name. Move Python wrap to separate directory. |
510 |
|
511 |
return pyList; |
|
512 |
}
|
|
346.1.22
by Vasilii Chernov
1. Http server add tree view |
513 |
|
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
514 |
PyObject* pcipywrap_read_dma(pcipywrap *self, unsigned char dma, size_t size) |
346.1.22
by Vasilii Chernov
1. Http server add tree view |
515 |
{
|
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
516 |
int err; |
517 |
void* buf = NULL; |
|
518 |
size_t real_size; |
|
519 |
||
520 |
err = pcilib_read_dma(self->ctx, dma, (uintptr_t)NULL, size, buf, &real_size); |
|
521 |
if(err) |
|
522 |
{
|
|
523 |
set_python_exception("Failed pcilib_read_dma", err); |
|
524 |
return NULL; |
|
525 |
}
|
|
526 |
||
527 |
||
528 |
PyObject* py_buf = PyByteArray_FromStringAndSize((const char*)buf, real_size); |
|
529 |
if(buf) |
|
530 |
free(buf); |
|
531 |
||
532 |
return py_buf; |
|
346.1.22
by Vasilii Chernov
1. Http server add tree view |
533 |
}
|
534 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
535 |
PyObject* pcipywrap_lock_global(pcipywrap *self) |
346.1.22
by Vasilii Chernov
1. Http server add tree view |
536 |
{
|
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
537 |
int err; |
538 |
||
539 |
err = pcilib_lock_global(self->ctx); |
|
540 |
if(err) |
|
541 |
{
|
|
542 |
set_python_exception("Failed pcilib_lock_global"); |
|
543 |
return NULL; |
|
544 |
}
|
|
545 |
||
346.1.35
by Vasilii Chernov
Add Python3 support |
546 |
return PyLong_FromLong((long)1); |
346.1.22
by Vasilii Chernov
1. Http server add tree view |
547 |
}
|
548 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
549 |
void pcipywrap_unlock_global(pcipywrap *self) |
346.1.22
by Vasilii Chernov
1. Http server add tree view |
550 |
{
|
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
551 |
pcilib_unlock_global(self->ctx); |
552 |
return; |
|
346.1.22
by Vasilii Chernov
1. Http server add tree view |
553 |
}
|
554 |
||
346.1.37
by Vasilii Chernov
1. Pcipywrap: add persistent locking wrappings |
555 |
PyObject* lock(pcipywrap *self, const char *lock_id, pcilib_lock_flags_t flags) |
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
556 |
{
|
557 |
pcilib_lock_t* lock = pcilib_get_lock(self->ctx, |
|
346.1.37
by Vasilii Chernov
1. Pcipywrap: add persistent locking wrappings |
558 |
flags, |
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
559 |
lock_id); |
346.1.22
by Vasilii Chernov
1. Http server add tree view |
560 |
if(!lock) |
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
561 |
{
|
562 |
set_python_exception("Failed pcilib_get_lock"); |
|
563 |
return NULL; |
|
564 |
}
|
|
565 |
||
566 |
||
567 |
int err = pcilib_lock(lock); |
|
568 |
if(err) |
|
569 |
{
|
|
570 |
set_python_exception("Failed pcilib_lock"); |
|
571 |
return NULL; |
|
572 |
}
|
|
573 |
||
346.1.35
by Vasilii Chernov
Add Python3 support |
574 |
return PyLong_FromLong((long)1); |
346.1.22
by Vasilii Chernov
1. Http server add tree view |
575 |
}
|
576 |
||
346.1.37
by Vasilii Chernov
1. Pcipywrap: add persistent locking wrappings |
577 |
PyObject* pcipywrap_lock(pcipywrap *self, const char *lock_id) |
578 |
{
|
|
579 |
return lock(self, lock_id, PCILIB_LOCK_FLAGS_DEFAULT); |
|
580 |
}
|
|
581 |
||
582 |
PyObject* pcipywrap_lock_persistent(pcipywrap *self, const char *lock_id) |
|
583 |
{
|
|
584 |
return lock(self, lock_id, PCILIB_LOCK_FLAG_PERSISTENT); |
|
585 |
}
|
|
586 |
||
587 |
||
588 |
PyObject* try_lock(pcipywrap *self, const char *lock_id, pcilib_lock_flags_t flags) |
|
346.1.22
by Vasilii Chernov
1. Http server add tree view |
589 |
{
|
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
590 |
pcilib_lock_t* lock = pcilib_get_lock(self->ctx, |
346.1.37
by Vasilii Chernov
1. Pcipywrap: add persistent locking wrappings |
591 |
flags, |
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
592 |
lock_id); |
346.1.22
by Vasilii Chernov
1. Http server add tree view |
593 |
if(!lock) |
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
594 |
{
|
595 |
set_python_exception("Failed pcilib_get_lock"); |
|
596 |
return NULL; |
|
597 |
}
|
|
598 |
||
599 |
int err = pcilib_try_lock(lock); |
|
600 |
if(err) |
|
601 |
{
|
|
602 |
set_python_exception("Failed pcilib_try_lock"); |
|
603 |
return NULL; |
|
604 |
}
|
|
605 |
||
346.1.35
by Vasilii Chernov
Add Python3 support |
606 |
return PyLong_FromLong((long)1); |
346.1.22
by Vasilii Chernov
1. Http server add tree view |
607 |
}
|
608 |
||
346.1.37
by Vasilii Chernov
1. Pcipywrap: add persistent locking wrappings |
609 |
PyObject* pcipywrap_try_lock(pcipywrap *self, const char *lock_id) |
610 |
{
|
|
611 |
return try_lock(self, lock_id, PCILIB_LOCK_FLAGS_DEFAULT); |
|
612 |
}
|
|
613 |
||
614 |
PyObject* pcipywrap_try_lock_persistent(pcipywrap *self, const char *lock_id) |
|
615 |
{
|
|
616 |
return try_lock(self, lock_id, PCILIB_LOCK_FLAG_PERSISTENT); |
|
617 |
}
|
|
618 |
||
619 |
PyObject* unlock(pcipywrap *self, const char *lock_id, pcilib_lock_flags_t flags) |
|
620 |
{
|
|
621 |
pcilib_lock_t* lock = pcilib_get_lock(self->ctx, |
|
622 |
flags, |
|
623 |
lock_id); |
|
624 |
if(!lock) |
|
625 |
{
|
|
626 |
set_python_exception("Failed pcilib_get_lock"); |
|
627 |
return NULL; |
|
628 |
}
|
|
629 |
||
630 |
pcilib_unlock(lock); |
|
631 |
return PyLong_FromLong((long)1); |
|
632 |
}
|
|
633 |
||
367
by Suren A. Chilingaryan
Further improvements of Python scripting and web-interface API for register manipulations by Vasiliy Chernov |
634 |
PyObject* pcipywrap_unlock(pcipywrap *self, const char *lock_id) |
346.1.22
by Vasilii Chernov
1. Http server add tree view |
635 |
{
|
346.1.37
by Vasilii Chernov
1. Pcipywrap: add persistent locking wrappings |
636 |
return unlock(self, lock_id, PCILIB_LOCK_FLAGS_DEFAULT); |
637 |
}
|
|
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
638 |
|
346.1.37
by Vasilii Chernov
1. Pcipywrap: add persistent locking wrappings |
639 |
PyObject* pcipywrap_unlock_persistent(pcipywrap *self, const char *lock_id) |
640 |
{
|
|
641 |
return unlock(self, lock_id, PCILIB_LOCK_FLAG_PERSISTENT); |
|
346.1.22
by Vasilii Chernov
1. Http server add tree view |
642 |
}
|
643 |
||
644 |