From d9a31945a92a76e590657dc2e65bb20b6ea95d90 Mon Sep 17 00:00:00 2001 From: Vasilii Chernov Date: Thu, 11 Feb 2016 10:37:24 +0100 Subject: Merge script and transform view. Add get register and properties info to python wrap. --- views/transform.c | 52 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 14 deletions(-) (limited to 'views/transform.c') diff --git a/views/transform.c b/views/transform.c index de7ee0e..f47e4ef 100644 --- a/views/transform.c +++ b/views/transform.c @@ -12,34 +12,58 @@ static int pcilib_transform_view_read(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t regval, pcilib_value_t *val) { - int err; - const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(model_info->views[view_ctx->view]); - err = pcilib_set_value_from_register_value(ctx, val, regval); - if (err) return err; + if(v->script) + { + return pcilib_script_read(ctx, v->script, val); + } + else + { + int err; + + err = pcilib_set_value_from_register_value(ctx, val, regval); + if (err) return err; - return pcilib_py_eval_string(ctx, v->read_from_reg, val); + return pcilib_py_eval_string(ctx, v->read_from_reg, val); + } } 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) { - int err = 0; - pcilib_value_t val_copy = {0}; + + const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(model_info->views[view_ctx->view]); - err = pcilib_copy_value(ctx, &val_copy, val); - if (err) return err; - err = pcilib_py_eval_string(ctx, v->write_to_reg, &val_copy); - if (err) return err; + if(!v->script) + { + int err = 0; + + pcilib_value_t val_copy = {0}; + err = pcilib_copy_value(ctx, &val_copy, val); + if (err) return err; + + err = pcilib_py_eval_string(ctx, v->write_to_reg, &val_copy); + if (err) return err; + + *regval = pcilib_get_value_as_register_value(ctx, &val_copy, &err); + return err; + } + else + pcilib_script_write(ctx, v->script, val); +} - *regval = pcilib_get_value_as_register_value(ctx, &val_copy, &err); - return err; +void pcilib_transform_view_free_description (pcilib_t *ctx, pcilib_view_description_t *view) +{ + pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(view); + + if(v->script) + pcilib_free_py_script(v->script); } const pcilib_view_api_description_t pcilib_transform_view_api = - { PCILIB_VERSION, sizeof(pcilib_transform_view_description_t), NULL, NULL, NULL, pcilib_transform_view_read, pcilib_transform_view_write }; + { PCILIB_VERSION, sizeof(pcilib_transform_view_description_t), NULL, NULL, pcilib_transform_view_free_description, pcilib_transform_view_read, pcilib_transform_view_write }; -- cgit v1.2.3 From 76ee5a167add1c169a982ab59aa0544f827cb365 Mon Sep 17 00:00:00 2001 From: Vasilii Chernov Date: Thu, 11 Feb 2016 12:28:37 +0100 Subject: Solve errors in serialing register_info function. Clear unused code --- views/transform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'views/transform.c') diff --git a/views/transform.c b/views/transform.c index f47e4ef..986cfd7 100644 --- a/views/transform.c +++ b/views/transform.c @@ -53,7 +53,7 @@ static int pcilib_transform_view_write(pcilib_t *ctx, pcilib_view_context_t *vie return err; } else - pcilib_script_write(ctx, v->script, val); + return pcilib_script_write(ctx, v->script, (pcilib_value_t *)val); } void pcilib_transform_view_free_description (pcilib_t *ctx, pcilib_view_description_t *view) -- cgit v1.2.3 From 55eab7196d0104c71e40136b3b22e9501d234e17 Mon Sep 17 00:00:00 2001 From: Vasilii Chernov Date: Fri, 12 Feb 2016 14:43:20 +0100 Subject: 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 --- views/transform.c | 53 +++++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 30 deletions(-) (limited to 'views/transform.c') diff --git a/views/transform.c b/views/transform.c index 986cfd7..ba2f48f 100644 --- a/views/transform.c +++ b/views/transform.c @@ -15,53 +15,46 @@ static int pcilib_transform_view_read(pcilib_t *ctx, pcilib_view_context_t *view const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(model_info->views[view_ctx->view]); - if(v->script) - { - return pcilib_script_read(ctx, v->script, val); - } - else - { - int err; - - err = pcilib_set_value_from_register_value(ctx, val, regval); - if (err) return err; + int err; + err = pcilib_set_value_from_register_value(ctx, val, regval); + if (err) return err; + + if(v->module) + return pcilib_script_read(ctx, v->module, val); + else return pcilib_py_eval_string(ctx, v->read_from_reg, val); - } } 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) { - - - + const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx); pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(model_info->views[view_ctx->view]); + int err = 0; + + pcilib_value_t val_copy = {0}; + err = pcilib_copy_value(ctx, &val_copy, val); + if (err) return err; - if(!v->script) - { - int err = 0; - - pcilib_value_t val_copy = {0}; - err = pcilib_copy_value(ctx, &val_copy, val); - if (err) return err; - - err = pcilib_py_eval_string(ctx, v->write_to_reg, &val_copy); - if (err) return err; - *regval = pcilib_get_value_as_register_value(ctx, &val_copy, &err); - return err; - } + if(v->module) + err = pcilib_script_write(ctx, v->module, &val_copy); else - return pcilib_script_write(ctx, v->script, (pcilib_value_t *)val); + err = pcilib_py_eval_string(ctx, v->write_to_reg, &val_copy); + + if (err) return err; + + *regval = pcilib_get_value_as_register_value(ctx, &val_copy, &err); + return err; } void pcilib_transform_view_free_description (pcilib_t *ctx, pcilib_view_description_t *view) { pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(view); - if(v->script) - pcilib_free_py_script(v->script); + if(v->module) + pcilib_py_free_script(v->module); } -- cgit v1.2.3 From 1b3342649294c6ce99aeb82664a29eac47687ee5 Mon Sep 17 00:00:00 2001 From: Vasilii Chernov Date: Fri, 12 Feb 2016 17:50:57 +0100 Subject: Move python module init code to transfom view constructor Update python logger and python exeption messages Change serialization method in create_pcilib_instance set_pcilib functions --- views/transform.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'views/transform.c') diff --git a/views/transform.c b/views/transform.c index ba2f48f..75b95b2 100644 --- a/views/transform.c +++ b/views/transform.c @@ -9,6 +9,7 @@ #include "model.h" #include "transform.h" #include "py.h" +#include "error.h" static int pcilib_transform_view_read(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t regval, pcilib_value_t *val) { @@ -57,6 +58,34 @@ void pcilib_transform_view_free_description (pcilib_t *ctx, pcilib_view_descript pcilib_py_free_script(v->module); } +pcilib_view_context_t * pcilib_transform_view_init(pcilib_t *ctx, const pcilib_view_description_t *desc) +{ + pcilib_transform_view_description_t *v_desc = (pcilib_transform_view_description_t*)desc; + + if(v_desc->module) + { + pcilib_access_mode_t mode = 0; + + int err = pcilib_py_init_script(ctx, v_desc->module, &mode); + if(err) + { + pcilib_error("Failed init script module (%s) - error %i", v_desc->module, err); + return NULL; + } + + v_desc->base.mode |= PCILIB_REGISTER_RW; + mode |= PCILIB_REGISTER_INCONSISTENT; + v_desc->base.mode &= mode; + } + + pcilib_view_context_t *view_ctx; + view_ctx = (pcilib_view_context_t*)malloc(sizeof(pcilib_view_context_t)); + if (view_ctx) memset(view_ctx, 0, sizeof(pcilib_view_context_t)); + + return view_ctx; +} + + const pcilib_view_api_description_t pcilib_transform_view_api = - { PCILIB_VERSION, sizeof(pcilib_transform_view_description_t), NULL, NULL, pcilib_transform_view_free_description, pcilib_transform_view_read, pcilib_transform_view_write }; + { PCILIB_VERSION, sizeof(pcilib_transform_view_description_t), pcilib_transform_view_init, NULL, pcilib_transform_view_free_description, pcilib_transform_view_read, pcilib_transform_view_write }; -- cgit v1.2.3 From ed9d8f285f4d81e1ce8bb5e7a5b9e471a73c1590 Mon Sep 17 00:00:00 2001 From: Vasilii Chernov Date: Tue, 16 Feb 2016 16:30:40 +0100 Subject: 1. Add python thread initialization to pcilib_init_py() -Fix pcilib_script_run_func() work in multithread mode 2. pcilib_close() - Move free_py() code after free views to make view destructors work properly 3. Move script hash to pcilib_py_s 4. Move pcilib_get_logger() pcilib_get_logger_min_prio() and pcilib_get_logger_argument() declarations to error.h 5. Refactor pcilib_get_value_as_pyobject pcilib_set_value_from_pyobject to more unified form 6. Add more memory checks. Fix some string memory allocations. 7. Refactor pcilib_py_s member names. 8. Merge pcilib_script_read() and pcilib_script_write() to pcilib_script_run_func() 9. Update test_pywrap views scripts --- views/transform.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'views/transform.c') diff --git a/views/transform.c b/views/transform.c index 75b95b2..24434e3 100644 --- a/views/transform.c +++ b/views/transform.c @@ -22,7 +22,8 @@ static int pcilib_transform_view_read(pcilib_t *ctx, pcilib_view_context_t *view if (err) return err; if(v->module) - return pcilib_script_read(ctx, v->module, val); + return err = pcilib_script_run_func(ctx, v->module, + "read_from_register", val); else return pcilib_py_eval_string(ctx, v->read_from_reg, val); } @@ -40,7 +41,8 @@ static int pcilib_transform_view_write(pcilib_t *ctx, pcilib_view_context_t *vie if(v->module) - err = pcilib_script_write(ctx, v->module, &val_copy); + err = pcilib_script_run_func(ctx, v->module, + "write_to_register", &val_copy); else err = pcilib_py_eval_string(ctx, v->write_to_reg, &val_copy); @@ -55,7 +57,7 @@ void pcilib_transform_view_free_description (pcilib_t *ctx, pcilib_view_descript pcilib_transform_view_description_t *v = (pcilib_transform_view_description_t*)(view); if(v->module) - pcilib_py_free_script(v->module); + pcilib_py_free_script(ctx, v->module); } pcilib_view_context_t * pcilib_transform_view_init(pcilib_t *ctx, const pcilib_view_description_t *desc) -- cgit v1.2.3 From 3269dce32883e14b45cc490a0cc0037b4c808a68 Mon Sep 17 00:00:00 2001 From: Vasilii Chernov Date: Wed, 17 Feb 2016 11:01:22 +0100 Subject: 1. Add cmake BUILD_PYTHON_MODULES option. 2. Rename log options getting functions. 3. py: - pcilib_init_py() - extract pcilib_py_add_script_dir() - pcilib_py_init_script() - extract view-specialized code to pcilib_py_get_transform_script_properties() 3. pcilib_open(): - move pcilib_init_py() to previous position. - add extract pcilib_py_add_script_dir() 4. pcilib_script_s - change hash key. Now it is (const char*) and contains script file name with extension 5. pcipywrap: - Add pcipywrap.h to remove swig generated file complile warnings - remove -includeall swig flag to prevent crash in multi-thread scripts - change set python expetion mechanic --- views/transform.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'views/transform.c') diff --git a/views/transform.c b/views/transform.c index 24434e3..eb3572a 100644 --- a/views/transform.c +++ b/views/transform.c @@ -68,12 +68,21 @@ pcilib_view_context_t * pcilib_transform_view_init(pcilib_t *ctx, const pcilib_v { pcilib_access_mode_t mode = 0; - int err = pcilib_py_init_script(ctx, v_desc->module, &mode); + int err = pcilib_py_init_script(ctx, v_desc->module); if(err) { - pcilib_error("Failed init script module (%s) - error %i", v_desc->module, err); + pcilib_error("Failed init script module (%s) - error %i", + v_desc->module, err); return NULL; - } + } + err = pcilib_py_get_transform_script_properties(ctx, v_desc->module, + &mode); + if(err) + { + pcilib_error("Failed get transform script properties (%s) - error %i", + v_desc->module, err); + return NULL; + } v_desc->base.mode |= PCILIB_REGISTER_RW; mode |= PCILIB_REGISTER_INCONSISTENT; @@ -87,7 +96,5 @@ pcilib_view_context_t * pcilib_transform_view_init(pcilib_t *ctx, const pcilib_v return view_ctx; } - - const pcilib_view_api_description_t pcilib_transform_view_api = { PCILIB_VERSION, sizeof(pcilib_transform_view_description_t), pcilib_transform_view_init, NULL, pcilib_transform_view_free_description, pcilib_transform_view_read, pcilib_transform_view_write }; -- cgit v1.2.3