grgsm_trx: Migrated argument parsing to argparse
Argparse makes adding new parameters easier and adds consistent way of handling default values of parameters and printing of their help info. Change-Id: Idf99fd7a581464aa2f77fe01e721dbd162686811
This commit is contained in:
parent
97dc84e9f3
commit
c62a3d9f55
203
apps/grgsm_trx
203
apps/grgsm_trx
|
@ -4,6 +4,7 @@
|
||||||
# GR-GSM based transceiver
|
# GR-GSM based transceiver
|
||||||
#
|
#
|
||||||
# (C) 2016-2018 by Vadim Yanitskiy <axilirator@gmail.com>
|
# (C) 2016-2018 by Vadim Yanitskiy <axilirator@gmail.com>
|
||||||
|
# (C) 2017-2018 by Piotr Krysik <ptrkrysik@gmail.com>
|
||||||
#
|
#
|
||||||
# All Rights Reserved
|
# All Rights Reserved
|
||||||
#
|
#
|
||||||
|
@ -30,34 +31,40 @@ from gnuradio import eng_notation
|
||||||
from grgsm.trx import ctrl_if_bb
|
from grgsm.trx import ctrl_if_bb
|
||||||
from grgsm.trx import radio_if
|
from grgsm.trx import radio_if
|
||||||
from grgsm.trx import fake_pm
|
from grgsm.trx import fake_pm
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
COPYRIGHT = \
|
COPYRIGHT = \
|
||||||
"Copyright (C) 2016-2018 by Vadim Yanitskiy <axilirator@gmail.com>\n" \
|
"Copyright (C) 2016-2018 by Vadim Yanitskiy <axilirator@gmail.com>\n" \
|
||||||
"Copyright (C) 2017 by Piotr Krysik <ptrkrysik@gmail.com>\n" \
|
"Copyright (C) 2017-2018 by Piotr Krysik <ptrkrysik@gmail.com>\n" \
|
||||||
"License GPLv2+: GNU GPL version 2 or later " \
|
"License GPLv2+: GNU GPL version 2 or later " \
|
||||||
"<http://gnu.org/licenses/gpl.html>\n" \
|
"<http://gnu.org/licenses/gpl.html>\n" \
|
||||||
"This is free software: you are free to change and redistribute it.\n" \
|
"This is free software: you are free to change and redistribute it.\n" \
|
||||||
"There is NO WARRANTY, to the extent permitted by law.\n"
|
"There is NO WARRANTY, to the extent permitted by law.\n"
|
||||||
|
|
||||||
class Application:
|
class grgsm_trx:
|
||||||
# Application variables
|
def __init__(self,
|
||||||
remote_addr = "127.0.0.1"
|
remote_addr,
|
||||||
bind_addr = "0.0.0.0"
|
bind_addr,
|
||||||
base_port = 6700
|
base_port,
|
||||||
|
args,
|
||||||
# PHY specific
|
sample_rate,
|
||||||
phy_sample_rate = 4 * 1625000 / 6
|
rx_gain,
|
||||||
phy_freq_offset_hz = None
|
tx_gain,
|
||||||
phy_tx_antenna = "TX/RX"
|
rx_antenna,
|
||||||
phy_rx_antenna = "RX2"
|
tx_antenna,
|
||||||
phy_rx_gain = 30
|
freq_offset,
|
||||||
phy_tx_gain = 10
|
ppm):
|
||||||
phy_args = ""
|
self.remote_addr = remote_addr
|
||||||
phy_ppm = 0
|
self.bind_addr = bind_addr
|
||||||
|
self.base_port = base_port
|
||||||
def __init__(self):
|
self.phy_args = args
|
||||||
self.print_copyright()
|
self.phy_sample_rate = sample_rate
|
||||||
self.parse_argv()
|
self.phy_rx_gain = rx_gain
|
||||||
|
self.phy_tx_gain = tx_gain
|
||||||
|
self.phy_rx_antenna = rx_antenna
|
||||||
|
self.phy_tx_antenna = tx_antenna
|
||||||
|
self.phy_freq_offset = freq_offset
|
||||||
|
self.phy_ppm = ppm
|
||||||
|
|
||||||
# Set up signal handlers
|
# Set up signal handlers
|
||||||
signal.signal(signal.SIGINT, self.sig_handler)
|
signal.signal(signal.SIGINT, self.sig_handler)
|
||||||
|
@ -66,14 +73,10 @@ class Application:
|
||||||
# Init Radio interface
|
# Init Radio interface
|
||||||
self.radio = radio_if(self.phy_args, self.phy_sample_rate,
|
self.radio = radio_if(self.phy_args, self.phy_sample_rate,
|
||||||
self.phy_rx_gain, self.phy_tx_gain, self.phy_ppm,
|
self.phy_rx_gain, self.phy_tx_gain, self.phy_ppm,
|
||||||
self.phy_rx_antenna, self.phy_tx_antenna,
|
self.phy_rx_antenna, self.phy_tx_antenna, self.phy_freq_offset,
|
||||||
self.bind_addr, self.remote_addr,
|
self.bind_addr, self.remote_addr,
|
||||||
self.base_port)
|
self.base_port)
|
||||||
|
|
||||||
# Optional frequency offset
|
|
||||||
if self.phy_freq_offset_hz is not None:
|
|
||||||
self.radio.freq_offset_hz = self.phy_freq_offset_hz
|
|
||||||
|
|
||||||
# Power measurement emulation
|
# Power measurement emulation
|
||||||
# Noise: -120 .. -105
|
# Noise: -120 .. -105
|
||||||
# BTS: -75 .. -50
|
# BTS: -75 .. -50
|
||||||
|
@ -95,97 +98,73 @@ class Application:
|
||||||
print("[i] Shutting down...")
|
print("[i] Shutting down...")
|
||||||
self.radio.shutdown()
|
self.radio.shutdown()
|
||||||
|
|
||||||
def print_copyright(self):
|
|
||||||
print(COPYRIGHT)
|
|
||||||
|
|
||||||
def print_help(self):
|
|
||||||
s = " Usage: " + sys.argv[0] + " [options]\n\n" \
|
|
||||||
" Some help...\n" \
|
|
||||||
" -h --help this text\n\n"
|
|
||||||
|
|
||||||
# TRX specific
|
|
||||||
s += " TRX interface specific\n" \
|
|
||||||
" -i --remote-addr Set remote address (default %s)\n" \
|
|
||||||
" -b --bind-addr Set bind address (default %s)\n" \
|
|
||||||
" -p --base-port Set base port number (default %d)\n\n"
|
|
||||||
|
|
||||||
# PHY specific
|
|
||||||
s += " Radio interface specific\n" \
|
|
||||||
" -a --device-args Set device arguments\n" \
|
|
||||||
" -s --sample-rate Set sample rate\n" \
|
|
||||||
" -g --rx-gain Set RX gain (default %d)\n" \
|
|
||||||
" -G --tx-gain Set TX gain (default %d)\n" \
|
|
||||||
" --rx-antenna Set RX antenna (default %s)\n" \
|
|
||||||
" --tx-antenna Set TX antenna (default %s)\n" \
|
|
||||||
" --freq-offset Shift baseband freq. (e.g. -500M)\n" \
|
|
||||||
" --ppm Set frequency correction (default %d)\n"
|
|
||||||
|
|
||||||
print(s % (
|
|
||||||
self.remote_addr,
|
|
||||||
self.bind_addr,
|
|
||||||
self.base_port,
|
|
||||||
self.phy_rx_gain,
|
|
||||||
self.phy_tx_gain,
|
|
||||||
self.phy_rx_antenna,
|
|
||||||
self.phy_tx_antenna,
|
|
||||||
self.phy_ppm))
|
|
||||||
|
|
||||||
def parse_argv(self):
|
|
||||||
try:
|
|
||||||
opts, args = getopt.getopt(sys.argv[1:],
|
|
||||||
"i:b:p:a:s:g:G:h",
|
|
||||||
["help", "remote-addr=", "bind-addr=", "base-port=",
|
|
||||||
"device-args=", "sample-rate=", "rx-gain=", "tx-gain=",
|
|
||||||
"ppm=", "rx-antenna=", "tx-antenna=", "freq-offset="])
|
|
||||||
except getopt.GetoptError as err:
|
|
||||||
# Print(help and exit)
|
|
||||||
self.print_help()
|
|
||||||
print("[!] " + str(err))
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
for o, v in opts:
|
|
||||||
if o in ("-h", "--help"):
|
|
||||||
self.print_help()
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
# TRX specific
|
|
||||||
elif o in ("-i", "--remote-addr"):
|
|
||||||
self.remote_addr = v
|
|
||||||
elif o in ("-b", "--bind-addr"):
|
|
||||||
self.bind_addr = v
|
|
||||||
elif o in ("-p", "--base-port"):
|
|
||||||
if int(v) >= 0 and int(v) <= 65535:
|
|
||||||
self.base_port = int(v)
|
|
||||||
else:
|
|
||||||
print("[!] The port number should be in range [0-65536]")
|
|
||||||
sys.exit(2)
|
|
||||||
|
|
||||||
# PHY specific
|
|
||||||
elif o in ("-a", "--device-args"):
|
|
||||||
self.phy_args = v
|
|
||||||
elif o in ("-s", "--sample-rate"):
|
|
||||||
self.phy_sample_rate = int(v)
|
|
||||||
elif o in ("-g", "--rx-gain"):
|
|
||||||
self.phy_rx_gain = int(v)
|
|
||||||
elif o in ("-G", "--tx-gain"):
|
|
||||||
self.phy_tx_gain = int(v)
|
|
||||||
elif o in ("--rx-antenna"):
|
|
||||||
self.phy_rx_antenna = v
|
|
||||||
elif o in ("--tx-antenna"):
|
|
||||||
self.phy_tx_antenna = v
|
|
||||||
elif o in ("--ppm"):
|
|
||||||
self.phy_ppm = int(v)
|
|
||||||
elif o in ("--freq-offset"):
|
|
||||||
# Convert /\d+(\.\d+)?(M|k)?/ to Hz
|
|
||||||
offset_hz = eng_notation.str_to_num(v)
|
|
||||||
self.phy_freq_offset_hz = offset_hz
|
|
||||||
|
|
||||||
def sig_handler(self, signum, frame):
|
def sig_handler(self, signum, frame):
|
||||||
print("Signal %d received" % signum)
|
print("Signal %d received" % signum)
|
||||||
if signum is signal.SIGINT:
|
if signum is signal.SIGINT:
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
def parse_args():
|
||||||
app = Application()
|
description = 'Burst transceiver for GSM Mobile Station'
|
||||||
|
parser = ArgumentParser(prog="grgsm_trx", usage='%(prog)s [options]',
|
||||||
|
description=description)
|
||||||
|
# TRX specific
|
||||||
|
parser.add_argument("-i", "--remote-addr", dest="remote_addr", type=str,
|
||||||
|
default='127.0.0.1',
|
||||||
|
help="Set remote address default=%(default)s")
|
||||||
|
parser.add_argument("-b", "--bind-addr", dest="bind_addr", type=str,
|
||||||
|
default='0.0.0.0',
|
||||||
|
help="Set bind address default=%(default)s")
|
||||||
|
parser.add_argument(
|
||||||
|
"-p", "--base_port", dest="base_port", type=int,
|
||||||
|
default=6700,
|
||||||
|
help="Set base port number default=%(default)s")
|
||||||
|
|
||||||
|
# PHY specific
|
||||||
|
parser.add_argument("-a", "--args", dest="args", type=str,
|
||||||
|
default="",
|
||||||
|
help="Set Device Arguments default=%(default)s")
|
||||||
|
parser.add_argument("-s", "--sample-rate", dest="sample_rate", type=float,
|
||||||
|
default=1083333.3333333333,
|
||||||
|
help="Set samp_rate default=%(default)s")
|
||||||
|
parser.add_argument("-g", "--rx-gain", dest="rx_gain", type=float,
|
||||||
|
default=30,
|
||||||
|
help="Set RX gain default=%(default)s")
|
||||||
|
parser.add_argument("-G", "--tx-gain", dest="tx_gain", type=float,
|
||||||
|
default=10,
|
||||||
|
help="Set TX gain default=%(default)s")
|
||||||
|
parser.add_argument("--rx-antenna", dest="rx_antenna", type=str,
|
||||||
|
default="RX2",
|
||||||
|
help="Set RX antenna")
|
||||||
|
parser.add_argument("--tx-antenna", dest="tx_antenna", type=str,
|
||||||
|
default='TX/RX',
|
||||||
|
help="Set TX antenna default=%(default)s")
|
||||||
|
parser.add_argument(
|
||||||
|
"--freq-offset", dest="freq_offset", type=float,
|
||||||
|
default=0,
|
||||||
|
help="Shift Tx and Rx frequencies default=%(default)s")
|
||||||
|
parser.add_argument("--ppm", dest="ppm", type=float,
|
||||||
|
default=0,
|
||||||
|
help="Set ppm default=%(default)s")
|
||||||
|
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print(COPYRIGHT)
|
||||||
|
options = parse_args()
|
||||||
|
app = grgsm_trx(
|
||||||
|
remote_addr=options.remote_addr,
|
||||||
|
bind_addr=options.bind_addr,
|
||||||
|
base_port=options.base_port,
|
||||||
|
args=options.args,
|
||||||
|
sample_rate=options.sample_rate,
|
||||||
|
rx_gain=options.rx_gain,
|
||||||
|
tx_gain=options.tx_gain,
|
||||||
|
rx_antenna=options.rx_antenna,
|
||||||
|
tx_antenna=options.tx_antenna,
|
||||||
|
freq_offset=options.freq_offset,
|
||||||
|
ppm=options.ppm)
|
||||||
app.run()
|
app.run()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
|
|
|
@ -59,251 +59,252 @@ class dict_toggle_sign(gr.basic_block):
|
||||||
self.message_port_pub(pmt.intern("dict_out"), pmt.to_pmt(d))
|
self.message_port_pub(pmt.intern("dict_out"), pmt.to_pmt(d))
|
||||||
|
|
||||||
class radio_if(gr.top_block):
|
class radio_if(gr.top_block):
|
||||||
# PHY specific variables
|
# PHY specific variables
|
||||||
freq_offset_hz = None
|
rx_freq = 935e6
|
||||||
rx_freq = 935e6
|
tx_freq = 890e6
|
||||||
tx_freq = 890e6
|
osr = 4
|
||||||
osr = 4
|
|
||||||
|
|
||||||
# Application state flags
|
# Application state flags
|
||||||
trx_started = False
|
trx_started = False
|
||||||
|
|
||||||
# GSM timings (in microseconds [uS])
|
# GSM timings (in microseconds [uS])
|
||||||
# One timeslot duration is 576.9 μs = 15/26 ms,
|
# One timeslot duration is 576.9 μs = 15/26 ms,
|
||||||
# or 156.25 symbol periods (a symbol period is 48/13 μs)
|
# or 156.25 symbol periods (a symbol period is 48/13 μs)
|
||||||
GSM_SYM_PERIOD_uS = 48.0 / 13.0
|
GSM_SYM_PERIOD_uS = 48.0 / 13.0
|
||||||
GSM_TS_PERIOD_uS = GSM_SYM_PERIOD_uS * 156.25
|
GSM_TS_PERIOD_uS = GSM_SYM_PERIOD_uS * 156.25
|
||||||
GSM_UL_DL_SHIFT_uS = -(GSM_TS_PERIOD_uS * 3)
|
GSM_UL_DL_SHIFT_uS = -(GSM_TS_PERIOD_uS * 3)
|
||||||
|
|
||||||
# FIXME: shall be measured (automatically?) for
|
# FIXME: shall be measured (automatically?) for
|
||||||
# particular device and particular clock rate.
|
# particular device and particular clock rate.
|
||||||
# The current value is measured for USRP B2X0 at 26e6.
|
# The current value is measured for USRP B2X0 at 26e6.
|
||||||
delay_correction = (285.616 + 2 * GSM_SYM_PERIOD_uS) * 1e-6
|
delay_correction = (285.616 + 2 * GSM_SYM_PERIOD_uS) * 1e-6
|
||||||
|
|
||||||
def __init__(self, phy_args, phy_sample_rate,
|
def __init__(self, phy_args, phy_sample_rate,
|
||||||
phy_rx_gain, phy_tx_gain, phy_ppm,
|
phy_rx_gain, phy_tx_gain, phy_ppm,
|
||||||
phy_rx_antenna, phy_tx_antenna,
|
phy_rx_antenna, phy_tx_antenna,
|
||||||
trx_bind_addr, trx_remote_addr,
|
phy_freq_offset,
|
||||||
trx_base_port):
|
trx_bind_addr, trx_remote_addr,
|
||||||
|
trx_base_port):
|
||||||
|
|
||||||
print("[i] Init Radio interface (L:%s:%u <-> R:%s:%u)"
|
print("[i] Init Radio interface (L:%s:%u <-> R:%s:%u)"
|
||||||
% (trx_bind_addr, trx_base_port + 2,
|
% (trx_bind_addr, trx_base_port + 2,
|
||||||
trx_remote_addr, trx_base_port + 102))
|
trx_remote_addr, trx_base_port + 102))
|
||||||
|
|
||||||
# PHY specific variables
|
# PHY specific variables
|
||||||
self.sample_rate = phy_sample_rate
|
self.sample_rate = phy_sample_rate
|
||||||
self.rx_gain = phy_rx_gain
|
self.rx_gain = phy_rx_gain
|
||||||
self.tx_gain = phy_tx_gain
|
self.tx_gain = phy_tx_gain
|
||||||
self.ppm = phy_ppm
|
self.phy_freq_offset = phy_freq_offset
|
||||||
|
self.ppm = phy_ppm
|
||||||
|
|
||||||
gr.top_block.__init__(self, "GR-GSM TRX")
|
gr.top_block.__init__(self, "GR-GSM TRX")
|
||||||
|
|
||||||
# TRX Burst Interface
|
# TRX Burst Interface
|
||||||
self.trx_burst_if = grgsm.trx_burst_if(
|
self.trx_burst_if = grgsm.trx_burst_if(
|
||||||
trx_bind_addr, trx_remote_addr,
|
trx_bind_addr, trx_remote_addr,
|
||||||
str(trx_base_port))
|
str(trx_base_port))
|
||||||
|
|
||||||
# RX path definition
|
# RX path definition
|
||||||
self.phy_src = uhd.usrp_source(phy_args,
|
self.phy_src = uhd.usrp_source(phy_args,
|
||||||
uhd.stream_args(cpu_format="fc32",
|
uhd.stream_args(cpu_format="fc32",
|
||||||
channels=range(1)))
|
channels=range(1)))
|
||||||
|
|
||||||
self.phy_src.set_clock_rate(26e6, uhd.ALL_MBOARDS)
|
self.phy_src.set_clock_rate(26e6, uhd.ALL_MBOARDS)
|
||||||
self.phy_src.set_center_freq(self.rx_freq, 0)
|
self.phy_src.set_center_freq(self.rx_freq, 0)
|
||||||
self.phy_src.set_antenna(phy_rx_antenna, 0)
|
self.phy_src.set_antenna(phy_rx_antenna, 0)
|
||||||
self.phy_src.set_samp_rate(phy_sample_rate)
|
self.phy_src.set_samp_rate(phy_sample_rate)
|
||||||
self.phy_src.set_bandwidth(650e3, 0)
|
self.phy_src.set_bandwidth(650e3, 0)
|
||||||
self.phy_src.set_gain(phy_rx_gain)
|
self.phy_src.set_gain(phy_rx_gain)
|
||||||
|
|
||||||
self.msg_to_tag_src = grgsm.msg_to_tag()
|
self.msg_to_tag_src = grgsm.msg_to_tag()
|
||||||
|
|
||||||
self.rotator_src = grgsm.controlled_rotator_cc(
|
self.rotator_src = grgsm.controlled_rotator_cc(
|
||||||
self.calc_phase_inc(self.rx_freq))
|
self.calc_phase_inc(self.rx_freq))
|
||||||
|
|
||||||
self.lpf = filter.fir_filter_ccf(1, firdes.low_pass(
|
self.lpf = filter.fir_filter_ccf(1, firdes.low_pass(
|
||||||
1, phy_sample_rate, 125e3, 5e3, firdes.WIN_HAMMING, 6.76))
|
1, phy_sample_rate, 125e3, 5e3, firdes.WIN_HAMMING, 6.76))
|
||||||
|
|
||||||
self.gsm_receiver = grgsm.receiver(self.osr, ([0]), ([]))
|
self.gsm_receiver = grgsm.receiver(self.osr, ([0]), ([]))
|
||||||
|
|
||||||
self.ts_filter = grgsm.burst_timeslot_filter(0)
|
self.ts_filter = grgsm.burst_timeslot_filter(0)
|
||||||
self.ts_filter.set_policy(grgsm.FILTER_POLICY_DROP_ALL)
|
self.ts_filter.set_policy(grgsm.FILTER_POLICY_DROP_ALL)
|
||||||
|
|
||||||
# Connections
|
# Connections
|
||||||
self.connect(
|
self.connect(
|
||||||
(self.phy_src, 0),
|
(self.phy_src, 0),
|
||||||
(self.msg_to_tag_src, 0))
|
(self.msg_to_tag_src, 0))
|
||||||
|
|
||||||
self.connect(
|
self.connect(
|
||||||
(self.msg_to_tag_src, 0),
|
(self.msg_to_tag_src, 0),
|
||||||
(self.rotator_src, 0))
|
(self.rotator_src, 0))
|
||||||
|
|
||||||
self.connect(
|
self.connect(
|
||||||
(self.rotator_src, 0),
|
(self.rotator_src, 0),
|
||||||
(self.lpf, 0))
|
(self.lpf, 0))
|
||||||
|
|
||||||
self.connect(
|
self.connect(
|
||||||
(self.lpf, 0),
|
(self.lpf, 0),
|
||||||
(self.gsm_receiver, 0))
|
(self.gsm_receiver, 0))
|
||||||
|
|
||||||
self.msg_connect(
|
self.msg_connect(
|
||||||
(self.gsm_receiver, 'C0'),
|
(self.gsm_receiver, 'C0'),
|
||||||
(self.ts_filter, 'in'))
|
(self.ts_filter, 'in'))
|
||||||
|
|
||||||
self.msg_connect(
|
self.msg_connect(
|
||||||
(self.ts_filter, 'out'),
|
(self.ts_filter, 'out'),
|
||||||
(self.trx_burst_if, 'bursts'))
|
(self.trx_burst_if, 'bursts'))
|
||||||
|
|
||||||
|
|
||||||
# TX Path Definition
|
# TX Path Definition
|
||||||
self.phy_sink = uhd.usrp_sink(phy_args,
|
self.phy_sink = uhd.usrp_sink(phy_args,
|
||||||
uhd.stream_args(cpu_format="fc32",
|
uhd.stream_args(cpu_format="fc32",
|
||||||
channels=range(1)), "packet_len")
|
channels=range(1)), "packet_len")
|
||||||
|
|
||||||
self.phy_sink.set_clock_rate(26e6, uhd.ALL_MBOARDS)
|
self.phy_sink.set_clock_rate(26e6, uhd.ALL_MBOARDS)
|
||||||
self.phy_sink.set_antenna(phy_tx_antenna, 0)
|
self.phy_sink.set_antenna(phy_tx_antenna, 0)
|
||||||
self.phy_sink.set_samp_rate(phy_sample_rate)
|
self.phy_sink.set_samp_rate(phy_sample_rate)
|
||||||
self.phy_sink.set_center_freq(self.tx_freq, 0)
|
self.phy_sink.set_center_freq(self.tx_freq, 0)
|
||||||
self.phy_sink.set_gain(self.tx_gain)
|
self.phy_sink.set_gain(self.tx_gain)
|
||||||
|
|
||||||
self.tx_time_setter = grgsm.txtime_setter(
|
self.tx_time_setter = grgsm.txtime_setter(
|
||||||
0xffffffff, 0, 0, 0, 0, 0,
|
0xffffffff, 0, 0, 0, 0, 0,
|
||||||
self.delay_correction + self.GSM_UL_DL_SHIFT_uS * 1e-6)
|
self.delay_correction + self.GSM_UL_DL_SHIFT_uS * 1e-6)
|
||||||
|
|
||||||
self.tx_burst_proc = grgsm.preprocess_tx_burst()
|
self.tx_burst_proc = grgsm.preprocess_tx_burst()
|
||||||
|
|
||||||
self.pdu_to_tagged_stream = blocks.pdu_to_tagged_stream(
|
self.pdu_to_tagged_stream = blocks.pdu_to_tagged_stream(
|
||||||
blocks.byte_t, 'packet_len')
|
blocks.byte_t, 'packet_len')
|
||||||
|
|
||||||
self.gmsk_mod = grgsm.gsm_gmsk_mod(
|
self.gmsk_mod = grgsm.gsm_gmsk_mod(
|
||||||
BT = 0.3, pulse_duration = 4, sps = self.osr)
|
BT = 0.3, pulse_duration = 4, sps = self.osr)
|
||||||
|
|
||||||
self.burst_shaper = digital.burst_shaper_cc(
|
self.burst_shaper = digital.burst_shaper_cc(
|
||||||
(firdes.window(firdes.WIN_HANN, 16, 0)),
|
(firdes.window(firdes.WIN_HANN, 16, 0)),
|
||||||
0, 20, False, "packet_len")
|
0, 20, False, "packet_len")
|
||||||
|
|
||||||
self.msg_to_tag_sink = grgsm.msg_to_tag()
|
self.msg_to_tag_sink = grgsm.msg_to_tag()
|
||||||
|
|
||||||
self.rotator_sink = grgsm.controlled_rotator_cc(
|
self.rotator_sink = grgsm.controlled_rotator_cc(
|
||||||
-self.calc_phase_inc(self.tx_freq))
|
-self.calc_phase_inc(self.tx_freq))
|
||||||
|
|
||||||
# Connections
|
# Connections
|
||||||
self.msg_connect(
|
self.msg_connect(
|
||||||
(self.trx_burst_if, 'bursts'),
|
(self.trx_burst_if, 'bursts'),
|
||||||
(self.tx_time_setter, 'bursts_in'))
|
(self.tx_time_setter, 'bursts_in'))
|
||||||
|
|
||||||
self.msg_connect(
|
self.msg_connect(
|
||||||
(self.tx_time_setter, 'bursts_out'),
|
(self.tx_time_setter, 'bursts_out'),
|
||||||
(self.tx_burst_proc, 'bursts_in'))
|
(self.tx_burst_proc, 'bursts_in'))
|
||||||
|
|
||||||
self.msg_connect(
|
self.msg_connect(
|
||||||
(self.tx_burst_proc, 'bursts_out'),
|
(self.tx_burst_proc, 'bursts_out'),
|
||||||
(self.pdu_to_tagged_stream, 'pdus'))
|
(self.pdu_to_tagged_stream, 'pdus'))
|
||||||
|
|
||||||
self.connect(
|
self.connect(
|
||||||
(self.pdu_to_tagged_stream, 0),
|
(self.pdu_to_tagged_stream, 0),
|
||||||
(self.gmsk_mod, 0))
|
(self.gmsk_mod, 0))
|
||||||
|
|
||||||
self.connect(
|
self.connect(
|
||||||
(self.gmsk_mod, 0),
|
(self.gmsk_mod, 0),
|
||||||
(self.burst_shaper, 0))
|
(self.burst_shaper, 0))
|
||||||
|
|
||||||
self.connect(
|
self.connect(
|
||||||
(self.burst_shaper, 0),
|
(self.burst_shaper, 0),
|
||||||
(self.msg_to_tag_sink, 0))
|
(self.msg_to_tag_sink, 0))
|
||||||
|
|
||||||
self.connect(
|
self.connect(
|
||||||
(self.msg_to_tag_sink, 0),
|
(self.msg_to_tag_sink, 0),
|
||||||
(self.rotator_sink, 0))
|
(self.rotator_sink, 0))
|
||||||
|
|
||||||
self.connect(
|
self.connect(
|
||||||
(self.rotator_sink, 0),
|
(self.rotator_sink, 0),
|
||||||
(self.phy_sink, 0))
|
(self.phy_sink, 0))
|
||||||
|
|
||||||
|
|
||||||
# RX & TX synchronization
|
# RX & TX synchronization
|
||||||
self.bt_filter = grgsm.burst_type_filter([3])
|
self.bt_filter = grgsm.burst_type_filter([3])
|
||||||
self.burst_to_fn_time = grgsm.burst_to_fn_time()
|
self.burst_to_fn_time = grgsm.burst_to_fn_time()
|
||||||
|
|
||||||
# Connections
|
# Connections
|
||||||
self.msg_connect(
|
self.msg_connect(
|
||||||
(self.gsm_receiver, 'C0'),
|
(self.gsm_receiver, 'C0'),
|
||||||
(self.bt_filter, 'bursts_in'))
|
(self.bt_filter, 'bursts_in'))
|
||||||
|
|
||||||
self.msg_connect(
|
self.msg_connect(
|
||||||
(self.bt_filter, 'bursts_out'),
|
(self.bt_filter, 'bursts_out'),
|
||||||
(self.burst_to_fn_time, 'bursts_in'))
|
(self.burst_to_fn_time, 'bursts_in'))
|
||||||
|
|
||||||
self.msg_connect(
|
self.msg_connect(
|
||||||
(self.burst_to_fn_time, 'fn_time_out'),
|
(self.burst_to_fn_time, 'fn_time_out'),
|
||||||
(self.tx_time_setter, 'fn_time'))
|
(self.tx_time_setter, 'fn_time'))
|
||||||
|
|
||||||
|
|
||||||
# AFC (Automatic Frequency Correction)
|
# AFC (Automatic Frequency Correction)
|
||||||
self.gsm_clck_ctrl = grgsm.clock_offset_control(
|
self.gsm_clck_ctrl = grgsm.clock_offset_control(
|
||||||
self.rx_freq, phy_sample_rate, osr = self.osr)
|
self.rx_freq, phy_sample_rate, osr = self.osr)
|
||||||
|
|
||||||
self.dict_toggle_sign = dict_toggle_sign()
|
self.dict_toggle_sign = dict_toggle_sign()
|
||||||
|
|
||||||
# Connections
|
# Connections
|
||||||
self.msg_connect(
|
self.msg_connect(
|
||||||
(self.gsm_receiver, 'measurements'),
|
(self.gsm_receiver, 'measurements'),
|
||||||
(self.gsm_clck_ctrl, 'measurements'))
|
(self.gsm_clck_ctrl, 'measurements'))
|
||||||
|
|
||||||
self.msg_connect(
|
self.msg_connect(
|
||||||
(self.gsm_clck_ctrl, 'ctrl'),
|
(self.gsm_clck_ctrl, 'ctrl'),
|
||||||
(self.msg_to_tag_src, 'msg'))
|
(self.msg_to_tag_src, 'msg'))
|
||||||
|
|
||||||
self.msg_connect(
|
self.msg_connect(
|
||||||
(self.gsm_clck_ctrl, 'ctrl'),
|
(self.gsm_clck_ctrl, 'ctrl'),
|
||||||
(self.dict_toggle_sign, 'dict_in'))
|
(self.dict_toggle_sign, 'dict_in'))
|
||||||
|
|
||||||
self.msg_connect(
|
self.msg_connect(
|
||||||
(self.dict_toggle_sign, 'dict_out'),
|
(self.dict_toggle_sign, 'dict_out'),
|
||||||
(self.msg_to_tag_sink, 'msg'))
|
(self.msg_to_tag_sink, 'msg'))
|
||||||
|
|
||||||
|
|
||||||
# Some UHD devices (such as UmTRX) do start the clock
|
# Some UHD devices (such as UmTRX) do start the clock
|
||||||
# not from 0, so it's required to reset it manually.
|
# not from 0, so it's required to reset it manually.
|
||||||
# Resetting UHD source will also affect the sink.
|
# Resetting UHD source will also affect the sink.
|
||||||
self.phy_src.set_time_now(uhd.time_spec(0.0))
|
self.phy_src.set_time_now(uhd.time_spec(0.0))
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
print("[i] Shutdown Radio interface")
|
print("[i] Shutdown Radio interface")
|
||||||
self.stop()
|
self.stop()
|
||||||
self.wait()
|
self.wait()
|
||||||
|
|
||||||
def calc_phase_inc(self, fc):
|
def calc_phase_inc(self, fc):
|
||||||
return self.ppm / 1.0e6 * 2 * pi * fc / self.sample_rate
|
return self.ppm / 1.0e6 * 2 * pi * fc / self.sample_rate
|
||||||
|
|
||||||
def set_rx_freq(self, fc):
|
def set_rx_freq(self, fc):
|
||||||
if self.freq_offset_hz is not None:
|
if self.phy_freq_offset != 0:
|
||||||
fc += self.freq_offset_hz
|
fc += self.phy_freq_offset
|
||||||
print("[#] Shifting RX freq. to %s (offset is %s)"
|
print("[#] Shifting RX freq. to %s (offset is %s)"
|
||||||
% (eng_notation.num_to_str(fc),
|
% (eng_notation.num_to_str(fc),
|
||||||
eng_notation.num_to_str(self.freq_offset_hz)))
|
eng_notation.num_to_str(self.freq_offset)))
|
||||||
self.phy_src.set_center_freq(fc, 0)
|
self.phy_src.set_center_freq(fc, 0)
|
||||||
self.rotator_src.set_phase_inc(self.calc_phase_inc(fc))
|
self.rotator_src.set_phase_inc(self.calc_phase_inc(fc))
|
||||||
self.rx_freq = fc
|
self.rx_freq = fc
|
||||||
|
|
||||||
def set_tx_freq(self, fc):
|
def set_tx_freq(self, fc):
|
||||||
if self.freq_offset_hz is not None:
|
if self.phy_freq_offset != 0:
|
||||||
fc += self.freq_offset_hz
|
fc += self.phy_freq_offset
|
||||||
print("[#] Shifting TX freq. to %s (offset is %s)"
|
print("[#] Shifting TX freq. to %s (offset is %s)"
|
||||||
% (eng_notation.num_to_str(fc),
|
% (eng_notation.num_to_str(fc),
|
||||||
eng_notation.num_to_str(self.freq_offset_hz)))
|
eng_notation.num_to_str(self.freq_offset)))
|
||||||
self.phy_sink.set_center_freq(fc, 0)
|
self.phy_sink.set_center_freq(fc, 0)
|
||||||
self.rotator_sink.set_phase_inc(-self.calc_phase_inc(fc))
|
self.rotator_sink.set_phase_inc(-self.calc_phase_inc(fc))
|
||||||
self.tx_freq = fc
|
self.tx_freq = fc
|
||||||
|
|
||||||
def set_rx_gain(self, gain):
|
def set_rx_gain(self, gain):
|
||||||
self.phy_src.set_gain(gain, 0)
|
self.phy_src.set_gain(gain, 0)
|
||||||
self.rx_gain = gain
|
self.rx_gain = gain
|
||||||
|
|
||||||
def set_tx_gain(self, gain):
|
def set_tx_gain(self, gain):
|
||||||
self.phy_sink.set_gain(gain, 0)
|
self.phy_sink.set_gain(gain, 0)
|
||||||
self.tx_gain = gain
|
self.tx_gain = gain
|
||||||
|
|
||||||
def set_ta(self, ta):
|
def set_ta(self, ta):
|
||||||
print("[i] Setting TA value %d" % ta)
|
print("[i] Setting TA value %d" % ta)
|
||||||
advance_time_sec = ta * self.GSM_SYM_PERIOD_uS * 1e-6
|
advance_time_sec = ta * self.GSM_SYM_PERIOD_uS * 1e-6
|
||||||
self.tx_time_setter.set_timing_advance(advance_time_sec)
|
self.tx_time_setter.set_timing_advance(advance_time_sec)
|
||||||
|
|
Loading…
Reference in New Issue