piotr | d77c9cf | 2014-04-17 11:09:30 +0200 | [diff] [blame] | 1 | /* -*- 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 | |
| 29 | namespace 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]; |
piotr | db6c221 | 2014-04-17 16:09:51 +0200 | [diff] [blame^] | 40 | uint32_t fn_mod51 = header->frame_number % 51; |
piotr | d77c9cf | 2014-04-17 11:09:30 +0200 | [diff] [blame] | 41 | |
| 42 | if(header->timeslot==0){ |
piotr | db6c221 | 2014-04-17 16:09:51 +0200 | [diff] [blame^] | 43 | if(fn_mod51>=2 && fn_mod51<=5){ |
| 44 | uint32_t ii = fn_mod51-2; |
piotr | d77c9cf | 2014-04-17 11:09:30 +0200 | [diff] [blame] | 45 | frame_numbers[ii]=header->frame_number; |
| 46 | msgs[ii] = msg; |
piotr | d77c9cf | 2014-04-17 11:09:30 +0200 | [diff] [blame] | 47 | } |
| 48 | |
piotr | db6c221 | 2014-04-17 16:09:51 +0200 | [diff] [blame^] | 49 | if(fn_mod51==5){ |
piotr | d77c9cf | 2014-04-17 11:09:30 +0200 | [diff] [blame] | 50 | //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; |
piotr | db6c221 | 2014-04-17 16:09:51 +0200 | [diff] [blame^] | 53 | for(int jj=1; jj<4; jj++){ |
piotr | d77c9cf | 2014-04-17 11:09:30 +0200 | [diff] [blame] | 54 | if((frame_numbers[jj]-frame_numbers[jj-1])!=1){ |
| 55 | frames_are_consecutive = false; |
| 56 | } |
| 57 | } |
piotr | d77c9cf | 2014-04-17 11:09:30 +0200 | [diff] [blame] | 58 | if(frames_are_consecutive){ |
| 59 | //send bursts to the output |
piotr | db6c221 | 2014-04-17 16:09:51 +0200 | [diff] [blame^] | 60 | for(int jj=1; jj<4; jj++){ |
| 61 | message_port_pub(pmt::mp("bursts_out"), msgs[jj]); |
piotr | d77c9cf | 2014-04-17 11:09:30 +0200 | [diff] [blame] | 62 | } |
| 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 | |