From a0889539e43cc7fa670c06f1b20df40fdc71b15a Mon Sep 17 00:00:00 2001 From: Petter Reinholdtsen Date: Tue, 8 Aug 2017 07:52:23 +0000 Subject: Remove language extention from remaining binaries. The install target install some binaries without language extentions and others with such extension: * grgsm_capture.py * grgsm_channelize.py * grgsm_decode * grgsm_livemon * grgsm_scanner It would be more consistent and according to the policy of Debian and Ubuntu if all the binaries were without such language extention. This commit rename grgsm_capture.py and grgsm_channelize.py to avoid the language extention. --- apps/helpers/CMakeLists.txt | 6 +- apps/helpers/grgsm_capture | 274 +++++++++++++++++++++++++++++++++++++++ apps/helpers/grgsm_capture.py | 274 --------------------------------------- apps/helpers/grgsm_channelize | 168 ++++++++++++++++++++++++ apps/helpers/grgsm_channelize.py | 168 ------------------------ 5 files changed, 445 insertions(+), 445 deletions(-) create mode 100755 apps/helpers/grgsm_capture delete mode 100755 apps/helpers/grgsm_capture.py create mode 100755 apps/helpers/grgsm_channelize delete mode 100755 apps/helpers/grgsm_channelize.py diff --git a/apps/helpers/CMakeLists.txt b/apps/helpers/CMakeLists.txt index 4418ed7..fff9593 100644 --- a/apps/helpers/CMakeLists.txt +++ b/apps/helpers/CMakeLists.txt @@ -22,12 +22,12 @@ include(CreateSymlink) GR_PYTHON_INSTALL( PROGRAMS - grgsm_capture.py - grgsm_channelize.py + grgsm_capture + grgsm_channelize DESTINATION bin ) -CREATE_SYMLINK(grgsm_capture.py airprobe_rtlsdr_capture.py) +CREATE_SYMLINK(grgsm_capture airprobe_rtlsdr_capture.py) add_custom_target(helpers_symlinks ALL DEPENDS ${symlinks}) diff --git a/apps/helpers/grgsm_capture b/apps/helpers/grgsm_capture new file mode 100755 index 0000000..a71c2c8 --- /dev/null +++ b/apps/helpers/grgsm_capture @@ -0,0 +1,274 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# @file +# @author Roman Khassraf +# @section LICENSE +# +# Gr-gsm 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 3, or (at your option) +# any later version. +# +# Gr-gsm 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 gr-gsm; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# +# + +from gnuradio import blocks +from gnuradio import eng_notation +from gnuradio import gr +from gnuradio.eng_option import eng_option +from gnuradio.filter import firdes +from math import pi +from optparse import OptionParser + +import grgsm +import osmosdr +import pmt +import signal +import sys + + +class grgsm_capture(gr.top_block): + + def __init__(self, fc, gain, samp_rate, ppm, arfcn, cfile=None, burst_file=None, band=None, verbose=False, rec_length=None, args=""): + + gr.top_block.__init__(self, "Gr-gsm Capture") + + ################################################## + # Parameters + ################################################## + self.fc = fc + self.gain = gain + self.samp_rate = samp_rate + self.ppm = ppm + self.arfcn = arfcn + self.cfile = cfile + self.burst_file = burst_file + self.band = band + self.verbose = verbose + self.shiftoff = shiftoff = 400e3 + self.rec_length = rec_length + + ################################################## + # Processing Blocks + ################################################## + + self.rtlsdr_source = osmosdr.source( args="numchan=" + str(1) + " " + args ) + self.rtlsdr_source.set_sample_rate(samp_rate) + self.rtlsdr_source.set_center_freq(fc - shiftoff, 0) + self.rtlsdr_source.set_freq_corr(ppm, 0) + self.rtlsdr_source.set_dc_offset_mode(2, 0) + self.rtlsdr_source.set_iq_balance_mode(2, 0) + self.rtlsdr_source.set_gain_mode(True, 0) + self.rtlsdr_source.set_gain(gain, 0) + self.rtlsdr_source.set_if_gain(20, 0) + self.rtlsdr_source.set_bb_gain(20, 0) + self.rtlsdr_source.set_antenna("", 0) + self.rtlsdr_source.set_bandwidth(250e3+abs(shiftoff), 0) + self.blocks_rotator = blocks.rotator_cc(-2*pi*shiftoff/samp_rate) + + if self.rec_length is not None: + self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex, int(samp_rate*rec_length)) + + if self.verbose or self.burst_file: + self.gsm_receiver = grgsm.receiver(4, ([self.arfcn]), ([])) + self.gsm_input = grgsm.gsm_input( + ppm=0, + osr=4, + fc=fc, + samp_rate_in=samp_rate, + ) + self.gsm_clock_offset_control = grgsm.clock_offset_control(fc-shiftoff, samp_rate, osr=4) + + if self.burst_file: + self.gsm_burst_file_sink = grgsm.burst_file_sink(self.burst_file) + + if self.cfile: + self.blocks_file_sink = blocks.file_sink(gr.sizeof_gr_complex*1, self.cfile, False) + self.blocks_file_sink.set_unbuffered(False) + + if self.verbose: + self.gsm_bursts_printer_0 = grgsm.bursts_printer(pmt.intern(""), + False, False, False, False) + + ################################################## + # Connections + ################################################## + + if self.rec_length is not None: #if recording length is defined connect head block after the source + self.connect((self.rtlsdr_source, 0), (self.blocks_head_0, 0)) + self.connect((self.blocks_head_0, 0), (self.blocks_rotator, 0)) + else: + self.connect((self.rtlsdr_source, 0), (self.blocks_rotator, 0)) + + if self.cfile: + self.connect((self.blocks_rotator, 0), (self.blocks_file_sink, 0)) + + if self.verbose or self.burst_file: + self.connect((self.gsm_input, 0), (self.gsm_receiver, 0)) + self.connect((self.blocks_rotator, 0), (self.gsm_input, 0)) + self.msg_connect(self.gsm_clock_offset_control, "ctrl", self.gsm_input, "ctrl_in") + self.msg_connect(self.gsm_receiver, "measurements", self.gsm_clock_offset_control, "measurements") + + if self.burst_file: + self.msg_connect(self.gsm_receiver, "C0", self.gsm_burst_file_sink, "in") + if self.verbose: + self.msg_connect(self.gsm_receiver, "C0", self.gsm_bursts_printer_0, "bursts") + + def get_fc(self): + return self.fc + + def set_fc(self, fc): + self.fc = fc + if self.verbose or self.burst_file: + self.gsm_input.set_fc(self.fc) + + def get_arfcn(self): + return self.arfcn + + def set_arfcn(self, arfcn): + self.arfcn = arfcn + if self.verbose or self.burst_file: + self.gsm_receiver.set_cell_allocation([self.arfcn]) + if options.band: + new_freq = grgsm.arfcn.arfcn2downlink(self.arfcn, self.band) + else: + for band in grgsm.arfcn.get_bands(): + if grgsm.arfcn.is_valid_arfcn(arfcn, band): + new_freq = grgsm.arfcn.arfcn2downlink(arfcn, band) + break + self.set_fc(new_freq) + + def get_gain(self): + return self.gain + + def set_gain(self, gain): + self.gain = gain + + def get_samp_rate(self): + return self.samp_rate + + def set_samp_rate(self, samp_rate): + self.samp_rate = samp_rate + self.rtlsdr_source.set_sample_rate(self.samp_rate) + if self.verbose or self.burst_file: + self.gsm_input.set_samp_rate_in(self.samp_rate) + + def get_ppm(self): + return self.ppm + + def set_ppm(self, ppm): + self.ppm = ppm + self.set_ppm_slider(self.ppm) + + def get_rec_length(self): + return self.rec_length + + def set_rec_length(self, rec_length): + self.rec_length = rec_length + self.blocks_head_0.set_length(int(self.samp_rate*self.rec_length)) + + +if __name__ == '__main__': + + parser = OptionParser(option_class=eng_option, usage="%prog [options]", + description="RTL-SDR capturing app of gr-gsm.") + + parser.add_option("-f", "--fc", dest="fc", type="eng_float", + help="Set frequency [default=%default]") + + parser.add_option("-a", "--arfcn", dest="arfcn", type="intx", + help="Set ARFCN instead of frequency. In some cases you may have to provide the GSM band also") + + parser.add_option("-g", "--gain", dest="gain", type="eng_float", + default=eng_notation.num_to_str(30), + help="Set gain [default=%default]") + + parser.add_option("-s", "--samp-rate", dest="samp_rate", type="eng_float", + default=eng_notation.num_to_str(1000000), + help="Set samp_rate [default=%default]") + + parser.add_option("-p", "--ppm", dest="ppm", type="intx", default=0, + help="Set ppm [default=%default]") + + parser.add_option("-b", "--burst-file", dest="burst_file", + help="File where the captured bursts are saved") + + parser.add_option("-c", "--cfile", dest="cfile", + help="File where the captured data are saved") + + bands_list = ", ".join(grgsm.arfcn.get_bands()) + parser.add_option("--band", dest="band", + help="Specify the GSM band for the frequency.\nAvailable bands are: " + bands_list + ".\nIf no band is specified, it will be determined automatically, defaulting to 0." ) + + parser.add_option("", "--args", dest="args", type="string", default="", + help="Set device arguments [default=%default]") + + parser.add_option("-v", "--verbose", action="store_true", + help="If set, the captured bursts are printed to stdout") + + parser.add_option("-T", "--rec-length", dest="rec_length", type="eng_float", + help="Set length of recording in seconds [default=%default]") + + (options, args) = parser.parse_args() + + if options.cfile is None and options.burst_file is None: + parser.error("Please provide a cfile or a burst file (or both) to save the captured data\n") + + if (options.fc is None and options.arfcn is None) or (options.fc is not None and options.arfcn is not None): + parser.error("You have to provide either a frequency or an ARFCN (but not both).\n") + + arfcn = 0 + fc = 939.4e6 + if options.arfcn: + if options.band: + if options.band not in grgsm.arfcn.get_bands(): + parser.error("Invalid GSM band\n") + elif not grgsm.arfcn.is_valid_arfcn(options.arfcn, options.band): + parser.error("ARFCN is not valid in the specified band\n") + else: + arfcn = options.arfcn + fc = grgsm.arfcn.arfcn2downlink(arfcn, options.band) + else: + arfcn = options.arfcn + for band in grgsm.arfcn.get_bands(): + if grgsm.arfcn.is_valid_arfcn(arfcn, band): + fc = grgsm.arfcn.arfcn2downlink(arfcn, band) + break + elif options.fc: + fc = options.fc + if options.band: + if options.band not in grgsm.arfcn.get_bands(): + parser.error("Invalid GSM band\n") + elif not grgsm.arfcn.is_valid_downlink(options.fc, options.band): + parser.error("Frequency is not valid in the specified band\n") + else: + arfcn = grgsm.arfcn.downlink2arfcn(options.fc, options.band) + else: + for band in grgsm.arfcn.get_bands(): + if grgsm.arfcn.is_valid_downlink(options.fc, band): + arfcn = grgsm.arfcn.downlink2arfcn(options.fc, band) + break + + tb = grgsm_capture(fc=fc, gain=options.gain, samp_rate=options.samp_rate, + ppm=options.ppm, arfcn=arfcn, cfile=options.cfile, + burst_file=options.burst_file, band=options.band, verbose=options.verbose, + rec_length=options.rec_length, args=options.args) + + def signal_handler(signal, frame): + tb.stop() + tb.wait() + sys.exit(0) + + signal.signal(signal.SIGINT, signal_handler) + + tb.start() + tb.wait() diff --git a/apps/helpers/grgsm_capture.py b/apps/helpers/grgsm_capture.py deleted file mode 100755 index a71c2c8..0000000 --- a/apps/helpers/grgsm_capture.py +++ /dev/null @@ -1,274 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# @file -# @author Roman Khassraf -# @section LICENSE -# -# Gr-gsm 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 3, or (at your option) -# any later version. -# -# Gr-gsm 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 gr-gsm; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# -# - -from gnuradio import blocks -from gnuradio import eng_notation -from gnuradio import gr -from gnuradio.eng_option import eng_option -from gnuradio.filter import firdes -from math import pi -from optparse import OptionParser - -import grgsm -import osmosdr -import pmt -import signal -import sys - - -class grgsm_capture(gr.top_block): - - def __init__(self, fc, gain, samp_rate, ppm, arfcn, cfile=None, burst_file=None, band=None, verbose=False, rec_length=None, args=""): - - gr.top_block.__init__(self, "Gr-gsm Capture") - - ################################################## - # Parameters - ################################################## - self.fc = fc - self.gain = gain - self.samp_rate = samp_rate - self.ppm = ppm - self.arfcn = arfcn - self.cfile = cfile - self.burst_file = burst_file - self.band = band - self.verbose = verbose - self.shiftoff = shiftoff = 400e3 - self.rec_length = rec_length - - ################################################## - # Processing Blocks - ################################################## - - self.rtlsdr_source = osmosdr.source( args="numchan=" + str(1) + " " + args ) - self.rtlsdr_source.set_sample_rate(samp_rate) - self.rtlsdr_source.set_center_freq(fc - shiftoff, 0) - self.rtlsdr_source.set_freq_corr(ppm, 0) - self.rtlsdr_source.set_dc_offset_mode(2, 0) - self.rtlsdr_source.set_iq_balance_mode(2, 0) - self.rtlsdr_source.set_gain_mode(True, 0) - self.rtlsdr_source.set_gain(gain, 0) - self.rtlsdr_source.set_if_gain(20, 0) - self.rtlsdr_source.set_bb_gain(20, 0) - self.rtlsdr_source.set_antenna("", 0) - self.rtlsdr_source.set_bandwidth(250e3+abs(shiftoff), 0) - self.blocks_rotator = blocks.rotator_cc(-2*pi*shiftoff/samp_rate) - - if self.rec_length is not None: - self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex, int(samp_rate*rec_length)) - - if self.verbose or self.burst_file: - self.gsm_receiver = grgsm.receiver(4, ([self.arfcn]), ([])) - self.gsm_input = grgsm.gsm_input( - ppm=0, - osr=4, - fc=fc, - samp_rate_in=samp_rate, - ) - self.gsm_clock_offset_control = grgsm.clock_offset_control(fc-shiftoff, samp_rate, osr=4) - - if self.burst_file: - self.gsm_burst_file_sink = grgsm.burst_file_sink(self.burst_file) - - if self.cfile: - self.blocks_file_sink = blocks.file_sink(gr.sizeof_gr_complex*1, self.cfile, False) - self.blocks_file_sink.set_unbuffered(False) - - if self.verbose: - self.gsm_bursts_printer_0 = grgsm.bursts_printer(pmt.intern(""), - False, False, False, False) - - ################################################## - # Connections - ################################################## - - if self.rec_length is not None: #if recording length is defined connect head block after the source - self.connect((self.rtlsdr_source, 0), (self.blocks_head_0, 0)) - self.connect((self.blocks_head_0, 0), (self.blocks_rotator, 0)) - else: - self.connect((self.rtlsdr_source, 0), (self.blocks_rotator, 0)) - - if self.cfile: - self.connect((self.blocks_rotator, 0), (self.blocks_file_sink, 0)) - - if self.verbose or self.burst_file: - self.connect((self.gsm_input, 0), (self.gsm_receiver, 0)) - self.connect((self.blocks_rotator, 0), (self.gsm_input, 0)) - self.msg_connect(self.gsm_clock_offset_control, "ctrl", self.gsm_input, "ctrl_in") - self.msg_connect(self.gsm_receiver, "measurements", self.gsm_clock_offset_control, "measurements") - - if self.burst_file: - self.msg_connect(self.gsm_receiver, "C0", self.gsm_burst_file_sink, "in") - if self.verbose: - self.msg_connect(self.gsm_receiver, "C0", self.gsm_bursts_printer_0, "bursts") - - def get_fc(self): - return self.fc - - def set_fc(self, fc): - self.fc = fc - if self.verbose or self.burst_file: - self.gsm_input.set_fc(self.fc) - - def get_arfcn(self): - return self.arfcn - - def set_arfcn(self, arfcn): - self.arfcn = arfcn - if self.verbose or self.burst_file: - self.gsm_receiver.set_cell_allocation([self.arfcn]) - if options.band: - new_freq = grgsm.arfcn.arfcn2downlink(self.arfcn, self.band) - else: - for band in grgsm.arfcn.get_bands(): - if grgsm.arfcn.is_valid_arfcn(arfcn, band): - new_freq = grgsm.arfcn.arfcn2downlink(arfcn, band) - break - self.set_fc(new_freq) - - def get_gain(self): - return self.gain - - def set_gain(self, gain): - self.gain = gain - - def get_samp_rate(self): - return self.samp_rate - - def set_samp_rate(self, samp_rate): - self.samp_rate = samp_rate - self.rtlsdr_source.set_sample_rate(self.samp_rate) - if self.verbose or self.burst_file: - self.gsm_input.set_samp_rate_in(self.samp_rate) - - def get_ppm(self): - return self.ppm - - def set_ppm(self, ppm): - self.ppm = ppm - self.set_ppm_slider(self.ppm) - - def get_rec_length(self): - return self.rec_length - - def set_rec_length(self, rec_length): - self.rec_length = rec_length - self.blocks_head_0.set_length(int(self.samp_rate*self.rec_length)) - - -if __name__ == '__main__': - - parser = OptionParser(option_class=eng_option, usage="%prog [options]", - description="RTL-SDR capturing app of gr-gsm.") - - parser.add_option("-f", "--fc", dest="fc", type="eng_float", - help="Set frequency [default=%default]") - - parser.add_option("-a", "--arfcn", dest="arfcn", type="intx", - help="Set ARFCN instead of frequency. In some cases you may have to provide the GSM band also") - - parser.add_option("-g", "--gain", dest="gain", type="eng_float", - default=eng_notation.num_to_str(30), - help="Set gain [default=%default]") - - parser.add_option("-s", "--samp-rate", dest="samp_rate", type="eng_float", - default=eng_notation.num_to_str(1000000), - help="Set samp_rate [default=%default]") - - parser.add_option("-p", "--ppm", dest="ppm", type="intx", default=0, - help="Set ppm [default=%default]") - - parser.add_option("-b", "--burst-file", dest="burst_file", - help="File where the captured bursts are saved") - - parser.add_option("-c", "--cfile", dest="cfile", - help="File where the captured data are saved") - - bands_list = ", ".join(grgsm.arfcn.get_bands()) - parser.add_option("--band", dest="band", - help="Specify the GSM band for the frequency.\nAvailable bands are: " + bands_list + ".\nIf no band is specified, it will be determined automatically, defaulting to 0." ) - - parser.add_option("", "--args", dest="args", type="string", default="", - help="Set device arguments [default=%default]") - - parser.add_option("-v", "--verbose", action="store_true", - help="If set, the captured bursts are printed to stdout") - - parser.add_option("-T", "--rec-length", dest="rec_length", type="eng_float", - help="Set length of recording in seconds [default=%default]") - - (options, args) = parser.parse_args() - - if options.cfile is None and options.burst_file is None: - parser.error("Please provide a cfile or a burst file (or both) to save the captured data\n") - - if (options.fc is None and options.arfcn is None) or (options.fc is not None and options.arfcn is not None): - parser.error("You have to provide either a frequency or an ARFCN (but not both).\n") - - arfcn = 0 - fc = 939.4e6 - if options.arfcn: - if options.band: - if options.band not in grgsm.arfcn.get_bands(): - parser.error("Invalid GSM band\n") - elif not grgsm.arfcn.is_valid_arfcn(options.arfcn, options.band): - parser.error("ARFCN is not valid in the specified band\n") - else: - arfcn = options.arfcn - fc = grgsm.arfcn.arfcn2downlink(arfcn, options.band) - else: - arfcn = options.arfcn - for band in grgsm.arfcn.get_bands(): - if grgsm.arfcn.is_valid_arfcn(arfcn, band): - fc = grgsm.arfcn.arfcn2downlink(arfcn, band) - break - elif options.fc: - fc = options.fc - if options.band: - if options.band not in grgsm.arfcn.get_bands(): - parser.error("Invalid GSM band\n") - elif not grgsm.arfcn.is_valid_downlink(options.fc, options.band): - parser.error("Frequency is not valid in the specified band\n") - else: - arfcn = grgsm.arfcn.downlink2arfcn(options.fc, options.band) - else: - for band in grgsm.arfcn.get_bands(): - if grgsm.arfcn.is_valid_downlink(options.fc, band): - arfcn = grgsm.arfcn.downlink2arfcn(options.fc, band) - break - - tb = grgsm_capture(fc=fc, gain=options.gain, samp_rate=options.samp_rate, - ppm=options.ppm, arfcn=arfcn, cfile=options.cfile, - burst_file=options.burst_file, band=options.band, verbose=options.verbose, - rec_length=options.rec_length, args=options.args) - - def signal_handler(signal, frame): - tb.stop() - tb.wait() - sys.exit(0) - - signal.signal(signal.SIGINT, signal_handler) - - tb.start() - tb.wait() diff --git a/apps/helpers/grgsm_channelize b/apps/helpers/grgsm_channelize new file mode 100755 index 0000000..146bb8f --- /dev/null +++ b/apps/helpers/grgsm_channelize @@ -0,0 +1,168 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- +# @file +# @author Pieter Robyns +# @section LICENSE +# +# Gr-gsm 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 3, or (at your option) +# any later version. +# +# Gr-gsm 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 gr-gsm; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# +# + +################################################## +# gr-gsm channelizer +# +# Standalone application to channelize a wideband +# GSM capture file into multiple seperate capture +# files for the specified ARFCNs. +################################################## + +from gnuradio import blocks +from gnuradio import eng_notation +from gnuradio import filter +from gnuradio import gr +from gnuradio.eng_option import eng_option +from gnuradio.filter import firdes +from argparse import ArgumentParser, ArgumentTypeError, RawDescriptionHelpFormatter +import grgsm.arfcn as arfcn +from gnuradio.filter import pfb +import math +import os + +EXTRA_HELP = """ +Example usage: +grgsm_channelize.py -c my_wideband_capture.cfile -f 925.2e6 990 991 992 993 994 995 1019 1020 1021 1022 1023 + +The above example will channelize my_wideband_capture.cfile, in this case a cfile captured at +925.2 MHz centered (ARFCN 975) and 2 Msps. As a result, 12 files will be generated for +ARFCNs 975 - 1023 at 1 Msps each. +""" + +def eng_float(value): + try: + return eng_notation.str_to_num(value) + except: + raise ArgumentTypeError("invalid engineering notation value: {0}".format(value)) + +def gsm_band(value): + choices = arfcn.get_bands() + if value in choices: + return value + else: + raise ArgumentTypeError("invalid GSM band: {0}. Possible choices are: {1}".format(value, choices)) + +class grgsm_channelize(gr.top_block): + def __init__(self, channels, resamp_rate, fc, band, samp_rate, input_file, dest_dir, data_type="complex"): + gr.top_block.__init__(self, "grgsm_channelize") + + ################################################## + # Parameters + ################################################## + self.channels = channels + self.resamp_rate = resamp_rate + self.fc = fc + self.band = band + self.samp_rate = samp_rate + self.blocks_resamplers = {} + self.blocks_rotators = {} + self.blocks_file_sinks = {} + + ################################################## + # Blocks and connections + ################################################## + self.source = None + if data_type == "ishort": + self.blocks_file_source = blocks.file_source(gr.sizeof_short, input_file, False) + self.source = blocks.interleaved_short_to_complex(False, False) + self.connect((self.blocks_file_source, 0), (self.source, 0)) + elif data_type == "complex": + self.source = blocks.file_source(gr.sizeof_gr_complex, input_file, False) + + fc_str = eng_notation.num_to_str(fc) + print("Extracting channels %s, given that the center frequency is at %s" % (str(channels), eng_notation.num_to_str(fc))) + + for channel in channels: + channel_freq = arfcn.arfcn2downlink(channel, band) + if channel_freq is None: + print("Warning: invalid ARFCN %d for band %s" % (channel, band)) + continue + freq_diff = channel_freq - fc + freq_diff_str = "+" if 0 <= freq_diff else "" + freq_diff_str += eng_notation.num_to_str(freq_diff) + print("ARFCN %d is at %sHz %sHz" % (channel, fc_str, freq_diff_str)) + + self.blocks_resamplers[channel] = pfb.arb_resampler_ccf( resamp_rate, taps=None, flt_size=32) + self.blocks_rotators[channel] = blocks.rotator_cc(-2*math.pi*(freq_diff)/samp_rate) + self.connect( (self.source, 0), (self.blocks_rotators[channel], 0) ) + self.connect( (self.blocks_rotators[channel], 0), (self.blocks_resamplers[channel], 0) ) + + self.blocks_file_sinks[channel] = blocks.file_sink(gr.sizeof_gr_complex, dest_dir+"/out_" + str(channel) + ".cfile", False) + self.blocks_file_sinks[channel].set_unbuffered(False) + self.connect((self.blocks_resamplers[channel], 0), (self.blocks_file_sinks[channel], 0)) + + +if __name__ == '__main__': + parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter, description='Split wideband a GSM capture into seperate files per ARFCN.', add_help=True, epilog=EXTRA_HELP) + parser.add_argument(dest="channel", type=int, nargs='+', + help="List of ARFCNs") + parser.add_argument("-s", "--samp-rate", dest="samp_rate", type=eng_float, default=eng_notation.num_to_str(2e6), + help="Sample rate of the wideband capture file [default=%(default)s]") + parser.add_argument("-f", "--fc", dest="fc", type=eng_float, default=eng_notation.num_to_str(935e6), required=True, + help="Carrier frequency in Hz [default=%(default)s]") + parser.add_argument("-b", "--band", dest="band", type=gsm_band, default='E-GSM', + help="GSM band [default=%(default)s]") #TODO: add automatic discovery based on fc + parser.add_argument("-o", "--out-samp-rate", dest="out_samp_rate", type=eng_float, default=eng_notation.num_to_str(1e6), + help="Sample rate of the output capture files [default=%(default)s]") + parser.add_argument("-i", "--input_file", dest="input_file", type=str, required=True, + help="Path to wideband GSM capture file") + parser.add_argument("-t", "--data_type", dest="data_type", type=str, choices=["complex","ishort"], default="complex", + help="Type of the input file [default=%(default)s]") + parser.add_argument("-d", "--dest_dir", dest="dest_dir", type=str, + help="Destination directory - if not given defaults to input file name without extension") + + args = parser.parse_args() + + if not os.path.exists(args.input_file): + raise IOError(args.input_file + " does not exist") + + input_filename, _ = os.path.splitext(os.path.basename(args.input_file)) + + if args.dest_dir is None: + args.dest_dir = input_filename + + if not os.path.exists("./"+args.dest_dir): + os.makedirs("./"+args.dest_dir) + + + if args.samp_rate % args.out_samp_rate != 0: + raise Exception("Input sample rate should be multiple of output sample rate in order to get integer decimation.") + + resamp_rate = args.out_samp_rate / args.samp_rate + print("Input sample rate: " + eng_notation.num_to_str(args.samp_rate)) + print("Output sample rate: " + eng_notation.num_to_str(args.out_samp_rate)) + print("==> using resample rate of " + str(resamp_rate)) + + tb = grgsm_channelize(channels=args.channel, + resamp_rate=resamp_rate, + fc=args.fc, + band=args.band, + samp_rate=args.samp_rate, + input_file=args.input_file, + dest_dir=args.dest_dir, + data_type=args.data_type + ) + tb.start() + tb.wait() + print("Done!") diff --git a/apps/helpers/grgsm_channelize.py b/apps/helpers/grgsm_channelize.py deleted file mode 100755 index 146bb8f..0000000 --- a/apps/helpers/grgsm_channelize.py +++ /dev/null @@ -1,168 +0,0 @@ -#!/usr/bin/env python2 -# -*- coding: utf-8 -*- -# @file -# @author Pieter Robyns -# @section LICENSE -# -# Gr-gsm 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 3, or (at your option) -# any later version. -# -# Gr-gsm 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 gr-gsm; see the file COPYING. If not, write to -# the Free Software Foundation, Inc., 51 Franklin Street, -# Boston, MA 02110-1301, USA. -# -# - -################################################## -# gr-gsm channelizer -# -# Standalone application to channelize a wideband -# GSM capture file into multiple seperate capture -# files for the specified ARFCNs. -################################################## - -from gnuradio import blocks -from gnuradio import eng_notation -from gnuradio import filter -from gnuradio import gr -from gnuradio.eng_option import eng_option -from gnuradio.filter import firdes -from argparse import ArgumentParser, ArgumentTypeError, RawDescriptionHelpFormatter -import grgsm.arfcn as arfcn -from gnuradio.filter import pfb -import math -import os - -EXTRA_HELP = """ -Example usage: -grgsm_channelize.py -c my_wideband_capture.cfile -f 925.2e6 990 991 992 993 994 995 1019 1020 1021 1022 1023 - -The above example will channelize my_wideband_capture.cfile, in this case a cfile captured at -925.2 MHz centered (ARFCN 975) and 2 Msps. As a result, 12 files will be generated for -ARFCNs 975 - 1023 at 1 Msps each. -""" - -def eng_float(value): - try: - return eng_notation.str_to_num(value) - except: - raise ArgumentTypeError("invalid engineering notation value: {0}".format(value)) - -def gsm_band(value): - choices = arfcn.get_bands() - if value in choices: - return value - else: - raise ArgumentTypeError("invalid GSM band: {0}. Possible choices are: {1}".format(value, choices)) - -class grgsm_channelize(gr.top_block): - def __init__(self, channels, resamp_rate, fc, band, samp_rate, input_file, dest_dir, data_type="complex"): - gr.top_block.__init__(self, "grgsm_channelize") - - ################################################## - # Parameters - ################################################## - self.channels = channels - self.resamp_rate = resamp_rate - self.fc = fc - self.band = band - self.samp_rate = samp_rate - self.blocks_resamplers = {} - self.blocks_rotators = {} - self.blocks_file_sinks = {} - - ################################################## - # Blocks and connections - ################################################## - self.source = None - if data_type == "ishort": - self.blocks_file_source = blocks.file_source(gr.sizeof_short, input_file, False) - self.source = blocks.interleaved_short_to_complex(False, False) - self.connect((self.blocks_file_source, 0), (self.source, 0)) - elif data_type == "complex": - self.source = blocks.file_source(gr.sizeof_gr_complex, input_file, False) - - fc_str = eng_notation.num_to_str(fc) - print("Extracting channels %s, given that the center frequency is at %s" % (str(channels), eng_notation.num_to_str(fc))) - - for channel in channels: - channel_freq = arfcn.arfcn2downlink(channel, band) - if channel_freq is None: - print("Warning: invalid ARFCN %d for band %s" % (channel, band)) - continue - freq_diff = channel_freq - fc - freq_diff_str = "+" if 0 <= freq_diff else "" - freq_diff_str += eng_notation.num_to_str(freq_diff) - print("ARFCN %d is at %sHz %sHz" % (channel, fc_str, freq_diff_str)) - - self.blocks_resamplers[channel] = pfb.arb_resampler_ccf( resamp_rate, taps=None, flt_size=32) - self.blocks_rotators[channel] = blocks.rotator_cc(-2*math.pi*(freq_diff)/samp_rate) - self.connect( (self.source, 0), (self.blocks_rotators[channel], 0) ) - self.connect( (self.blocks_rotators[channel], 0), (self.blocks_resamplers[channel], 0) ) - - self.blocks_file_sinks[channel] = blocks.file_sink(gr.sizeof_gr_complex, dest_dir+"/out_" + str(channel) + ".cfile", False) - self.blocks_file_sinks[channel].set_unbuffered(False) - self.connect((self.blocks_resamplers[channel], 0), (self.blocks_file_sinks[channel], 0)) - - -if __name__ == '__main__': - parser = ArgumentParser(formatter_class=RawDescriptionHelpFormatter, description='Split wideband a GSM capture into seperate files per ARFCN.', add_help=True, epilog=EXTRA_HELP) - parser.add_argument(dest="channel", type=int, nargs='+', - help="List of ARFCNs") - parser.add_argument("-s", "--samp-rate", dest="samp_rate", type=eng_float, default=eng_notation.num_to_str(2e6), - help="Sample rate of the wideband capture file [default=%(default)s]") - parser.add_argument("-f", "--fc", dest="fc", type=eng_float, default=eng_notation.num_to_str(935e6), required=True, - help="Carrier frequency in Hz [default=%(default)s]") - parser.add_argument("-b", "--band", dest="band", type=gsm_band, default='E-GSM', - help="GSM band [default=%(default)s]") #TODO: add automatic discovery based on fc - parser.add_argument("-o", "--out-samp-rate", dest="out_samp_rate", type=eng_float, default=eng_notation.num_to_str(1e6), - help="Sample rate of the output capture files [default=%(default)s]") - parser.add_argument("-i", "--input_file", dest="input_file", type=str, required=True, - help="Path to wideband GSM capture file") - parser.add_argument("-t", "--data_type", dest="data_type", type=str, choices=["complex","ishort"], default="complex", - help="Type of the input file [default=%(default)s]") - parser.add_argument("-d", "--dest_dir", dest="dest_dir", type=str, - help="Destination directory - if not given defaults to input file name without extension") - - args = parser.parse_args() - - if not os.path.exists(args.input_file): - raise IOError(args.input_file + " does not exist") - - input_filename, _ = os.path.splitext(os.path.basename(args.input_file)) - - if args.dest_dir is None: - args.dest_dir = input_filename - - if not os.path.exists("./"+args.dest_dir): - os.makedirs("./"+args.dest_dir) - - - if args.samp_rate % args.out_samp_rate != 0: - raise Exception("Input sample rate should be multiple of output sample rate in order to get integer decimation.") - - resamp_rate = args.out_samp_rate / args.samp_rate - print("Input sample rate: " + eng_notation.num_to_str(args.samp_rate)) - print("Output sample rate: " + eng_notation.num_to_str(args.out_samp_rate)) - print("==> using resample rate of " + str(resamp_rate)) - - tb = grgsm_channelize(channels=args.channel, - resamp_rate=resamp_rate, - fc=args.fc, - band=args.band, - samp_rate=args.samp_rate, - input_file=args.input_file, - dest_dir=args.dest_dir, - data_type=args.data_type - ) - tb.start() - tb.wait() - print("Done!") -- cgit v1.2.3