From 8d2bc49fb9e0c9a5fbd75aa3cad207608e72bf99 Mon Sep 17 00:00:00 2001 From: Piotr Krysik Date: Tue, 30 Jun 2009 23:03:33 +0200 Subject: moved gsm-receiver into directory - preparation to move to airprobe --- gsm-receiver/src/python/Makefile.am | 24 +++++ gsm-receiver/src/python/capture.sh | 45 +++++++++ gsm-receiver/src/python/cfile | Bin 0 -> 640000 bytes gsm-receiver/src/python/go.sh | 12 +++ gsm-receiver/src/python/gsm_receive.py | 117 +++++++++++++++++++++++ gsm-receiver/src/python/gsm_receive_usrp.py | 141 ++++++++++++++++++++++++++++ gsm-receiver/src/python/test.sh | 16 ++++ 7 files changed, 355 insertions(+) create mode 100644 gsm-receiver/src/python/Makefile.am create mode 100755 gsm-receiver/src/python/capture.sh create mode 100644 gsm-receiver/src/python/cfile create mode 100755 gsm-receiver/src/python/go.sh create mode 100755 gsm-receiver/src/python/gsm_receive.py create mode 100755 gsm-receiver/src/python/gsm_receive_usrp.py create mode 100755 gsm-receiver/src/python/test.sh (limited to 'gsm-receiver/src/python') diff --git a/gsm-receiver/src/python/Makefile.am b/gsm-receiver/src/python/Makefile.am new file mode 100644 index 0000000..9a4befd --- /dev/null +++ b/gsm-receiver/src/python/Makefile.am @@ -0,0 +1,24 @@ +# +# Copyright 2004 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +include $(top_srcdir)/Makefile.common + +EXTRA_DIST = gsm_findfcch.py gsm_findfcch_usrp.py diff --git a/gsm-receiver/src/python/capture.sh b/gsm-receiver/src/python/capture.sh new file mode 100755 index 0000000..ef205d8 --- /dev/null +++ b/gsm-receiver/src/python/capture.sh @@ -0,0 +1,45 @@ +#! /bin/sh + +if [ $1"x" = x ]; then + echo "./capture.sh [duration==10] [decim==112] [gain==52]" + echo "Example: ./capture.sh 940.4M" + exit 1 +fi +FREQ=$1 + +DURATION=$2 +if [ $2"x" = x ]; then + DURATION=10 +fi +DECIM=$3 +if [ $3"x" = x ]; then + DECIM=112 +fi + +GAIN=$4 +if [ $4"x" = x ]; then + GAIN=52 +fi + + +USRP_PROG=usrp_rx_cfile.py +while :; do + which "$USRP_PROG" + if [ $? -eq 0 ]; then + break + fi + USRP_PROG=/usr/share/gnuradio/usrp/usrp_rx_cfile.py + which "$USRP_PROG" + if [ $? -eq 0 ]; then + break + fi + + echo "ERROR: usrp_rx_cfile.py not found. Make sure it's in your PATH!" + exit 1 +done + +FILE="capture_${FREQ}_${DECIM}.cfile" +samples=`expr 64000000 / $DECIM '*' $DURATION` +echo "Capturing for $DURATION seconds to $FILE ($samples samples)" +$USRP_PROG -g $GAIN -d "$DECIM" -f "$FREQ" -N $samples $FILE + diff --git a/gsm-receiver/src/python/cfile b/gsm-receiver/src/python/cfile new file mode 100644 index 0000000..943e35f Binary files /dev/null and b/gsm-receiver/src/python/cfile differ diff --git a/gsm-receiver/src/python/go.sh b/gsm-receiver/src/python/go.sh new file mode 100755 index 0000000..e0d1290 --- /dev/null +++ b/gsm-receiver/src/python/go.sh @@ -0,0 +1,12 @@ +#! /bin/sh + +#echo "go.sh [decim==112]" + +DECIM=$2 +FILE=$1 + +if [ $DECIM"x" = x ]; then + DECIM=112 +fi + +./gsm_receive.py -d "$DECIM" -I "$FILE" | ../../../gsmdecode/src/gsmdecode -i diff --git a/gsm-receiver/src/python/gsm_receive.py b/gsm-receiver/src/python/gsm_receive.py new file mode 100755 index 0000000..4cfb876 --- /dev/null +++ b/gsm-receiver/src/python/gsm_receive.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python + +from gnuradio import gr, gru, blks2 +#, gsm +from gnuradio.eng_option import eng_option +from optparse import OptionParser +from os import sys + +for extdir in ['../../debug/src/lib','../../debug/src/lib/.libs','../lib','../lib/.libs','../..debug/src/lib/decoder/openbts/SIP']: + if extdir not in sys.path: + sys.path.append(extdir) +import gsm + +class tuner(gr.feval_dd): + def __init__(self, top_block): + gr.feval_dd.__init__(self) + self.top_block = top_block + def eval(self, freq_offet): + self.top_block.set_center_frequency(freq_offet) + return freq_offet + +class synchronizer(gr.feval_dd): + def __init__(self, top_block): + gr.feval_dd.__init__(self) + self.top_block = top_block + + def eval(self, timing_offset): + self.top_block.set_timing(timing_offset) + return freq_offet + +class gsm_receiver_first_blood(gr.top_block): + def __init__(self): + gr.top_block.__init__(self) + (options, args) = self._process_options() + self.tuner_callback = tuner(self) + self.synchronizer_callback = synchronizer(self) + self.options = options + self.args = args + self._set_rates() + self.source = self._set_source() + self.filtr = self._set_filter() + self.interpolator = self._set_interpolator() + self.receiver = self._set_receiver() + self.converter = self._set_converter() + self.sink = self._set_sink() + + self.connect(self.source, self.filtr, self.interpolator, self.receiver, self.converter, self.sink) + + def _set_sink(self): + nazwa_pliku_wy = self.options.outputfile + ujscie = gr.file_sink(gr.sizeof_float, nazwa_pliku_wy) + return ujscie + + def _set_source(self): + nazwa_pliku = self.options.inputfile + zrodlo = gr.file_source(gr.sizeof_gr_complex, nazwa_pliku, False) + return zrodlo + + def _set_rates(self): + options = self.options + clock_rate = 64e6 + self.clock_rate = clock_rate + self.input_rate = clock_rate / options.decim + self.gsm_symb_rate = 1625000.0 / 6.0 + self.sps = self.input_rate / self.gsm_symb_rate / self.options.osr + + def _set_filter(self): + filter_cutoff = 145e3 + filter_t_width = 10e3 + offset = 0 +# print "input_rate:", self.input_rate, "sample rate:", self.sps, " filter_cutoff:", filter_cutoff, " filter_t_width:", filter_t_width + filter_taps = gr.firdes.low_pass(1.0, self.input_rate, filter_cutoff, filter_t_width, gr.firdes.WIN_HAMMING) + filtr = gr.freq_xlating_fir_filter_ccf(1, filter_taps, offset, self.input_rate) + return filtr + + def _set_converter(self): + v2s = gr.vector_to_stream(gr.sizeof_float, 142) + return v2s + + def _set_interpolator(self): + interpolator = gr.fractional_interpolator_cc(0, self.sps) + return interpolator + + def _set_receiver(self): + receiver = gsm.receiver_cf(self.tuner_callback, self.synchronizer_callback, self.options.osr, self.options.key.replace(' ', '').lower()) + return receiver + + def _process_options(self): + parser = OptionParser(option_class=eng_option) + parser.add_option("-d", "--decim", type="int", default=128, + help="Set USRP decimation rate to DECIM [default=%default]") + parser.add_option("-r", "--osr", type="int", default=4, + help="Oversampling ratio [default=%default]") + parser.add_option("-I", "--inputfile", type="string", default="cfile", + help="Input filename") + parser.add_option("-O", "--outputfile", type="string", default="cfile2.out", + help="Output filename") + parser.add_option("-k", "--key", type="string", default="2B 08 74 9F DD 0D 9C 00", + help="KC session key") + + (options, args) = parser.parse_args () + return (options, args) + + def set_center_frequency(self, center_freq): + self.filtr.set_center_freq(center_freq) + + def set_timing(self, timing_offset): + pass + +def main(): + try: + gsm_receiver_first_blood().run() + except KeyboardInterrupt: + pass + +if __name__ == '__main__': + main() diff --git a/gsm-receiver/src/python/gsm_receive_usrp.py b/gsm-receiver/src/python/gsm_receive_usrp.py new file mode 100755 index 0000000..a4e9720 --- /dev/null +++ b/gsm-receiver/src/python/gsm_receive_usrp.py @@ -0,0 +1,141 @@ +#!/usr/bin/env python +#this file isn't ready to use now - gsm-receiver lacks realtime processing capability +#there are many underruns of buffer for samples from usrp's, many blocks of samples get lost and +#receiver isn't prepared for this situation too well + +from gnuradio import gr, gru, blks2 +#, gsm +from gnuradio import usrp +from gnuradio.eng_option import eng_option +from optparse import OptionParser +from os import sys + +for extdir in ['../../debug/src/lib','../../debug/src/lib/.libs']: + if extdir not in sys.path: + sys.path.append(extdir) +import gsm + +def pick_subdevice(u): + if u.db[0][0].dbid() >= 0: + return (0, 0) + if u.db[1][0].dbid() >= 0: + return (1, 0) + return (0, 0) + +class tune(gr.feval_dd): + def __init__(self, top_block): + gr.feval_dd.__init__(self) + self.top_block = top_block + # self.center_freq = 0 + def eval(self, freq_offet): + # self.center_freq = self.center_freq - freq_offet + self.top_block.set_frequency(freq_offet) + return freq_offet + +class gsm_receiver_first_blood(gr.top_block): + def __init__(self): + gr.top_block.__init__(self) + (options, args) = self._process_options() + self.tune_callback = tune(self) + self.options = options + self.args = args + self._set_rates() + self.source = self._set_source() + self.filtr = self._set_filter() + self.interpolator = self._set_interpolator() + self.receiver = self._set_receiver() + self.converter = self._set_converter() + self.sink = self._set_sink() + + self.connect(self.source, self.filtr, self.interpolator, self.receiver, self.converter, self.sink) + + def _set_sink(self): + nazwa_pliku_wy = self.options.outputfile + ujscie = gr.file_sink(gr.sizeof_float, nazwa_pliku_wy) + return ujscie + + def _set_source(self): + options = self.options + fusb_block_size = gr.prefs().get_long('fusb', 'block_size', 4096) + fusb_nblocks = gr.prefs().get_long('fusb', 'nblocks', 16) + self.usrp = usrp.source_c(decim_rate=options.decim, fusb_block_size=fusb_block_size, fusb_nblocks=fusb_nblocks) + + if options.rx_subdev_spec is None: + options.rx_subdev_spec = pick_subdevice(self.usrp) + + self.usrp.set_mux(usrp.determine_rx_mux_value(self.usrp, options.rx_subdev_spec)) + # determine the daughterboard subdevice + self.subdev = usrp.selected_subdev(self.usrp, options.rx_subdev_spec) + input_rate = self.usrp.adc_freq() / self.usrp.decim_rate() + + # set initial values + if options.gain is None: + # if no gain was specified, use the mid-point in dB + g = self.subdev.gain_range() + options.gain = float(g[0]+g[1])/2 + + r = self.usrp.tune(0, self.subdev, options.freq) + self.subdev.set_gain(options.gain) + return self.usrp + + def _set_rates(self): + options = self.options + clock_rate = 64e6 + self.clock_rate = clock_rate + self.input_rate = clock_rate / options.decim + self.gsm_symb_rate = 1625000.0 / 6.0 + self.sps = self.input_rate / self.gsm_symb_rate / self.options.osr + + def _set_filter(self): + filter_cutoff = 145e3 + filter_t_width = 10e3 + offset = 0 +# print "input_rate:", self.input_rate, "sample rate:", self.sps, " filter_cutoff:", filter_cutoff, " filter_t_width:", filter_t_width + filter_taps = gr.firdes.low_pass(1.0, self.input_rate, filter_cutoff, filter_t_width, gr.firdes.WIN_HAMMING) + filtr = gr.freq_xlating_fir_filter_ccf(1, filter_taps, offset, self.input_rate) + return filtr + + def _set_converter(self): + v2s = gr.vector_to_stream(gr.sizeof_float, 142) + return v2s + + def _set_interpolator(self): + interpolator = gr.fractional_interpolator_cc(0, self.sps) + return interpolator + + def _set_receiver(self): + receiver = gsm.receiver_cf(self.tune_callback, self.options.osr) + return receiver + + def _process_options(self): + parser = OptionParser(option_class=eng_option) + parser.add_option("-d", "--decim", type="int", default=128, + help="Set USRP decimation rate to DECIM [default=%default]") + parser.add_option("-I", "--inputfile", type="string", default="cfile", + help="Input filename") + parser.add_option("-O", "--outputfile", type="string", default="cfile2.out", + help="Output filename") + parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None, + help="Select USRP Rx side A or B (default=first one with a daughterboard)") + parser.add_option("-r", "--osr", type="int", default=4, + help="Oversampling ratio [default=%default]") + parser.add_option("-f", "--freq", type="eng_float", default="950.4M", + help="set frequency to FREQ", metavar="FREQ") + parser.add_option("-g", "--gain", type="eng_float", default=None, + help="Set gain in dB (default is midpoint)") + (options, args) = parser.parse_args () + return (options, args) + + def set_frequency(self, center_freq): + self.filtr.set_center_freq(center_freq) + +def main(): + try: + gsm_receiver_first_blood().run() + except KeyboardInterrupt: + pass + +if __name__ == '__main__': + main() + + diff --git a/gsm-receiver/src/python/test.sh b/gsm-receiver/src/python/test.sh new file mode 100755 index 0000000..0a828e9 --- /dev/null +++ b/gsm-receiver/src/python/test.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +./gsm_receive.py -I cfile > receiver-test.out 2> /dev/null +echo " 01 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b\n 15 06 21 00 01 00 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b" > receiver-comp.out +diff receiver-test.out receiver-comp.out > receiver-test-diff.out +test_result=`cat receiver-test-diff.out` + +rm receiver-test.out receiver-test-diff.out receiver-comp.out + +if [ "x$test_result" = "x" ]; then + echo "Test: passed" + exit 0 +else + echo "Test: failed" + exit 1 +fi -- cgit v1.2.3