bzr branch
http://suren.me/webbzr/alps/pcitool
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
1 |
#define _PCILIB_VIEW_TRANSFORM_C
|
2 |
||
3 |
#include <stdio.h> |
|
4 |
#include <unistd.h> |
|
5 |
#include <stdlib.h> |
|
6 |
#include <string.h> |
|
7 |
||
8 |
#include "version.h" |
|
9 |
#include "model.h" |
|
10 |
#include "transform.h" |
|
312
by Suren A. Chilingaryan
Support transform views |
11 |
#include "py.h" |
346.1.11
by Vasilii Chernov
Move python module init code to transfom view constructor |
12 |
#include "error.h" |
354
by Suren A. Chilingaryan
Stabilize merged code |
13 |
#include "pci.h" |
312
by Suren A. Chilingaryan
Support transform views |
14 |
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
15 |
static pcilib_view_context_t * pcilib_transform_view_init(pcilib_t *ctx, pcilib_view_t view) { |
16 |
int err; |
|
17 |
||
18 |
pcilib_view_context_t *view_ctx; |
|
354
by Suren A. Chilingaryan
Stabilize merged code |
19 |
pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(ctx->views[view]); |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
20 |
|
369
by Suren A. Chilingaryan
Make Python problems non-fatal |
21 |
if (v->script) { |
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
22 |
pcilib_access_mode_t mode = 0; |
23 |
||
24 |
err = pcilib_py_load_script(ctx, v->script); |
|
25 |
if(err) { |
|
26 |
pcilib_error("Error (%i), loading script %s", err, v->script); |
|
27 |
return NULL; |
|
28 |
}
|
|
29 |
||
30 |
err = pcilib_py_get_transform_script_properties(ctx, v->script, &mode); |
|
31 |
if(err) { |
|
32 |
pcilib_error("Error (%i) obtaining properties of transform script %s", err, v->script); |
|
33 |
return NULL; |
|
34 |
}
|
|
35 |
||
36 |
if ((v->base.mode&PCILIB_REGISTER_RW) == 0) |
|
37 |
v->base.mode |= PCILIB_REGISTER_RW; |
|
38 |
v->base.mode &= (~PCILIB_REGISTER_RW)|mode; |
|
39 |
||
40 |
if (!v->read_from_reg) v->read_from_reg = "read_from_register"; |
|
41 |
if (!v->write_to_reg) v->write_to_reg = "write_to_register"; |
|
369
by Suren A. Chilingaryan
Make Python problems non-fatal |
42 |
} else if (!ctx->py) { |
43 |
v->base.mode &= (~PCILIB_REGISTER_RW); |
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
44 |
}
|
369
by Suren A. Chilingaryan
Make Python problems non-fatal |
45 |
|
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
46 |
view_ctx = (pcilib_view_context_t*)malloc(sizeof(pcilib_view_context_t)); |
346.1.11
by Vasilii Chernov
Move python module init code to transfom view constructor |
47 |
if (view_ctx) memset(view_ctx, 0, sizeof(pcilib_view_context_t)); |
369
by Suren A. Chilingaryan
Make Python problems non-fatal |
48 |
|
346.1.11
by Vasilii Chernov
Move python module init code to transfom view constructor |
49 |
return view_ctx; |
50 |
}
|
|
51 |
||
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
52 |
static int pcilib_transform_view_read(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t regval, pcilib_value_t *val) { |
53 |
int err; |
|
54 |
||
55 |
const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); |
|
56 |
pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(model_info->views[view_ctx->view]); |
|
57 |
||
58 |
err = pcilib_set_value_from_register_value(ctx, val, regval); |
|
59 |
if (err) return err; |
|
60 |
||
61 |
if (v->script) |
|
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
62 |
err = pcilib_py_eval_func(ctx, v->script, v->read_from_reg, val); |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
63 |
else
|
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
64 |
err = pcilib_py_eval_string(ctx, v->read_from_reg, val); |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
65 |
|
66 |
return err; |
|
67 |
}
|
|
68 |
||
69 |
static int pcilib_transform_view_write(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t *regval, const pcilib_value_t *val) { |
|
70 |
int err = 0; |
|
71 |
pcilib_value_t val_copy = {0}; |
|
72 |
||
73 |
const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); |
|
74 |
pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(model_info->views[view_ctx->view]); |
|
75 |
||
76 |
err = pcilib_copy_value(ctx, &val_copy, val); |
|
77 |
if (err) return err; |
|
78 |
||
79 |
if (v->script) |
|
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
80 |
err = pcilib_py_eval_func(ctx, v->script, v->write_to_reg, &val_copy); |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
81 |
else
|
357
by Suren A. Chilingaryan
Merge of further work on Python scripting from Vasiliy Chernov |
82 |
err = pcilib_py_eval_string(ctx, v->write_to_reg, &val_copy); |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
83 |
|
84 |
if (err) return err; |
|
85 |
||
86 |
*regval = pcilib_get_value_as_register_value(ctx, &val_copy, &err); |
|
87 |
return err; |
|
88 |
}
|
|
89 |
||
307
by Suren A. Chilingaryan
Finalyze XML support and provide initial support for views (only descriptions so far) |
90 |
const pcilib_view_api_description_t pcilib_transform_view_api = |
353
by Suren A. Chilingaryan
Merge Python scripting support from Vasiliy Chernov |
91 |
{ PCILIB_VERSION, sizeof(pcilib_transform_view_description_t), pcilib_transform_view_init, NULL, NULL, pcilib_transform_view_read, pcilib_transform_view_write }; |