piotr | faacc72 | 2014-07-20 23:48:32 +0200 | [diff] [blame] | 1 | /* -*- 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 | |
| 29 | namespace gr { |
| 30 | namespace gsm { |
| 31 | |
| 32 | get_bcch_or_ccch_bursts::sptr |
piotr | df30459 | 2014-08-04 11:22:47 +0200 | [diff] [blame] | 33 | get_bcch_or_ccch_bursts::make(unsigned int fn51_start) |
piotr | faacc72 | 2014-07-20 23:48:32 +0200 | [diff] [blame] | 34 | { |
| 35 | return gnuradio::get_initial_sptr |
piotr | df30459 | 2014-08-04 11:22:47 +0200 | [diff] [blame] | 36 | (new get_bcch_or_ccch_bursts_impl(fn51_start)); |
piotr | faacc72 | 2014-07-20 23:48:32 +0200 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /* |
| 40 | * The private constructor |
| 41 | */ |
piotr | df30459 | 2014-08-04 11:22:47 +0200 | [diff] [blame] | 42 | get_bcch_or_ccch_bursts_impl::get_bcch_or_ccch_bursts_impl(unsigned int fn51_start) |
piotr | faacc72 | 2014-07-20 23:48:32 +0200 | [diff] [blame] | 43 | : gr::block("get_bcch_or_ccch_bursts", |
| 44 | gr::io_signature::make(0, 0, 0), |
piotr | df30459 | 2014-08-04 11:22:47 +0200 | [diff] [blame] | 45 | gr::io_signature::make(0, 0, 0)), |
| 46 | d_fn51_start(fn51_start) |
piotr | faacc72 | 2014-07-20 23:48:32 +0200 | [diff] [blame] | 47 | { |
| 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 | { |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 62 | pmt::pmt_t header_plus_burst = pmt::cdr(msg); |
| 63 | gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst); |
ptrkrysik | 6f6d46d | 2014-11-12 22:50:18 +0100 | [diff] [blame] | 64 | uint32_t frame_nr = be32toh(header->frame_number); |
piotr | faacc72 | 2014-07-20 23:48:32 +0200 | [diff] [blame] | 65 | |
ptrkrysik | 6f6d46d | 2014-11-12 22:50:18 +0100 | [diff] [blame] | 66 | uint32_t fn_mod51 = frame_nr % 51; |
piotr | df30459 | 2014-08-04 11:22:47 +0200 | [diff] [blame] | 67 | int fn51_stop = d_fn51_start+3; |
piotr | faacc72 | 2014-07-20 23:48:32 +0200 | [diff] [blame] | 68 | |
| 69 | if(header->timeslot==0){ |
piotr | df30459 | 2014-08-04 11:22:47 +0200 | [diff] [blame] | 70 | if(fn_mod51>=d_fn51_start && fn_mod51<=fn51_stop){ |
| 71 | uint32_t ii = fn_mod51-d_fn51_start; |
ptrkrysik | 6f6d46d | 2014-11-12 22:50:18 +0100 | [diff] [blame] | 72 | d_frame_numbers[ii]=frame_nr; |
piotr | faacc72 | 2014-07-20 23:48:32 +0200 | [diff] [blame] | 73 | 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 | |