Roman Khassraf | 7cccb52 | 2015-08-04 12:26:54 +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 "dummy_burst_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 | // dummy burst defined in gsm 05.02, section 5.2.6 |
| 38 | const int8_t dummy_burst_filter_impl::d_dummy_burst[] = {0,0,0, |
| 39 | 1,1,1,1,1,0,1,1,0,1,1,1,0,1,1,0, |
| 40 | 0,0,0,0,1,0,1,0,0,1,0,0,1,1,1,0, |
| 41 | 0,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0, |
| 42 | 0,0,0,1,1,1,1,1,0,0,0,1,1,1,0,0, |
| 43 | 0,1,0,1,1,1,0,0,0,1,0,1,1,1,0,0, |
| 44 | 0,1,0,1,0,1,1,1,0,1,0,0,1,0,1,0, |
| 45 | 0,0,1,1,0,0,1,1,0,0,1,1,1,0,0,1, |
| 46 | 1,1,1,0,1,0,0,1,1,1,1,1,0,0,0,1, |
| 47 | 0,0,1,0,1,1,1,1,1,0,1,0,1,0, |
| 48 | 0,0,0 }; |
| 49 | |
| 50 | dummy_burst_filter::sptr |
| 51 | dummy_burst_filter::make() |
| 52 | { |
| 53 | return gnuradio::get_initial_sptr |
| 54 | (new dummy_burst_filter_impl()); |
| 55 | } |
| 56 | |
| 57 | /* |
| 58 | * The private constructor |
| 59 | */ |
| 60 | dummy_burst_filter_impl::dummy_burst_filter_impl() |
| 61 | : gr::block("dummy_burst_filter", |
| 62 | gr::io_signature::make(0, 0, 0), |
| 63 | gr::io_signature::make(0, 0, 0)) |
| 64 | { |
| 65 | message_port_register_in(pmt::mp("in")); |
| 66 | message_port_register_out(pmt::mp("out")); |
| 67 | |
| 68 | set_msg_handler(pmt::mp("in"), boost::bind(&dummy_burst_filter_impl::process_burst, this, _1)); |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * Our virtual destructor. |
| 73 | */ |
| 74 | dummy_burst_filter_impl::~dummy_burst_filter_impl() {} |
| 75 | |
| 76 | void dummy_burst_filter_impl::process_burst(pmt::pmt_t msg) |
| 77 | { |
| 78 | pmt::pmt_t header_plus_burst = pmt::cdr(msg); |
| 79 | int8_t * burst = (int8_t *)(pmt::blob_data(header_plus_burst)) + sizeof(gsmtap_hdr); |
| 80 | size_t burst_len = pmt::blob_length(header_plus_burst) - sizeof(gsmtap_hdr); |
| 81 | |
| 82 | if (!is_dummy_burst(burst, burst_len)) |
| 83 | { |
| 84 | message_port_pub(pmt::mp("out"), msg); |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | bool dummy_burst_filter_impl::is_dummy_burst(int8_t *burst, size_t burst_len) |
| 89 | { |
| 90 | if (burst_len != DUMMY_BURST_LEN) |
| 91 | { |
| 92 | return false; |
| 93 | } |
| 94 | for (int i=0; i<DUMMY_BURST_LEN; i++) |
| 95 | { |
| 96 | if (burst[i] != d_dummy_burst[i]) |
| 97 | { |
| 98 | return false; |
| 99 | } |
| 100 | } |
| 101 | return true; |
| 102 | } |
| 103 | |
| 104 | } /* namespace gsm */ |
| 105 | } /* namespace gr */ |