blob: 113a4a6893e19a8d881f0cf3a1c030e9042bb250 [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
Piotr Krysikf849faf2017-11-11 11:14:26 +010055 message_port_register_in(pmt::mp("bursts_in"));
56 message_port_register_out(pmt::mp("bursts_out"));
Piotr Krysikacc365f2017-11-07 19:31:42 +010057
Vadim Yanitskiya1169202021-05-03 19:00:43 +020058 set_msg_handler(pmt::mp("bursts_in"), boost::bind(&burst_type_filter_impl::process_burst, this, boost::placeholders::_1));
Piotr Krysikacc365f2017-11-07 19:31:42 +010059 }
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) {
Piotr Krysikf849faf2017-11-11 11:14:26 +010072 message_port_pub(pmt::mp("bursts_out"), msg);
Piotr Krysikacc365f2017-11-07 19:31:42 +010073 return;
74 }
75
76 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(pmt::cdr(msg));
Piotr Krysikacc365f2017-11-07 19:31:42 +010077 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
78 {
Piotr Krysikf849faf2017-11-11 11:14:26 +010079 message_port_pub(pmt::mp("bursts_out"), msg);
Piotr Krysikacc365f2017-11-07 19:31:42 +010080 }
81 }
82
83 /* Filtering policy */
84 filter_policy
85 burst_type_filter_impl::get_policy(void)
86 {
87 return d_filter_policy;
88 }
89
90 filter_policy
91 burst_type_filter_impl::set_policy(filter_policy policy)
92 {
93 d_filter_policy = policy;
94 return d_filter_policy;
95 }
96
97 void
98 burst_type_filter_impl::set_selected_burst_types(const std::vector<uint8_t> & selected_burst_types)
99 {
100 d_selected_burst_types.assign(selected_burst_types.begin(), selected_burst_types.end());
101 }
102 } /* namespace gsm */
103} /* namespace gr */