summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/target/fake_trx/ctrl_if_bb.py14
-rw-r--r--src/target/fake_trx/ctrl_if_bts.py11
-rw-r--r--src/target/fake_trx/fake_pm.py53
-rwxr-xr-xsrc/target/fake_trx/fake_trx.py10
4 files changed, 88 insertions, 0 deletions
diff --git a/src/target/fake_trx/ctrl_if_bb.py b/src/target/fake_trx/ctrl_if_bb.py
index 32b82d3..f840c09 100644
--- a/src/target/fake_trx/ctrl_if_bb.py
+++ b/src/target/fake_trx/ctrl_if_bb.py
@@ -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,
diff --git a/src/target/fake_trx/ctrl_if_bts.py b/src/target/fake_trx/ctrl_if_bts.py
index d184f2e..a6b03cf 100644
--- a/src/target/fake_trx/ctrl_if_bts.py
+++ b/src/target/fake_trx/ctrl_if_bts.py
@@ -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
diff --git a/src/target/fake_trx/fake_pm.py b/src/target/fake_trx/fake_pm.py
new file mode 100644
index 0000000..1d76916
--- /dev/null
+++ b/src/target/fake_trx/fake_pm.py
@@ -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)
diff --git a/src/target/fake_trx/fake_trx.py b/src/target/fake_trx/fake_trx.py
index c30382b..724a520 100755
--- a/src/target/fake_trx/fake_trx.py
+++ b/src/target/fake_trx/fake_trx.py
@@ -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)