Roman Khassraf | 8e3b0ec | 2015-08-04 11:16:04 +0200 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* @file |
Piotr Krysik | a6268a5 | 2017-08-23 16:02:19 +0200 | [diff] [blame] | 3 | * @author (C) 2015 by Roman Khassraf <rkhassraf@gmail.com> |
Roman Khassraf | 8e3b0ec | 2015-08-04 11:16:04 +0200 | [diff] [blame] | 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 | |
| 34 | namespace 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), |
Vadim Yanitskiy | 04536ab | 2017-07-21 10:59:51 +0700 | [diff] [blame] | 52 | d_framenr(fnr), |
| 53 | d_filter_policy(FILTER_POLICY_DEFAULT) |
Roman Khassraf | 8e3b0ec | 2015-08-04 11:16:04 +0200 | [diff] [blame] | 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_fnr_filter_impl::process_burst, this, _1)); |
| 59 | } |
| 60 | |
| 61 | /* |
| 62 | * Our virtual destructor. |
| 63 | */ |
| 64 | burst_fnr_filter_impl::~burst_fnr_filter_impl() {} |
| 65 | |
| 66 | void burst_fnr_filter_impl::process_burst(pmt::pmt_t msg) |
| 67 | { |
Vadim Yanitskiy | 04536ab | 2017-07-21 10:59:51 +0700 | [diff] [blame] | 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 | |
Roman Khassraf | 8e3b0ec | 2015-08-04 11:16:04 +0200 | [diff] [blame] | 76 | pmt::pmt_t header_plus_burst = pmt::cdr(msg); |
| 77 | gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst); |
| 78 | |
| 79 | unsigned int frame_nr = be32toh(header->frame_number); |
| 80 | |
| 81 | if ((d_mode == FILTER_LESS_OR_EQUAL && frame_nr <= d_framenr) |
Steve Glass | c8edec5 | 2015-09-27 16:14:33 +1000 | [diff] [blame] | 82 | || (d_mode == FILTER_GREATER_OR_EQUAL && frame_nr >= d_framenr)) |
Roman Khassraf | 8e3b0ec | 2015-08-04 11:16:04 +0200 | [diff] [blame] | 83 | { |
| 84 | message_port_pub(pmt::mp("out"), msg); |
| 85 | } |
| 86 | } |
Vadim Yanitskiy | ccc7183 | 2017-07-21 07:00:45 +0700 | [diff] [blame] | 87 | |
| 88 | /* External API */ |
| 89 | unsigned int |
| 90 | burst_fnr_filter_impl::get_fn(void) |
| 91 | { |
| 92 | return d_framenr; |
| 93 | } |
| 94 | |
| 95 | unsigned int |
| 96 | burst_fnr_filter_impl::set_fn(unsigned int fn) |
| 97 | { |
| 98 | if (fn <= GSM_HYPERFRAME) |
| 99 | d_framenr = fn; |
| 100 | |
| 101 | return d_framenr; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | filter_mode |
| 106 | burst_fnr_filter_impl::get_mode(void) |
| 107 | { |
| 108 | return d_mode; |
| 109 | } |
| 110 | |
| 111 | filter_mode |
| 112 | burst_fnr_filter_impl::set_mode(filter_mode mode) |
| 113 | { |
| 114 | d_mode = mode; |
| 115 | return d_mode; |
| 116 | } |
| 117 | |
Vadim Yanitskiy | 04536ab | 2017-07-21 10:59:51 +0700 | [diff] [blame] | 118 | /* Filtering policy */ |
| 119 | filter_policy |
| 120 | burst_fnr_filter_impl::get_policy(void) |
| 121 | { |
| 122 | return d_filter_policy; |
| 123 | } |
| 124 | |
| 125 | filter_policy |
| 126 | burst_fnr_filter_impl::set_policy(filter_policy policy) |
| 127 | { |
| 128 | d_filter_policy = policy; |
| 129 | return d_filter_policy; |
| 130 | } |
| 131 | |
Roman Khassraf | 8e3b0ec | 2015-08-04 11:16:04 +0200 | [diff] [blame] | 132 | } /* namespace gsm */ |
| 133 | } /* namespace gr */ |