diff options
Diffstat (limited to 'cir_measure.py')
| -rwxr-xr-x | cir_measure.py | 52 |
1 files changed, 33 insertions, 19 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: |
