blob: cb809ed147e23e190b015a1b1bfe35eeba991f0a [file] [log] [blame]
Vadim Yanitskiy89e1ad12019-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):
Vadim Yanitskiydbb3daae2019-01-19 12:14:28 +070030 # Human-readable description
31 def __str__(self):
32 return "UHD"
33
Vadim Yanitskiy89e1ad12019-01-19 11:55:01 +070034 def phy_init_source(self):
35 self._phy_src = uhd.usrp_source(self.phy_args,
36 uhd.stream_args(cpu_format = "fc32",
37 channels = range(1)))
38
39 self._phy_src.set_clock_rate(26e6, uhd.ALL_MBOARDS)
40 self._phy_src.set_antenna(self.rx_antenna, 0)
41 self._phy_src.set_samp_rate(self.sample_rate)
42 self._phy_src.set_bandwidth(650e3, 0)
43 self._phy_src.set_gain(self.rx_gain)
44
45 # Some UHD devices (such as UmTRX) do start the clock
46 # not from 0, so it's required to reset it manually.
47 # Resetting UHD source will also affect the sink.
48 self._phy_src.set_time_now(uhd.time_spec(0.0))
49
50 def phy_init_sink(self):
51 self._phy_sink = uhd.usrp_sink(self.phy_args,
52 uhd.stream_args(cpu_format = "fc32",
53 channels = range(1)), "packet_len")
54
55 self._phy_sink.set_clock_rate(26e6, uhd.ALL_MBOARDS)
56 self._phy_sink.set_antenna(self.tx_antenna, 0)
57 self._phy_sink.set_samp_rate(self.sample_rate)
58 self._phy_sink.set_gain(self.tx_gain)
59
60 def phy_set_rx_freq(self, freq):
61 self._phy_src.set_center_freq(freq, 0)
62
63 def phy_set_tx_freq(self, freq):
64 self._phy_sink.set_center_freq(freq, 0)
65
66 def phy_set_rx_gain(self, gain):
67 self._phy_src.set_gain(gain, 0)
68
69 def phy_set_tx_gain(self, gain):
70 self._phy_sink.set_gain(gain, 0)