blob: 940dcdf2745b69a5244729e7873c695990bb3f03 [file] [log] [blame]
Roman Khassraf8e3b0ec2015-08-04 11:16:04 +02001/* -*- c++ -*- */
2/* @file
3 * @author Roman Khassraf <rkhassraf@gmail.com>
4 * @section LICENSE
5 *
6 * Gr-gsm is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3, or (at your option)
9 * any later version.
10 *
11 * Gr-gsm is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with gr-gsm; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <gnuradio/io_signature.h>
28#include "burst_fnr_filter_impl.h"
29#include <stdio.h>
30#include <grgsm/endian.h>
31#include <grgsm/gsmtap.h>
32
33
34namespace gr {
35 namespace gsm {
36
37 burst_fnr_filter::sptr
38 burst_fnr_filter::make(filter_mode mode, unsigned int fnr)
39 {
40 return gnuradio::get_initial_sptr
41 (new burst_fnr_filter_impl(mode, fnr));
42 }
43
44 /*
45 * The private constructor
46 */
47 burst_fnr_filter_impl::burst_fnr_filter_impl(filter_mode mode, unsigned int fnr)
48 : gr::block("burst_fnr_filter",
49 gr::io_signature::make(0, 0, 0),
50 gr::io_signature::make(0, 0, 0)),
51 d_mode(mode),
52 d_framenr(fnr)
53 {
54 message_port_register_in(pmt::mp("in"));
55 message_port_register_out(pmt::mp("out"));
56
57 set_msg_handler(pmt::mp("in"), boost::bind(&burst_fnr_filter_impl::process_burst, this, _1));
58 }
59
60 /*
61 * Our virtual destructor.
62 */
63 burst_fnr_filter_impl::~burst_fnr_filter_impl() {}
64
65 void burst_fnr_filter_impl::process_burst(pmt::pmt_t msg)
66 {
67 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
68 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
69
70 unsigned int frame_nr = be32toh(header->frame_number);
71
72 if ((d_mode == FILTER_LESS_OR_EQUAL && frame_nr <= d_framenr)
Steve Glassc8edec52015-09-27 16:14:33 +100073 || (d_mode == FILTER_GREATER_OR_EQUAL && frame_nr >= d_framenr))
Roman Khassraf8e3b0ec2015-08-04 11:16:04 +020074 {
75 message_port_pub(pmt::mp("out"), msg);
76 }
77 }
Vadim Yanitskiyccc71832017-07-21 07:00:45 +070078
79 /* External API */
80 unsigned int
81 burst_fnr_filter_impl::get_fn(void)
82 {
83 return d_framenr;
84 }
85
86 unsigned int
87 burst_fnr_filter_impl::set_fn(unsigned int fn)
88 {
89 if (fn <= GSM_HYPERFRAME)
90 d_framenr = fn;
91
92 return d_framenr;
93 }
94
95
96 filter_mode
97 burst_fnr_filter_impl::get_mode(void)
98 {
99 return d_mode;
100 }
101
102 filter_mode
103 burst_fnr_filter_impl::set_mode(filter_mode mode)
104 {
105 d_mode = mode;
106 return d_mode;
107 }
108
Roman Khassraf8e3b0ec2015-08-04 11:16:04 +0200109 } /* namespace gsm */
110} /* namespace gr */