blob: b431fb642ee87ed9831d71931a1fb1b888673d18 [file] [log] [blame]
Vadim Yanitskiy6ee957f2019-01-19 11:55:01 +07001#!/usr/bin/env python2
2# -*- coding: utf-8 -*-
3
4# GR-GSM based transceiver
5# Radio interface for UHD devices
6#
7# (C) 2019 by Vadim Yanitskiy <axilirator@gmail.com>
8#
9# All Rights Reserved
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 2 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License along
22# with this program; if not, write to the Free Software Foundation, Inc.,
23# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24
25from gnuradio import uhd
26
27from radio_if import RadioInterface
28
29class RadioInterfaceUHD(RadioInterface):
30 @property
31 def phy_proc_delay(self):
32 # FIXME: shall be measured (automatically?) for
33 # particular device and particular clock rate.
34 # The current value is measured for USRP B2X0 at 26e6.
35 return (285.616 + 2 * self.GSM_SYM_PERIOD_uS) * 1e-6
36
37 def phy_init_source(self):
38 self._phy_src = uhd.usrp_source(self.phy_args,
39 uhd.stream_args(cpu_format = "fc32",
40 channels = range(1)))
41
42 self._phy_src.set_clock_rate(26e6, uhd.ALL_MBOARDS)
43 self._phy_src.set_antenna(self.rx_antenna, 0)
44 self._phy_src.set_samp_rate(self.sample_rate)
45 self._phy_src.set_bandwidth(650e3, 0)
46 self._phy_src.set_gain(self.rx_gain)
47
48 # Some UHD devices (such as UmTRX) do start the clock
49 # not from 0, so it's required to reset it manually.
50 # Resetting UHD source will also affect the sink.
51 self._phy_src.set_time_now(uhd.time_spec(0.0))
52
53 def phy_init_sink(self):
54 self._phy_sink = uhd.usrp_sink(self.phy_args,
55 uhd.stream_args(cpu_format = "fc32",
56 channels = range(1)), "packet_len")
57
58 self._phy_sink.set_clock_rate(26e6, uhd.ALL_MBOARDS)
59 self._phy_sink.set_antenna(self.tx_antenna, 0)
60 self._phy_sink.set_samp_rate(self.sample_rate)
61 self._phy_sink.set_gain(self.tx_gain)
62
63 def phy_set_rx_freq(self, freq):
64 self._phy_src.set_center_freq(freq, 0)
65
66 def phy_set_tx_freq(self, freq):
67 self._phy_sink.set_center_freq(freq, 0)
68
69 def phy_set_rx_gain(self, gain):
70 self._phy_src.set_gain(gain, 0)
71
72 def phy_set_tx_gain(self, gain):
73 self._phy_sink.set_gain(gain, 0)