summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorVasilii Chernov <vchernov@inr.ru>2016-02-08 11:55:33 +0100
committerVasilii Chernov <vchernov@inr.ru>2016-02-08 11:55:33 +0100
commite10e102b8b0ff3bf35f16b5276d56059d242e1fd (patch)
treee5ae763aa808412523ee74d6c8cbdabf5b01695f /views
parent5349163e93a107fdfea2ad58760f6149a8d749b0 (diff)
downloadpcitool-e10e102b8b0ff3bf35f16b5276d56059d242e1fd.tar.gz
pcitool-e10e102b8b0ff3bf35f16b5276d56059d242e1fd.tar.bz2
pcitool-e10e102b8b0ff3bf35f16b5276d56059d242e1fd.tar.xz
pcitool-e10e102b8b0ff3bf35f16b5276d56059d242e1fd.zip
Add support for setting register value to script transfrom. Add set_property and get_property functions to pcipywrap. Cleaning cmakelists from unused dependencies
Diffstat (limited to 'views')
-rw-r--r--views/script.c91
1 files changed, 70 insertions, 21 deletions
diff --git a/views/script.c b/views/script.c
index 50b31b5..3d018e9 100644
--- a/views/script.c
+++ b/views/script.c
@@ -4,17 +4,15 @@
#include <stdlib.h>
#include "pci.h"
+#include "pcipywrap.h"
#include "error.h"
#include "model.h"
#include "script.h"
-static int pcilib_script_view_read(pcilib_t *ctx, pcilib_view_context_t *view_ctx, pcilib_register_value_t regval, pcilib_value_t *val) {
-
+static int pcilib_script_view_module_init(pcilib_t *ctx, pcilib_script_view_description_t *v)
+{
int err;
-
- const pcilib_model_description_t *model_info = pcilib_get_model_description(ctx);
- pcilib_script_view_description_t *v = (pcilib_script_view_description_t*)(model_info->views[view_ctx->view]);
//Initialize python script, if it has not initialized already.
if(!v->py_script_module)
@@ -103,6 +101,19 @@ static int pcilib_script_view_read(pcilib_t *ctx, pcilib_view_context_t *view_ct
NULL);
}
+ return 0;
+}
+
+static int pcilib_script_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_script_view_description_t *v = (pcilib_script_view_description_t*)(model_info->views[view_ctx->view]);
+
+ err = pcilib_script_view_module_init(ctx, v);
+ if(err)
+ return err;
PyObject *ret = PyObject_CallMethod(v->py_script_module, "read_from_register", "()");
if (!ret)
@@ -112,30 +123,68 @@ static int pcilib_script_view_read(pcilib_t *ctx, pcilib_view_context_t *view_ct
return PCILIB_ERROR_FAILED;
}
- if(PyInt_Check(ret))
+ err = pcilib_convert_pyobject_to_val(ctx, ret, val);
+
+ if(err)
{
- err = pcilib_set_value_from_int(ctx, val, PyInt_AsLong(ret));
+ pcilib_error("Failed to convert python script return value to internal type: %i", err);
+ return err;
}
- else
- if(PyFloat_Check(ret))
- err = pcilib_set_value_from_float(ctx, val, PyFloat_AsDouble(ret));
- else
- if(PyString_Check(ret))
- err = pcilib_set_value_from_static_string(ctx, val, PyString_AsString(ret));
- else
- {
- pcilib_error("Invalid return type in read_from_register() method. Return type should be int, float or string.");
- return PCILIB_ERROR_NOTSUPPORTED;
- }
+ return 0;
+}
+
+static int pcilib_script_view_write(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_script_view_description_t *v = (pcilib_script_view_description_t*)(model_info->views[view_ctx->view]);
+
+ err = pcilib_script_view_module_init(ctx, v);
if(err)
+ return err;
+
+ PyObject *input = pcilib_convert_val_to_pyobject(ctx, val, printf);
+ if(!input)
{
- pcilib_error("Failed to convert python script return value to internal type: %i", err);
+ printf("Failed to convert input value to Python object");
+ PyErr_Print();
+ return PCILIB_ERROR_FAILED;
+ }
+
+ PyObject *ret = PyObject_CallMethodObjArgs(v->py_script_module,
+ PyUnicode_FromString("write_to_register"),
+ input,
+ NULL);
+ if (!ret)
+ {
+ printf("Python script error: ");
+ PyErr_Print();
+ return PCILIB_ERROR_FAILED;
+ }
+
+ //convert output value back to pcilib_value_t
+ //no need because it wont be used later, and the script return could be none
+ /*
+ err = pcilib_convert_pyobject_to_val(ctx, ret, val);
+ if(err)
+ {
+ pcilib_error("failed to convert script write_to_register function return value to internal type: %i", err);
return err;
}
+
+ uint64_t output = pcilib_get_value_as_register_value(ctx, val, &err);
+ if(err)
+ {
+ pcilib_error("failed to convert value to register value (%i)", err);
+ return err;
+ }
+ regval[0] = output;
+ */
+
return 0;
}
-
void pcilib_script_view_free_description (pcilib_t *ctx, pcilib_view_description_t *view)
{
pcilib_script_view_description_t *v = (pcilib_script_view_description_t*)(view);
@@ -154,4 +203,4 @@ void pcilib_script_view_free_description (pcilib_t *ctx, pcilib_view_description
}
const pcilib_view_api_description_t pcilib_script_view_api =
- { PCILIB_VERSION, sizeof(pcilib_script_view_description_t), NULL, NULL, pcilib_script_view_free_description, pcilib_script_view_read, NULL};
+ { PCILIB_VERSION, sizeof(pcilib_script_view_description_t), NULL, NULL, pcilib_script_view_free_description, pcilib_script_view_read, pcilib_script_view_write};