diff options
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | pywrap/html_server.py | 105 | ||||
-rw-r--r-- | pywrap/pcipywrap.c | 2 | ||||
-rw-r--r-- | pywrap/templates/base.html | 15 | ||||
-rw-r--r-- | pywrap/templates/property_info.html | 91 | ||||
-rw-r--r-- | pywrap/templates/register_info.html | 106 | ||||
-rw-r--r-- | pywrap/templates/registers_list.html | 26 |
7 files changed, 346 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bfff47..3a9e0eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,8 @@ set_target_properties(pcilib PROPERTIES ) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/xml DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/pywrap/templates DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/pywrap) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pywrap/html_server.py ${CMAKE_CURRENT_BINARY_DIR}/pywrap/html_server.py) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/misc/pcitool.pc.in ${CMAKE_CURRENT_BINARY_DIR}/misc/pcitool.pc) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/pcilib/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/pcilib/config.h) 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 @@ +<!doctype html> +<title>{% block title %}Device {{ device }}{% endblock %}</title> +{% block info %} + <h1>Device {{ device }} model={{ model }} control page </h1> +{% endblock %} + +{% block content %} +{% endblock %} + +<ul> + <li><a href="{{ url_for('get_registers_list') }}">Registers list</li> + <li><a href="{{ url_for('get_property_list') }}">Property info</li> + <li><a href="{{ url_for('greet') }}">Main page</li> +</ul> + 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 %} +<h1>List of properties in branch {{ branch }}</h1> +{% endblock %} + +{% block content %} + + <script> + function set_property() + { + var value = document.getElementById("set_val_box").value; + window.location.href = "{{ url_for('set_property') }}?prop={{ branch }}&"+ + 'val='+value; + }; + </script> + +<table border="1" style="width:100%"> + <tr> + <th>Name</th> + <th>Description</th> + </tr> + {% for property in properties %} + <tr> + {% if ('childs' in property.flags) or (properties|length != 1) %} + <td><a href="{{ url_for('get_property_list', branch = property.path) }}">"{{ property.name }}"</td> + {% if 'description' in property %} + <script> + function set_property() + { + var value = document.getElementById("set_val_box").value; + window.location.href = "{{ url_for('set_property') }}?prop={{ branch }}&"+ + 'val='+value; + }; + </script> + <td>{{ property.description }}</td> + {% else %} + <td></td> + {% endif %} + {% else %} + <td>{{ property.name }}"</td> + <td> + <table border="1" style="width:100%"> + {% if 'description' in property %} + <tr> + <th> Description </th> + <td> {{ property.description }} </td> + </tr> + {% endif %} + <tr> + <th> Current value </th> + <td> {{ value }} </td> + </tr> + {% if 'W' in property.mode %} + <tr> + <th> Set value</th> + <td> + <input type="text" name="set_val_box" id="set_val_box" value="" /> + <input type="button" value="set" onclick="set_property()"> + </td> + </tr> + {% endif %} + <tr> + <th>Mode</th> + <td> + <ul> + {% for m in property.mode %} + <li>{{ m }}</li> + {% endfor %} + </ul> + </td> + </tr> + <tr> + <th>Type</th> + <td> {{ property.type }} </td> + </tr> + <tr> + <th>Unit</th> + <td> {{ property.unit }} </td> + </tr> + <tr> + <th>Path</th> + <td> {{ property.path }} </td> + </tr> + </table> + </td> + {% endif %} + </tr> + {% endfor %} + </table> +{% 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 %} +<h1>Register '{{ register.name }}' info</h1> +{% endblock %} + +{% block content %} + <script> + function write_register() + { + var value = document.getElementById("set_val_box").value; + window.location.href = "{{ url_for('write_register') }}?name={{ register.name }}&"+ + 'bank={{ register.bank }}&val='+value; + }; + </script> + + <table border="1" style="width:100%"> + {% if 'description' in register %} + <tr> + <th> Description </th> + <td> {{ register.description }} </td> + </tr> + {% endif %} + <tr> + <th> Current value </th> + <td> {{ value }} </td> + </tr> + {% if 'W' in register.mode %} + <tr> + <th> Set value</th> + <td> + <input type="text" name="set_val_box" id="set_val_box" value="" /> + <input type="button" value="set" onclick="write_register()"> + </td> + </tr> + {% endif %} + <tr> + <th>Bank</th> + <td>{{ register.bank }}</td> + </tr> + <tr> + <th>Default value</th> + <td>{{ register.defvalue }}</td> + </tr> + <tr> + <th>Mode</th> + <td> + <ul> + {% for m in register.mode %} + <li>{{ m }}</li> + {% endfor %} + </ul> + </td> + </tr> + {% if 'range' in register %} + <tr> + <th> + Range + </th> + <td> + <table> + <tr> + <th> min </th> + <td> {{ register.range.min }} </td> + </tr> + <tr> + <th> max </th> + <td> {{ register.range.max }} </td> + </tr> + </table> + </td> + </tr> + {% endif %} + {% if 'values' in register %} + {% for v in register['values'] %} + <tr> + {% if 'name' in v %} + <th> {{v.name}} </th> + {% endif %} + <td> + <table> + {% if 'description' in v %} + <tr> + <th> description </th> + <td> {{ v.description }} </td> + </tr> + {% endif %} + <tr> + <th> min </th> + <td> {{ v.min }} </td> + </tr> + <tr> + <th> max </th> + <td> {{ v.max }} </td> + </tr> + <tr> + <th> value </th> + <td> {{ v.value }} </td> + </tr> + </table> + </td> + </tr> + {% endfor %} + {% endif %} + </table> +{% 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 %} +<h1>List of aviable registers</h1> +{% endblock %} + +{% block content %} +<table border="1" style="width:100%"> + <tr> + <th>Name</th> + <th>Description</th> + </tr> +{% for register in registers %} + <tr> + <td><a href="{{ url_for('get_register_info', bank=register.bank, name=register.name) }}">{{ register.name }}</td> + {% if 'description' in register %} + <td>{{ register.description }}</td> + {% else %} + <td></td> + {% endif %} + </tr> +{% endfor %} +</table> +{% endblock %} + + |