trx_toolkit/fake_trx.py: enrich TRX logging messages
Since fake_trx.py can handle multiple transceivers, it makes sense to print some info in logging messages about transceivers they belong to. This acvieved by defining __str__() for Transceiver. Some examples: [DEBUG] ctrl_if_trx.py:83 (127.0.0.1:5700) Recv POWEROFF cmd [INFO] ctrl_if_trx.py:85 (127.0.0.1:5700) Stopping transceiver... [DEBUG] ctrl_if_trx.py:95 (127.0.0.1:5700/1) Recv RXTUNE cmd [DEBUG] ctrl_if_trx.py:102 (127.0.0.1:5700/1) Recv TXTUNE cmd [DEBUG] ctrl_if_trx.py:155 (127.0.0.1:5700/1) Ignore CMD SETTSC [DEBUG] ctrl_if_trx.py:155 (127.0.0.1:5700/1) Ignore CMD SETPOWER Change-Id: I1f706790a2da226f1418f89d2cfbb55baa6ea624
This commit is contained in:
parent
71fee86391
commit
ba28c3efc1
|
@ -59,19 +59,19 @@ class CTRLInterfaceTRX(CTRLInterface):
|
|||
|
||||
# Power control
|
||||
if self.verify_cmd(request, "POWERON", 0):
|
||||
log.debug("Recv POWERON CMD")
|
||||
log.debug("(%s) Recv POWERON CMD" % self.trx)
|
||||
|
||||
# Ensure transceiver isn't working
|
||||
if self.trx.running:
|
||||
log.error("Transceiver already started")
|
||||
log.error("(%s) Transceiver already started" % self.trx)
|
||||
return -1
|
||||
|
||||
# Ensure RX / TX freq. are set
|
||||
if (self.trx.rx_freq is None) or (self.trx.tx_freq is None):
|
||||
log.error("RX / TX freq. are not set")
|
||||
log.error("(%s) RX / TX freq. are not set" % self.trx)
|
||||
return -1
|
||||
|
||||
log.info("Starting transceiver...")
|
||||
log.info("(%s) Starting transceiver..." % self.trx)
|
||||
self.trx.running = True
|
||||
|
||||
# Notify transceiver about that
|
||||
|
@ -80,9 +80,9 @@ class CTRLInterfaceTRX(CTRLInterface):
|
|||
return 0
|
||||
|
||||
elif self.verify_cmd(request, "POWEROFF", 0):
|
||||
log.debug("Recv POWEROFF cmd")
|
||||
log.debug("(%s) Recv POWEROFF cmd" % self.trx)
|
||||
|
||||
log.info("Stopping transceiver...")
|
||||
log.info("(%s) Stopping transceiver..." % self.trx)
|
||||
self.trx.running = False
|
||||
|
||||
# Notify transceiver about that
|
||||
|
@ -92,26 +92,27 @@ class CTRLInterfaceTRX(CTRLInterface):
|
|||
|
||||
# Tuning Control
|
||||
elif self.verify_cmd(request, "RXTUNE", 1):
|
||||
log.debug("Recv RXTUNE cmd")
|
||||
log.debug("(%s) Recv RXTUNE cmd" % self.trx)
|
||||
|
||||
# TODO: check freq range
|
||||
self.trx.rx_freq = int(request[1]) * 1000
|
||||
return 0
|
||||
|
||||
elif self.verify_cmd(request, "TXTUNE", 1):
|
||||
log.debug("Recv TXTUNE cmd")
|
||||
log.debug("(%s) Recv TXTUNE cmd" % self.trx)
|
||||
|
||||
# TODO: check freq range
|
||||
self.trx.tx_freq = int(request[1]) * 1000
|
||||
return 0
|
||||
|
||||
elif self.verify_cmd(request, "SETSLOT", 2):
|
||||
log.debug("Recv SETSLOT cmd")
|
||||
log.debug("(%s) Recv SETSLOT cmd" % self.trx)
|
||||
|
||||
# Obtain TS index
|
||||
ts = int(request[1])
|
||||
if ts not in range(0, 8):
|
||||
log.error("TS index should be in range: 0..7")
|
||||
log.error("(%s) TS index should be in "
|
||||
"range: 0..7" % self.trx)
|
||||
return -1
|
||||
|
||||
# Parse TS type
|
||||
|
@ -132,13 +133,13 @@ class CTRLInterfaceTRX(CTRLInterface):
|
|||
|
||||
# Power measurement
|
||||
if self.verify_cmd(request, "MEASURE", 1):
|
||||
log.debug("Recv MEASURE cmd")
|
||||
log.debug("(%s) Recv MEASURE cmd" % self.trx)
|
||||
|
||||
# Power Measurement interface is optional
|
||||
# for Transceiver, thus may be uninitialized
|
||||
if self.trx.pwr_meas is None:
|
||||
log.error("Power Measurement interface "
|
||||
"is not initialized => rejecting command")
|
||||
log.error("(%s) Power Measurement interface is not "
|
||||
"initialized => rejecting command" % self.trx)
|
||||
return -1
|
||||
|
||||
# TODO: check freq range
|
||||
|
@ -151,5 +152,5 @@ class CTRLInterfaceTRX(CTRLInterface):
|
|||
else:
|
||||
# We don't care about other commands,
|
||||
# so let's merely ignore them ;)
|
||||
log.debug("Ignore CMD %s" % request[0])
|
||||
log.debug("(%s) Ignore CMD %s" % (self.trx, request[0]))
|
||||
return 0
|
||||
|
|
|
@ -145,8 +145,8 @@ class FakeTRX(Transceiver):
|
|||
return False
|
||||
|
||||
if msg.fn % self.burst_drop_period == 0:
|
||||
log.info("Simulation: dropping burst (fn=%u %% %u == 0)"
|
||||
% (msg.fn, self.burst_drop_period))
|
||||
log.info("(%s) Simulation: dropping burst (fn=%u %% %u == 0)"
|
||||
% (self, msg.fn, self.burst_drop_period))
|
||||
self.burst_drop_amount -= 1
|
||||
return True
|
||||
|
||||
|
@ -176,7 +176,7 @@ class FakeTRX(Transceiver):
|
|||
# Timing Advance
|
||||
# Syntax: CMD SETTA <TA>
|
||||
if self.ctrl_if.verify_cmd(request, "SETTA", 1):
|
||||
log.debug("Recv SETTA cmd")
|
||||
log.debug("(%s) Recv SETTA cmd" % self)
|
||||
|
||||
# Store indicated value
|
||||
self.ta = int(request[1])
|
||||
|
@ -185,7 +185,7 @@ class FakeTRX(Transceiver):
|
|||
# Timing of Arrival simulation
|
||||
# Absolute form: CMD FAKE_TOA <BASE> <THRESH>
|
||||
elif self.ctrl_if.verify_cmd(request, "FAKE_TOA", 2):
|
||||
log.debug("Recv FAKE_TOA cmd")
|
||||
log.debug("(%s) Recv FAKE_TOA cmd" % self)
|
||||
|
||||
# Parse and apply both base and threshold
|
||||
self.toa256_base = int(request[1])
|
||||
|
@ -195,7 +195,7 @@ class FakeTRX(Transceiver):
|
|||
# Timing of Arrival simulation
|
||||
# Relative form: CMD FAKE_TOA <+-BASE_DELTA>
|
||||
elif self.ctrl_if.verify_cmd(request, "FAKE_TOA", 1):
|
||||
log.debug("Recv FAKE_TOA cmd")
|
||||
log.debug("(%s) Recv FAKE_TOA cmd" % self)
|
||||
|
||||
# Parse and apply delta
|
||||
self.toa256_base += int(request[1])
|
||||
|
@ -204,7 +204,7 @@ class FakeTRX(Transceiver):
|
|||
# RSSI simulation
|
||||
# Absolute form: CMD FAKE_RSSI <BASE> <THRESH>
|
||||
elif self.ctrl_if.verify_cmd(request, "FAKE_RSSI", 2):
|
||||
log.debug("Recv FAKE_RSSI cmd")
|
||||
log.debug("(%s) Recv FAKE_RSSI cmd" % self)
|
||||
|
||||
# Parse and apply both base and threshold
|
||||
self.rssi_base = int(request[1])
|
||||
|
@ -214,7 +214,7 @@ class FakeTRX(Transceiver):
|
|||
# RSSI simulation
|
||||
# Relative form: CMD FAKE_RSSI <+-BASE_DELTA>
|
||||
elif self.ctrl_if.verify_cmd(request, "FAKE_RSSI", 1):
|
||||
log.debug("Recv FAKE_RSSI cmd")
|
||||
log.debug("(%s) Recv FAKE_RSSI cmd" % self)
|
||||
|
||||
# Parse and apply delta
|
||||
self.rssi_base += int(request[1])
|
||||
|
@ -224,12 +224,13 @@ class FakeTRX(Transceiver):
|
|||
# Syntax: CMD FAKE_DROP <AMOUNT>
|
||||
# Dropping pattern: fn % 1 == 0
|
||||
elif self.ctrl_if.verify_cmd(request, "FAKE_DROP", 1):
|
||||
log.debug("Recv FAKE_DROP cmd")
|
||||
log.debug("(%s) Recv FAKE_DROP cmd" % self)
|
||||
|
||||
# Parse / validate amount of bursts
|
||||
num = int(request[1])
|
||||
if num < 0:
|
||||
log.error("FAKE_DROP amount shall not be negative")
|
||||
log.error("(%s) FAKE_DROP amount shall not "
|
||||
"be negative" % self)
|
||||
return -1
|
||||
|
||||
self.burst_drop_amount = num
|
||||
|
@ -240,18 +241,20 @@ class FakeTRX(Transceiver):
|
|||
# Syntax: CMD FAKE_DROP <AMOUNT> <FN_PERIOD>
|
||||
# Dropping pattern: fn % period == 0
|
||||
elif self.ctrl_if.verify_cmd(request, "FAKE_DROP", 2):
|
||||
log.debug("Recv FAKE_DROP cmd")
|
||||
log.debug("(%s) Recv FAKE_DROP cmd" % self)
|
||||
|
||||
# Parse / validate amount of bursts
|
||||
num = int(request[1])
|
||||
if num < 0:
|
||||
log.error("FAKE_DROP amount shall not be negative")
|
||||
log.error("(%s) FAKE_DROP amount shall not "
|
||||
"be negative" % self)
|
||||
return -1
|
||||
|
||||
# Parse / validate period
|
||||
period = int(request[2])
|
||||
if period <= 0:
|
||||
log.error("FAKE_DROP period shall be greater than zero")
|
||||
log.error("(%s) FAKE_DROP period shall "
|
||||
"be greater than zero" % self)
|
||||
return -1
|
||||
|
||||
self.burst_drop_amount = num
|
||||
|
|
|
@ -135,6 +135,13 @@ class Transceiver:
|
|||
# List of child transceivers
|
||||
self.child_trx_list = TRXList()
|
||||
|
||||
def __str__(self):
|
||||
desc = "%s:%d" % (self.remote_addr, self.base_port)
|
||||
if self.child_idx > 0:
|
||||
desc += "/%d" % self.child_idx
|
||||
|
||||
return desc
|
||||
|
||||
# To be overwritten if required,
|
||||
# no custom command handlers by default
|
||||
def ctrl_cmd_handler(self, request):
|
||||
|
@ -173,14 +180,14 @@ class Transceiver:
|
|||
|
||||
# Make sure that transceiver is configured and running
|
||||
if not self.running:
|
||||
log.warning("RX DATA message (%s), but transceiver "
|
||||
"is not running => dropping..." % msg.desc_hdr())
|
||||
log.warning("(%s) RX DATA message (%s), but transceiver "
|
||||
"is not running => dropping..." % (self, msg.desc_hdr()))
|
||||
return None
|
||||
|
||||
# Make sure that indicated timeslot is configured
|
||||
if msg.tn not in self.ts_list:
|
||||
log.warning("RX DATA message (%s), but timeslot "
|
||||
"is not configured => dropping..." % msg.desc_hdr())
|
||||
log.warning("(%s) RX DATA message (%s), but timeslot is not "
|
||||
"configured => dropping..." % (self, msg.desc_hdr()))
|
||||
return None
|
||||
|
||||
return msg
|
||||
|
|
Loading…
Reference in New Issue