Roman Khassraf | 8e3b0ec | 2015-08-04 11:16:04 +0200 | [diff] [blame] | 1 | /* -*- 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 | |
| 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), |
| 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 Glass | c8edec5 | 2015-09-27 16:14:33 +1000 | [diff] [blame] | 73 | || (d_mode == FILTER_GREATER_OR_EQUAL && frame_nr >= d_framenr)) |
Roman Khassraf | 8e3b0ec | 2015-08-04 11:16:04 +0200 | [diff] [blame] | 74 | { |
| 75 | message_port_pub(pmt::mp("out"), msg); |
| 76 | } |
| 77 | } |
| 78 | } /* namespace gsm */ |
| 79 | } /* namespace gr */ |