diff options
author | piotr <Piotr Krysik pkrysik@elka.pw.edu.pl> | 2014-02-04 17:57:25 +0100 |
---|---|---|
committer | piotr <Piotr Krysik pkrysik@elka.pw.edu.pl> | 2014-02-04 17:57:25 +0100 |
commit | 437f5467a12ceddbc93a88f704697bd024378959 (patch) | |
tree | 68fb7a5ca2d4e72358c3444156072392a9fe627f /python |
Initial commit - gsm-receiver with removed quick hacks
Diffstat (limited to 'python')
-rw-r--r-- | python/CMakeLists.txt | 45 | ||||
-rw-r--r-- | python/__init__.py | 55 | ||||
-rw-r--r-- | python/build_utils.py | 226 | ||||
-rw-r--r-- | python/build_utils_codes.py | 52 | ||||
-rw-r--r-- | python/cfile | bin | 0 -> 640000 bytes | |||
-rw-r--r-- | python/cfile2.out | 0 | ||||
-rwxr-xr-x | python/receiver_hier.py | 59 | ||||
-rw-r--r-- | python/receiver_hier.pyc | bin | 0 -> 2997 bytes |
8 files changed, 437 insertions, 0 deletions
diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt new file mode 100644 index 0000000..7d68803 --- /dev/null +++ b/python/CMakeLists.txt @@ -0,0 +1,45 @@ +# Copyright 2011 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 3, 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 python install macros +######################################################################## +include(GrPython) +if(NOT PYTHONINTERP_FOUND) + return() +endif() + +######################################################################## +# Install python sources +######################################################################## +GR_PYTHON_INSTALL( + FILES + __init__.py + receiver_hier.py DESTINATION ${GR_PYTHON_DIR}/gsm +) + +######################################################################## +# Handle the unit tests +######################################################################## +include(GrTest) + +set(GR_TEST_TARGET_DEPS gnuradio-gsm) +set(GR_TEST_PYTHON_DIRS ${CMAKE_BINARY_DIR}/swig) +GR_ADD_TEST(qa_receiver ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_receiver.py) +GR_ADD_TEST(qa_receiver_hier ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/qa_receiver_hier.py) diff --git a/python/__init__.py b/python/__init__.py new file mode 100644 index 0000000..d6dec38 --- /dev/null +++ b/python/__init__.py @@ -0,0 +1,55 @@ +# +# Copyright 2008,2009 Free Software Foundation, Inc. +# +# This application 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. +# +# This application 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 this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +# The presence of this file turns this directory into a Python package + +''' +This is the GNU Radio GSM module. Place your Python package +description here (python/__init__.py). +''' + +# ---------------------------------------------------------------- +# Temporary workaround for ticket:181 (swig+python problem) +import sys +_RTLD_GLOBAL = 0 +try: + from dl import RTLD_GLOBAL as _RTLD_GLOBAL +except ImportError: + try: + from DLFCN import RTLD_GLOBAL as _RTLD_GLOBAL + except ImportError: + pass + +if _RTLD_GLOBAL != 0: + _dlopenflags = sys.getdlopenflags() + sys.setdlopenflags(_dlopenflags|_RTLD_GLOBAL) +# ---------------------------------------------------------------- + + +# import swig generated symbols into the gsm namespace +from gsm_swig import * + +# import any pure python here +from receiver_hier import receiver_hier +# + +# ---------------------------------------------------------------- +# Tail of workaround +if _RTLD_GLOBAL != 0: + sys.setdlopenflags(_dlopenflags) # Restore original flags +# ---------------------------------------------------------------- diff --git a/python/build_utils.py b/python/build_utils.py new file mode 100644 index 0000000..cf58a97 --- /dev/null +++ b/python/build_utils.py @@ -0,0 +1,226 @@ +# +# Copyright 2004,2009,2012 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 3, 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. +# + +"""Misc utilities used at build time +""" + +import re, os, os.path +from build_utils_codes import * + + +# set srcdir to the directory that contains Makefile.am +try: + srcdir = os.environ['srcdir'] +except KeyError, e: + srcdir = "." +srcdir = srcdir + '/' + +# set do_makefile to either true or false dependeing on the environment +try: + if os.environ['do_makefile'] == '0': + do_makefile = False + else: + do_makefile = True +except KeyError, e: + do_makefile = False + +# set do_sources to either true or false dependeing on the environment +try: + if os.environ['do_sources'] == '0': + do_sources = False + else: + do_sources = True +except KeyError, e: + do_sources = True + +name_dict = {} + +def log_output_name (name): + (base, ext) = os.path.splitext (name) + ext = ext[1:] # drop the leading '.' + + entry = name_dict.setdefault (ext, []) + entry.append (name) + +def open_and_log_name (name, dir): + global do_sources + if do_sources: + f = open (name, dir) + else: + f = None + log_output_name (name) + return f + +def expand_template (d, template_filename, extra = ""): + '''Given a dictionary D and a TEMPLATE_FILENAME, expand template into output file + ''' + global do_sources + output_extension = extract_extension (template_filename) + template = open_src (template_filename, 'r') + output_name = d['NAME'] + extra + '.' + output_extension + log_output_name (output_name) + if do_sources: + output = open (output_name, 'w') + do_substitution (d, template, output) + output.close () + template.close () + +def output_glue (dirname): + output_makefile_fragment () + output_ifile_include (dirname) + +def output_makefile_fragment (): + global do_makefile + if not do_makefile: + return +# overwrite the source, which must be writable; this should have been +# checked for beforehand in the top-level Makefile.gen.gen . + f = open (os.path.join (os.environ.get('gendir', os.environ.get('srcdir', '.')), 'Makefile.gen'), 'w') + f.write ('#\n# This file is machine generated. All edits will be overwritten\n#\n') + output_subfrag (f, 'h') + output_subfrag (f, 'i') + output_subfrag (f, 'cc') + f.close () + +def output_ifile_include (dirname): + global do_sources + if do_sources: + f = open ('%s_generated.i' % (dirname,), 'w') + f.write ('//\n// This file is machine generated. All edits will be overwritten\n//\n') + files = name_dict.setdefault ('i', []) + files.sort () + f.write ('%{\n') + for file in files: + f.write ('#include <%s>\n' % (file[0:-1] + 'h',)) + f.write ('%}\n\n') + for file in files: + f.write ('%%include <%s>\n' % (file,)) + +def output_subfrag (f, ext): + files = name_dict.setdefault (ext, []) + files.sort () + f.write ("GENERATED_%s =" % (ext.upper ())) + for file in files: + f.write (" \\\n\t%s" % (file,)) + f.write ("\n\n") + +def extract_extension (template_name): + # template name is something like: GrFIRfilterXXX.h.t + # we return everything between the penultimate . and .t + mo = re.search (r'\.([a-z]+)\.t$', template_name) + if not mo: + raise ValueError, "Incorrectly formed template_name '%s'" % (template_name,) + return mo.group (1) + +def open_src (name, mode): + global srcdir + return open (os.path.join (srcdir, name), mode) + +def do_substitution (d, in_file, out_file): + def repl (match_obj): + key = match_obj.group (1) + # print key + return d[key] + + inp = in_file.read () + out = re.sub (r"@([a-zA-Z0-9_]+)@", repl, inp) + out_file.write (out) + + + +copyright = '''/* -*- c++ -*- */ +/* + * Copyright 2003,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 3, 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. + */ +''' + +def is_complex (code3): + if i_code (code3) == 'c' or o_code (code3) == 'c': + return '1' + else: + return '0' + + +def standard_dict (name, code3, package='gr'): + d = {} + d['NAME'] = name + d['NAME_IMPL'] = name+'_impl' + d['GUARD_NAME'] = 'INCLUDED_%s_%s_H' % (package.upper(), name.upper()) + d['GUARD_NAME_IMPL'] = 'INCLUDED_%s_%s_IMPL_H' % (package.upper(), name.upper()) + d['BASE_NAME'] = re.sub ('^' + package + '_', '', name) + d['SPTR_NAME'] = '%s_sptr' % name + d['WARNING'] = 'WARNING: this file is machine generated. Edits will be overwritten' + d['COPYRIGHT'] = copyright + d['TYPE'] = i_type (code3) + d['I_TYPE'] = i_type (code3) + d['O_TYPE'] = o_type (code3) + d['TAP_TYPE'] = tap_type (code3) + d['IS_COMPLEX'] = is_complex (code3) + return d + + +def standard_dict2 (name, code3, package): + d = {} + d['NAME'] = name + d['BASE_NAME'] = name + d['GUARD_NAME'] = 'INCLUDED_%s_%s_H' % (package.upper(), name.upper()) + d['WARNING'] = 'WARNING: this file is machine generated. Edits will be overwritten' + d['COPYRIGHT'] = copyright + d['TYPE'] = i_type (code3) + d['I_TYPE'] = i_type (code3) + d['O_TYPE'] = o_type (code3) + d['TAP_TYPE'] = tap_type (code3) + d['IS_COMPLEX'] = is_complex (code3) + return d + +def standard_impl_dict2 (name, code3, package): + d = {} + d['NAME'] = name + d['IMPL_NAME'] = name + d['BASE_NAME'] = name.rstrip("impl").rstrip("_") + d['GUARD_NAME'] = 'INCLUDED_%s_%s_H' % (package.upper(), name.upper()) + d['WARNING'] = 'WARNING: this file is machine generated. Edits will be overwritten' + d['COPYRIGHT'] = copyright + d['FIR_TYPE'] = "fir_filter_" + code3 + d['CFIR_TYPE'] = "fir_filter_" + code3[0:2] + 'c' + d['TYPE'] = i_type (code3) + d['I_TYPE'] = i_type (code3) + d['O_TYPE'] = o_type (code3) + d['TAP_TYPE'] = tap_type (code3) + d['IS_COMPLEX'] = is_complex (code3) + return d diff --git a/python/build_utils_codes.py b/python/build_utils_codes.py new file mode 100644 index 0000000..9ea96ba --- /dev/null +++ b/python/build_utils_codes.py @@ -0,0 +1,52 @@ +# +# 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 3, 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. +# + +def i_code (code3): + return code3[0] + +def o_code (code3): + if len (code3) >= 2: + return code3[1] + else: + return code3[0] + +def tap_code (code3): + if len (code3) >= 3: + return code3[2] + else: + return code3[0] + +def i_type (code3): + return char_to_type[i_code (code3)] + +def o_type (code3): + return char_to_type[o_code (code3)] + +def tap_type (code3): + return char_to_type[tap_code (code3)] + + +char_to_type = {} +char_to_type['s'] = 'short' +char_to_type['i'] = 'int' +char_to_type['f'] = 'float' +char_to_type['c'] = 'gr_complex' +char_to_type['b'] = 'unsigned char' diff --git a/python/cfile b/python/cfile Binary files differnew file mode 100644 index 0000000..943e35f --- /dev/null +++ b/python/cfile diff --git a/python/cfile2.out b/python/cfile2.out new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/python/cfile2.out diff --git a/python/receiver_hier.py b/python/receiver_hier.py new file mode 100755 index 0000000..1737d41 --- /dev/null +++ b/python/receiver_hier.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python + +import gsm +from gnuradio.eng_option import eng_option +from gnuradio import gr, gru, blocks +from gnuradio import filter + + +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 receiver_hier(gr.hier_block2): + def __init__(self, input_rate, osr=4): + gr.hier_block2.__init__(self, + "receiver_hier", + gr.io_signature(1, 1, gr.sizeof_gr_complex), + gr.io_signature(1, 1, 142*gr.sizeof_float)) + #set rates + gsm_symb_rate = 1625000/6.0 + self.input_rate = input_rate + self.osr = osr + self.sps = input_rate / gsm_symb_rate / osr + + #create callbacks + self.tuner_callback = tuner(self) + #create accompaning blocks + self.filtr = self._set_filter() + self.interpolator = self._set_interpolator() + self.receiver = self._set_receiver() + self.connect(self, self.filtr, self.interpolator, self.receiver, self) + + def _set_filter(self): + filter_cutoff = 125e3 + filter_t_width = 10e3 + offset = 0 + + filter_taps = filter.firdes.low_pass(1.0, self.input_rate, filter_cutoff, filter_t_width, filter.firdes.WIN_HAMMING) + filtr = filter.freq_xlating_fir_filter_ccf(1, filter_taps, offset, self.input_rate) + return filtr + + def _set_interpolator(self): + interpolator = filter.fractional_resampler_cc(0, self.sps) + return interpolator + + def _set_receiver(self): + receiver = gsm.receiver(self.tuner_callback, self.osr) + return receiver + + def set_center_frequency(self, center_freq): + self.filtr.set_center_freq(center_freq) + + def set_timing(self, timing_offset): + pass + diff --git a/python/receiver_hier.pyc b/python/receiver_hier.pyc Binary files differnew file mode 100644 index 0000000..87bf0d6 --- /dev/null +++ b/python/receiver_hier.pyc |