blob: 4fcd847b32c23ccba6cd2cf8bbfd628e57fdda68 [file] [log] [blame]
Roman Khassrafd7e3eec2015-08-06 11:54:22 +02001/* -*- c++ -*- */
2/* @file
Piotr Krysika6268a52017-08-23 16:02:19 +02003 * @author (C) 2015 by Roman Khassraf <rkhassraf@gmail.com>
Roman Khassrafd7e3eec2015-08-06 11:54:22 +02004 * @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_timeslot_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_timeslot_filter::sptr
38 burst_timeslot_filter::make(unsigned int timeslot)
39 {
40 return gnuradio::get_initial_sptr
41 (new burst_timeslot_filter_impl(timeslot));
42 }
43
44 /*
45 * The private constructor
46 */
47 burst_timeslot_filter_impl::burst_timeslot_filter_impl(unsigned int timeslot)
48 : gr::block("burst_timeslot_filter",
49 gr::io_signature::make(0, 0, 0),
50 gr::io_signature::make(0, 0, 0)),
Vadim Yanitskiy04536ab2017-07-21 10:59:51 +070051 d_timeslot(timeslot),
52 d_filter_policy(FILTER_POLICY_DEFAULT)
Roman Khassrafd7e3eec2015-08-06 11:54:22 +020053 {
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_timeslot_filter_impl::process_burst, this, _1));
58 }
59
60 /*
61 * Our virtual destructor.
62 */
63 burst_timeslot_filter_impl::~burst_timeslot_filter_impl() {}
64
65 void burst_timeslot_filter_impl::process_burst(pmt::pmt_t msg)
66 {
Vadim Yanitskiy04536ab2017-07-21 10:59:51 +070067 if (d_filter_policy == FILTER_POLICY_DROP_ALL)
68 return;
69
70 if (d_filter_policy == FILTER_POLICY_PASS_ALL) {
71 message_port_pub(pmt::mp("out"), msg);
72 return;
73 }
74
Roman Khassrafd7e3eec2015-08-06 11:54:22 +020075 pmt::pmt_t header_plus_burst = pmt::cdr(msg);
76 gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst);
77
78 unsigned int timeslot = header->timeslot;
79
80 if (header->timeslot == d_timeslot)
81 {
82 message_port_pub(pmt::mp("out"), msg);
83 }
84 }
Vadim Yanitskiy91195eb2017-07-21 06:39:40 +070085
86 /*
87 * External API
88 */
89 unsigned int
90 burst_timeslot_filter_impl::get_tn(void)
91 {
92 return d_timeslot;
93 }
94
95 unsigned int
96 burst_timeslot_filter_impl::set_tn(unsigned int tn)
97 {
98 if (tn < 8)
99 d_timeslot = tn;
100
101 return d_timeslot;
102 }
103
Vadim Yanitskiy04536ab2017-07-21 10:59:51 +0700104 /* Filtering policy */
105 filter_policy
106 burst_timeslot_filter_impl::get_policy(void)
107 {
108 return d_filter_policy;
109 }
110
111 filter_policy
112 burst_timeslot_filter_impl::set_policy(filter_policy policy)
113 {
114 d_filter_policy = policy;
115 return d_filter_policy;
116 }
117
Roman Khassrafd7e3eec2015-08-06 11:54:22 +0200118 } /* namespace gsm */
119} /* namespace gr */