aboutsummaryrefslogtreecommitdiffstats
path: root/python/gui
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2018-12-05 11:19:07 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2018-12-05 11:19:07 +0100
commit31b65e41043900c0cadd80961f4b22cdfc171e7d (patch)
treecdeceac026a2d1e0fe8c00af5d0f867767d17ef4 /python/gui
parent5cf52c74e9eb6bf8a82af4509ff3eb5106f928f9 (diff)
downloaddabmod-31b65e41043900c0cadd80961f4b22cdfc171e7d.tar.gz
dabmod-31b65e41043900c0cadd80961f4b22cdfc171e7d.tar.bz2
dabmod-31b65e41043900c0cadd80961f4b22cdfc171e7d.zip
Get GUI to communicate with DPDCE
Diffstat (limited to 'python/gui')
-rwxr-xr-xpython/gui/api.py56
-rw-r--r--python/gui/static/js/odr-predistortion.js17
-rw-r--r--python/gui/static/js/odr.js16
-rw-r--r--python/gui/templates/predistortion.html10
4 files changed, 80 insertions, 19 deletions
diff --git a/python/gui/api.py b/python/gui/api.py
index ae54e8b..0d24bac 100755
--- a/python/gui/api.py
+++ b/python/gui/api.py
@@ -46,8 +46,10 @@ def send_error(reason=""):
return {'status' : 'error'}
class API:
- def __init__(self, mod_rc):
+ def __init__(self, mod_rc, dpd_port):
self.mod_rc = mod_rc
+ self.dpd_port = dpd_port
+ self.dpd_rpc = yamlrpc.Socket(bind_port=0)
@cherrypy.expose
def index(self):
@@ -71,38 +73,66 @@ class API:
try:
self.mod_rc.set_param_value(params['controllable'], params['param'], params['value'])
except IOError as e:
+ cherrypy.response.status = 503
return send_error(str(e))
except ValueError as e:
- cherrypy.response.status = 400
+ cherrypy.response.status = 503
return send_error(str(e))
return send_ok()
else:
cherrypy.response.status = 400
return send_error("POST only")
+ def _wrap_dpd(self, method, data=None):
+ try:
+ reply = self.dpd_rpc.call_rpc_method(self.dpd_port, method, data)
+ return send_ok(reply)
+ except ValueError as e:
+ cherrypy.response.status = 503
+ return send_error("YAML-RPC call error: {}".format(e))
+ except TimeoutError as e:
+ cherrypy.response.status = 503
+ return send_error("YAML-RPC timeout: {}".format(e))
+ cherrypy.response.status = 500
+ return send_error("YAML-RPC unknown error")
+
@cherrypy.expose
@cherrypy.tools.json_out()
- def trigger_capture(self, **kwargs):
+ def dpd_trigger_run(self, **kwargs):
if cherrypy.request.method == 'POST':
- # TODO dpd send capture
- return send_ok()
+ return self._wrap_dpd("trigger_run")
else:
cherrypy.response.status = 400
return send_error("POST only")
@cherrypy.expose
@cherrypy.tools.json_out()
- def dpd_status(self, **kwargs):
- # TODO Request DPD state
- return send_error("DPD state unknown")
+ def dpd_reset(self, **kwargs):
+ if cherrypy.request.method == 'POST':
+ return self._wrap_dpd("reset")
+ else:
+ cherrypy.response.status = 400
+ return send_error("POST only")
@cherrypy.expose
@cherrypy.tools.json_out()
- def calibrate(self, **kwargs):
+ def dpd_settings(self, setting: str, value: str, **kwargs):
if cherrypy.request.method == 'POST':
- # TODO dpd send capture
- return send_ok()
+ data = {'setting': setting, 'value': value}
+ return self._wrap_dpd("set_setting", data)
+ else:
+ return self._wrap_dpd("get_settings")
+
+ @cherrypy.expose
+ @cherrypy.tools.json_out()
+ def dpd_results(self, **kwargs):
+ return self._wrap_dpd("get_results")
+
+ @cherrypy.expose
+ @cherrypy.tools.json_out()
+ def dpd_calibrate(self, **kwargs):
+ if cherrypy.request.method == 'POST':
+ return self._wrap_dpd("calibrate")
else:
- # Fetch dpd status
- return send_error("DPD calibration result unknown")
+ return self._wrap_dpd("get_calibration_result")
diff --git a/python/gui/static/js/odr-predistortion.js b/python/gui/static/js/odr-predistortion.js
index 7a93b2b..b2f1d22 100644
--- a/python/gui/static/js/odr-predistortion.js
+++ b/python/gui/static/js/odr-predistortion.js
@@ -18,6 +18,21 @@
// You should have received a copy of the GNU General Public License
// along with ODR-DabMod. If not, see <http://www.gnu.org/licenses/>.
+function resultrefresh() {
+ var jqxhr = doApiRequestGET("/api/dpd_results", function(data) {
+ $('#dpdresults').text(data['summary']);
+ });
+
+ jqxhr.always(function() {
+ setTimeout(resultrefresh, 2000);
+ });
+}
+
+$(function(){
+ setTimeout(resultrefresh, 2000);
+});
+
+/*
function calibraterefresh() {
doApiRequestGET("/api/calibrate", function(data) {
var text = "Captured TX signal and feedback." +
@@ -92,6 +107,8 @@ $(function(){
});
});
+*/
+
// ToolTip init
$(function(){
diff --git a/python/gui/static/js/odr.js b/python/gui/static/js/odr.js
index ecb02c5..0bf7729 100644
--- a/python/gui/static/js/odr.js
+++ b/python/gui/static/js/odr.js
@@ -20,7 +20,7 @@
function doApiRequestGET(uri, callback) {
- $.ajax({
+ return $.ajax({
type: "GET",
url: uri,
contentType: 'application/json',
@@ -32,6 +32,8 @@ function doApiRequestGET(uri, callback) {
errorWindow.document.write(data.responseText);
}
else {
+ console.log(data.responseText);
+
$.gritter.add({ title: 'API',
text: "AJAX failed: " + data.statusText,
image: '/fonts/warning.png',
@@ -56,7 +58,7 @@ function doApiRequestGET(uri, callback) {
}
function doApiRequestPOST(uri, data, callback) {
- $.ajax({
+ return $.ajax({
type: "POST",
url: uri,
contentType: 'application/json',
@@ -65,10 +67,14 @@ function doApiRequestPOST(uri, data, callback) {
error: function(data) {
if (data.status == 500) {
- var errorWindow = window.open("", "_self");
+ var windowObjectReference;
+ var winFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";
+ var errorWindow = window.open("", "Error 500", winFeatures);
errorWindow.document.write(data.responseText);
}
else {
+ console.log(data.responseText);
+
$.gritter.add({
title: 'API',
text: "AJAX failed: " + data.statusText,
@@ -100,10 +106,10 @@ function setRc(controllable, param, value, callback) {
param: param,
value: value
};
- doApiRequestPOST("/api/parameter/", data, callback);
+ return doApiRequestPOST("/api/parameter/", data, callback);
}
function getRc(callback) {
- doApiRequestGET("/api/rc_parameters", callback);
+ return doApiRequestGET("/api/rc_parameters", callback);
}
diff --git a/python/gui/templates/predistortion.html b/python/gui/templates/predistortion.html
index 2ebf7ea..ac68537 100644
--- a/python/gui/templates/predistortion.html
+++ b/python/gui/templates/predistortion.html
@@ -29,6 +29,15 @@ along with ODR-DabMod. If not, see <http://www.gnu.org/licenses/>.
<div class="container-fluid">
<div class="panel-group">
<div class="panel panel-default">
+ <div class="panel-heading">Status</div>
+ <div class="panel-body">
+ <div>Current DPDCE status:
+ <div class="well well-sm" id="dpdresults">N/A<div>
+ </div>
+ </div>
+ </div>
+ <!--
+ <div class="panel panel-default">
<div class="panel-heading">Calibration</div>
<div class="panel-body">
<div>Calibration needs to be done once before the PA model
@@ -55,7 +64,6 @@ along with ODR-DabMod. If not, see <http://www.gnu.org/licenses/>.
</div>
</div>
- <!--
<div class="panel panel-default">
<div class="panel-heading">Capture</div>
<div class="panel-body">