From bf8a3a4e67701d992ace4e76650b5d2142ab9fd2 Mon Sep 17 00:00:00 2001 From: Vasil Velichkov Date: Mon, 2 Sep 2019 04:06:41 +0300 Subject: Various python3 related changes - Use relative import for grgsm's modules - Convert map to list - Remove the hier_block.py workaround as as gnuradio 3.7 is no longer supported in this branch Change-Id: I5ca8fd340823996e8c444aaf18ddacd85c92ab1c --- apps/grgsm_decode | 2 +- apps/grgsm_scanner | 26 ++++++++------ python/__init__.py | 23 ++++++------ python/demapping/gsm_bcch_ccch_demapper.py | 4 +-- python/demapping/gsm_bcch_ccch_sdcch4_demapper.py | 4 +-- python/demapping/gsm_sdcch8_demapper.py | 4 +-- python/misc_utils/CMakeLists.txt | 1 - python/misc_utils/clock_offset_corrector_tagged.py | 2 +- python/misc_utils/device.py | 2 +- python/misc_utils/hier_block.py | 41 ---------------------- python/qa_txtime_bursts_tagger.py | 4 +-- python/receiver/fcch_detector.py | 4 +-- python/receiver/gsm_input.py | 2 +- python/transmitter/gsm_gmsk_mod.py | 2 +- python/transmitter/txtime_bursts_tagger.py | 2 +- python/trx/__init__.py | 12 +++---- python/trx/ctrl_if.py | 2 +- python/trx/ctrl_if_bb.py | 2 +- python/trx/radio_if.py | 2 +- python/trx/radio_if_uhd.py | 2 +- python/trx/transceiver.py | 2 +- 21 files changed, 53 insertions(+), 92 deletions(-) delete mode 100644 python/misc_utils/hier_block.py diff --git a/apps/grgsm_decode b/apps/grgsm_decode index 4bd1d95..034014e 100755 --- a/apps/grgsm_decode +++ b/apps/grgsm_decode @@ -336,7 +336,7 @@ if __name__ == '__main__': parser, 'TCH Options', 'Options for setting Traffic channel decoding parameters.', ) tch_options.add_option("-d", "--speech-codec", dest="speech_codec", default='FR', - type='choice', choices=tch_codecs.keys(), + type='choice', choices=list(tch_codecs.keys()), help="TCH-F speech codec [default=%default]. " "Valid options are " + ", ".join(tch_codecs.keys())) tch_options.add_option("-o", "--output-tch", dest="speech_output_file", default="/tmp/speech.au.gsm", diff --git a/apps/grgsm_scanner b/apps/grgsm_scanner index ce33a60..e3d7a61 100755 --- a/apps/grgsm_scanner +++ b/apps/grgsm_scanner @@ -40,9 +40,9 @@ import sys # from wideband_receiver import * -class receiver_with_decoder(grgsm.hier_block): +class receiver_with_decoder(gr.hier_block2): def __init__(self, OSR=4, chan_num=0, fc=939.4e6, ppm=0, samp_rate=0.2e6): - grgsm.hier_block.__init__( + gr.hier_block2.__init__( self, "Receiver With Decoder", gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(0, 0, 0), @@ -132,9 +132,9 @@ class receiver_with_decoder(grgsm.hier_block): self.samp_rate_out = samp_rate_out -class wideband_receiver(grgsm.hier_block): +class wideband_receiver(gr.hier_block2): def __init__(self, OSR=4, fc=939.4e6, samp_rate=0.4e6): - grgsm.hier_block.__init__( + gr.hier_block2.__init__( self, "Wideband receiver", gr.io_signature(1, 1, gr.sizeof_gr_complex * 1), gr.io_signature(0, 0, 0), @@ -168,14 +168,14 @@ class wideband_receiver(grgsm.hier_block): # Connections ################################################## self.connect((self, 0), (self.pfb_channelizer_ccf_0, 0)) - for chan in xrange(0, self.channels_num): + for chan in range(0, self.channels_num): self.connect((self.pfb_channelizer_ccf_0, chan), (self.receivers_with_decoders[chan], 0)) self.msg_connect(self.receivers_with_decoders[chan], 'bursts', self, 'bursts') self.msg_connect(self.receivers_with_decoders[chan], 'msgs', self, 'msgs') def create_receivers(self): self.receivers_with_decoders = {} - for chan in xrange(0, self.channels_num): + for chan in range(0, self.channels_num): self.receivers_with_decoders[chan] = receiver_with_decoder(fc=self.fc, OSR=self.OSR, chan_num=chan, samp_rate=self.OSR_PFB * 0.2e6) @@ -207,7 +207,7 @@ class wideband_scanner(gr.top_block): self.ppm = ppm # if no file name is given process data from rtl_sdr source - print "Args=", args + print("Args=", args) self.rtlsdr_source = osmosdr.source(args="numchan=" + str(1) + " " + str(grgsm.device.get_default_args(args))) #self.rtlsdr_source.set_min_output_buffer(int(sample_rate*rec_len)) #this line causes segfaults on HackRF @@ -261,6 +261,10 @@ class channel_info(object): self.neighbours = neighbours self.cell_arfcns = cell_arfcns + def __lt__(self, other): + return self.arfcn < other.arfcn + + def get_verbose_info(self): i = " |---- Configuration: %s\n" % self.get_ccch_conf() i += " |---- Cell ARFCNs: " + ", ".join(map(str, self.cell_arfcns)) + "\n" @@ -315,7 +319,7 @@ def do_scan(samp_rate, band, speed, ppm, gain, args, prn = None, debug = False): if not debug: # silence rtl_sdr output: # open 2 fds - null_fds = [os.open(os.devnull, os.O_RDWR) for x in xrange(2)] + null_fds = [os.open(os.devnull, os.O_RDWR) for x in range(2)] # save the current file descriptors to a tuple save = os.dup(1), os.dup(2) # put /dev/null fds on 1 and 2 @@ -423,10 +427,10 @@ def main(options = None): def printfunc(found_list): for info in sorted(found_list): - print info + print(info) if options.verbose: - print info.get_verbose_info() - print "" + print(info.get_verbose_info()) + print("") do_scan(options.samp_rate, options.band, options.speed, options.ppm, options.gain, options.args, prn = printfunc, debug = options.debug) diff --git a/python/__init__.py b/python/__init__.py index 8241b01..557a8d6 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -42,24 +42,23 @@ if _RTLD_GLOBAL != 0: # import swig generated symbols into the gsm namespace -from grgsm_swig import * +from .grgsm_swig import * # import any pure python here -from hier_block import hier_block #from fcch_burst_tagger import fcch_burst_tagger #from sch_detector import sch_detector #from fcch_detector import fcch_detector -from clock_offset_corrector_tagged import clock_offset_corrector_tagged -from gsm_input import gsm_input -from gsm_bcch_ccch_demapper import gsm_bcch_ccch_demapper -from gsm_bcch_ccch_sdcch4_demapper import gsm_bcch_ccch_sdcch4_demapper -from gsm_sdcch8_demapper import gsm_sdcch8_demapper -from gsm_gmsk_mod import gsm_gmsk_mod -from fn_time import * -from txtime_bursts_tagger import * -import arfcn -import device +from .clock_offset_corrector_tagged import clock_offset_corrector_tagged +from .gsm_input import gsm_input +from .gsm_bcch_ccch_demapper import gsm_bcch_ccch_demapper +from .gsm_bcch_ccch_sdcch4_demapper import gsm_bcch_ccch_sdcch4_demapper +from .gsm_sdcch8_demapper import gsm_sdcch8_demapper +from .gsm_gmsk_mod import gsm_gmsk_mod +from .fn_time import * +from .txtime_bursts_tagger import * +from .arfcn import * +from .device import * # diff --git a/python/demapping/gsm_bcch_ccch_demapper.py b/python/demapping/gsm_bcch_ccch_demapper.py index e036831..06baa62 100644 --- a/python/demapping/gsm_bcch_ccch_demapper.py +++ b/python/demapping/gsm_bcch_ccch_demapper.py @@ -32,10 +32,10 @@ from gnuradio.filter import firdes import grgsm -class gsm_bcch_ccch_demapper(grgsm.hier_block): +class gsm_bcch_ccch_demapper(gr.hier_block2): def __init__(self, timeslot_nr=0): - grgsm.hier_block.__init__( + gr.hier_block2.__init__( self, "BCCH + CCCH demapper", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0), diff --git a/python/demapping/gsm_bcch_ccch_sdcch4_demapper.py b/python/demapping/gsm_bcch_ccch_sdcch4_demapper.py index bff67a4..f025a70 100644 --- a/python/demapping/gsm_bcch_ccch_sdcch4_demapper.py +++ b/python/demapping/gsm_bcch_ccch_sdcch4_demapper.py @@ -32,10 +32,10 @@ from gnuradio.filter import firdes import grgsm -class gsm_bcch_ccch_sdcch4_demapper(grgsm.hier_block): +class gsm_bcch_ccch_sdcch4_demapper(gr.hier_block2): def __init__(self, timeslot_nr=0): - grgsm.hier_block.__init__( + gr.hier_block2.__init__( self, "BCCH + CCCH + SDCCH/4 demapper", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0), diff --git a/python/demapping/gsm_sdcch8_demapper.py b/python/demapping/gsm_sdcch8_demapper.py index b412594..30450bf 100644 --- a/python/demapping/gsm_sdcch8_demapper.py +++ b/python/demapping/gsm_sdcch8_demapper.py @@ -32,10 +32,10 @@ from gnuradio.filter import firdes import grgsm -class gsm_sdcch8_demapper(grgsm.hier_block): +class gsm_sdcch8_demapper(gr.hier_block2): def __init__(self, timeslot_nr=1): - grgsm.hier_block.__init__( + gr.hier_block2.__init__( self, "SDCCH/8 demapper", gr.io_signature(0, 0, 0), gr.io_signature(0, 0, 0), diff --git a/python/misc_utils/CMakeLists.txt b/python/misc_utils/CMakeLists.txt index 76304ca..57ed275 100644 --- a/python/misc_utils/CMakeLists.txt +++ b/python/misc_utils/CMakeLists.txt @@ -21,7 +21,6 @@ GR_PYTHON_INSTALL( FILES arfcn.py clock_offset_corrector_tagged.py - hier_block.py fn_time.py device.py DESTINATION ${GR_PYTHON_DIR}/grgsm diff --git a/python/misc_utils/clock_offset_corrector_tagged.py b/python/misc_utils/clock_offset_corrector_tagged.py index be55212..ea474b1 100644 --- a/python/misc_utils/clock_offset_corrector_tagged.py +++ b/python/misc_utils/clock_offset_corrector_tagged.py @@ -33,7 +33,7 @@ import grgsm import math -class clock_offset_corrector_tagged(grgsm.hier_block): +class clock_offset_corrector_tagged(gr.hier_block2): def __init__(self, fc=936.6e6, osr=4, ppm=0, samp_rate_in=1625000.0/6.0*4.0): gr.hier_block2.__init__( diff --git a/python/misc_utils/device.py b/python/misc_utils/device.py index de967ab..ddd9dec 100644 --- a/python/misc_utils/device.py +++ b/python/misc_utils/device.py @@ -40,7 +40,7 @@ def exclude(devices, filters = ({'driver': 'audio'},)): return [dev for dev in devices if not match(dev, filters)] def get_all_args(hint="nofake"): - return map(lambda dev: dev.to_string(), exclude(get_devices(hint))) + return list(map(lambda dev: dev.to_string(), exclude(get_devices(hint)))) def get_default_args(args): # The presence of GRC_BLOCKS_PATH environment variable indicates that diff --git a/python/misc_utils/hier_block.py b/python/misc_utils/hier_block.py deleted file mode 100644 index 0dc9c78..0000000 --- a/python/misc_utils/hier_block.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python2 -# -*- coding: utf-8 -*- -# @file -# @author (C) 2016 by Piotr Krysik -# @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 gr -from distutils.version import LooseVersion as version - -#class created to solve incompatibility of reginstration of message inputs -#that was introduced in gnuradio 3.7.9 - -class hier_block(gr.hier_block2): - def message_port_register_hier_in(self, port_id): - if version(gr.version()) >= version('3.7.9'): - super(hier_block, self).message_port_register_hier_in(port_id) - else: - super(hier_block, self).message_port_register_hier_out(port_id) - - def message_port_register_hier_out(self, port_id): - if version(gr.version()) >= version('3.7.9'): - super(hier_block, self).message_port_register_hier_out(port_id) - else: - super(hier_block, self).message_port_register_hier_in(port_id) - diff --git a/python/qa_txtime_bursts_tagger.py b/python/qa_txtime_bursts_tagger.py index bdbf1af..fd15b10 100755 --- a/python/qa_txtime_bursts_tagger.py +++ b/python/qa_txtime_bursts_tagger.py @@ -64,8 +64,8 @@ class qa_txtime_bursts_tagger (gr_unittest.TestCase): tb.start() tb.wait() - print "Dupa" - print sink + print("Dupa") + print(sink) # msg1 = make_msg(1,"lol1") diff --git a/python/receiver/fcch_detector.py b/python/receiver/fcch_detector.py index 81438e2..9b787c2 100644 --- a/python/receiver/fcch_detector.py +++ b/python/receiver/fcch_detector.py @@ -36,10 +36,10 @@ from gnuradio import gr from gnuradio.filter import firdes import grgsm -class fcch_detector(grgsm.hier_block): +class fcch_detector(gr.hier_block2): def __init__(self, OSR=4): - grgsm.hier_block.__init__( + gr.hier_block2.__init__( self, "FCCH bursts detector", gr.io_signature(1, 1, gr.sizeof_gr_complex*1), gr.io_signature(1, 1, gr.sizeof_gr_complex*1), diff --git a/python/receiver/gsm_input.py b/python/receiver/gsm_input.py index 8c4ad51..05e323d 100644 --- a/python/receiver/gsm_input.py +++ b/python/receiver/gsm_input.py @@ -33,7 +33,7 @@ from gnuradio.filter import firdes import grgsm -class gsm_input(grgsm.hier_block): +class gsm_input(gr.hier_block2): def __init__(self, fc=940e6, osr=4, ppm=0, samp_rate_in=1e6): gr.hier_block2.__init__( diff --git a/python/transmitter/gsm_gmsk_mod.py b/python/transmitter/gsm_gmsk_mod.py index e8ecc7a..fec936c 100644 --- a/python/transmitter/gsm_gmsk_mod.py +++ b/python/transmitter/gsm_gmsk_mod.py @@ -14,7 +14,7 @@ from gnuradio.analog import cpm from gnuradio.filter import firdes import grgsm -class gsm_gmsk_mod(grgsm.hier_block): +class gsm_gmsk_mod(gr.hier_block2): def __init__(self, BT=4, pulse_duration=4, sps=4): gr.hier_block2.__init__( diff --git a/python/transmitter/txtime_bursts_tagger.py b/python/transmitter/txtime_bursts_tagger.py index de42f65..952c8d1 100644 --- a/python/transmitter/txtime_bursts_tagger.py +++ b/python/transmitter/txtime_bursts_tagger.py @@ -22,7 +22,7 @@ # from gnuradio import gr -from fn_time import fn_time_delta +from .fn_time import fn_time_delta import pmt import numpy diff --git a/python/trx/__init__.py b/python/trx/__init__.py index c8bddbe..23042b0 100644 --- a/python/trx/__init__.py +++ b/python/trx/__init__.py @@ -20,10 +20,10 @@ This is a set of helper classes for the grgsm_trx application. ''' -from udp_link import UDPLink -from ctrl_if import CTRLInterface -from ctrl_if_bb import CTRLInterfaceBB -from radio_if import RadioInterface -from transceiver import Transceiver +from .udp_link import UDPLink +from .ctrl_if import CTRLInterface +from .ctrl_if_bb import CTRLInterfaceBB +from .radio_if import RadioInterface +from .transceiver import Transceiver -from dict_toggle_sign import dict_toggle_sign +from .dict_toggle_sign import dict_toggle_sign diff --git a/python/trx/ctrl_if.py b/python/trx/ctrl_if.py index 1a7c0c3..d7e14f1 100644 --- a/python/trx/ctrl_if.py +++ b/python/trx/ctrl_if.py @@ -22,7 +22,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -from udp_link import UDPLink +from .udp_link import UDPLink class CTRLInterface(UDPLink): def handle_rx(self, data, remote): diff --git a/python/trx/ctrl_if_bb.py b/python/trx/ctrl_if_bb.py index 4814263..1c21c55 100644 --- a/python/trx/ctrl_if_bb.py +++ b/python/trx/ctrl_if_bb.py @@ -22,7 +22,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -from ctrl_if import CTRLInterface +from .ctrl_if import CTRLInterface class CTRLInterfaceBB(CTRLInterface): def __init__(self, trx, *ctrl_if_args): diff --git a/python/trx/radio_if.py b/python/trx/radio_if.py index 0d844c0..acbc3cd 100644 --- a/python/trx/radio_if.py +++ b/python/trx/radio_if.py @@ -38,7 +38,7 @@ from gnuradio import gr from gnuradio import filter from gnuradio.filter import firdes -from dict_toggle_sign import dict_toggle_sign +from .dict_toggle_sign import dict_toggle_sign class RadioInterface(gr.top_block): # PHY specific variables diff --git a/python/trx/radio_if_uhd.py b/python/trx/radio_if_uhd.py index ef2e0ed..664a51c 100644 --- a/python/trx/radio_if_uhd.py +++ b/python/trx/radio_if_uhd.py @@ -24,7 +24,7 @@ from gnuradio import uhd -from radio_if import RadioInterface +from .radio_if import RadioInterface class RadioInterfaceUHD(RadioInterface): # Human-readable description diff --git a/python/trx/transceiver.py b/python/trx/transceiver.py index 837a61f..4e706e3 100644 --- a/python/trx/transceiver.py +++ b/python/trx/transceiver.py @@ -22,7 +22,7 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -from ctrl_if_bb import CTRLInterfaceBB +from .ctrl_if_bb import CTRLInterfaceBB class Transceiver: """ Base transceiver implementation. -- cgit v1.2.3