Vasil Velichkov | 0ccec37 | 2018-05-03 05:05:43 +0300 | [diff] [blame] | 1 | #!/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 | |
| 24 | import numpy as np |
| 25 | from gnuradio import gr, gr_unittest, blocks |
| 26 | import grgsm_swig as grgsm |
| 27 | import pmt |
| 28 | |
| 29 | class qa_tch_f_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_fr_demapper (self): |
| 71 | """ |
| 72 | TCH/F Full Rate demapper |
| 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_f_chans_demapper(3) |
| 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[ 1], b[ 2], b[ 3], b[ 4], b[ 5], b[ 6], b[ 7], |
| 107 | b[ 4], b[ 5], b[ 6], b[ 7], b[ 8], b[ 9], b[10], b[11], |
| 108 | b[ 8], b[ 9], b[10], b[11], |
| 109 | b[13], b[14], b[15], b[16], |
| 110 | b[13], b[14], b[15], b[16], b[17], b[18], b[19], b[20], |
| 111 | b[17], b[18], b[19], b[20], b[21], b[22], b[23], b[24], |
| 112 | b[21], b[22], b[23], b[24], |
| 113 | b[26], b[27], b[28], b[29], |
| 114 | ], list(tch.get_burst_data())) |
| 115 | |
| 116 | self.assertEqual([], list(acch.get_burst_data())) |
| 117 | |
| 118 | def sacch_fr_test (self, ts, frames, bursts): |
| 119 | timeslots = [ts, ts, ts, ts, ts, ts, ts, ts] |
| 120 | |
| 121 | src = grgsm.burst_source(frames, timeslots, bursts) |
| 122 | demapper = grgsm.tch_f_chans_demapper(ts) |
| 123 | tch = grgsm.burst_sink() |
| 124 | acch = grgsm.burst_sink() |
| 125 | |
| 126 | self.tb.msg_connect(src, "out", demapper, "bursts") |
| 127 | self.tb.msg_connect(demapper, "tch_bursts", tch, "in") |
| 128 | self.tb.msg_connect(demapper, "acch_bursts", acch, "in") |
| 129 | |
| 130 | self.tb.run () |
| 131 | |
| 132 | self.assertEqual([], list(tch.get_burst_data())) |
| 133 | |
| 134 | return list(acch.get_burst_data()) |
| 135 | |
| 136 | def test_sacch_tf (self): |
| 137 | """ |
| 138 | SACCH/TF tests |
| 139 | """ |
| 140 | b = self.bursts |
| 141 | bursts=[b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]] |
| 142 | even = [b[0], b[2], b[4], b[6]] |
| 143 | odd = [b[1], b[3], b[5], b[7]] |
| 144 | self.assertEqual(even, self.sacch_fr_test(ts=0, frames=[12, 25, 38, 51, 64, 77, 90, 103], bursts=bursts)) |
| 145 | self.assertEqual(odd, self.sacch_fr_test(ts=1, frames=[12, 25, 38, 51, 64, 77, 90, 103], bursts=bursts)) |
| 146 | self.assertEqual(even, self.sacch_fr_test(ts=2, frames=[38, 51, 64, 77, 90, 103, 116, 129], bursts=bursts)) |
| 147 | self.assertEqual(odd, self.sacch_fr_test(ts=3, frames=[38, 51, 64, 77, 90, 103, 116, 129], bursts=bursts)) |
| 148 | self.assertEqual(even, self.sacch_fr_test(ts=4, frames=[64, 77, 90, 103, 116, 129, 142, 155], bursts=bursts)) |
| 149 | self.assertEqual(odd, self.sacch_fr_test(ts=5, frames=[64, 77, 90, 103, 116, 129, 142, 155], bursts=bursts)) |
| 150 | self.assertEqual(even, self.sacch_fr_test(ts=6, frames=[90, 103, 116, 129, 142, 155, 168, 181], bursts=bursts)) |
| 151 | self.assertEqual(odd, self.sacch_fr_test(ts=7, frames=[90, 103, 116, 129, 142, 155, 168, 181], bursts=bursts)) |
| 152 | |
| 153 | if __name__ == '__main__': |
| 154 | gr_unittest.run(qa_tch_f_chans_demapper, "qa_tch_f_chans_demapper.xml") |