fake_trx/data_msg.py: implement header randomization
This feature could be used by both burst_gen.py and burst_send.py. Change-Id: I724e267382ff32ef1f964b1ee6cbe99069139867
This commit is contained in:
parent
f10a8d4c92
commit
8c79e2ce6b
|
@ -44,6 +44,19 @@ class DATAMSG:
|
||||||
def parse_hdr(self, hdr):
|
def parse_hdr(self, hdr):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
# Generates a random frame number
|
||||||
|
def rand_fn(self):
|
||||||
|
return random.randint(0, GSM_HYPERFRAME)
|
||||||
|
|
||||||
|
# Generates a random timeslot number
|
||||||
|
def rand_tn(self):
|
||||||
|
return random.randint(0, 7)
|
||||||
|
|
||||||
|
# Randomizes the message header
|
||||||
|
def rand_hdr(self):
|
||||||
|
self.fn = self.rand_fn()
|
||||||
|
self.tn = self.rand_tn()
|
||||||
|
|
||||||
# Converts unsigned soft-bits {254..0} to soft-bits {-127..127}
|
# Converts unsigned soft-bits {254..0} to soft-bits {-127..127}
|
||||||
def usbit2sbit(self, bits):
|
def usbit2sbit(self, bits):
|
||||||
buf = []
|
buf = []
|
||||||
|
@ -201,6 +214,21 @@ class DATAMSG_L12TRX(DATAMSG):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# Generates a random power level
|
||||||
|
def rand_pwr(self, min = None, max = None):
|
||||||
|
if min is None:
|
||||||
|
min = self.PWR_MIN
|
||||||
|
|
||||||
|
if max is None:
|
||||||
|
max = self.PWR_MAX
|
||||||
|
|
||||||
|
return random.randint(min, max)
|
||||||
|
|
||||||
|
# Randomizes message specific header
|
||||||
|
def rand_hdr(self):
|
||||||
|
DATAMSG.rand_hdr(self)
|
||||||
|
self.pwr = self.rand_pwr()
|
||||||
|
|
||||||
# Generates message specific header part
|
# Generates message specific header part
|
||||||
def gen_hdr(self):
|
def gen_hdr(self):
|
||||||
# Allocate an empty byte-array
|
# Allocate an empty byte-array
|
||||||
|
@ -258,6 +286,32 @@ class DATAMSG_TRX2L1(DATAMSG):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
# Generates a random RSSI value
|
||||||
|
def rand_rssi(self, min = None, max = None):
|
||||||
|
if min is None:
|
||||||
|
min = self.RSSI_MIN
|
||||||
|
|
||||||
|
if max is None:
|
||||||
|
max = self.RSSI_MAX
|
||||||
|
|
||||||
|
return random.randint(min, max)
|
||||||
|
|
||||||
|
# Generates a ToA (Time of Arrival) value
|
||||||
|
def rand_toa(self, min = None, max = None):
|
||||||
|
if min is None:
|
||||||
|
min = self.TOA_MIN
|
||||||
|
|
||||||
|
if max is None:
|
||||||
|
max = self.TOA_MAX
|
||||||
|
|
||||||
|
return random.uniform(min, max)
|
||||||
|
|
||||||
|
# Randomizes message specific header
|
||||||
|
def rand_hdr(self):
|
||||||
|
DATAMSG.rand_hdr(self)
|
||||||
|
self.rssi = self.rand_rssi()
|
||||||
|
self.toa = self.rand_toa()
|
||||||
|
|
||||||
# Generates message specific header part
|
# Generates message specific header part
|
||||||
def gen_hdr(self):
|
def gen_hdr(self):
|
||||||
# Allocate an empty byte-array
|
# Allocate an empty byte-array
|
||||||
|
@ -350,6 +404,16 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
print("[?] Compare message specific data: OK")
|
print("[?] Compare message specific data: OK")
|
||||||
|
|
||||||
|
# Validate header randomization
|
||||||
|
for i in range(0, 100):
|
||||||
|
msg_l12trx_ref.rand_hdr()
|
||||||
|
msg_trx2l1_ref.rand_hdr()
|
||||||
|
|
||||||
|
assert(msg_l12trx_ref.validate())
|
||||||
|
assert(msg_trx2l1_ref.validate())
|
||||||
|
|
||||||
|
print("[?] Validate header randomization: OK")
|
||||||
|
|
||||||
# Bit conversation test
|
# Bit conversation test
|
||||||
usbits_ref = range(0, 256)
|
usbits_ref = range(0, 256)
|
||||||
sbits_ref = range(-127, 128)
|
sbits_ref = range(-127, 128)
|
||||||
|
|
Loading…
Reference in New Issue