From e84f532b9e97dc2ad53ad96cc9543a178d6f20fd Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 25 Sep 2018 12:41:41 +0200 Subject: gui: add input to RC page, improve predistortion page --- gui/api/__init__.py | 7 +++++-- gui/dpd/Capture.py | 4 ++-- gui/dpd/__init__.py | 11 ++--------- gui/static/js/odr-predistortion.js | 8 ++++++-- gui/static/js/odr-rcvalues.js | 24 +++++++++++++++++++++--- gui/templates/predistortion.html | 6 ++++-- 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/gui/api/__init__.py b/gui/api/__init__.py index 74f5feb..cef81c6 100755 --- a/gui/api/__init__.py +++ b/gui/api/__init__.py @@ -33,7 +33,7 @@ import datetime def send_ok(data): return json.dumps({'status' : 'ok', 'data': data}).encode() -def send_error(data, reason=""): +def send_error(reason=""): return json.dumps({'status' : 'error', 'reason': reason}).encode() class API: @@ -72,7 +72,10 @@ class API: def trigger_capture(self, **kwargs): if cherrypy.request.method == 'POST': cherrypy.response.headers["Content-Type"] = "application/json" - return send_ok(self.dpd.capture_samples()) + try: + return send_ok(self.dpd.capture_samples()) + except ValueError as e: + return send_error(str(e)) else: cherrypy.response.headers["Content-Type"] = "application/json" cherrypy.response.status = 400 diff --git a/gui/dpd/Capture.py b/gui/dpd/Capture.py index 31fa78d..de428cb 100644 --- a/gui/dpd/Capture.py +++ b/gui/dpd/Capture.py @@ -163,9 +163,9 @@ class Capture: tx_median = np.median(np.abs(txframe)) if self.median_max < tx_median: - raise ValueError("Median {} too high, decrease digital_gain!".format(tx_median)) + raise ValueError("TX median {} too high, decrease digital_gain!".format(tx_median)) elif tx_median < self.median_min: - raise ValueError("Median {} too low, increase digital_gain!".format(tx_median)) + raise ValueError("TX median {} too low, increase digital_gain!".format(tx_median)) else: rx_median = np.median(np.abs(rxframe)) rxframe = rxframe / rx_median * tx_median diff --git a/gui/dpd/__init__.py b/gui/dpd/__init__.py index 16017ee..8dd0807 100644 --- a/gui/dpd/__init__.py +++ b/gui/dpd/__init__.py @@ -24,13 +24,6 @@ from . import Capture -class DPDError: - def __init__(self, reason): - self.reason = reason - - def __str__(self): - return "DPD Error: {}".format(self.reason) - class DPD: def __init__(self, samplerate=8192000): self.samplerate = samplerate @@ -56,7 +49,7 @@ class DPD: def capture_samples(self): """Captures samples and store them in the accumulated samples, - returns a string with some info""" + returns a dict with some info""" try: txframe_aligned, tx_ts, tx_median, rxframe_aligned, rx_ts, rx_median = self.capture.get_samples() self.last_capture_info['length'] = len(txframe_aligned) @@ -66,7 +59,7 @@ class DPD: self.last_capture_info['rx_ts'] = rx_ts return self.last_capture_info except ValueError as e: - raise DPDError("Capture failed: {}".format(e)) + raise ValueError("Capture failed: {}".format(e)) # tx, rx, phase_diff, n_per_bin = extStat.extract(txframe_aligned, rxframe_aligned) # off = SA.calc_offset(txframe_aligned) diff --git a/gui/static/js/odr-predistortion.js b/gui/static/js/odr-predistortion.js index c9b5c17..6b09202 100644 --- a/gui/static/js/odr-predistortion.js +++ b/gui/static/js/odr-predistortion.js @@ -21,13 +21,17 @@ $(function(){ $('#capturebutton').click(function() { doApiRequestPOST("/api/trigger_capture", {}, function(data) { - $('#capturelength').val(data.length); + console.log("trigger_capture succeeded: " + JSON.stringify(data)); + $('#capturelength').text(data.length); + $('#tx_median').text(data.tx_median); + $('#rx_median').text(data.rx_median); }); }); $('#dpdstatusbutton').click(function() { doApiRequestGET("/api/dpd_status", function(data) { - $('#dpdstatus').val(data); + console.log("dpd_status succeeded: " + JSON.stringify(data)); + $('#histogram').text(data.histogram); }); }); }); diff --git a/gui/static/js/odr-rcvalues.js b/gui/static/js/odr-rcvalues.js index f40279d..81d895c 100644 --- a/gui/static/js/odr-rcvalues.js +++ b/gui/static/js/odr-rcvalues.js @@ -18,16 +18,34 @@ // You should have received a copy of the GNU General Public License // along with ODR-DabMod. If not, see . -function requestStatus(callback) { +function buttonSetRc(key, controllable, param) { + var value = $("#" + key).val(); + + setRc(controllable, param, value, function(data) { + requestStatus(); + }); +} + +function requestStatus() { $('#rctable > tbody').empty(); doApiRequestGET("/api/rc_parameters", function(data) { $.each( data, function( key1, controllable ) { $.each( controllable, function( key2, param ) { + var key = key1 + "_" + key2; + var valueentry = '' + + ''; + $('#rctable > tbody:last').append( - ''+key1+'.'+key2+''+ - ''+param['value']+''+ + ''+key+''+ + ''+valueentry+''+ ''+param['help']+''); + + $('#button'+key).click(function() { + buttonSetRc("input"+key, key1, key2); + }); }); }); }); diff --git a/gui/templates/predistortion.html b/gui/templates/predistortion.html index 0acaf81..8d5f1a5 100644 --- a/gui/templates/predistortion.html +++ b/gui/templates/predistortion.html @@ -32,8 +32,10 @@ along with ODR-DabMod. If not, see .

Capture

Number of samples captured: None
+
TX median: N/A
+
RX median: N/A
-
On pressing this button, +
On pressing this button, the DPDCE will trigger a capture and a quick data analysis, without updating any DPD models.
@@ -41,7 +43,7 @@ along with ODR-DabMod. If not, see .

Status

-
+
Histogram: N/A
-- cgit v1.2.3