aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2016-07-25 19:49:09 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2016-07-25 19:49:09 +0200
commit80b4eacd1d51a96e120192122774d1e83da2da5e (patch)
tree461db722889a2f0a32fffa0e2392d18c37b175aa
parentd4b41da4ccc7c9f55a8cdc1fa7b3373d067cd986 (diff)
downloadodr-dab-cir-80b4eacd1d51a96e120192122774d1e83da2da5e.tar.gz
odr-dab-cir-80b4eacd1d51a96e120192122774d1e83da2da5e.tar.bz2
odr-dab-cir-80b4eacd1d51a96e120192122774d1e83da2da5e.zip
Fix webserver process and image update
-rwxr-xr-xcir_measure.py52
-rwxr-xr-xcorrelate_with_ref.py27
-rw-r--r--static/style.css2
3 files changed, 55 insertions, 26 deletions
diff --git a/cir_measure.py b/cir_measure.py
index 5e69b7c..03d742c 100755
--- a/cir_measure.py
+++ b/cir_measure.py
@@ -25,15 +25,20 @@ import argparse
# pipeline.
class RTLSDR_CIR_Runner(mp.Process):
- def __init__(self, rtl_sdr_cmdline, iq_format, iq_file, fig_file):
- """Initialise a new runner, which runs rtl_sdr_cmdline
- that has to save to iq_file, and run the CIR analysis
- that will save to fig_file"""
+ def __init__(self, options, iq_file, fig_file):
+ """Initialise a new runner, which runs rtl_sdr
+ that will save to iq_file, and run the CIR analysis
+ that will save to fig_file.
+
+ options must contain freq, rate and samps fields"""
mp.Process.__init__(self)
self.events = mp.Queue()
- self.rtl_sdr_cmdline = rtl_sdr_cmdline
- self.iq_format = iq_format
+
+ self.freq = options.freq
+ self.rate = options.rate
+ self.samps = options.samps
+
self.iq_file = iq_file
self.fig_file = fig_file
@@ -43,7 +48,10 @@ class RTLSDR_CIR_Runner(mp.Process):
def run(self):
while True:
time.sleep(1)
- self.do_one_cir_run()
+ try:
+ self.do_one_cir_run()
+ except Exception as e:
+ print("Exception occurred: {}".format(e))
try:
ev = self.events.get_nowait()
@@ -53,17 +61,30 @@ class RTLSDR_CIR_Runner(mp.Process):
pass
def do_one_cir_run(self):
- rtlsdr = subprocess.Popen(self.rtl_sdr_cmdline, shell=True)
- rtlsdr.wait()
+ # Build the rtl_sdr command line from the settings in config
+ rtl_sdr_cmdline = shlex.split("rtl_sdr -f {} -s {} -g 20 -S -".format(self.freq, self.rate))
+ dd_cmdline = shlex.split("dd of={} bs=2 count={}".format(self.iq_file, self.samps))
+
+ # To avoid calling the shell, we do the pipe between rtlsdr and dd using Popen
+ rtlsdr_proc = subprocess.Popen(rtl_sdr_cmdline, stdout=subprocess.PIPE)
+ dd_proc = subprocess.Popen(dd_cmdline, stdin=rtlsdr_proc.stdout)
+
+ # close our connection to the pipe so that rtlsdr gets the SIGPIPE
+ rtlsdr_proc.stdout.close()
+
+ dd_proc.communicate()
+ dd_proc.wait()
+ rtlsdr_proc.wait()
# The RTLSDR outputs u8 format
- cir_corr = correlate_with_ref.CIR_Correlate(self.iq_file, self.iq_format)
+ print("Starting correlation")
+ cir_corr = correlate_with_ref.CIR_Correlate(self.iq_file, "u8")
cir_corr.plot(self.fig_file)
@route('/')
def index():
return template('index',
- rtl_sdr_cmdline = rtl_sdr_cmdline,
+ rtl_sdr_cmdline = "rtl_sdr",
fig_file = FIG_FILE)
@route('/static/<filename:path>')
@@ -76,8 +97,6 @@ if __name__ == '__main__':
# Options for the webserver
parser.add_argument('--host', default='127.0.0.1', help='socket host (default: 127.0.0.1)',required=False)
parser.add_argument('--port', default='8000', help='socket port (default: 8000)',required=False)
- parser.add_argument('--mhost', default='127.0.0.1', help='mux host (default: 127.0.0.1)',required=False)
- parser.add_argument('--mport', default='12720', help='mux port (default: 12720)',required=False)
# Options for RTLSDR reception
parser.add_argument('--freq', help='Receive frequency', required=True)
@@ -92,16 +111,11 @@ if __name__ == '__main__':
# File to save the recorded IQ file to
IQ_FILE = "static/rtlsdr.iq"
- IQ_FORMAT = "fc64"
# The figures are saved to a file
FIG_FILE = "static/rtlsdr.svg"
- # Build the rtl_sdr command line from the settings in config
- rtl_sdr_cmdline = shlex.split("rtl_sdr -f {} -s {} -g 20 -S - | dd of={} bs=2 count={}".format(
- cli_args.freq, cli_args.rate, IQ_FILE, cli_args.samps))
-
- rtlsdr_cir = RTLSDR_CIR_Runner(rtl_sdr_cmdline, IQ_FORMAT, IQ_FILE, FIG_FILE)
+ rtlsdr_cir = RTLSDR_CIR_Runner(cli_args, IQ_FILE, FIG_FILE)
rtlsdr_cir.start()
try:
diff --git a/correlate_with_ref.py b/correlate_with_ref.py
index 44e5a16..31e9710 100755
--- a/correlate_with_ref.py
+++ b/correlate_with_ref.py
@@ -11,6 +11,15 @@
# Licence: The MIT License, see LICENCE file
import numpy as np
+import matplotlib
+
+# When running on a machine that has no X server running, the normal
+# matplotlib backend won't work. In case we are running as a module by cir_measure,
+# switch to the Agg backend
+# See http://matplotlib.org/faq/howto_faq.html#matplotlib-in-a-web-application-server
+if __name__ != "__main__":
+ matplotlib.use("Agg")
+
import matplotlib.pyplot as pp
import sys
@@ -50,6 +59,7 @@ class CIR_Correlate:
def calc_one_cir_(self, start_ix):
"""Calculate correlation with phase reference for one start index"""
+ print("Correlation at {}".format(start_ix))
channel = self.channel_out
# As we do not want to correlate of the whole recording that might be
@@ -101,19 +111,24 @@ class CIR_Correlate:
def plot(self, plot_file):
num_correlations = int(len(self.channel_out) / T_TF)
+ self.null_symbol_ixs = []
+
cirs = np.array([
self.calc_one_cir_(i * T_TF)
for i in range(num_correlations) ])
- pp.subplot(211)
- pp.plot(cirs.sum(axis=0))
- pp.subplot(212)
- pp.imshow(cirs, aspect='auto')
+ fig = pp.figure()
+ ax1 = fig.add_subplot(211)
+ ax1.plot(cirs.sum(axis=0))
+ ax2 = fig.add_subplot(212)
+ ax2.imshow(cirs, aspect='auto')
if plot_file:
- pp.savefig(plot_file)
+ print("Save to file {}".format(plot_file))
+ fig.savefig(plot_file)
else:
- pp.show()
+ print("Plotting to screen")
+ fig.show()
if __name__ == "__main__":
diff --git a/static/style.css b/static/style.css
index 05228bc..c7aebf0 100644
--- a/static/style.css
+++ b/static/style.css
@@ -9,7 +9,7 @@ p {
}
#info{
- width: 600px;
+ width: 900px;
border: 1px solid #999;
padding: 0 10px;
}