fake_trx: implement power measurement emulation
This change introduces a new class named FakePM, which is intended to generate pseudo-random power levels for base stations and noise levels inactive frequencies. Also, there is a new command in BB CTRL, which instructs transceiver to perform a power measurement on requested frequency. As we work in virtual Um-interface, a FakePM instance is used to provide some fake power levels. Change-Id: If48c12fd0b1ba10e1cf76559b359e17a1256617d
This commit is contained in:
parent
e39bb0f0d1
commit
02996abeda
|
@ -29,6 +29,7 @@ class CTRLInterfaceBB(CTRLInterface):
|
|||
trx_started = False
|
||||
rx_freq = None
|
||||
tx_freq = None
|
||||
pm = None
|
||||
|
||||
def __init__(self, remote_addr, remote_port, bind_port):
|
||||
print("[i] Init CTRL interface for BB")
|
||||
|
@ -79,6 +80,19 @@ class CTRLInterfaceBB(CTRLInterface):
|
|||
self.tx_freq = int(request[1]) * 1000
|
||||
return 0
|
||||
|
||||
# Power measurement
|
||||
elif self.verify_cmd(request, "MEASURE", 1):
|
||||
print("[i] Recv MEASURE cmd")
|
||||
|
||||
if self.pm is None:
|
||||
return -1
|
||||
|
||||
# TODO: check freq range
|
||||
meas_freq = int(request[1]) * 1000
|
||||
meas_dbm = str(self.pm.measure(meas_freq))
|
||||
|
||||
return (0, [meas_dbm])
|
||||
|
||||
# Wrong / unknown command
|
||||
else:
|
||||
# We don't care about other commands,
|
||||
|
|
|
@ -29,6 +29,7 @@ class CTRLInterfaceBTS(CTRLInterface):
|
|||
trx_started = False
|
||||
rx_freq = None
|
||||
tx_freq = None
|
||||
pm = None
|
||||
|
||||
def __init__(self, remote_addr, remote_port, bind_port):
|
||||
print("[i] Init CTRL interface for BTS")
|
||||
|
@ -55,6 +56,11 @@ class CTRLInterfaceBTS(CTRLInterface):
|
|||
|
||||
print("[i] Starting transceiver...")
|
||||
self.trx_started = True
|
||||
|
||||
# Power emulation
|
||||
if self.pm is not None:
|
||||
self.pm.add_bts_list([self.tx_freq])
|
||||
|
||||
return 0
|
||||
|
||||
elif self.verify_cmd(request, "POWEROFF", 0):
|
||||
|
@ -62,6 +68,11 @@ class CTRLInterfaceBTS(CTRLInterface):
|
|||
|
||||
print("[i] Stopping transceiver...")
|
||||
self.trx_started = False
|
||||
|
||||
# Power emulation
|
||||
if self.pm is not None:
|
||||
self.pm.del_bts_list([self.tx_freq])
|
||||
|
||||
return 0
|
||||
|
||||
# Tuning Control
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Virtual Um-interface (fake transceiver)
|
||||
# Power measurement emulation for BB
|
||||
#
|
||||
# (C) 2017 by Vadim Yanitskiy <axilirator@gmail.com>
|
||||
#
|
||||
# All Rights Reserved
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
from random import randint
|
||||
|
||||
class FakePM:
|
||||
# Freq. list for good power level
|
||||
bts_list = []
|
||||
|
||||
def __init__(self, noise_min, noise_max, bts_min, bts_max):
|
||||
# Save power level ranges
|
||||
self.noise_min = noise_min
|
||||
self.noise_max = noise_max
|
||||
self.bts_min = bts_min
|
||||
self.bts_max = bts_max
|
||||
|
||||
def measure(self, bts):
|
||||
if bts in self.bts_list:
|
||||
return randint(self.bts_min, self.bts_max)
|
||||
else:
|
||||
return randint(self.noise_min, self.noise_max)
|
||||
|
||||
def update_bts_list(self, new_list):
|
||||
self.bts_list = new_list
|
||||
|
||||
def add_bts_list(self, add_list):
|
||||
self.bts_list += add_list
|
||||
|
||||
def del_bts_list(self, del_list):
|
||||
for item in del_list:
|
||||
if item in self.bts_list:
|
||||
self.bts_list.remove(item)
|
|
@ -30,6 +30,7 @@ import sys
|
|||
from ctrl_if_bts import CTRLInterfaceBTS
|
||||
from ctrl_if_bb import CTRLInterfaceBB
|
||||
from burst_fwd import BurstForwarder
|
||||
from fake_pm import FakePM
|
||||
|
||||
from udp_link import UDPLink
|
||||
from clck_gen import CLCKGen
|
||||
|
@ -64,6 +65,15 @@ class Application:
|
|||
self.bb_ctrl = CTRLInterfaceBB(self.bb_addr,
|
||||
self.bb_base_port + 101, self.bb_base_port + 1)
|
||||
|
||||
# Power measurement emulation
|
||||
# Noise: -120 .. -105
|
||||
# BTS: -75 .. -50
|
||||
self.pm = FakePM(-120, -105, -75, -50)
|
||||
|
||||
# Share a FakePM instance between both BTS and BB
|
||||
self.bts_ctrl.pm = self.pm
|
||||
self.bb_ctrl.pm = self.pm
|
||||
|
||||
# BTS <-> BB burst forwarding
|
||||
self.bts_data = UDPLink(self.bts_addr,
|
||||
self.bts_base_port + 102, self.bts_base_port + 2)
|
||||
|
|
Loading…
Reference in New Issue