/alps/pcitool

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to pywrap/pcipywrap.c

  • Committer: Vasilii Chernov
  • Date: 2016-02-12 13:43:20 UTC
  • mto: This revision was merged to the branch mainline in revision 353.
  • Revision ID: vchernov@inr.ru-20160212134320-qj1oj1v4g6ixn9c8
1. Cmakelists - move copy xml folder command to root file
2. - Move set python paths code to python module init funtction
     - pci.c move python module init block code after checking model
       to get paths before it runs.
   - Fix set python path code to work with PYTHONPATH
   - Update pci run script to work with PYTHONPATH
   - Fix python finalize code
3. Change pcilib_script_s interacting method. Now it stores in hash.
4. Change names of some fucntions to more unified ones
5. Remove old unused function pcilib_xml_create_script_or_transform_view
6. cli - disable reading register after set if write_verification flag is off
7. Remove uninformative error messages fro Python wrap.
8. - Server.py - add read/write property/register command handling
   - Add help message
   - Correcting paths

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
/*!
6
6
 * \brief Global pointer to pcilib_t context.
7
 
 * Used by setPcilib and read_register.
 
7
 * Used by set_pcilib and read_register.
8
8
 */
9
9
pcilib_t* __ctx = 0;
10
10
 
68
68
 */
69
69
void init_pcipywrap_module()
70
70
{
 
71
        printf("init_pcipywrap_module\n");
71
72
        pcilib_set_logger(pcilib_get_logger_min_prio(), 
72
73
                                          pcilib_print_error_to_py,
73
74
                                          pcilib_get_logger_argument());
79
80
 * \param[in] model specifies the model of hardware, autodetected if NULL is passed
80
81
 * \return Pointer to pcilib_t, created by pcilib_open, serialized to bytearray; NULL with exeption text, if failed.
81
82
 */
82
 
PyObject* createPcilibInstance(const char *fpga_device, const char *model)
 
83
PyObject* create_pcilib_instance(const char *fpga_device, const char *model)
83
84
{
84
85
        //opening device
85
86
    pcilib_t* ctx = pcilib_open(fpga_device, model);
93
94
/*!
94
95
 * \brief Closes current pciliv instance, if its open.
95
96
 */
96
 
void closeCurrentPcilibInstance()
 
97
void close_curr_pcilib_instance()
97
98
{
98
99
    if(__ctx)
99
100
    {
106
107
 * \brief Returns current opened pcilib_t instatnce
107
108
 * \return Pointer to pcilib_t, serialized to bytearray
108
109
 */
109
 
PyObject* getCurrentPcilibInstance()
 
110
PyObject* get_curr_pcilib_instance()
110
111
{
111
112
    return PyByteArray_FromStringAndSize((const char*)&__ctx, sizeof(pcilib_t*));
112
113
}
116
117
 * \param[in] addr Pointer to pcilib_t, serialized to bytearray
117
118
 * \return 1, serialized to PyObject or NULL with exeption text, if failed.
118
119
 */
119
 
PyObject* setPcilib(PyObject* addr)
 
120
PyObject* set_pcilib(PyObject* addr)
120
121
{
121
122
        if(!PyByteArray_Check(addr))
122
123
        {
156
157
        
157
158
        err = pcilib_read_register(__ctx, bank, regname, &reg_value);
158
159
        if(err)
159
 
        {
160
 
        pcilib_error("Failed: pcilib_read_register (%i)", err);
161
160
                return NULL;
162
 
        }
163
161
        
164
162
        err = pcilib_set_value_from_register_value(__ctx, &val, reg_value);
165
163
        if(err)
166
 
        {
167
 
        pcilib_error("Failed: pcilib_set_value_from_register_value (%i)", err);
168
164
                return NULL;
169
 
        }
170
165
 
171
 
    return pcilib_convert_val_to_pyobject(__ctx, &val);
 
166
    return pcilib_get_value_as_pyobject(__ctx, &val);
172
167
}
173
168
 
174
169
/*!
190
185
    pcilib_register_value_t reg_value;
191
186
        
192
187
        int err; 
193
 
        err = pcilib_convert_pyobject_to_val(__ctx, val, &val_internal);
 
188
        err = pcilib_set_value_from_pyobject(__ctx, val, &val_internal);
194
189
        if(err)
195
 
        {
196
 
        pcilib_error("Failed pcilib_convert_pyobject_to_val (%i)", err);
197
190
                return NULL;
198
 
        }
199
191
        
200
192
        reg_value = pcilib_get_value_as_register_value(__ctx, &val_internal, &err);
201
193
        if(err)
202
 
        {
203
 
        pcilib_error("Failed: pcilib_get_value_as_register_value (%i)", err);
204
194
                return NULL;
205
 
        }
206
195
        
207
196
        err = pcilib_write_register(__ctx, bank, regname, reg_value);
208
197
        if(err)
209
 
        {
210
 
        pcilib_error("Failed: pcilib_write_register (%i)", err);
211
198
                return NULL;
212
 
        }
213
199
    return PyInt_FromLong((long)1);
214
200
}
215
201
 
232
218
        err  = pcilib_get_property(__ctx, prop, &val);
233
219
        
234
220
        if(err)
235
 
        {
236
 
            pcilib_error("Failed pcilib_get_property (%i)", err);
237
 
                        return NULL;
238
 
        }
 
221
                return NULL;
239
222
        
240
 
    return pcilib_convert_val_to_pyobject(__ctx, &val);
 
223
    return pcilib_get_value_as_pyobject(__ctx, &val);
241
224
}
242
225
 
243
226
/*!
246
229
 * \param[in] val Property value, that needs to be set. Can be int, float or string.
247
230
 * \return 1, serialized to PyObject or NULL with exeption text, if failed.
248
231
 */
249
 
PyObject* set_property(const char *prop, PyObject* val)
 
232
PyObject* set_property(PyObject* val, const char *prop)
250
233
{
251
234
        int err;
252
235
        
257
240
        }
258
241
        
259
242
        pcilib_value_t val_internal = {0};
260
 
        err = pcilib_convert_pyobject_to_val(__ctx, val, &val_internal);
 
243
        err = pcilib_set_value_from_pyobject(__ctx, val, &val_internal);
261
244
        if(err)
262
 
        {
263
 
        pcilib_error("Failed pcilib_convert_pyobject_to_val (%i)", err);
264
245
                return NULL;
265
 
        }
266
246
        
267
247
        err  = pcilib_set_property(__ctx, prop, &val_internal);
268
248
        
269
249
        if(err)
270
 
        {
271
 
        pcilib_error("Failed pcilib_get_property (%i)", err);
272
250
                return NULL;
273
 
        }
274
251
        
275
252
        return PyInt_FromLong((long)1);
276
253
}
277
254
 
278
255
void add_pcilib_value_to_dict(PyObject* dict, pcilib_value_t* val, const char *name)
279
256
{
280
 
    PyObject *py_val = (PyObject*)pcilib_convert_val_to_pyobject(__ctx, val);
 
257
    PyObject *py_val = (PyObject*)pcilib_get_value_as_pyobject(__ctx, val);
281
258
 
282
259
        if(py_val)
283
260
                PyDict_SetItem(dict,
506
483
 
507
484
        if(!info)
508
485
        {
509
 
        pcilib_error("Failed pcilib_get_register_info");
510
486
        return NULL;
511
487
        }
512
488