From 5da2ac71971d8568a4c0379a71198c6d759eb5da Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Wed, 24 Jan 2018 22:58:48 +0600 Subject: 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 --- src/target/fake_trx/burst_gen.py | 5 +++-- src/target/fake_trx/burst_send.py | 5 +++-- src/target/fake_trx/clck_gen.py | 6 +++--- src/target/fake_trx/data_if.py | 7 +++---- src/target/fake_trx/gsm_shared.py | 31 +++++++++++++++++++++++++++++++ src/target/fake_trx/rand_burst_gen.py | 6 +++--- 6 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 src/target/fake_trx/gsm_shared.py diff --git a/src/target/fake_trx/burst_gen.py b/src/target/fake_trx/burst_gen.py index 087fe791..68ba0ece 100755 --- a/src/target/fake_trx/burst_gen.py +++ b/src/target/fake_trx/burst_gen.py @@ -29,6 +29,7 @@ import sys from rand_burst_gen import RandBurstGen from data_if import DATAInterface +from gsm_shared import * COPYRIGHT = \ "Copyright (C) 2017 by Vadim Yanitskiy \n" \ @@ -73,7 +74,7 @@ class Application: # 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 @@ class Application: 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 a8519edc..ee8e51ab 100755 --- a/src/target/fake_trx/burst_send.py +++ b/src/target/fake_trx/burst_send.py @@ -27,6 +27,7 @@ import getopt import sys from data_if import DATAInterface +from gsm_shared import * COPYRIGHT = \ "Copyright (C) 2017 by Vadim Yanitskiy \n" \ @@ -75,7 +76,7 @@ class Application: # 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 @@ class Application: 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 088155b7..484ecde5 100755 --- a/src/target/fake_trx/clck_gen.py +++ b/src/target/fake_trx/clck_gen.py @@ -28,6 +28,7 @@ import sys from threading import Timer from udp_link import UDPLink +from gsm_shared import * COPYRIGHT = \ "Copyright (C) 2017 by Vadim Yanitskiy \n" \ @@ -39,7 +40,6 @@ COPYRIGHT = \ 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 @@ class CLCKGen: 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 6662f984..0f373ab5 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 @@ class DATAInterface(UDPLink): # 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 @@ class DATAInterface(UDPLink): # 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 00000000..cfe94b01 --- /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 +# +# 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 75887f2f..33e7c53a 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 @@ class RandBurstGen: # 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): -- cgit v1.2.3