Change in ...osmocom-bb[master]: trx_toolkit/fake_trx.py: add basic TRXD version 0x01 support

fixeria gerrit-no-reply at lists.osmocom.org
Mon Jun 24 14:16:18 UTC 2019


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/14585


Change subject: trx_toolkit/fake_trx.py: add basic TRXD version 0x01 support
......................................................................

trx_toolkit/fake_trx.py: add basic TRXD version 0x01 support

Change-Id: I164f5ae4ce7694d6e324aab927a04e96d489ebd8
---
M src/target/trx_toolkit/ctrl_if_trx.py
M src/target/trx_toolkit/data_if.py
M src/target/trx_toolkit/fake_trx.py
3 files changed, 71 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/85/14585/1

diff --git a/src/target/trx_toolkit/ctrl_if_trx.py b/src/target/trx_toolkit/ctrl_if_trx.py
index 26a844f..f343215 100644
--- a/src/target/trx_toolkit/ctrl_if_trx.py
+++ b/src/target/trx_toolkit/ctrl_if_trx.py
@@ -4,7 +4,7 @@
 # TRX Toolkit
 # CTRL interface implementation (common commands)
 #
-# (C) 2016-2018 by Vadim Yanitskiy <axilirator at gmail.com>
+# (C) 2016-2019 by Vadim Yanitskiy <axilirator at gmail.com>
 #
 # All Rights Reserved
 #
@@ -147,6 +147,18 @@
 
 			return (0, [str(meas_dbm)])
 
+		# Protocol version negotiation
+		if self.verify_cmd(request, "SETVER", 1):
+			log.debug("(%s) Recv SETVER cmd" % self.trx)
+
+			ver = int(request[1])
+			if not self.trx.data_if.set_hdr_ver(ver):
+				log.error("Protocol version 0x%02x is not supported" % ver)
+				return -1
+
+			log.info("Using protocol version 0x%02x on DATA interface" % ver)
+			return 0
+
 		# Wrong / unknown command
 		else:
 			# We don't care about other commands,
diff --git a/src/target/trx_toolkit/data_if.py b/src/target/trx_toolkit/data_if.py
index 027fd85..5dcb5d1 100644
--- a/src/target/trx_toolkit/data_if.py
+++ b/src/target/trx_toolkit/data_if.py
@@ -4,7 +4,7 @@
 # TRX Toolkit
 # DATA interface implementation
 #
-# (C) 2017-2018 by Vadim Yanitskiy <axilirator at gmail.com>
+# (C) 2017-2019 by Vadim Yanitskiy <axilirator at gmail.com>
 #
 # All Rights Reserved
 #
@@ -29,9 +29,29 @@
 
 class DATAInterface(UDPLink):
 	def __init__(self, *udp_link_args):
+		# Default header version (legacy)
+		self._hdr_ver = 0x00
+
 		UDPLink.__init__(self, *udp_link_args)
 		log.debug("Init TRXD interface (%s)" % self.desc_link())
 
+	def set_hdr_ver(self, ver):
+		if not ver in DATAMSG.known_versions:
+			return False
+
+		self._hdr_ver = ver
+		return True
+
+	def match_hdr_ver(self, msg):
+		if msg.ver == self._hdr_ver:
+			return True
+
+		log.error("Rx unexpected version %u message "
+			  "from R:%s:%u, we need version %u"
+			% (msg.ver, self.remote_addr,
+			   self.remote_port, self._hdr_ver))
+		return None
+
 	def recv_raw_data(self):
 		data, _ = self.sock.recvfrom(512)
 		return data
@@ -64,6 +84,13 @@
 				"from R:%s:%u" % (self.remote_addr, self.remote_port))
 			return None
 
+		if msg.ver != self._hdr_ver:
+			log.error("Rx unexpected version %u message "
+				"from R:%s:%u, we need version %u"
+				% (msg.ver, self.remote_addr,
+				   self.remote_port, self._hdr_ver))
+			return None
+
 		return msg
 
 	def send_msg(self, msg, legacy = False):
diff --git a/src/target/trx_toolkit/fake_trx.py b/src/target/trx_toolkit/fake_trx.py
index 928333f..12bcb80 100755
--- a/src/target/trx_toolkit/fake_trx.py
+++ b/src/target/trx_toolkit/fake_trx.py
@@ -35,6 +35,7 @@
 from app_common import ApplicationBase
 from burst_fwd import BurstForwarder
 from transceiver import Transceiver
+from data_msg import Modulation
 from clck_gen import CLCKGen
 from trx_list import TRXList
 from fake_pm import FakePM
@@ -98,6 +99,7 @@
 
 	TOA256_BASE_DEFAULT = 0
 	RSSI_BASE_DEFAULT = -60
+	CI_BASE_DEFAULT = 0 # FIXME!
 
 	def __init__(self, *trx_args, **trx_kwargs):
 		Transceiver.__init__(self, *trx_args, **trx_kwargs)
@@ -105,11 +107,14 @@
 		# Actual ToA / RSSI / TA values
 		self.toa256_base = self.TOA256_BASE_DEFAULT
 		self.rssi_base = self.RSSI_BASE_DEFAULT
+		self.ci_base = self.CI_BASE_DEFAULT
+		self.tsc = 0 # FIXME!
 		self.ta = 0
 
 		# ToA / RSSI randomization threshold
 		self.toa256_rand_threshold = 0
 		self.rssi_rand_threshold = 0
+		self.ci_rand_threshold = 0
 
 		# Path loss simulation (burst dropping)
 		self.burst_drop_amount = 0
@@ -137,6 +142,17 @@
 		rssi_max = self.rssi_base + self.rssi_rand_threshold
 		return random.randint(rssi_min, rssi_max)
 
+	@property
+	def ci(self):
+		# Check if randomization is required
+		if self.ci_rand_threshold is 0:
+			return self.ci_base
+
+		# Generate a random RSSI value in required range
+		ci_min = self.ci_base - self.ci_rand_threshold
+		ci_max = self.ci_base + self.ci_rand_threshold
+		return random.randint(ci_min, ci_max)
+
 	# Path loss simulation: burst dropping
 	# Returns: True - drop, False - keep
 	def sim_burst_drop(self, msg):
@@ -156,10 +172,24 @@
 	# simulates RF path parameters (such as RSSI),
 	# and sends towards the L1
 	def send_data_msg(self, src_trx, msg):
+		# Override header version
+		msg.ver = self.data_if._hdr_ver
+
 		# Complete message header
 		msg.toa256 = self.toa256
 		msg.rssi = self.rssi
 
+		# Version specific fields
+		if msg.ver >= 0x01:
+			# Hard-coded values
+			msg.mod_type = Modulation.ModGMSK
+			msg.nope_ind = False
+			msg.tsc_set = 0
+
+			# Configurable values
+			msg.tsc = self.tsc
+			msg.ci = self.ci
+
 		# Apply optional Timing Advance
 		if src_trx.ta is not 0:
 			msg.toa256 -= src_trx.ta * 256

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

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I164f5ae4ce7694d6e324aab927a04e96d489ebd8
Gerrit-Change-Number: 14585
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <axilirator at gmail.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190624/f1040691/attachment.html>


More information about the gerrit-log mailing list