blob: 325a59bd4e6fd6021bbfeb74c50a2287fde2deb1 [file] [log] [blame]
ptrkrysik6dded652014-11-19 11:32:05 +01001/* -*- c++ -*- */
ptrkrysik529895b2014-12-02 18:07:38 +01002/*
3 * @file
4 * @author Piotr Krysik <ptrkrysik@gmail.com>
5 * @section LICENSE
6 *
7 * Gr-gsm is free software; you can redistribute it and/or modify
ptrkrysik6dded652014-11-19 11:32:05 +01008 * 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.
ptrkrysik529895b2014-12-02 18:07:38 +010011 *
12 * Gr-gsm is distributed in the hope that it will be useful,
ptrkrysik6dded652014-11-19 11:32:05 +010013 * 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.
ptrkrysik529895b2014-12-02 18:07:38 +010016 *
ptrkrysik6dded652014-11-19 11:32:05 +010017 * You should have received a copy of the GNU General Public License
ptrkrysik529895b2014-12-02 18:07:38 +010018 * along with gr-gsm; see the file COPYING. If not, write to
ptrkrysik6dded652014-11-19 11:32:05 +010019 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <gnuradio/io_signature.h>
28#include "universal_ctrl_chans_demapper_impl.h"
David Holm98806532014-12-01 21:19:18 +010029#include <gsm/endian.h>
ptrkrysik6dded652014-11-19 11:32:05 +010030#include <gsm/gsmtap.h>
31
32namespace gr {
33 namespace gsm {
34
35 universal_ctrl_chans_demapper::sptr
36 universal_ctrl_chans_demapper::make(const std::vector<int> &starts_fn_mod51, const std::vector<int> &channel_types)
37 {
38 return gnuradio::get_initial_sptr
39 (new universal_ctrl_chans_demapper_impl(starts_fn_mod51, channel_types));
40 }
41
42 /*
43 * The private constructor
44 */
45 universal_ctrl_chans_demapper_impl::universal_ctrl_chans_demapper_impl(const std::vector<int> &starts_fn_mod51, const std::vector<int> &channel_types)
46 : gr::block("universal_ctrl_chans_demapper",
47 gr::io_signature::make(0, 0, 0),
48 gr::io_signature::make(0, 0, 0))
49 {
50
51 d_timeslot=0;
52 for(int ii=0; ii<51; ii++)
53 {
54 d_starts_fn_mod51[ii]=0;
55 d_channel_types[ii]=0;
56 }
57
58 std::vector<int>::const_iterator s;
59 std::vector<int>::const_iterator ch_type;
60
61 for(s=starts_fn_mod51.begin(), ch_type=channel_types.begin();s != starts_fn_mod51.end(); s++)
62 {
63 if((*s > 0) and (*s < (51-4)))
64 {
65 for(int ii=0; ii<4; ii++){
66 d_starts_fn_mod51[*s+ii] = *s;
67 if(ch_type!=channel_types.end())
68 {
69 d_channel_types[*s+ii] = *ch_type;
70 }
71 }
72 if(ch_type!=channel_types.end())
73 {
74 ch_type++;
75 }
76 }
77 }
78
79
80 message_port_register_in(pmt::mp("bursts"));
81 set_msg_handler(pmt::mp("bursts"), boost::bind(&universal_ctrl_chans_demapper_impl::filter_ctrl_chans, this, _1));
82 message_port_register_out(pmt::mp("bursts"));
83 }
84
85 /*
86 * Our virtual destructor.
87 */
88 universal_ctrl_chans_demapper_impl::~universal_ctrl_chans_demapper_impl()
89 {
90 }
91
92 void universal_ctrl_chans_demapper_impl::filter_ctrl_chans(pmt::pmt_t msg)
93 {
ptrkrysik617ba032014-11-21 10:11:05 +010094 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
95 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
ptrkrysik6dded652014-11-19 11:32:05 +010096
ptrkrysik617ba032014-11-21 10:11:05 +010097 uint32_t frame_nr = be32toh(header->frame_number);
ptrkrysik6dded652014-11-19 11:32:05 +010098 uint32_t fn_mod51 = frame_nr % 51;
99 uint32_t fn51_start = d_starts_fn_mod51[fn_mod51];
100 uint32_t fn51_stop = fn51_start + 3;
101 uint32_t ch_type = d_channel_types[fn_mod51];
102 header->sub_type = ch_type;
103
104 if(header->timeslot==d_timeslot){
105 if(fn_mod51>=fn51_start && fn_mod51<=fn51_stop)
106 {
107 uint32_t ii = fn_mod51 - fn51_start;
108 d_frame_numbers[ii] = frame_nr;
109 d_bursts[ii] = msg;
110 }
111
112 if(fn_mod51==fn51_stop)
113 {
114 //check for a situation where some bursts were lost
115 //in this situation frame numbers won't be consecutive
116 bool frames_are_consecutive = true;
117 for(int jj=1; jj<4; jj++)
118 {
119 if((d_frame_numbers[jj]-d_frame_numbers[jj-1])!=1)
120 {
121 frames_are_consecutive = false;
122 }
123 }
124 if(frames_are_consecutive)
125 {
126 //send bursts to the output
127 for(int jj=0; jj<4; jj++)
128 {
129 message_port_pub(pmt::mp("bursts"), d_bursts[jj]);
130 }
131 }
132 }
133 }
134 }
135 } /* namespace gsm */
136} /* namespace gr */
137