kirr has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmocom-bb/+/40083?usp=email )
Change subject: trx_toolkit/data_msg: Switch RxMsg .rssi .toa256 .tsc_set .tsc .ci from object to int ......................................................................
trx_toolkit/data_msg: Switch RxMsg .rssi .toa256 .tsc_set .tsc .ci from object to int
This are integer fields, assigning C-level type avoids py-related overhead on access and arithmetics.
Change-Id: I66abcf26896ab83f94f144941ea2dd64f7a4821f --- M src/target/trx_toolkit/data_msg.pxd M src/target/trx_toolkit/data_msg.pyx M src/target/trx_toolkit/test_data_msg.py 3 files changed, 28 insertions(+), 25 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/83/40083/1
diff --git a/src/target/trx_toolkit/data_msg.pxd b/src/target/trx_toolkit/data_msg.pxd index e5c605e..e0acbda 100644 --- a/src/target/trx_toolkit/data_msg.pxd +++ b/src/target/trx_toolkit/data_msg.pxd @@ -70,15 +70,15 @@ cdef class RxMsg(Msg): cdef public array.array burst # array.array[b] | None
- cdef public object rssi # int | None - cdef public object toa256 # int | None + cdef public int rssi # RSSI_UNSET - unset + cdef public int toa256 # TOA256_UNSET - unset
# Version 0x01 specific cdef public Modulation mod_type # Modulation | None
- cdef public object tsc_set # int | None - cdef public object tsc # int | None - cdef public object ci # int | None + cdef public int tsc_set # -1 if unset + cdef public int tsc # -1 if unset + cdef public int ci # CI_UNSET if unset
cdef _validate_burst_v0(self) diff --git a/src/target/trx_toolkit/data_msg.pyx b/src/target/trx_toolkit/data_msg.pyx index 1d40726..1e786c1 100644 --- a/src/target/trx_toolkit/data_msg.pyx +++ b/src/target/trx_toolkit/data_msg.pyx @@ -453,10 +453,12 @@ # rxlev2dbm(0..63) gives us [-110..-47], plus -10 dbm for noise cdef int RSSI_MIN = -120 cdef int RSSI_MAX = -47 +cdef int RSSI_UNSET = 0
# Min and max values of int16_t cdef int TOA256_MIN = -32768 -cdef int TOA256_MAX = 32767 +cdef int TOA256_MAX = 32767-1 +cdef int TOA256_UNSET = TOA256_MAX+1
# TSC (Training Sequence Code) range is [0, 7] cdef int TSC_MAX = 7 @@ -464,6 +466,7 @@ # C/I range (in centiBels) cdef int CI_MIN = -1280 cdef int CI_MAX = 1280 +cdef int CI_UNSET = 0x7fff
# IDLE frame / nope detection indicator cdef int NOPE_IND = (1 << 7) @@ -474,16 +477,16 @@ ''' Rx (TRX -> L1) message coding API. '''
def __cinit__(self): - self.rssi = None - self.toa256 = None + self.rssi = RSSI_UNSET + self.toa256 = TOA256_UNSET
# Version 0x01 specific (default values) self.mod_type = ModGMSK self.nope_ind = False
- self.tsc_set = None - self.tsc = None - self.ci = None + self.tsc_set = -1 + self.tsc = -1 + self.ci = CI_UNSET
cdef int HDR_LEN(self) except -1: ''' Calculate header length depending on its version. ''' @@ -541,13 +544,13 @@ # Validate common fields Msg._validate(self)
- if self.rssi is None: + if self.rssi == RSSI_UNSET: raise ValueError("RSSI is not set")
if self.rssi < RSSI_MIN or self.rssi > RSSI_MAX: raise ValueError("RSSI %d is out of range" % self.rssi)
- if self.toa256 is None: + if self.toa256 == TOA256_UNSET: raise ValueError("ToA256 is not set")
if self.toa256 < TOA256_MIN or self.toa256 > TOA256_MAX: @@ -558,7 +561,7 @@ if type(self.mod_type) is not Modulation: raise ValueError("Unknown Rx modulation type")
- if self.tsc_set is None: + if self.tsc_set == -1: raise ValueError("TSC set is not set")
if self.mod_type is ModGMSK: @@ -568,7 +571,7 @@ if not (0 <= self.tsc_set < 2): raise ValueError("TSC set %d is out of range" % self.tsc_set)
- if self.tsc is None: + if self.tsc == -1: raise ValueError("TSC is not set")
if not (0 <= self.tsc <= TSC_MAX): @@ -576,7 +579,7 @@
# Version specific parameters (also present in NOPE.ind) if self.ver >= 0x01: - if self.ci is None: + if self.ci == CI_UNSET: raise ValueError("C/I is not set")
if self.ci < CI_MIN or self.ci > CI_MAX: @@ -630,21 +633,21 @@ # Describe the common part result = Msg.desc_hdr(self)
- if self.rssi is not None: + if self.rssi != RSSI_UNSET: result += ("rssi=%d " % self.rssi)
- if self.toa256 is not None: + if self.toa256 != TOA256_UNSET: result += ("toa256=%d " % self.toa256)
if self.ver >= 0x01: if not self.nope_ind: if self.mod_type is not None: result += ("%s " % self.mod_type) - if self.tsc_set is not None: + if self.tsc_set != -1: result += ("set=%u " % self.tsc_set) - if self.tsc is not None: + if self.tsc != -1: result += ("tsc=%u " % self.tsc) - if self.ci is not None: + if self.ci != CI_UNSET: result += ("C/I=%d cB " % self.ci) else: result += "(IDLE / NOPE IND) " @@ -676,8 +679,8 @@ self.nope_ind = (mts & NOPE_IND) > 0 if self.nope_ind: self.mod_type = None - self.tsc_set = None - self.tsc = None + self.tsc_set = -1 + self.tsc = -1 return 0
# TSC: . . . . . X X X diff --git a/src/target/trx_toolkit/test_data_msg.py b/src/target/trx_toolkit/test_data_msg.py index db9a998..8d1d014 100644 --- a/src/target/trx_toolkit/test_data_msg.py +++ b/src/target/trx_toolkit/test_data_msg.py @@ -102,8 +102,8 @@ else: msg.nope_ind = True msg.mod_type = None - msg.tsc_set = None - msg.tsc = None + msg.tsc_set = -1 + msg.tsc = -1
# Encode a given message to bytes msg_enc = msg.gen_msg(legacy)