blob: 875360ed915552254ea98292a11fef2398834399 [file] [log] [blame]
piotrfaacc722014-07-20 23:48:32 +02001/* -*- c++ -*- */
ptrkrysik529895b2014-12-02 18:07:38 +01002/*
3 * @file
4 * @author Piotr Krysik <ptrkrysik@gmail.com>
5 * @section LICENSE
6 *
7 * Gr-gsm is free software; you can redistribute it and/or modify
piotrfaacc722014-07-20 23:48:32 +02008 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
10 * any later version.
ptrkrysik529895b2014-12-02 18:07:38 +010011 *
12 * Gr-gsm is distributed in the hope that it will be useful,
piotrfaacc722014-07-20 23:48:32 +020013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
ptrkrysik529895b2014-12-02 18:07:38 +010016 *
piotrfaacc722014-07-20 23:48:32 +020017 * You should have received a copy of the GNU General Public License
ptrkrysik529895b2014-12-02 18:07:38 +010018 * along with gr-gsm; see the file COPYING. If not, write to
piotrfaacc722014-07-20 23:48:32 +020019 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <gnuradio/io_signature.h>
David Holm98806532014-12-01 21:19:18 +010028#include <gsm/endian.h>
piotrfaacc722014-07-20 23:48:32 +020029#include <gsm/gsmtap.h>
30#include "get_bcch_or_ccch_bursts_impl.h"
31
32namespace gr {
33 namespace gsm {
34
35 get_bcch_or_ccch_bursts::sptr
piotrdf304592014-08-04 11:22:47 +020036 get_bcch_or_ccch_bursts::make(unsigned int fn51_start)
piotrfaacc722014-07-20 23:48:32 +020037 {
38 return gnuradio::get_initial_sptr
piotrdf304592014-08-04 11:22:47 +020039 (new get_bcch_or_ccch_bursts_impl(fn51_start));
piotrfaacc722014-07-20 23:48:32 +020040 }
41
42 /*
43 * The private constructor
44 */
piotrdf304592014-08-04 11:22:47 +020045 get_bcch_or_ccch_bursts_impl::get_bcch_or_ccch_bursts_impl(unsigned int fn51_start)
piotrfaacc722014-07-20 23:48:32 +020046 : gr::block("get_bcch_or_ccch_bursts",
47 gr::io_signature::make(0, 0, 0),
piotrdf304592014-08-04 11:22:47 +020048 gr::io_signature::make(0, 0, 0)),
49 d_fn51_start(fn51_start)
piotrfaacc722014-07-20 23:48:32 +020050 {
51 message_port_register_in(pmt::mp("bursts"));
52 set_msg_handler(pmt::mp("bursts"), boost::bind(&get_bcch_or_ccch_bursts_impl::filter_ccch, this, _1));
53 message_port_register_out(pmt::mp("bursts"));
54 }
55
56 /*
57 * Our virtual destructor.
58 */
59 get_bcch_or_ccch_bursts_impl::~get_bcch_or_ccch_bursts_impl()
60 {
61 }
62
63 void get_bcch_or_ccch_bursts_impl::filter_ccch(pmt::pmt_t msg)
64 {
ptrkrysik617ba032014-11-21 10:11:05 +010065 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
66 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
ptrkrysik6f6d46d2014-11-12 22:50:18 +010067 uint32_t frame_nr = be32toh(header->frame_number);
piotrfaacc722014-07-20 23:48:32 +020068
ptrkrysik6f6d46d2014-11-12 22:50:18 +010069 uint32_t fn_mod51 = frame_nr % 51;
piotrdf304592014-08-04 11:22:47 +020070 int fn51_stop = d_fn51_start+3;
piotrfaacc722014-07-20 23:48:32 +020071
72 if(header->timeslot==0){
piotrdf304592014-08-04 11:22:47 +020073 if(fn_mod51>=d_fn51_start && fn_mod51<=fn51_stop){
74 uint32_t ii = fn_mod51-d_fn51_start;
ptrkrysik6f6d46d2014-11-12 22:50:18 +010075 d_frame_numbers[ii]=frame_nr;
piotrfaacc722014-07-20 23:48:32 +020076 d_bursts[ii] = msg;
77 }
78
79 if(fn_mod51==fn51_stop){
80 //check for a situation where some BCCH bursts were lost
81 //in this situation frame numbers won't be consecutive
82 bool frames_are_consecutive = true;
83 for(int jj=1; jj<4; jj++)
84 {
85 if((d_frame_numbers[jj]-d_frame_numbers[jj-1])!=1){
86 frames_are_consecutive = false;
87 }
88 }
89 if(frames_are_consecutive)
90 {
91 //send bursts to the output
92 for(int jj=0; jj<4; jj++)
93 {
94 message_port_pub(pmt::mp("bursts"), d_bursts[jj]);
95 }
96 }
97 }
98 }
99 }
100 } /* namespace gsm */
101} /* namespace gr */
102