blob: a5617c054884a638846191f735e5f86ceec221f5 [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"
ptrkrysik3be74a72014-12-13 10:11:00 +010029#include <grgsm/endian.h>
30#include <grgsm/gsmtap.h>
ptrkrysik6dded652014-11-19 11:32:05 +010031
32namespace gr {
33 namespace gsm {
34
35 universal_ctrl_chans_demapper::sptr
ptrkrysikd8d4fbc2015-02-07 19:37:42 +010036 universal_ctrl_chans_demapper::make(unsigned int timeslot_nr, const std::vector<int> &starts_fn_mod51, const std::vector<int> &channel_types)
ptrkrysik6dded652014-11-19 11:32:05 +010037 {
38 return gnuradio::get_initial_sptr
ptrkrysikd8d4fbc2015-02-07 19:37:42 +010039 (new universal_ctrl_chans_demapper_impl(timeslot_nr, starts_fn_mod51, channel_types));
ptrkrysik6dded652014-11-19 11:32:05 +010040 }
41
42 /*
43 * The private constructor
44 */
ptrkrysikd8d4fbc2015-02-07 19:37:42 +010045 universal_ctrl_chans_demapper_impl::universal_ctrl_chans_demapper_impl(unsigned int timeslot_nr, const std::vector<int> &starts_fn_mod51, const std::vector<int> &channel_types)
ptrkrysik6dded652014-11-19 11:32:05 +010046 : gr::block("universal_ctrl_chans_demapper",
47 gr::io_signature::make(0, 0, 0),
ptrkrysikd8d4fbc2015-02-07 19:37:42 +010048 gr::io_signature::make(0, 0, 0)),
49 d_timeslot(timeslot_nr)
50
ptrkrysik6dded652014-11-19 11:32:05 +010051 {
52
ptrkrysikd8d4fbc2015-02-07 19:37:42 +010053
ptrkrysik6dded652014-11-19 11:32:05 +010054 for(int ii=0; ii<51; ii++)
55 {
56 d_starts_fn_mod51[ii]=0;
57 d_channel_types[ii]=0;
58 }
59
60 std::vector<int>::const_iterator s;
61 std::vector<int>::const_iterator ch_type;
62
63 for(s=starts_fn_mod51.begin(), ch_type=channel_types.begin();s != starts_fn_mod51.end(); s++)
64 {
65 if((*s > 0) and (*s < (51-4)))
66 {
67 for(int ii=0; ii<4; ii++){
68 d_starts_fn_mod51[*s+ii] = *s;
69 if(ch_type!=channel_types.end())
70 {
71 d_channel_types[*s+ii] = *ch_type;
72 }
73 }
74 if(ch_type!=channel_types.end())
75 {
76 ch_type++;
77 }
78 }
79 }
80
81
82 message_port_register_in(pmt::mp("bursts"));
83 set_msg_handler(pmt::mp("bursts"), boost::bind(&universal_ctrl_chans_demapper_impl::filter_ctrl_chans, this, _1));
84 message_port_register_out(pmt::mp("bursts"));
85 }
86
87 /*
88 * Our virtual destructor.
89 */
90 universal_ctrl_chans_demapper_impl::~universal_ctrl_chans_demapper_impl()
91 {
92 }
93
94 void universal_ctrl_chans_demapper_impl::filter_ctrl_chans(pmt::pmt_t msg)
95 {
ptrkrysik617ba032014-11-21 10:11:05 +010096 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
97 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
ptrkrysik6dded652014-11-19 11:32:05 +010098
ptrkrysik617ba032014-11-21 10:11:05 +010099 uint32_t frame_nr = be32toh(header->frame_number);
ptrkrysik6dded652014-11-19 11:32:05 +0100100 uint32_t fn_mod51 = frame_nr % 51;
101 uint32_t fn51_start = d_starts_fn_mod51[fn_mod51];
102 uint32_t fn51_stop = fn51_start + 3;
103 uint32_t ch_type = d_channel_types[fn_mod51];
104 header->sub_type = ch_type;
105
106 if(header->timeslot==d_timeslot){
107 if(fn_mod51>=fn51_start && fn_mod51<=fn51_stop)
108 {
109 uint32_t ii = fn_mod51 - fn51_start;
110 d_frame_numbers[ii] = frame_nr;
111 d_bursts[ii] = msg;
112 }
113
114 if(fn_mod51==fn51_stop)
115 {
116 //check for a situation where some bursts were lost
117 //in this situation frame numbers won't be consecutive
118 bool frames_are_consecutive = true;
119 for(int jj=1; jj<4; jj++)
120 {
121 if((d_frame_numbers[jj]-d_frame_numbers[jj-1])!=1)
122 {
123 frames_are_consecutive = false;
124 }
125 }
126 if(frames_are_consecutive)
127 {
128 //send bursts to the output
129 for(int jj=0; jj<4; jj++)
130 {
131 message_port_pub(pmt::mp("bursts"), d_bursts[jj]);
132 }
133 }
134 }
135 }
136 }
137 } /* namespace gsm */
138} /* namespace gr */
139