Change in gr-gsm[master]: python/trx: fork RadioInterfaceUHD from RadioInterface

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Piotr Krysik gerrit-no-reply at lists.osmocom.org
Tue Feb 5 12:10:38 UTC 2019


Piotr Krysik has submitted this change and it was merged. ( https://gerrit.osmocom.org/12673 )

Change subject: python/trx: fork RadioInterfaceUHD from RadioInterface
......................................................................

python/trx: fork RadioInterfaceUHD from RadioInterface

Change-Id: I1644a3f6b8da0d5f2a1a133058269e5383948fda
---
M apps/grgsm_trx
M python/trx/CMakeLists.txt
M python/trx/__init__.py
M python/trx/radio_if.py
A python/trx/radio_if_uhd.py
5 files changed, 97 insertions(+), 36 deletions(-)

Approvals:
  Piotr Krysik: Looks good to me, approved; Verified



diff --git a/apps/grgsm_trx b/apps/grgsm_trx
index 5e5e3be..b911719 100755
--- a/apps/grgsm_trx
+++ b/apps/grgsm_trx
@@ -29,6 +29,7 @@
 from argparse import ArgumentTypeError
 from gnuradio import eng_notation
 
+from grgsm.trx import RadioInterfaceUHD
 from grgsm.trx import RadioInterface
 from grgsm.trx import Transceiver
 
@@ -58,7 +59,7 @@
 		signal.signal(signal.SIGINT, self.sig_handler)
 
 		# Init Radio interface
-		self.radio = RadioInterface(self.phy_args, self.phy_sample_rate,
+		self.radio = RadioInterfaceUHD(self.phy_args, self.phy_sample_rate,
 			self.phy_rx_gain, self.phy_tx_gain, self.phy_ppm,
 			self.phy_rx_antenna, self.phy_tx_antenna,
 			self.phy_freq_offset, self.bind_addr,
diff --git a/python/trx/CMakeLists.txt b/python/trx/CMakeLists.txt
index 11290f3..dbb3daa9 100644
--- a/python/trx/CMakeLists.txt
+++ b/python/trx/CMakeLists.txt
@@ -24,6 +24,7 @@
     ctrl_if.py
     ctrl_if_bb.py
     radio_if.py
+    radio_if_uhd.py
     radio_if_grc.py
     transceiver.py
     dict_toggle_sign.py
diff --git a/python/trx/__init__.py b/python/trx/__init__.py
index 00d370b..17ff9d7 100644
--- a/python/trx/__init__.py
+++ b/python/trx/__init__.py
@@ -25,6 +25,7 @@
 from ctrl_if_bb import CTRLInterfaceBB
 from radio_if_grc import RadioInterfaceGRC
 from radio_if import RadioInterface
+from radio_if import RadioInterfaceUHD
 from transceiver import Transceiver
 
 from dict_toggle_sign import dict_toggle_sign
diff --git a/python/trx/radio_if.py b/python/trx/radio_if.py
index 4c678e7..c4d4bd1 100644
--- a/python/trx/radio_if.py
+++ b/python/trx/radio_if.py
@@ -2,7 +2,7 @@
 # -*- coding: utf-8 -*-
 
 # GR-GSM based transceiver
-# Follow graph implementation
+# Generic (device independent) flow-graph implementation
 #
 # (C) 2016-2019 by Vadim Yanitskiy <axilirator at gmail.com>
 # (C) 2017      by Piotr Krysik <ptrkrysik at gmail.com>
@@ -33,7 +33,6 @@
 from gnuradio import eng_notation
 from gnuradio import digital
 from gnuradio import blocks
-from gnuradio import uhd
 from gnuradio import gr
 
 from gnuradio import filter
@@ -57,11 +56,6 @@
 	GSM_SYM_RATE = (1.0 / GSM_SYM_PERIOD_uS) * 1e6
 	SAMPLE_RATE = GSM_SYM_RATE * osr
 
-	# FIXME: shall be measured (automatically?) for
-	# particular device and particular clock rate.
-	# The current value is measured for USRP B2X0 at 26e6.
-	delay_correction = (285.616 + 2 * GSM_SYM_PERIOD_uS) * 1e-6
-
 	# Dummy freq. value that is used during initialization
 	# basically, the DL freq. of ARFCN 0
 	DUMMY_FREQ = 935e6
@@ -83,6 +77,10 @@
 		self.ppm = phy_ppm
 		self.freq_offset = phy_freq_offset
 
+		self.phy_args = phy_args
+		self.rx_antenna = phy_rx_antenna
+		self.tx_antenna = phy_tx_antenna
+
 		gr.top_block.__init__(self, "GR-GSM TRX")
 
 		# TRX Burst Interface
@@ -91,15 +89,7 @@
 			str(trx_base_port))
 
 		# RX path definition
-		self.phy_src = uhd.usrp_source(phy_args,
-			uhd.stream_args(cpu_format="fc32",
-				channels=range(1)))
-
-		self.phy_src.set_clock_rate(26e6, uhd.ALL_MBOARDS)
-		self.phy_src.set_antenna(phy_rx_antenna, 0)
-		self.phy_src.set_samp_rate(phy_sample_rate)
-		self.phy_src.set_bandwidth(650e3, 0)
-		self.phy_src.set_gain(phy_rx_gain)
+		self.phy_init_source()
 
 		self.msg_to_tag_src = grgsm.msg_to_tag()
 
@@ -115,7 +105,7 @@
 
 		# Connections
 		self.connect(
-			(self.phy_src, 0),
+			(self._phy_src, 0),
 			(self.msg_to_tag_src, 0))
 
 		self.connect(
@@ -140,18 +130,11 @@
 
 
 		# TX Path Definition
-		self.phy_sink = uhd.usrp_sink(phy_args,
-			uhd.stream_args(cpu_format="fc32",
-				channels=range(1)), "packet_len")
-
-		self.phy_sink.set_clock_rate(26e6, uhd.ALL_MBOARDS)
-		self.phy_sink.set_antenna(phy_tx_antenna, 0)
-		self.phy_sink.set_samp_rate(phy_sample_rate)
-		self.phy_sink.set_gain(self.tx_gain)
+		self.phy_init_sink()
 
 		self.tx_time_setter = grgsm.txtime_setter(
 			0xffffffff, 0, 0, 0, 0, 0,
-			self.delay_correction + self.GSM_UL_DL_SHIFT_uS * 1e-6)
+			self.phy_proc_delay + self.GSM_UL_DL_SHIFT_uS * 1e-6)
 
 		self.tx_burst_proc = grgsm.preprocess_tx_burst()
 
@@ -200,7 +183,7 @@
 
 		self.connect(
 			(self.rotator_sink, 0),
-			(self.phy_sink, 0))
+			(self._phy_sink, 0))
 
 
 		# RX & TX synchronization
@@ -245,11 +228,11 @@
 			(self.dict_toggle_sign, 'dict_out'),
 			(self.msg_to_tag_sink, 'msg'))
 
+	def phy_init_source(self):
+		raise NotImplementedError
 
-		# Some UHD devices (such as UmTRX) do start the clock
-		# not from 0, so it's required to reset it manually.
-		# Resetting UHD source will also affect the sink.
-		self.phy_src.set_time_now(uhd.time_spec(0.0))
+	def phy_init_sink(self):
+		raise NotImplementedError
 
 	def shutdown(self):
 		print("[i] Shutdown Radio interface")
@@ -281,9 +264,10 @@
 			print("[#] Shifting RX freq. to %s (offset is %s)"
 				% (eng_notation.num_to_str(fc),
 					eng_notation.num_to_str(self.freq_offset)))
-		self.phy_src.set_center_freq(fc, 0)
+
 		self.rotator_src.set_phase_inc(self.calc_phase_inc(fc))
 		self.gsm_clck_ctrl.set_fc(fc)
+		self.phy_set_rx_freq(fc)
 		self.rx_freq = fc
 
 	def set_tx_freq(self, fc):
@@ -292,16 +276,17 @@
 			print("[#] Shifting TX freq. to %s (offset is %s)"
 				% (eng_notation.num_to_str(fc),
 					eng_notation.num_to_str(self.freq_offset)))
-		self.phy_sink.set_center_freq(fc, 0)
+
 		self.rotator_sink.set_phase_inc(-self.calc_phase_inc(fc))
+		self.phy_set_tx_freq(fc)
 		self.tx_freq = fc
 
 	def set_rx_gain(self, gain):
-		self.phy_src.set_gain(gain, 0)
+		self.phy_set_rx_gain(gain)
 		self.rx_gain = gain
 
 	def set_tx_gain(self, gain):
-		self.phy_sink.set_gain(gain, 0)
+		self.phy_set_tx_gain(gain)
 		self.tx_gain = gain
 
 	def set_slot(self, slot, config):
diff --git a/python/trx/radio_if_uhd.py b/python/trx/radio_if_uhd.py
new file mode 100644
index 0000000..b431fb6
--- /dev/null
+++ b/python/trx/radio_if_uhd.py
@@ -0,0 +1,73 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# GR-GSM based transceiver
+# Radio interface for UHD devices
+#
+# (C) 2019 by Vadim Yanitskiy <axilirator at gmail.com>
+#
+# All Rights Reserved
+#
+# This program 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 2 of the License, or
+# (at your option) any later version.
+#
+# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+from gnuradio import uhd
+
+from radio_if import RadioInterface
+
+class RadioInterfaceUHD(RadioInterface):
+	@property
+	def phy_proc_delay(self):
+		# FIXME: shall be measured (automatically?) for
+		# particular device and particular clock rate.
+		# The current value is measured for USRP B2X0 at 26e6.
+		return (285.616 + 2 * self.GSM_SYM_PERIOD_uS) * 1e-6
+
+	def phy_init_source(self):
+		self._phy_src = uhd.usrp_source(self.phy_args,
+			uhd.stream_args(cpu_format = "fc32",
+				channels = range(1)))
+
+		self._phy_src.set_clock_rate(26e6, uhd.ALL_MBOARDS)
+		self._phy_src.set_antenna(self.rx_antenna, 0)
+		self._phy_src.set_samp_rate(self.sample_rate)
+		self._phy_src.set_bandwidth(650e3, 0)
+		self._phy_src.set_gain(self.rx_gain)
+
+		# Some UHD devices (such as UmTRX) do start the clock
+		# not from 0, so it's required to reset it manually.
+		# Resetting UHD source will also affect the sink.
+		self._phy_src.set_time_now(uhd.time_spec(0.0))
+
+	def phy_init_sink(self):
+		self._phy_sink = uhd.usrp_sink(self.phy_args,
+			uhd.stream_args(cpu_format = "fc32",
+				channels = range(1)), "packet_len")
+
+		self._phy_sink.set_clock_rate(26e6, uhd.ALL_MBOARDS)
+		self._phy_sink.set_antenna(self.tx_antenna, 0)
+		self._phy_sink.set_samp_rate(self.sample_rate)
+		self._phy_sink.set_gain(self.tx_gain)
+
+	def phy_set_rx_freq(self, freq):
+		self._phy_src.set_center_freq(freq, 0)
+
+	def phy_set_tx_freq(self, freq):
+		self._phy_sink.set_center_freq(freq, 0)
+
+	def phy_set_rx_gain(self, gain):
+		self._phy_src.set_gain(gain, 0)
+
+	def phy_set_tx_gain(self, gain):
+		self._phy_sink.set_gain(gain, 0)

-- 
To view, visit https://gerrit.osmocom.org/12673
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: gr-gsm
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I1644a3f6b8da0d5f2a1a133058269e5383948fda
Gerrit-Change-Number: 12673
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Piotr Krysik <ptrkrysik at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190205/a337704b/attachment.htm>


More information about the gerrit-log mailing list