trxcon/l1sched: clarify TDMA Fn (mod 26) maps
[osmocom-bb.git] / src / target / trx_toolkit / rand_burst_gen.py
blobc474c75911442a3a70f5f2f24b7dfda94211529e
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
4 # TRX Toolkit
5 # Random burst (NB, FB, SB, AB) generator
7 # (C) 2017 by Vadim Yanitskiy <axilirator@gmail.com>
9 # All Rights Reserved
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 import random
23 from gsm_shared import *
25 class RandBurstGen:
27 # GSM 05.02 Chapter 5.2.6 Dummy Burst
28 db_bits = [
29 0, 0, 0,
30 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0,
31 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0,
32 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0,
33 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0,
34 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0,
35 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0,
36 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1,
37 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1,
38 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0,
39 0, 0, 0,
42 # Pick a random TSC for a given burst type
43 def get_rand_tsc(self, bt):
44 tsc_list = filter(lambda seq: seq.bt == bt, list(TrainingSeqGMSK))
45 tsc_list = list(tsc_list) # In Python 3 filter() returns an iterator
46 return random.choice(tsc_list)
48 # Generate a normal burst
49 def gen_nb(self, tsc = None):
50 buf = []
52 # Tailing bits
53 buf += [0] * 3
55 # Random data 1 / 2
56 buf += [random.randint(0, 1) for _ in range(57)]
58 # Steal flag 1 / 2
59 buf.append(random.randint(0, 1))
61 # Training sequence
62 if tsc is None:
63 tsc = self.get_rand_tsc(BurstType.NORMAL)
64 buf += tsc.seq
66 # Steal flag 2 / 2
67 buf.append(random.randint(0, 1))
69 # Random data 2 / 2
70 buf += [random.randint(0, 1) for _ in range(57)]
72 # Tailing bits
73 buf += [0] * 3
75 return buf
77 # Generate a frequency correction burst
78 def gen_fb(self):
79 return [0] * GMSK_BURST_LEN
81 # Generate a synchronization burst
82 def gen_sb(self, tsc = None):
83 buf = []
85 # Tailing bits
86 buf += [0] * 3
88 # Random data 1 / 2
89 buf += [random.randint(0, 1) for _ in range(39)]
91 # Training sequence
92 if tsc is None:
93 tsc = self.get_rand_tsc(BurstType.SYNC)
94 buf += tsc.seq
96 # Random data 2 / 2
97 buf += [random.randint(0, 1) for _ in range(39)]
99 # Tailing bits
100 buf += [0] * 3
102 return buf
104 # Generate a dummy burst
105 def gen_db(self):
106 return self.db_bits
108 # Generate an access burst
109 def gen_ab(self, tsc = None):
110 buf = []
112 # Tailing bits
113 buf += [0] * 8
115 # Training sequence
116 if tsc is None:
117 tsc = self.get_rand_tsc(BurstType.ACCESS)
118 buf += tsc.seq
120 # Random data
121 buf += [random.randint(0, 1) for _ in range(36)]
123 # Tailing bits
124 buf += [0] * 3
126 # Guard period
127 buf += [0] * 60
129 return buf