aboutsummaryrefslogtreecommitdiffstats
path: root/python/qa_gsm_bcch_ccch_demapper.py
blob: 14e12241c61a8f89e2061178670b41978c5ef8c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @file
# @author (C) 2019 by Vasil Velichkov <vvvelichkov@gmail.com>
# @section LICENSE
#
# Gr-gsm 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 3, or (at your option)
# any later version.
#
# Gr-gsm 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 gr-gsm; see the file COPYING.  If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
#

import unittest
import numpy as np
from gnuradio import gr, gr_unittest, blocks
import grgsm
import pmt
import qa_gsm_demapper_data as test_data

class qa_gsm_bcch_ccch_demapper (gr_unittest.TestCase):

    def setUp (self):
        self.tb = gr.top_block ()
        self.maxDiff = None

    def tearDown (self):
        self.tb = None

    def test_downlink (self):
        """
           BCCH_CCCH demapper downlink test
        """
        src = grgsm.burst_source(test_data.frames, test_data.timeslots, test_data.bursts)
        src.set_arfcn(0); # downlink
        demapper = grgsm.gsm_bcch_ccch_demapper(timeslot_nr=0)
        dst = grgsm.burst_sink()

        self.tb.msg_connect(src, "out", demapper, "bursts")
        self.tb.msg_connect(demapper, "bursts", dst, "in")
        self.tb.run ()

        b = test_data.bursts
        self.assertEqual([
            b[  2], b[  3], b[  4], b[  5], #BCCH
            b[  6], b[  7], b[  8], b[  9], #CCCH skip 10-11
            b[ 12], b[ 13], b[ 14], b[ 15],
            b[ 16], b[ 17], b[ 18], b[ 19], #skip 20-21
            b[ 22], b[ 23], b[ 24], b[ 25],
            b[ 26], b[ 27], b[ 28], b[ 29], #skip 30-31
            b[ 32], b[ 33], b[ 34], b[ 35],
            b[ 36], b[ 37], b[ 38], b[ 39], #skip 40-41
            b[ 42], b[ 43], b[ 44], b[ 45],
            b[ 46], b[ 47], b[ 48], b[ 49], #skip 50-52
            b[ 53], b[ 54], b[ 55], b[ 56], #BCCH
            b[ 57], b[ 58], b[ 59], b[ 60], #CCCH skip 61-62
            b[ 63], b[ 64], b[ 65], b[ 66],
            b[ 67], b[ 68], b[ 69], b[ 70], #skip 71-72
            b[ 73], b[ 74], b[ 75], b[ 76],
            b[ 77], b[ 78], b[ 79], b[ 80], #skip 81-82
            b[ 83], b[ 84], b[ 85], b[ 86],
            b[ 87], b[ 88], b[ 89], b[ 90], #skip 91-92
            b[ 93], b[ 94], b[ 95], b[ 96],
            b[ 97], b[ 98], b[ 99], b[100], #skip 101-103
            b[104], b[105], b[106], b[107]  #BCCH
            ], list(dst.get_burst_data()))

        self.assertEqual([
              1,   1,   1,   1, #BCCH
              2,   2,   2,   2, #CCCH
              2,   2,   2,   2,
              2,   2,   2,   2,
              2,   2,   2,   2,
              2,   2,   2,   2,
              2,   2,   2,   2,
              2,   2,   2,   2,
              2,   2,   2,   2,
              2,   2,   2,   2,
              1,   1,   1,   1, #BCCH
              2,   2,   2,   2, #CCCH
              2,   2,   2,   2,
              2,   2,   2,   2,
              2,   2,   2,   2,
              2,   2,   2,   2,
              2,   2,   2,   2,
              2,   2,   2,   2,
              2,   2,   2,   2,
              2,   2,   2,   2,
              1,   1,   1,   1, #BCCH
            ], list(dst.get_sub_types()))

        self.assertEqual([
            0, 0, 0, 0, #BCCH
            0, 0, 0, 0, #CCCH 0
            1, 1, 1, 1,
            2, 2, 2, 2,
            3, 3, 3, 3,
            4, 4, 4, 4,
            5, 5, 5, 5,
            6, 6, 6, 6,
            7, 7, 7, 7,
            8, 8, 8, 8, #CCCH 8
            0, 0, 0, 0, #BCCH
            0, 0, 0, 0, #CCCH 0
            1, 1, 1, 1,
            2, 2, 2, 2,
            3, 3, 3, 3,
            4, 4, 4, 4,
            5, 5, 5, 5,
            6, 6, 6, 6,
            7, 7, 7, 7,
            8, 8, 8, 8, #CCCH 8
            0, 0, 0, 0, #BCCH
            ], list(dst.get_sub_slots()))

    def test_uplink (self):
        """
           BCCH_CCCH demapper uplink test
        """
        src = grgsm.burst_source(test_data.frames, test_data.timeslots, test_data.bursts)
        src.set_arfcn(0x2240); #uplink flag is 40
        demapper = grgsm.gsm_bcch_ccch_demapper(timeslot_nr=0)
        dst = grgsm.burst_sink()

        self.tb.msg_connect(src, "out", demapper, "bursts")
        self.tb.msg_connect(demapper, "bursts", dst, "in")
        self.tb.run ()

        b = test_data.bursts
        self.assertEqual(b, list(dst.get_burst_data()))
        self.assertEqual([3]*len(b), list(dst.get_sub_types()))
        self.assertEqual([0]*len(b), list(dst.get_sub_slots()))

if __name__ == '__main__':
    gr_unittest.run(qa_gsm_bcch_ccch_demapper, "qa_gsm_bcch_ccch_demapper.xml")