aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2017-07-19 17:51:24 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2017-07-19 17:51:24 +0700
commit76e4b334535223a07c0a8d93186a046b7d9818cb (patch)
tree871b40f3e46e27b25477b5430d9f315ba123db96 /apps
parent45d9f2235261fa5ad48f908d4ed216e59d8e9836 (diff)
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.
Diffstat (limited to 'apps')
-rw-r--r--apps/trx/ctrl_if_bb.py17
-rw-r--r--apps/trx/fake_pm.py53
-rwxr-xr-xapps/trx/grgsm_trx.py9
3 files changed, 77 insertions, 2 deletions
diff --git a/apps/trx/ctrl_if_bb.py b/apps/trx/ctrl_if_bb.py
index 1705cf1..b0d54f9 100644
--- a/apps/trx/ctrl_if_bb.py
+++ b/apps/trx/ctrl_if_bb.py
@@ -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")
diff --git a/apps/trx/fake_pm.py b/apps/trx/fake_pm.py
new file mode 100644
index 0000000..1d76916
--- /dev/null
+++ b/apps/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/apps/trx/grgsm_trx.py b/apps/trx/grgsm_trx.py
index dbc1c9f..fbc9350 100755
--- a/apps/trx/grgsm_trx.py
+++ b/apps/trx/grgsm_trx.py
@@ -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")