summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2018-01-27 20:44:15 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2018-01-29 04:19:01 +0700
commitd9553faf62a6e5eec339dd0c324b1a31a71350ab (patch)
tree48874341cf4aa785595e3ffa2ea78cc4e8c0336f
parent475ece71825f38b9cbface49b432346b9a9cdf8a (diff)
fake_trx/data_msg.py: implement header description
This change introduces a new method for both types of messages called 'desc_hdr', that generates human-readable header description. Examples: TRX -> L1: fn=571353 tn=1 rssi=-108 toa=-0.53 L1 -> TRX: fn=1777477 tn=3 pwr=161 Change-Id: Iafe63e39ad68f4ff373ae098424d76ca9f83c8fc
-rw-r--r--src/target/fake_trx/data_msg.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/target/fake_trx/data_msg.py b/src/target/fake_trx/data_msg.py
index 2805113c..77d4f52b 100644
--- a/src/target/fake_trx/data_msg.py
+++ b/src/target/fake_trx/data_msg.py
@@ -65,6 +65,18 @@ class DATAMSG:
self.fn = self.rand_fn()
self.tn = self.rand_tn()
+ # Generates human-readable header description
+ def desc_hdr(self):
+ result = ""
+
+ if self.fn is not None:
+ result += ("fn=%u " % self.fn)
+
+ if self.tn is not None:
+ result += ("tn=%u " % self.tn)
+
+ return result
+
# Converts unsigned soft-bits {254..0} to soft-bits {-127..127}
def usbit2sbit(self, bits):
buf = []
@@ -237,6 +249,17 @@ class DATAMSG_L12TRX(DATAMSG):
DATAMSG.rand_hdr(self)
self.pwr = self.rand_pwr()
+ # Generates human-readable header description
+ def desc_hdr(self):
+ # Describe the common part
+ result = DATAMSG.desc_hdr(self)
+
+ if self.pwr is not None:
+ result += ("pwr=%u " % self.pwr)
+
+ # Strip useless whitespace and return
+ return result.strip()
+
# Generates message specific header part
def gen_hdr(self):
# Allocate an empty byte-array
@@ -335,6 +358,20 @@ class DATAMSG_TRX2L1(DATAMSG):
self.rssi = self.rand_rssi()
self.toa = self.rand_toa()
+ # Generates human-readable header description
+ def desc_hdr(self):
+ # Describe the common part
+ result = DATAMSG.desc_hdr(self)
+
+ if self.rssi is not None:
+ result += ("rssi=%d " % self.rssi)
+
+ if self.toa is not None:
+ result += ("toa=%.2f " % self.toa)
+
+ # Strip useless whitespace and return
+ return result.strip()
+
# Generates message specific header part
def gen_hdr(self):
# Allocate an empty byte-array