blob: 066382bb1f0f727a043756d09adcbb563ce1b907 [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;
piotrd77c9cf2014-04-17 11:09:30 +020038 uint32_t frame_numbers[4];
piotrdb6c2212014-04-17 16:09:51 +020039 uint32_t fn_mod51 = header->frame_number % 51;
piotrd77c9cf2014-04-17 11:09:30 +020040
41 if(header->timeslot==0){
piotrdb6c2212014-04-17 16:09:51 +020042 if(fn_mod51>=2 && fn_mod51<=5){
43 uint32_t ii = fn_mod51-2;
piotrd77c9cf2014-04-17 11:09:30 +020044 frame_numbers[ii]=header->frame_number;
piotr10cd1f42014-04-17 23:34:39 +020045 d_msgs[ii] = msg;
piotrd77c9cf2014-04-17 11:09:30 +020046 }
47
piotrdb6c2212014-04-17 16:09:51 +020048 if(fn_mod51==5){
piotrd77c9cf2014-04-17 11:09:30 +020049 //check for a situation where some BCCH bursts were lost
50 //in this situation frame numbers won't be consecutive
51 bool frames_are_consecutive = true;
piotrdb6c2212014-04-17 16:09:51 +020052 for(int jj=1; jj<4; jj++){
piotrd77c9cf2014-04-17 11:09:30 +020053 if((frame_numbers[jj]-frame_numbers[jj-1])!=1){
54 frames_are_consecutive = false;
55 }
56 }
piotrd77c9cf2014-04-17 11:09:30 +020057 if(frames_are_consecutive){
58 //send bursts to the output
piotr10cd1f42014-04-17 23:34:39 +020059 for(int jj=0; jj<4; jj++){
60 message_port_pub(pmt::mp("bursts_out"), d_msgs[jj]);
piotrd77c9cf2014-04-17 11:09:30 +020061 }
62 }
63 }
64 }
65 }
66
67 get_ccch_bursts::sptr
68 get_ccch_bursts::make()
69 {
70 return gnuradio::get_initial_sptr
71 (new get_ccch_bursts_impl());
72 }
73
74 /*
75 * The private constructor
76 */
77 get_ccch_bursts_impl::get_ccch_bursts_impl()
78 : gr::block("get_ccch_bursts",
79 gr::io_signature::make(0, 0, 0),
80 gr::io_signature::make(0, 0, 0))
81 {
82 message_port_register_in(pmt::mp("bursts_in"));
83 set_msg_handler(pmt::mp("bursts_in"), boost::bind(&get_ccch_bursts_impl::filter_ccch, this, _1));
84 message_port_register_out(pmt::mp("bursts_out"));
85 }
86
87 /*
88 * Our virtual destructor.
89 */
90 get_ccch_bursts_impl::~get_ccch_bursts_impl()
91 {
92 }
93
94 } /* namespace gsm */
95} /* namespace gr */
96