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
This commit is contained in:
Vasil Velichkov 2019-09-02 04:06:41 +03:00 committed by Piotr Krysik
parent 333027f406
commit 46c90bec99
21 changed files with 53 additions and 92 deletions

View File

@ -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",

View File

@ -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)

View File

@ -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 *
#

View File

@ -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),

View File

@ -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),

View File

@ -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),

View File

@ -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

View File

@ -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__(

View File

@ -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

View File

@ -1,41 +0,0 @@
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# @file
# @author (C) 2016 by Piotr Krysik <ptrkrysik@gmail.com>
# @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)

View File

@ -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")

View File

@ -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),

View File

@ -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__(

View File

@ -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__(

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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):

View File

@ -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

View File

@ -24,7 +24,7 @@
from gnuradio import uhd
from radio_if import RadioInterface
from .radio_if import RadioInterface
class RadioInterfaceUHD(RadioInterface):
# Human-readable description

View File

@ -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.