aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/dpd/Measure.py16
-rw-r--r--python/dpd/RX_Agc.py2
-rwxr-xr-xpython/dpdce.py22
-rw-r--r--python/gui/static/js/odr-predistortion.js6
-rw-r--r--python/gui/templates/predistortion.html6
5 files changed, 37 insertions, 15 deletions
diff --git a/python/dpd/Measure.py b/python/dpd/Measure.py
index 489c4c0..eb3c199 100644
--- a/python/dpd/Measure.py
+++ b/python/dpd/Measure.py
@@ -15,7 +15,7 @@ import logging
class Measure:
"""Collect Measurement from DabMod"""
- def __init__(self, config, samplerate, port, num_samples_to_request):
+ def __init__(self, config, samplerate : int, port : int, num_samples_to_request : int):
logging.info("Instantiate Measure object")
self.c = config
self.samplerate = samplerate
@@ -23,7 +23,7 @@ class Measure:
self.port = port
self.num_samples_to_request = num_samples_to_request
- def _recv_exact(self, sock, num_bytes):
+ def _recv_exact(self, sock : socket.socket, num_bytes : int) -> bytes:
"""Receive an exact number of bytes from a socket. This is
a wrapper around sock.recv() that can return less than the number
of requested bytes.
@@ -41,7 +41,7 @@ class Measure:
bufs.append(b)
return b''.join(bufs)
- def receive_tcp(self):
+ def receive_tcp(self, num_samples_to_request : int):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(4)
s.connect(('localhost', self.port))
@@ -49,8 +49,8 @@ class Measure:
logging.debug("Send version")
s.sendall(b"\x01")
- logging.debug("Send request for {} samples".format(self.num_samples_to_request))
- s.sendall(struct.pack("=I", self.num_samples_to_request))
+ logging.debug("Send request for {} samples".format(num_samples_to_request))
+ s.sendall(struct.pack("=I", num_samples_to_request))
logging.debug("Wait for TX metadata")
num_samps, tx_second, tx_pps = struct.unpack("=III", self._recv_exact(s, 12))
@@ -91,13 +91,14 @@ class Measure:
return txframe, tx_ts, rxframe, rx_ts
- def get_samples(self):
+ def get_samples(self, short=False):
"""Connect to ODR-DabMod, retrieve TX and RX samples, load
into numpy arrays, and return a tuple
(txframe_aligned, tx_ts, rxframe_aligned, rx_ts, rx_median, tx_median)
"""
- txframe, tx_ts, rxframe, rx_ts = self.receive_tcp()
+ n_samps = int(self.num_samples_to_request / 4) if short else self.num_samples_to_request
+ txframe, tx_ts, rxframe, rx_ts = self.receive_tcp(n_samps)
# Normalize received signal with sent signal
rx_median = np.median(np.abs(rxframe))
@@ -116,6 +117,7 @@ class Measure:
# The MIT License (MIT)
#
+# Copyright (c) 2018 Matthias P. Braendli
# Copyright (c) 2017 Andreas Steger
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
diff --git a/python/dpd/RX_Agc.py b/python/dpd/RX_Agc.py
index 48ef7f3..bca9643 100644
--- a/python/dpd/RX_Agc.py
+++ b/python/dpd/RX_Agc.py
@@ -48,7 +48,7 @@ class Agc:
self.adapt.set_rxgain(self.rxgain)
# Measure
- txframe_aligned, tx_ts, rxframe_aligned, rx_ts, rx_median, tx_median = self.measure.get_samples()
+ txframe_aligned, tx_ts, rxframe_aligned, rx_ts, rx_median, tx_median = self.measure.get_samples(short=True)
# Estimate Maximum
rx_peak = self.peak_to_median * rx_median
diff --git a/python/dpdce.py b/python/dpdce.py
index 838d265..03bc907 100755
--- a/python/dpdce.py
+++ b/python/dpdce.py
@@ -138,6 +138,7 @@ results = {
'tx_median': 0,
'rx_median': 0,
'state': 'Idle',
+ 'stateprogress': 0, # in percent
'summary': ['DPD has not been calibrated yet'],
}
lock = Lock()
@@ -155,13 +156,20 @@ def engine_worker():
break
elif cmd == "calibrate":
with lock:
- results['state'] = 'rx gain calibration'
+ results['state'] = 'RX Gain Calibration'
+ results['stateprogress'] = 0
- agc_success, agc_summary = agc.run()
- summary = ["First calibration run:"] + agc_summary.split("\n")
- if agc_success:
+ summary = []
+ N_ITER = 5
+ for i in range(N_ITER):
agc_success, agc_summary = agc.run()
- summary += ["Second calibration run: "] + agc_summary.split("\n")
+ summary = ["calibration run {}:".format(i)] + agc_summary.split("\n")
+
+ with lock:
+ results['stateprogress'] = int((i + 1) * 100/N_ITER)
+
+ if not agc_success:
+ break
txframe_aligned, tx_ts, rxframe_aligned, rx_ts, rx_median, tx_median = meas.get_samples()
@@ -171,11 +179,13 @@ def engine_worker():
results['tx_median'] = float(tx_median)
results['rx_median'] = float(rx_median)
results['state'] = 'Idle'
+ results['stateprogress'] = 0
results['summary'] = ["Calibration was done:"] + summary
finally:
with lock:
- results['state'] = 'terminated'
+ results['state'] = 'Terminated'
+ results['stateprogress'] = 0
engine = Thread(target=engine_worker)
diff --git a/python/gui/static/js/odr-predistortion.js b/python/gui/static/js/odr-predistortion.js
index 04d2773..739e0ee 100644
--- a/python/gui/static/js/odr-predistortion.js
+++ b/python/gui/static/js/odr-predistortion.js
@@ -29,6 +29,12 @@ function resultrefresh() {
$('#dpdresults').html(summary);
$('#dpdstatus').text(data['state']);
+ var percentage = data['stateprogress'];
+ if (percentage > 100) {
+ percentage = 100;
+ }
+ $('#dpdprogress').css('width', percentage + '%');
+ $('#dpdprogresstext').text(percentage + '%');
});
jqxhr.always(function() {
diff --git a/python/gui/templates/predistortion.html b/python/gui/templates/predistortion.html
index cc5ecb0..f9af2f1 100644
--- a/python/gui/templates/predistortion.html
+++ b/python/gui/templates/predistortion.html
@@ -31,7 +31,11 @@ along with ODR-DabMod. If not, see <http://www.gnu.org/licenses/>.
<div class="panel panel-default">
<div class="panel-heading">Status and calibration</div>
<div class="panel-body">
- <div>Current DPDCE status: <span id="dpdstatus" style="font-weight:bold;">N/A</span>
+ <div>Current DPDCE status:
+ <span id="dpdstatus" style="font-weight:bold;">N/A</span>
+ <div id="dpdprogress" class="progress-bar" role="progressbar" style="width:0%">
+ <span id="dpdprogresstext"></span>
+ </div>
<div class="well well-sm" id="dpdresults">N/A</div>
</div>