blob: 542a004bab30c82799e7f7610e084d755b36df92 [file] [log] [blame]
Piotr Krysikacc365f2017-11-07 19:31:42 +01001/* -*- c++ -*- */
2/* @file
3 * @author (C) 2017 by Piotr Krysik <ptrkrysik@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_type_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_type_filter::sptr
38 burst_type_filter::make(const std::vector<uint8_t> & selected_burst_types)
39 {
40 return gnuradio::get_initial_sptr
41 (new burst_type_filter_impl(selected_burst_types));
42 }
43
44 /*
45 * The private constructor
46 */
47 burst_type_filter_impl::burst_type_filter_impl(const std::vector<uint8_t> & selected_burst_types)
48 : gr::block("burst_type_filter",
49 gr::io_signature::make(0, 0, 0),
50 gr::io_signature::make(0, 0, 0)),
51 d_filter_policy(FILTER_POLICY_DEFAULT)
52 {
53 set_selected_burst_types(selected_burst_types);
54
55 message_port_register_in(pmt::mp("in"));
56 message_port_register_out(pmt::mp("out"));
57
58 set_msg_handler(pmt::mp("in"), boost::bind(&burst_type_filter_impl::process_burst, this, _1));
59 }
60
61 /*
62 * Our virtual destructor.
63 */
64 burst_type_filter_impl::~burst_type_filter_impl() {}
65
66 void burst_type_filter_impl::process_burst(pmt::pmt_t msg)
67 {
68 if (d_filter_policy == FILTER_POLICY_DROP_ALL)
69 return;
70
71 if (d_filter_policy == FILTER_POLICY_PASS_ALL) {
72 message_port_pub(pmt::mp("out"), msg);
73 return;
74 }
75
76 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(pmt::cdr(msg));
77// std::cout << "header->type: " << (int)(header->sub_type) << std::endl;
78 if (std::find(d_selected_burst_types.begin(), d_selected_burst_types.end(), header->sub_type) != d_selected_burst_types.end()) //check if burst type is listed in burst types to pass
79 {
80 message_port_pub(pmt::mp("out"), msg);
81 }
82 }
83
84 /* Filtering policy */
85 filter_policy
86 burst_type_filter_impl::get_policy(void)
87 {
88 return d_filter_policy;
89 }
90
91 filter_policy
92 burst_type_filter_impl::set_policy(filter_policy policy)
93 {
94 d_filter_policy = policy;
95 return d_filter_policy;
96 }
97
98 void
99 burst_type_filter_impl::set_selected_burst_types(const std::vector<uint8_t> & selected_burst_types)
100 {
101 d_selected_burst_types.assign(selected_burst_types.begin(), selected_burst_types.end());
102 }
103 } /* namespace gsm */
104} /* namespace gr */