Vadim Yanitskiy | 6ee957f | 2019-01-19 11:55:01 +0700 | [diff] [blame] | 1 | #!/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 | |
| 25 | from gnuradio import uhd |
| 26 | |
| 27 | from radio_if import RadioInterface |
| 28 | |
| 29 | class RadioInterfaceUHD(RadioInterface): |
Vadim Yanitskiy | 2520380 | 2019-01-19 12:14:28 +0700 | [diff] [blame] | 30 | # Human-readable description |
| 31 | def __str__(self): |
| 32 | return "UHD" |
| 33 | |
Vadim Yanitskiy | 6ee957f | 2019-01-19 11:55:01 +0700 | [diff] [blame] | 34 | @property |
| 35 | def phy_proc_delay(self): |
| 36 | # FIXME: shall be measured (automatically?) for |
| 37 | # particular device and particular clock rate. |
| 38 | # The current value is measured for USRP B2X0 at 26e6. |
| 39 | return (285.616 + 2 * self.GSM_SYM_PERIOD_uS) * 1e-6 |
| 40 | |
| 41 | def phy_init_source(self): |
| 42 | self._phy_src = uhd.usrp_source(self.phy_args, |
| 43 | uhd.stream_args(cpu_format = "fc32", |
| 44 | channels = range(1))) |
| 45 | |
| 46 | self._phy_src.set_clock_rate(26e6, uhd.ALL_MBOARDS) |
| 47 | self._phy_src.set_antenna(self.rx_antenna, 0) |
| 48 | self._phy_src.set_samp_rate(self.sample_rate) |
| 49 | self._phy_src.set_bandwidth(650e3, 0) |
| 50 | self._phy_src.set_gain(self.rx_gain) |
| 51 | |
| 52 | # Some UHD devices (such as UmTRX) do start the clock |
| 53 | # not from 0, so it's required to reset it manually. |
| 54 | # Resetting UHD source will also affect the sink. |
| 55 | self._phy_src.set_time_now(uhd.time_spec(0.0)) |
| 56 | |
| 57 | def phy_init_sink(self): |
| 58 | self._phy_sink = uhd.usrp_sink(self.phy_args, |
| 59 | uhd.stream_args(cpu_format = "fc32", |
| 60 | channels = range(1)), "packet_len") |
| 61 | |
| 62 | self._phy_sink.set_clock_rate(26e6, uhd.ALL_MBOARDS) |
| 63 | self._phy_sink.set_antenna(self.tx_antenna, 0) |
| 64 | self._phy_sink.set_samp_rate(self.sample_rate) |
| 65 | self._phy_sink.set_gain(self.tx_gain) |
| 66 | |
| 67 | def phy_set_rx_freq(self, freq): |
| 68 | self._phy_src.set_center_freq(freq, 0) |
| 69 | |
| 70 | def phy_set_tx_freq(self, freq): |
| 71 | self._phy_sink.set_center_freq(freq, 0) |
| 72 | |
| 73 | def phy_set_rx_gain(self, gain): |
| 74 | self._phy_src.set_gain(gain, 0) |
| 75 | |
| 76 | def phy_set_tx_gain(self, gain): |
| 77 | self._phy_sink.set_gain(gain, 0) |