Review at  https://gerrit.osmocom.org/6822

fake_trx: share and use common GSM constants

Previously there were multiple definitions of some common GSM
constants in different modules. Let's share them.

Change-Id: Id6cdfbc6e8688755a0df7e44daa512c9afa7dad2
---
M src/target/fake_trx/burst_gen.py
M src/target/fake_trx/burst_send.py
M src/target/fake_trx/clck_gen.py
M src/target/fake_trx/data_if.py
A src/target/fake_trx/gsm_shared.py
M src/target/fake_trx/rand_burst_gen.py
6 files changed, 46 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmocom-bb refs/changes/22/6822/1

diff --git a/src/target/fake_trx/burst_gen.py b/src/target/fake_trx/burst_gen.py
index 087fe79..68ba0ec 100755
--- a/src/target/fake_trx/burst_gen.py
+++ b/src/target/fake_trx/burst_gen.py
@@ -29,6 +29,7 @@
 
 from rand_burst_gen import RandBurstGen
 from data_if import DATAInterface
+from gsm_shared import *
 
 COPYRIGHT = \
        "Copyright (C) 2017 by Vadim Yanitskiy <axilira...@gmail.com>\n" \
@@ -73,7 +74,7 @@
 
                # Generate a random frame number or use provided one
                if self.fn is None:
-                       fn = random.randint(0, DATAInterface.GSM_HYPERFRAME)
+                       fn = random.randint(0, GSM_HYPERFRAME)
                else:
                        fn = self.fn
 
@@ -106,7 +107,7 @@
                                        self.tn, fn, self.pwr)
 
                        # Increase frame number (for count > 1)
-                       fn = (fn + 1) % DATAInterface.GSM_HYPERFRAME
+                       fn = (fn + 1) % GSM_HYPERFRAME
 
                self.shutdown()
 
diff --git a/src/target/fake_trx/burst_send.py 
b/src/target/fake_trx/burst_send.py
index a8519ed..ee8e51a 100755
--- a/src/target/fake_trx/burst_send.py
+++ b/src/target/fake_trx/burst_send.py
@@ -27,6 +27,7 @@
 import sys
 
 from data_if import DATAInterface
+from gsm_shared import *
 
 COPYRIGHT = \
        "Copyright (C) 2017 by Vadim Yanitskiy <axilira...@gmail.com>\n" \
@@ -75,7 +76,7 @@
 
                # Generate a random frame number or use provided one
                if self.fn is None:
-                       fn = random.randint(0, DATAInterface.GSM_HYPERFRAME)
+                       fn = random.randint(0, GSM_HYPERFRAME)
                else:
                        fn = self.fn
 
@@ -109,7 +110,7 @@
                                        self.tn, fn, self.pwr)
 
                        # Increase frame number (for count > 1)
-                       fn = (fn + 1) % DATAInterface.GSM_HYPERFRAME
+                       fn = (fn + 1) % GSM_HYPERFRAME
 
                # Finish
                self.shutdown()
diff --git a/src/target/fake_trx/clck_gen.py b/src/target/fake_trx/clck_gen.py
index 088155b..484ecde 100755
--- a/src/target/fake_trx/clck_gen.py
+++ b/src/target/fake_trx/clck_gen.py
@@ -28,6 +28,7 @@
 
 from threading import Timer
 from udp_link import UDPLink
+from gsm_shared import *
 
 COPYRIGHT = \
        "Copyright (C) 2017 by Vadim Yanitskiy <axilira...@gmail.com>\n" \
@@ -39,7 +40,6 @@
 class CLCKGen:
        # GSM TDMA definitions
        SEC_DELAY_US = 1000 * 1000
-       GSM_SUPERFRAME = 2715648
        GSM_FRAME_US = 4615.0
 
        # Average loop back delay
@@ -74,8 +74,8 @@
 
        def send_clck_ind(self):
                # Keep clock cycle
-               if self.clck_src % self.GSM_SUPERFRAME >= 0:
-                       self.clck_src %= self.GSM_SUPERFRAME
+               if self.clck_src % GSM_HYPERFRAME >= 0:
+                       self.clck_src %= GSM_HYPERFRAME
 
                # We don't need to send so often
                if self.clck_src % self.ind_period == 0:
diff --git a/src/target/fake_trx/data_if.py b/src/target/fake_trx/data_if.py
index 6662f98..0f373ab 100644
--- a/src/target/fake_trx/data_if.py
+++ b/src/target/fake_trx/data_if.py
@@ -25,10 +25,9 @@
 import random
 
 from udp_link import UDPLink
+from gsm_shared import *
 
 class DATAInterface(UDPLink):
-       # GSM PHY definitions
-       GSM_HYPERFRAME = 2048 * 26 * 51
 
        def send_l1_msg(self, burst,
                tn = None, fn = None, rssi = None):
@@ -38,7 +37,7 @@
 
                # Generate random frame number if not preset
                if fn is None:
-                       fn = random.randint(0, self.GSM_HYPERFRAME)
+                       fn = random.randint(0, GSM_HYPERFRAME)
 
                # Generate random RSSI if not preset
                if rssi is None:
@@ -79,7 +78,7 @@
 
                # Generate random frame number if not preset
                if fn is None:
-                       fn = random.randint(0, self.GSM_HYPERFRAME)
+                       fn = random.randint(0, GSM_HYPERFRAME)
 
                # Generate random power level if not preset
                if pwr is None:
diff --git a/src/target/fake_trx/gsm_shared.py 
b/src/target/fake_trx/gsm_shared.py
new file mode 100644
index 0000000..cfe94b0
--- /dev/null
+++ b/src/target/fake_trx/gsm_shared.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python2
+# -*- coding: utf-8 -*-
+
+# Virtual Um-interface (fake transceiver)
+# Common GSM constants
+#
+# (C) 2018 by Vadim Yanitskiy <axilira...@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.
+
+# TDMA definitions
+GSM_SUPERFRAME = 26 * 51
+GSM_HYPERFRAME = 2048 * GSM_SUPERFRAME
+
+# Burst length
+GSM_BURST_LEN = 148
+EDGE_BURST_LEN = GSM_BURST_LEN * 3
diff --git a/src/target/fake_trx/rand_burst_gen.py 
b/src/target/fake_trx/rand_burst_gen.py
index 75887f2..33e7c53 100644
--- a/src/target/fake_trx/rand_burst_gen.py
+++ b/src/target/fake_trx/rand_burst_gen.py
@@ -24,9 +24,9 @@
 
 import random
 
+from gsm_shared import *
+
 class RandBurstGen:
-       # GSM L1 definitions
-       GSM_BURST_LEN = 148
 
        # GSM 05.02 Chapter 5.2.3 Normal Burst
        nb_tsc_list = [
@@ -125,7 +125,7 @@
 
        # Generate a frequency correction burst
        def gen_fb(self):
-               return [0] * self.GSM_BURST_LEN
+               return [0] * GSM_BURST_LEN
 
        # Generate a synchronization burst
        def gen_sb(self):

-- 
To view, visit https://gerrit.osmocom.org/6822
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id6cdfbc6e8688755a0df7e44daa512c9afa7dad2
Gerrit-PatchSet: 1
Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <lafo...@gnumonks.org>

Reply via email to