summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <vyanitskiy@sysmocom.de>2021-04-14 04:30:08 +0200
committerVadim Yanitskiy <vyanitskiy@sysmocom.de>2021-04-15 21:51:11 +0200
commit393158ac0844cdd835c807c51fab18c48fa5ef63 (patch)
treeb4e070c590fd3f1dcddf7d3bf8720bae42435e96
parentd4900f93eea0582eaa169db29d9d9946e61818d9 (diff)
trx_toolkit: change coding of 'PWR' and 'SCPIR' fields
During an internal discussion, it was decided to keep field 'PWR' as-is and move 'SCPIR' into a separate octet. This is easier to parse, less confusing, and would save us some CPU cycles. Change-Id: I482f72fd9305c51f43a0339d03904fb693d90ac9 Related: OS#4006, SYS#4895
-rw-r--r--src/target/trx_toolkit/trxd_proto.py37
1 files changed, 6 insertions, 31 deletions
diff --git a/src/target/trx_toolkit/trxd_proto.py b/src/target/trx_toolkit/trxd_proto.py
index 80d8de8b..7afa4840 100644
--- a/src/target/trx_toolkit/trxd_proto.py
+++ b/src/target/trx_toolkit/trxd_proto.py
@@ -75,35 +75,6 @@ class MTS(codec.BitFieldSet):
return 1 * GMSK_BURST_LEN
raise ValueError('Unknown modulation type')
-class Power(codec.Codec):
- ''' SCPIR and Tx power reduction (TRXDv2 and higher).
-
- +-----------------+---------------------------------+
- | 7 6 5 4 3 2 1 0 | Description |
- +-----------------+---------------------------------+
- | . . . . x x x x | Power REDuction (in 2 dB steps) |
- +-----------------+---------------------------------+
- | . x x x . . . . | SCPIR value (in 2 dB steps) |
- +-----------------+---------------------------------+
- | x . . . . . . . | SCPIR sign indicator |
- +-----------------+---------------------------------+
-
- '''
-
- def from_bytes(self, vals: dict, data: bytes) -> int:
- blob = ord(data) # Convert a byte to an int
- vals['red'] = (blob & 0b1111) * 2
- vals['scpir'] = ((blob >> 4) & 0b111) * 2
- if blob & (1 << 7): # negative sign
- vals['scpir'] *= -1
- return 1
-
- def to_bytes(self, vals: dict) -> bytes:
- blob = (vals['red'] & 0b1111) \
- | (abs(vals['scpir']) << 4) // 2 \
- | (0x80 if (vals['scpir'] < 0) else 0x00)
- return bytes((blob,))
-
class BurstBits(codec.Buf):
''' Soft-/hard-bits with variable length. '''
@@ -188,14 +159,18 @@ class PDUv2Tx(codec.Envelope):
STRUCT = (
Header(ver=2, batched=True),
MTS(),
- Power(),
+ codec.Uint('pwr'),
+ codec.Int('scpir'),
+ codec.Spare(len=3),
BurstBits('hard-bits'),
)
STRUCT = (
Header(ver=2),
MTS(),
- Power(),
+ codec.Uint('pwr'),
+ codec.Int('scpir'),
+ codec.Spare(len=3),
codec.Uint32BE('fn'),
BurstBits('hard-bits'),
codec.Sequence(item=BPDU()).f('bpdu'),