blob: 78d4280cbb35d145fd7f33fcd4687c8431a1a8b5 [file] [log] [blame]
piotrfaacc722014-07-20 23:48:32 +02001/* -*- 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 <gsm/gsmtap.h>
27#include "get_bcch_or_ccch_bursts_impl.h"
28
29namespace gr {
30 namespace gsm {
31
32 get_bcch_or_ccch_bursts::sptr
piotrdf304592014-08-04 11:22:47 +020033 get_bcch_or_ccch_bursts::make(unsigned int fn51_start)
piotrfaacc722014-07-20 23:48:32 +020034 {
35 return gnuradio::get_initial_sptr
piotrdf304592014-08-04 11:22:47 +020036 (new get_bcch_or_ccch_bursts_impl(fn51_start));
piotrfaacc722014-07-20 23:48:32 +020037 }
38
39 /*
40 * The private constructor
41 */
piotrdf304592014-08-04 11:22:47 +020042 get_bcch_or_ccch_bursts_impl::get_bcch_or_ccch_bursts_impl(unsigned int fn51_start)
piotrfaacc722014-07-20 23:48:32 +020043 : gr::block("get_bcch_or_ccch_bursts",
44 gr::io_signature::make(0, 0, 0),
piotrdf304592014-08-04 11:22:47 +020045 gr::io_signature::make(0, 0, 0)),
46 d_fn51_start(fn51_start)
piotrfaacc722014-07-20 23:48:32 +020047 {
48 message_port_register_in(pmt::mp("bursts"));
49 set_msg_handler(pmt::mp("bursts"), boost::bind(&get_bcch_or_ccch_bursts_impl::filter_ccch, this, _1));
50 message_port_register_out(pmt::mp("bursts"));
51 }
52
53 /*
54 * Our virtual destructor.
55 */
56 get_bcch_or_ccch_bursts_impl::~get_bcch_or_ccch_bursts_impl()
57 {
58 }
59
60 void get_bcch_or_ccch_bursts_impl::filter_ccch(pmt::pmt_t msg)
61 {
ptrkrysik617ba032014-11-21 10:11:05 +010062 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
63 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
ptrkrysik6f6d46d2014-11-12 22:50:18 +010064 uint32_t frame_nr = be32toh(header->frame_number);
piotrfaacc722014-07-20 23:48:32 +020065
ptrkrysik6f6d46d2014-11-12 22:50:18 +010066 uint32_t fn_mod51 = frame_nr % 51;
piotrdf304592014-08-04 11:22:47 +020067 int fn51_stop = d_fn51_start+3;
piotrfaacc722014-07-20 23:48:32 +020068
69 if(header->timeslot==0){
piotrdf304592014-08-04 11:22:47 +020070 if(fn_mod51>=d_fn51_start && fn_mod51<=fn51_stop){
71 uint32_t ii = fn_mod51-d_fn51_start;
ptrkrysik6f6d46d2014-11-12 22:50:18 +010072 d_frame_numbers[ii]=frame_nr;
piotrfaacc722014-07-20 23:48:32 +020073 d_bursts[ii] = msg;
74 }
75
76 if(fn_mod51==fn51_stop){
77 //check for a situation where some BCCH bursts were lost
78 //in this situation frame numbers won't be consecutive
79 bool frames_are_consecutive = true;
80 for(int jj=1; jj<4; jj++)
81 {
82 if((d_frame_numbers[jj]-d_frame_numbers[jj-1])!=1){
83 frames_are_consecutive = false;
84 }
85 }
86 if(frames_are_consecutive)
87 {
88 //send bursts to the output
89 for(int jj=0; jj<4; jj++)
90 {
91 message_port_pub(pmt::mp("bursts"), d_bursts[jj]);
92 }
93 }
94 }
95 }
96 }
97 } /* namespace gsm */
98} /* namespace gr */
99