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