apps/trx: handle MEASURE command
As the actual power measurement isn't implemented yet, we will emulate this process sending random power levels from specified range.
This commit is contained in:
parent
45d9f22352
commit
76e4b33453
|
@ -25,12 +25,14 @@
|
|||
from ctrl_if import CTRLInterface
|
||||
|
||||
class CTRLInterfaceBB(CTRLInterface):
|
||||
def __init__(self, remote_addr, remote_port, bind_port, tb):
|
||||
def __init__(self, remote_addr, remote_port, bind_port, tb, pm):
|
||||
print("[i] Init CTRL interface")
|
||||
CTRLInterface.__init__(self, remote_addr, remote_port, bind_port)
|
||||
|
||||
# Set link to the follow graph (top block)
|
||||
self.tb = tb
|
||||
# Power measurement
|
||||
self.pm = pm
|
||||
|
||||
def shutdown(self):
|
||||
print("[i] Shutdown CTRL interface")
|
||||
|
@ -116,6 +118,19 @@ class CTRLInterfaceBB(CTRLInterface):
|
|||
|
||||
return 0
|
||||
|
||||
# Power measurement
|
||||
elif self.verify_cmd(request, "MEASURE", 1):
|
||||
print("[i] Recv MEASURE cmd")
|
||||
|
||||
# TODO: check freq range
|
||||
meas_freq = int(request[1]) * 1000
|
||||
|
||||
# HACK: send fake low power values
|
||||
# until actual power measurement is implemented
|
||||
meas_dbm = str(self.pm.measure(meas_freq))
|
||||
|
||||
return (0, [meas_dbm])
|
||||
|
||||
# Misc
|
||||
elif self.verify_cmd(request, "ECHO", 0):
|
||||
print("[i] Recv ECHO cmd")
|
||||
|
|
|
@ -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)
|
|
@ -27,6 +27,7 @@ import sys
|
|||
|
||||
from ctrl_if_bb import CTRLInterfaceBB
|
||||
from radio_if import RadioInterface
|
||||
from fake_pm import FakePM
|
||||
|
||||
COPYRIGHT = \
|
||||
"Copyright (C) 2016-2017 by Vadim Yanitskiy <axilirator@gmail.com>\n" \
|
||||
|
@ -60,9 +61,15 @@ class Application:
|
|||
self.phy_sample_rate, self.phy_gain, self.phy_ppm,
|
||||
self.remote_addr, self.base_port)
|
||||
|
||||
# Power measurement emulation
|
||||
# Noise: -120 .. -105
|
||||
# BTS: -75 .. -50
|
||||
self.pm = FakePM(-120, -105, -75, -50)
|
||||
|
||||
# Init TRX CTRL interface
|
||||
self.server = CTRLInterfaceBB(self.remote_addr,
|
||||
self.base_port + 101, self.base_port + 1, self.radio)
|
||||
self.base_port + 101, self.base_port + 1,
|
||||
self.radio, self.pm)
|
||||
|
||||
print("[i] Init complete")
|
||||
|
||||
|
|
Loading…
Reference in New Issue