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