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/.
Vadim Yanitskiy gerrit-no-reply at lists.osmocom.orgVadim Yanitskiy has submitted this change and it was merged. ( https://gerrit.osmocom.org/12341 )
Change subject: trx_toolkit/data_msg.py: use struct API for fn and toa256 coding
......................................................................
trx_toolkit/data_msg.py: use struct API for fn and toa256 coding
The built-in struct module is already used for toa256 decoding,
so let's use it for toa256 encoding, and TDMA frame number
coding too - no need to (re)implement the wheel!
Change-Id: I10d2e15ac57a0524e9bc1c80ed6a0f6f5a263436
---
M src/target/trx_toolkit/data_msg.py
1 file changed, 4 insertions(+), 16 deletions(-)
Approvals:
Jenkins Builder: Verified
Pau Espin Pedrol: Looks good to me, but someone else must approve
Vadim Yanitskiy: Looks good to me, approved
diff --git a/src/target/trx_toolkit/data_msg.py b/src/target/trx_toolkit/data_msg.py
index 95ec9dc..bbc9d93 100644
--- a/src/target/trx_toolkit/data_msg.py
+++ b/src/target/trx_toolkit/data_msg.py
@@ -143,24 +143,13 @@
# Generates frame number to bytes
def gen_fn(self, fn):
- # Allocate an empty byte-array
- buf = bytearray()
-
# Big endian, 4 bytes
- buf.append((fn >> 24) & 0xff)
- buf.append((fn >> 16) & 0xff)
- buf.append((fn >> 8) & 0xff)
- buf.append((fn >> 0) & 0xff)
-
- return buf
+ return struct.pack(">L", fn)
# Parses frame number from bytes
def parse_fn(self, buf):
# Big endian, 4 bytes
- return (buf[0] << 24) \
- | (buf[1] << 16) \
- | (buf[2] << 8) \
- | (buf[3] << 0)
+ return struct.unpack(">L", buf)[0]
# Generates a TRX DATA message
def gen_msg(self):
@@ -197,7 +186,7 @@
raise ValueError("Message is to short")
# Parse both fn and tn
- self.fn = self.parse_fn(msg[1:])
+ self.fn = self.parse_fn(msg[1:5])
self.tn = msg[0]
# Specific message part
@@ -381,8 +370,7 @@
# Encode ToA (Time of Arrival)
# Big endian, 2 bytes (int32_t)
- buf.append((self.toa256 >> 8) & 0xff)
- buf.append(self.toa256 & 0xff)
+ buf += struct.pack(">h", self.toa256)
return buf
--
To view, visit https://gerrit.osmocom.org/12341
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I10d2e15ac57a0524e9bc1c80ed6a0f6f5a263436
Gerrit-Change-Number: 12341
Gerrit-PatchSet: 1
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>
Gerrit-Reviewer: Jenkins Builder (1000002)
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at gmail.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20181218/420424f1/attachment.htm>