blob: 75fa6f7d63a4cff76f7707e3d4a63314598ce8f0 [file] [log] [blame]
ptrkrysik6dded652014-11-19 11:32:05 +01001/* -*- c++ -*- */
2/*
3 * Copyright 2014 <+YOU OR YOUR COMPANY+>.
4 *
5 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3, or (at your option)
8 * any later version.
9 *
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this software; see the file COPYING. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifdef HAVE_CONFIG_H
22#include "config.h"
23#endif
24
25#include <gnuradio/io_signature.h>
26#include "universal_ctrl_chans_demapper_impl.h"
27#include <gsm/gsmtap.h>
28
29namespace gr {
30 namespace gsm {
31
32 universal_ctrl_chans_demapper::sptr
33 universal_ctrl_chans_demapper::make(const std::vector<int> &starts_fn_mod51, const std::vector<int> &channel_types)
34 {
35 return gnuradio::get_initial_sptr
36 (new universal_ctrl_chans_demapper_impl(starts_fn_mod51, channel_types));
37 }
38
39 /*
40 * The private constructor
41 */
42 universal_ctrl_chans_demapper_impl::universal_ctrl_chans_demapper_impl(const std::vector<int> &starts_fn_mod51, const std::vector<int> &channel_types)
43 : gr::block("universal_ctrl_chans_demapper",
44 gr::io_signature::make(0, 0, 0),
45 gr::io_signature::make(0, 0, 0))
46 {
47
48 d_timeslot=0;
49 for(int ii=0; ii<51; ii++)
50 {
51 d_starts_fn_mod51[ii]=0;
52 d_channel_types[ii]=0;
53 }
54
55 std::vector<int>::const_iterator s;
56 std::vector<int>::const_iterator ch_type;
57
58 for(s=starts_fn_mod51.begin(), ch_type=channel_types.begin();s != starts_fn_mod51.end(); s++)
59 {
60 if((*s > 0) and (*s < (51-4)))
61 {
62 for(int ii=0; ii<4; ii++){
63 d_starts_fn_mod51[*s+ii] = *s;
64 if(ch_type!=channel_types.end())
65 {
66 d_channel_types[*s+ii] = *ch_type;
67 }
68 }
69 if(ch_type!=channel_types.end())
70 {
71 ch_type++;
72 }
73 }
74 }
75
76
77 message_port_register_in(pmt::mp("bursts"));
78 set_msg_handler(pmt::mp("bursts"), boost::bind(&universal_ctrl_chans_demapper_impl::filter_ctrl_chans, this, _1));
79 message_port_register_out(pmt::mp("bursts"));
80 }
81
82 /*
83 * Our virtual destructor.
84 */
85 universal_ctrl_chans_demapper_impl::~universal_ctrl_chans_demapper_impl()
86 {
87 }
88
89 void universal_ctrl_chans_demapper_impl::filter_ctrl_chans(pmt::pmt_t msg)
90 {
ptrkrysik617ba032014-11-21 10:11:05 +010091 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
92 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
ptrkrysik6dded652014-11-19 11:32:05 +010093
ptrkrysik617ba032014-11-21 10:11:05 +010094 uint32_t frame_nr = be32toh(header->frame_number);
ptrkrysik6dded652014-11-19 11:32:05 +010095 uint32_t fn_mod51 = frame_nr % 51;
96 uint32_t fn51_start = d_starts_fn_mod51[fn_mod51];
97 uint32_t fn51_stop = fn51_start + 3;
98 uint32_t ch_type = d_channel_types[fn_mod51];
99 header->sub_type = ch_type;
100
101 if(header->timeslot==d_timeslot){
102 if(fn_mod51>=fn51_start && fn_mod51<=fn51_stop)
103 {
104 uint32_t ii = fn_mod51 - fn51_start;
105 d_frame_numbers[ii] = frame_nr;
106 d_bursts[ii] = msg;
107 }
108
109 if(fn_mod51==fn51_stop)
110 {
111 //check for a situation where some bursts were lost
112 //in this situation frame numbers won't be consecutive
113 bool frames_are_consecutive = true;
114 for(int jj=1; jj<4; jj++)
115 {
116 if((d_frame_numbers[jj]-d_frame_numbers[jj-1])!=1)
117 {
118 frames_are_consecutive = false;
119 }
120 }
121 if(frames_are_consecutive)
122 {
123 //send bursts to the output
124 for(int jj=0; jj<4; jj++)
125 {
126 message_port_pub(pmt::mp("bursts"), d_bursts[jj]);
127 }
128 }
129 }
130 }
131 }
132 } /* namespace gsm */
133} /* namespace gr */
134