blob: 4348f98ae425e105c187d84ae2eaaf22090f3e2e [file] [log] [blame]
Vasil Velichkov0ccec372018-05-03 05:05:43 +03001#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3# @file
4# @author (C) 2018 by Vasil Velichkov <vvvelichkov@gmail.com>
5# @section LICENSE
6#
7# Gr-gsm is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3, or (at your option)
10# any later version.
11#
12# Gr-gsm is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with gr-gsm; see the file COPYING. If not, write to
19# the Free Software Foundation, Inc., 51 Franklin Street,
20# Boston, MA 02110-1301, USA.
21#
22#
23
24import numpy as np
25from gnuradio import gr, gr_unittest, blocks
26import grgsm_swig as grgsm
27import pmt
28
29class qa_tch_h_chans_demapper (gr_unittest.TestCase):
30
31 def setUp (self):
32 self.tb = gr.top_block ()
33
34 self.bursts = [
35 "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
36 "0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
37 "0010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
38 "0001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
39 "0000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
40 "0000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
41 "0000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
42 "0000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
43 "0000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
44 "0000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
45 "0000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
46 "0000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
47 "0000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
48 "0000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
49 "0000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
50 "0000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
51 "0000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
52 "0000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
53 "0000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
54 "0000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
55 "0000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
56 "0000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
57 "0000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
58 "0000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
59 "0000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
60 "0000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
61 "0000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
62 "0000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
63 "0000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
64 "0000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
65 "0000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"]
66
67 def tearDown (self):
68 self.tb = None
69
70 def test_hr_demapper_sub0 (self):
71 """
72 TCH/F Half Rate demapper sub-channel 0
73 """
74 frames = [
75 0, 1, 2, 3, 4, 5, 6, 7,
76 8, 9, 10, 11, 12, 13, 14, 15,
77 16, 17, 18, 19, 20, 21, 22, 23,
78 24, 25, 26, 27, 28, 29]
79 timeslots = [
80 3, 3, 3, 3, 3, 3, 3, 3,
81 3, 3, 3, 3, 3, 3, 3, 3,
82 3, 3, 3, 3, 3, 3, 3, 3,
83 3, 3, 3, 3, 3, 3
84 ]
85 b = self.bursts
86 bursts = [
87 b[ 0], b[ 1], b[ 2], b[ 3], b[ 4], b[ 5], b[ 6], b[ 7],
88 b[ 8], b[ 9], b[10], b[11], b[12], #12 - sacch
89 b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20],
90 b[21], b[22], b[23], b[24], b[25], #25 - idle
91 b[26], b[27], b[28], b[29], b[30]
92 ]
93
94 src = grgsm.burst_source(frames, timeslots, bursts)
95 demapper = grgsm.tch_h_chans_demapper(3, 0)
96 tch = grgsm.burst_sink()
97 acch = grgsm.burst_sink()
98
99 self.tb.msg_connect(src, "out", demapper, "bursts")
100 self.tb.msg_connect(demapper, "tch_bursts", tch, "in")
101 self.tb.msg_connect(demapper, "acch_bursts", acch, "in")
102
103 self.tb.run ()
104
105 self.assertEqual([
106 b[ 0], b[ 2], b[ 4], b[ 6],
107 b[ 4], b[ 6], b[ 8], b[10],
108 b[ 8], b[10],
109 b[13], b[15],
110 b[13], b[15], b[17], b[19],
111 b[17], b[19], b[21], b[23],
112 b[21], b[23],
113 b[26], b[28],
114 ], list(tch.get_burst_data()))
115
116 self.assertEqual([], list(acch.get_burst_data()))
117
118 def test_hr_demapper_sub1 (self):
119 """
120 TCH/F Half Rate demapper sub-channel 1
121 """
122 frames = [
123 0, 1, 2, 3, 4, 5, 6, 7,
124 8, 9, 10, 11, 12, 13, 14, 15,
125 16, 17, 18, 19, 20, 21, 22, 23,
126 24, 25, 26, 27, 28, 29]
127 timeslots = [
128 3, 3, 3, 3, 3, 3, 3, 3,
129 3, 3, 3, 3, 3, 3, 3, 3,
130 3, 3, 3, 3, 3, 3, 3, 3,
131 3, 3, 3, 3, 3, 3
132 ]
133 b = self.bursts
134 bursts = [
135 b[ 0], b[ 1], b[ 2], b[ 3], b[ 4], b[ 5], b[ 6], b[ 7],
136 b[ 8], b[ 9], b[10], b[11], b[12], #12 - sacch
137 b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20],
138 b[21], b[22], b[23], b[24], b[25], #25 - idle
139 b[26], b[27], b[28], b[29], b[30]
140 ]
141 src = grgsm.burst_source(frames, timeslots, bursts)
142 demapper = grgsm.tch_h_chans_demapper(3, 1)
143 tch = grgsm.burst_sink()
144 acch = grgsm.burst_sink()
145
146 self.tb.msg_connect(src, "out", demapper, "bursts")
147 self.tb.msg_connect(demapper, "tch_bursts", tch, "in")
148 self.tb.msg_connect(demapper, "acch_bursts", acch, "in")
149
150 self.tb.run ()
151
152 self.assertEqual([
153 b[ 1], b[ 3], b[ 5], b[ 7],
154 b[ 5], b[ 7], b[ 9], b[11],
155 b[ 9], b[11],
156 b[14], b[16],
157 b[14], b[16], b[18], b[20],
158 b[18], b[20], b[22], b[24],
159 b[22], b[24],
160 b[27], b[29],
161 ], list(tch.get_burst_data()))
162
163 self.assertEqual([], list(acch.get_burst_data()))
164
165 def sacch_hr_test (self, ts, sub, frames, bursts):
166 timeslots = [ts, ts, ts, ts, ts, ts, ts, ts]
167
168 src = grgsm.burst_source(frames, timeslots, bursts)
169 demapper = grgsm.tch_h_chans_demapper(ts, sub)
170 tch = grgsm.burst_sink()
171 acch = grgsm.burst_sink()
172
173 self.tb.msg_connect(src, "out", demapper, "bursts")
174 self.tb.msg_connect(demapper, "tch_bursts", tch, "in")
175 self.tb.msg_connect(demapper, "acch_bursts", acch, "in")
176
177 self.tb.run ()
178
179 self.assertEqual([], list(tch.get_burst_data()))
180
181 return list(acch.get_burst_data())
182
183 def test_sacch_th (self):
184 """
185 SACCH/TH tests
186 """
187 b = self.bursts
188 bursts=[b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]]
189 even = [b[0], b[2], b[4], b[6]]
190 odd = [b[1], b[3], b[5], b[7]]
191 self.assertEqual(even, self.sacch_hr_test(ts=0, sub=0, frames=[12, 25, 38, 51, 64, 77, 90, 103], bursts=bursts))
192 self.assertEqual(odd, self.sacch_hr_test(ts=0, sub=1, frames=[12, 25, 38, 51, 64, 77, 90, 103], bursts=bursts))
193 self.assertEqual(even, self.sacch_hr_test(ts=1, sub=0, frames=[12, 25, 38, 51, 64, 77, 90, 103], bursts=bursts))
194 self.assertEqual(odd, self.sacch_hr_test(ts=1, sub=1, frames=[12, 25, 38, 51, 64, 77, 90, 103], bursts=bursts))
195 self.assertEqual(even, self.sacch_hr_test(ts=2, sub=0, frames=[38, 51, 64, 77, 90, 103, 116, 129], bursts=bursts))
196 self.assertEqual(odd, self.sacch_hr_test(ts=2, sub=1, frames=[38, 51, 64, 77, 90, 103, 116, 129], bursts=bursts))
197 self.assertEqual(even, self.sacch_hr_test(ts=3, sub=0, frames=[38, 51, 64, 77, 90, 103, 116, 129], bursts=bursts))
198 self.assertEqual(odd, self.sacch_hr_test(ts=3, sub=1, frames=[38, 51, 64, 77, 90, 103, 116, 129], bursts=bursts))
199 self.assertEqual(even, self.sacch_hr_test(ts=4, sub=0, frames=[64, 77, 90, 103, 116, 129, 142, 155], bursts=bursts))
200 self.assertEqual(odd, self.sacch_hr_test(ts=4, sub=1, frames=[64, 77, 90, 103, 116, 129, 142, 155], bursts=bursts))
201 self.assertEqual(even, self.sacch_hr_test(ts=5, sub=0, frames=[64, 77, 90, 103, 116, 129, 142, 155], bursts=bursts))
202 self.assertEqual(odd, self.sacch_hr_test(ts=5, sub=1, frames=[64, 77, 90, 103, 116, 129, 142, 155], bursts=bursts))
203 self.assertEqual(even, self.sacch_hr_test(ts=6, sub=0, frames=[90, 103, 116, 129, 142, 155, 168, 181], bursts=bursts))
204 self.assertEqual(odd, self.sacch_hr_test(ts=6, sub=1, frames=[90, 103, 116, 129, 142, 155, 168, 181], bursts=bursts))
205 self.assertEqual(even, self.sacch_hr_test(ts=7, sub=0, frames=[90, 103, 116, 129, 142, 155, 168, 181], bursts=bursts))
206 self.assertEqual(odd, self.sacch_hr_test(ts=7, sub=1, frames=[90, 103, 116, 129, 142, 155, 168, 181], bursts=bursts))
207
208if __name__ == '__main__':
209 gr_unittest.run(qa_tch_h_chans_demapper, "qa_tch_h_chans_demapper.xml")