blob: d75d8b184714a998f7007298238113db848ac8a8 [file] [log] [blame]
piotrd77c9cf2014-04-17 11:09:30 +02001/* -*- c++ -*- */
2/*
3 * Copyright 2014 <perper@o2.pl>.
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 "get_ccch_bursts_impl.h"
27#include <gsmtap.h>
28
29namespace gr {
30 namespace gsm {
31
32 void get_ccch_bursts_impl::filter_ccch(pmt::pmt_t msg)
33 {
34 pmt::pmt_t header_blob = pmt::car(msg);
35 pmt::pmt_t content = pmt::cdr(msg);
36 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_blob);
37 uint32_t frame_nr = header->frame_number;
38 pmt::pmt_t msgs[4];
39 uint32_t frame_numbers[4];
piotrdb6c2212014-04-17 16:09:51 +020040 uint32_t fn_mod51 = header->frame_number % 51;
piotrd77c9cf2014-04-17 11:09:30 +020041
42 if(header->timeslot==0){
piotrdb6c2212014-04-17 16:09:51 +020043 if(fn_mod51>=2 && fn_mod51<=5){
44 uint32_t ii = fn_mod51-2;
piotrd77c9cf2014-04-17 11:09:30 +020045 frame_numbers[ii]=header->frame_number;
46 msgs[ii] = msg;
piotrd77c9cf2014-04-17 11:09:30 +020047 }
48
piotrdb6c2212014-04-17 16:09:51 +020049 if(fn_mod51==5){
piotrd77c9cf2014-04-17 11:09:30 +020050 //check for a situation where some BCCH bursts were lost
51 //in this situation frame numbers won't be consecutive
52 bool frames_are_consecutive = true;
piotrdb6c2212014-04-17 16:09:51 +020053 for(int jj=1; jj<4; jj++){
piotrd77c9cf2014-04-17 11:09:30 +020054 if((frame_numbers[jj]-frame_numbers[jj-1])!=1){
55 frames_are_consecutive = false;
56 }
57 }
piotrd77c9cf2014-04-17 11:09:30 +020058 if(frames_are_consecutive){
59 //send bursts to the output
piotrdb6c2212014-04-17 16:09:51 +020060 for(int jj=1; jj<4; jj++){
61 message_port_pub(pmt::mp("bursts_out"), msgs[jj]);
piotrd77c9cf2014-04-17 11:09:30 +020062 }
63 }
64 }
65 }
66 }
67
68 get_ccch_bursts::sptr
69 get_ccch_bursts::make()
70 {
71 return gnuradio::get_initial_sptr
72 (new get_ccch_bursts_impl());
73 }
74
75 /*
76 * The private constructor
77 */
78 get_ccch_bursts_impl::get_ccch_bursts_impl()
79 : gr::block("get_ccch_bursts",
80 gr::io_signature::make(0, 0, 0),
81 gr::io_signature::make(0, 0, 0))
82 {
83 message_port_register_in(pmt::mp("bursts_in"));
84 set_msg_handler(pmt::mp("bursts_in"), boost::bind(&get_ccch_bursts_impl::filter_ccch, this, _1));
85 message_port_register_out(pmt::mp("bursts_out"));
86 }
87
88 /*
89 * Our virtual destructor.
90 */
91 get_ccch_bursts_impl::~get_ccch_bursts_impl()
92 {
93 }
94
95 } /* namespace gsm */
96} /* namespace gr */
97