Review at https://gerrit.osmocom.org/6826
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 --- M src/target/fake_trx/data_msg.py 1 file changed, 37 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/26/6826/1 diff --git a/src/target/fake_trx/data_msg.py b/src/target/fake_trx/data_msg.py index 2805113..77d4f52 100644 --- a/src/target/fake_trx/data_msg.py +++ b/src/target/fake_trx/data_msg.py @@ -65,6 +65,18 @@ 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 @@ 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 @@ 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 -- To view, visit https://gerrit.osmocom.org/6826 To unsubscribe, visit https://gerrit.osmocom.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iafe63e39ad68f4ff373ae098424d76ca9f83c8fc Gerrit-PatchSet: 1 Gerrit-Project: osmocom-bb Gerrit-Branch: master Gerrit-Owner: Harald Welte <lafo...@gnumonks.org>