From 2c2a714e0615d6aff3773fabfd3b93e8672a40a1 Mon Sep 17 00:00:00 2001 From: Vasilii Chernov Date: Mon, 22 Feb 2016 12:21:04 +0100 Subject: Add device html server --- pywrap/html_server.py | 105 ++++++++++++++++++++++++++++++++++ pywrap/pcipywrap.c | 2 +- pywrap/templates/base.html | 15 +++++ pywrap/templates/property_info.html | 91 ++++++++++++++++++++++++++++++ pywrap/templates/register_info.html | 106 +++++++++++++++++++++++++++++++++++ pywrap/templates/registers_list.html | 26 +++++++++ 6 files changed, 344 insertions(+), 1 deletion(-) create mode 100644 pywrap/html_server.py create mode 100644 pywrap/templates/base.html create mode 100644 pywrap/templates/property_info.html create mode 100644 pywrap/templates/register_info.html create mode 100644 pywrap/templates/registers_list.html (limited to 'pywrap') diff --git a/pywrap/html_server.py b/pywrap/html_server.py new file mode 100644 index 0000000..1731cae --- /dev/null +++ b/pywrap/html_server.py @@ -0,0 +1,105 @@ +import pcipywrap +import json + +#import flask elements +from flask import render_template +from flask import Flask +from flask import request +from flask import url_for +from flask import redirect + +app = Flask(__name__) +pcilib = 0; +device = '/dev/fpga0' +model = 'test_pywrap' + +@app.route('/set_property') +def set_property(): + val = request.args.get('val') + prop = request.args.get('prop') + + try: + pcilib.set_property(float(val), str(prop)) + return redirect(url_for('get_property_list', branch=prop)) + except Exception as e: + return str(e) + +@app.route('/write_register') +def write_register(): + val = request.args.get('val') + name = request.args.get('name') + bank = request.args.get('bank') + + try: + pcilib.write_register(float(val), str(name), str(bank)) + return redirect(url_for('get_register_info', name=name, bank=bank)) + except Exception as e: + return str(e) + +@app.route('/register_info') +def get_register_info(): + name = request.args.get('name') + bank = request.args.get('bank') + + reg_info = 0 + value = 0 + try: + reg_info = pcilib.get_register_info(str(name), str(bank)) + value = pcilib.read_register(str(name), str(bank)) + except Exception as e: + return str(e) + return render_template('register_info.html', + register=reg_info, + value=value) + + +@app.route("/registers_list") +def get_registers_list(): + reg_list = 0 + try: + reg_list = pcilib.get_registers_list() + except Exception as e: + return str(e) + + return render_template('registers_list.html', + registers=reg_list, + ) + +@app.route("/property_info") +def get_property_list(): + branch = request.args.get('branch') + if not branch is None: + branch = str(branch) + + prop_info = 0 + try: + prop_info = pcilib.get_property_list(branch) + except Exception as e: + return str(e) + + value = -1 + if (len(prop_info) == 1) and not ('childs' in (prop_info[0])['flags']): + try: + branch = (prop_info[0])['path'] + value = pcilib.get_property(branch) + except Exception as e: + return str(e) + + return render_template('property_info.html', + value = value, + branch = branch, + properties = prop_info, + json = json + ) + +@app.route("/") +def greet(): + return render_template('base.html', + device = device, + model = model) + +if __name__ == "__main__": + pcilib = pcipywrap.Pcipywrap(device, model) + pcipywrap.__redirect_logs_to_exeption() + app.debug = True + app.run() diff --git a/pywrap/pcipywrap.c b/pywrap/pcipywrap.c index 11e3ce7..df5f194 100644 --- a/pywrap/pcipywrap.c +++ b/pywrap/pcipywrap.c @@ -303,7 +303,7 @@ PyObject * pcilib_convert_register_info_to_pyobject(pcilib_t* ctx, pcilib_regist if(listItem.values[j].description) pcilib_pydict_set_item(valuesItem, - PyString_FromString("name"), + PyString_FromString("description"), PyString_FromString(listItem.values[j].description)); pcilib_pylist_append(values, valuesItem); diff --git a/pywrap/templates/base.html b/pywrap/templates/base.html new file mode 100644 index 0000000..e62dbdf --- /dev/null +++ b/pywrap/templates/base.html @@ -0,0 +1,15 @@ + +{% block title %}Device {{ device }}{% endblock %} +{% block info %} +

Device {{ device }} model={{ model }} control page

+{% endblock %} + +{% block content %} +{% endblock %} + + + diff --git a/pywrap/templates/property_info.html b/pywrap/templates/property_info.html new file mode 100644 index 0000000..912d3d5 --- /dev/null +++ b/pywrap/templates/property_info.html @@ -0,0 +1,91 @@ +{% extends "base.html" %} +{% block title %}Property list{% endblock %} +{% block info %} +

List of properties in branch {{ branch }}

+{% endblock %} + +{% block content %} + + + + + + + + + {% for property in properties %} + + {% if ('childs' in property.flags) or (properties|length != 1) %} + + {% if 'description' in property %} + + + {% else %} + + {% endif %} + {% else %} + + + {% endif %} + + {% endfor %} +
NameDescription
"{{ property.name }}"{{ property.description }}{{ property.name }}" + + {% if 'description' in property %} + + + + + {% endif %} + + + + + {% if 'W' in property.mode %} + + + + + {% endif %} + + + + + + + + + + + + + + + + +
Description {{ property.description }}
Current value {{ value }}
Set value + + +
Mode +
    + {% for m in property.mode %} +
  • {{ m }}
  • + {% endfor %} +
+
Type {{ property.type }}
Unit {{ property.unit }}
Path {{ property.path }}
+
+{% endblock %} diff --git a/pywrap/templates/register_info.html b/pywrap/templates/register_info.html new file mode 100644 index 0000000..a7f11dc --- /dev/null +++ b/pywrap/templates/register_info.html @@ -0,0 +1,106 @@ +{% extends "base.html" %} +{% block title %}Register info{% endblock %} +{% block info %} +

Register '{{ register.name }}' info

+{% endblock %} + +{% block content %} + + + + {% if 'description' in register %} + + + + + {% endif %} + + + + + {% if 'W' in register.mode %} + + + + + {% endif %} + + + + + + + + + + + + + {% if 'range' in register %} + + + + + {% endif %} + {% if 'values' in register %} + {% for v in register['values'] %} + + {% if 'name' in v %} + + {% endif %} + + + {% endfor %} + {% endif %} +
Description {{ register.description }}
Current value {{ value }}
Set value + + +
Bank{{ register.bank }}
Default value{{ register.defvalue }}
Mode +
    + {% for m in register.mode %} +
  • {{ m }}
  • + {% endfor %} +
+
+ Range + + + + + + + + + + +
min {{ register.range.min }}
max {{ register.range.max }}
+
{{v.name}} + + {% if 'description' in v %} + + + + + {% endif %} + + + + + + + + + + + + +
description {{ v.description }}
min {{ v.min }}
max {{ v.max }}
value {{ v.value }}
+
+{% endblock %} diff --git a/pywrap/templates/registers_list.html b/pywrap/templates/registers_list.html new file mode 100644 index 0000000..199475b --- /dev/null +++ b/pywrap/templates/registers_list.html @@ -0,0 +1,26 @@ +{% extends "base.html" %} +{% block title %}Registers list{% endblock %} +{% block info %} +

List of aviable registers

+{% endblock %} + +{% block content %} + + + + + +{% for register in registers %} + + + {% if 'description' in register %} + + {% else %} + + {% endif %} + +{% endfor %} +
NameDescription
{{ register.name }}{{ register.description }}
+{% endblock %} + + -- cgit v1.2.3