blob: 0a2a3be3e56807daa5b28740689f2e5f9864c4c7 [file] [log] [blame]
Roman Khassrafa1eb1882015-08-05 12:30:29 +02001/* -*- c++ -*- */
2/* @file
3 * @author Roman Khassraf <rkhassraf@gmail.com>
4 * @section LICENSE
5 *
6 * Gr-gsm is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3, or (at your option)
9 * any later version.
10 *
11 * Gr-gsm is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with gr-gsm; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <gnuradio/io_signature.h>
28#include "burst_sdcch_subslot_splitter_impl.h"
29#include <stdio.h>
30#include <grgsm/endian.h>
31#include <grgsm/gsmtap.h>
32
33
34namespace gr {
35 namespace gsm {
36
37 burst_sdcch_subslot_splitter::sptr
38 burst_sdcch_subslot_splitter::make(splitter_mode mode)
39 {
40 return gnuradio::get_initial_sptr
41 (new burst_sdcch_subslot_splitter_impl(mode));
42 }
43
44 /*
45 * The private constructor
46 */
47 burst_sdcch_subslot_splitter_impl::burst_sdcch_subslot_splitter_impl(splitter_mode mode)
48 : gr::block("burst_sdcch_subslot_splitter",
49 gr::io_signature::make(0, 0, 0),
50 gr::io_signature::make(0, 0, 0)),
51 d_mode(mode)
52 {
53 message_port_register_in(pmt::mp("in"));
54
55 message_port_register_out(pmt::mp("out0"));
56 message_port_register_out(pmt::mp("out1"));
57 message_port_register_out(pmt::mp("out2"));
58 message_port_register_out(pmt::mp("out3"));
59 if (d_mode == SPLITTER_SDCCH8)
60 {
61 message_port_register_out(pmt::mp("out4"));
62 message_port_register_out(pmt::mp("out5"));
63 message_port_register_out(pmt::mp("out6"));
64 message_port_register_out(pmt::mp("out7"));
65 }
66
67 set_msg_handler(pmt::mp("in"), boost::bind(&burst_sdcch_subslot_splitter_impl::process_burst, this, _1));
68 }
69
70 /*
71 * Our virtual destructor.
72 */
73 burst_sdcch_subslot_splitter_impl::~burst_sdcch_subslot_splitter_impl() {}
74
75 void burst_sdcch_subslot_splitter_impl::process_burst(pmt::pmt_t msg)
76 {
Steve Glassc8edec52015-09-27 16:14:33 +100077 // hardcoded subslots of the channels, both SDCCH and the associated SACCH
78 // -1 means that the particular position in the frame is not SDCCH
79 static const int8_t subslots_sdcch4[102] = {
80 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0, 1, 1, 1, 1,-1,-1, 2, 2, 2, 2, 3, 3, 3, 3,-1,-1, 0, 0, 0, 0, 1, 1, 1, 1,-1,
81 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0, 1, 1, 1, 1,-1,-1, 2, 2, 2, 2, 3, 3, 3, 3,-1,-1, 2, 2, 2, 2, 3, 3, 3, 3,-1
82 };
83 static const int8_t subslots_sdcch8[102] = {
84 0, 0, 0, 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, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3,-1,-1,-1,
85 0, 0, 0, 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, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7,-1,-1,-1
86 };
87
Roman Khassrafa1eb1882015-08-05 12:30:29 +020088 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
89 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
90
91 uint32_t frame_nr = be32toh(header->frame_number);
92 uint32_t fn_mod102 = frame_nr % 102;
93
94 int8_t subslot;
Steve Glassc8edec52015-09-27 16:14:33 +100095
Roman Khassrafa1eb1882015-08-05 12:30:29 +020096 if (d_mode == SPLITTER_SDCCH8)
97 {
Steve Glassc8edec52015-09-27 16:14:33 +100098 subslot = subslots_sdcch8[fn_mod102];
Roman Khassrafa1eb1882015-08-05 12:30:29 +020099 }
100 else if (d_mode == SPLITTER_SDCCH4)
101 {
Steve Glassc8edec52015-09-27 16:14:33 +1000102 subslot = subslots_sdcch4[fn_mod102];
Roman Khassrafa1eb1882015-08-05 12:30:29 +0200103 }
104
105 if ((subslot == -1) || (d_mode == SPLITTER_SDCCH4 && subslot > 3))
106 {
107 return;
108 }
109
110 std::string port("out");
111
112 switch (subslot)
113 {
114 case 0:
115 port.append("0");
116 break;
117 case 1:
118 port.append("1");
119 break;
120 case 2:
121 port.append("2");
122 break;
123 case 3:
124 port.append("3");
125 break;
126 case 4:
127 port.append("4");
128 break;
129 case 5:
130 port.append("5");
131 break;
132 case 6:
133 port.append("6");
134 break;
135 case 7:
136 port.append("7");
137 break;
138 default:
139 port.append("0");
140 break;
141 }
142
143 message_port_pub(pmt::mp(port), msg);
144 }
145 } /* namespace gsm */
146} /* namespace gr */