Change in osmocom-bb[master]: trx_toolkit: define TRXD PDUs using declarative codec

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/.

fixeria gerrit-no-reply at lists.osmocom.org
Fri Feb 26 21:28:22 UTC 2021


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


Change subject: trx_toolkit: define TRXD PDUs using declarative codec
......................................................................

trx_toolkit: define TRXD PDUs using declarative codec

Change-Id: I739ae5da22c603fb2cf1e84d3a79fb1a6e7343b6
Related: OS#4006, SYS#4895
---
A src/target/trx_toolkit/trxd_proto.py
1 file changed, 101 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/37/23137/1

diff --git a/src/target/trx_toolkit/trxd_proto.py b/src/target/trx_toolkit/trxd_proto.py
new file mode 100644
index 0000000..60b8d28
--- /dev/null
+++ b/src/target/trx_toolkit/trxd_proto.py
@@ -0,0 +1,101 @@
+# -*- coding: utf-8 -*-
+
+'''
+TRXD PDU definitions based on declarative codec.
+'''
+
+# TRX Toolkit
+#
+# (C) 2021 by sysmocom - s.f.m.c. GmbH <info at sysmocom.de>
+# Author: Vadim Yanitskiy <vyanitskiy at sysmocom.de>
+#
+# 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.
+
+import codec
+
+class Header(codec.BitFieldSet):
+	''' Common header for all TRXD PDUs. '''
+
+	DEF_LEN = 1
+	STRUCT = (
+		codec.BitField('ver', bl=4),
+		codec.BitField('rfu', bl=1),
+		codec.BitField('tn', bl=3),
+	)
+
+
+class PDUv0Rx(codec.Envelope):
+	STRUCT = (
+		Header(),
+		codec.Uint32BE('fn'),
+		codec.Uint('rssi', mult=-1),
+		codec.Int16BE('toa256'),
+		codec.Buf('soft-bits'),
+		codec.Buf('pad', len=2),
+	)
+
+	def __init__(self, *args, **kw) -> None:
+		codec.Envelope.__init__(self, *args, **kw)
+
+		# Field 'soft-bits' is either 148 (GMSK) or 444 (8-PSK) octets long
+		self.STRUCT[-2].get_len = lambda _, data: 444 if len(data) > 148 else 148
+		# Field 'pad' may optionally be present during decoding
+		self.STRUCT[-1].get_pres_dec = lambda _, data: len(data) > 0
+		# ... or may intentionally be appended during encoding
+		self.STRUCT[-1].get_pres_enc = lambda vals: 'pad' in vals
+
+class PDUv0Tx(codec.Envelope):
+	STRUCT = (
+		Header(),
+		codec.Uint32BE('fn'),
+		codec.Uint('red'),
+		codec.Buf('hard-bits'),
+	)
+
+
+class MTS(codec.BitFieldSet):
+	''' Modulation and Training Sequence. '''
+
+	DEF_LEN = 1
+	STRUCT = (
+		codec.BitField('nope', bl=1),
+		codec.BitField('mod', bl=4),
+		codec.BitField('tsc', bl=3),
+	)
+
+class PDUv1Rx(codec.Envelope):
+	STRUCT = (
+		Header(),
+		codec.Uint32BE('fn'),
+		codec.Uint('rssi', mult=-1),
+		codec.Int16BE('toa256'),
+		MTS(),
+		codec.Int16BE('cir'),
+		codec.Buf('soft-bits'),
+	)
+
+	def __init__(self, *args, **kw) -> None:
+		codec.Envelope.__init__(self, *args, **kw)
+
+		# Field 'soft-bits' has a variable length that depends on moduletion type
+		self.STRUCT[-1].get_len = lambda _, data: 444 if len(data) > 148 else 148
+		# Field 'soft-bits' is not present in NOPE / IDLE indications
+		self.STRUCT[-1].get_pres = lambda v, _: not v['nope']
+
+
+class PDUv1Tx(PDUv0Tx):
+	pass

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

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I739ae5da22c603fb2cf1e84d3a79fb1a6e7343b6
Gerrit-Change-Number: 23137
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210226/db759372/attachment.htm>


More information about the gerrit-log mailing list