Roman Khassraf | a1eb188 | 2015-08-05 12:30:29 +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_sdcch_subslot_splitter_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_sdcch_subslot_splitter::sptr |
| 38 | burst_sdcch_subslot_splitter::make(splitter_mode mode) |
| 39 | { |
| 40 | return gnuradio::get_initial_sptr |
| 41 | (new burst_sdcch_subslot_splitter_impl(mode)); |
| 42 | } |
| 43 | |
| 44 | /* |
| 45 | * The private constructor |
| 46 | */ |
| 47 | burst_sdcch_subslot_splitter_impl::burst_sdcch_subslot_splitter_impl(splitter_mode mode) |
| 48 | : gr::block("burst_sdcch_subslot_splitter", |
| 49 | gr::io_signature::make(0, 0, 0), |
| 50 | gr::io_signature::make(0, 0, 0)), |
| 51 | d_mode(mode) |
| 52 | { |
| 53 | message_port_register_in(pmt::mp("in")); |
| 54 | |
| 55 | message_port_register_out(pmt::mp("out0")); |
| 56 | message_port_register_out(pmt::mp("out1")); |
| 57 | message_port_register_out(pmt::mp("out2")); |
| 58 | message_port_register_out(pmt::mp("out3")); |
| 59 | if (d_mode == SPLITTER_SDCCH8) |
| 60 | { |
| 61 | message_port_register_out(pmt::mp("out4")); |
| 62 | message_port_register_out(pmt::mp("out5")); |
| 63 | message_port_register_out(pmt::mp("out6")); |
| 64 | message_port_register_out(pmt::mp("out7")); |
| 65 | } |
| 66 | |
| 67 | set_msg_handler(pmt::mp("in"), boost::bind(&burst_sdcch_subslot_splitter_impl::process_burst, this, _1)); |
| 68 | } |
| 69 | |
| 70 | /* |
| 71 | * Our virtual destructor. |
| 72 | */ |
| 73 | burst_sdcch_subslot_splitter_impl::~burst_sdcch_subslot_splitter_impl() {} |
| 74 | |
| 75 | void burst_sdcch_subslot_splitter_impl::process_burst(pmt::pmt_t msg) |
| 76 | { |
| 77 | pmt::pmt_t header_plus_burst = pmt::cdr(msg); |
| 78 | gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst); |
| 79 | |
| 80 | uint32_t frame_nr = be32toh(header->frame_number); |
| 81 | uint32_t fn_mod102 = frame_nr % 102; |
| 82 | |
| 83 | int8_t subslot; |
| 84 | |
| 85 | if (d_mode == SPLITTER_SDCCH8) |
| 86 | { |
| 87 | subslot = d_subslots_sdcch8[fn_mod102]; |
| 88 | } |
| 89 | else if (d_mode == SPLITTER_SDCCH4) |
| 90 | { |
| 91 | subslot = d_subslots_sdcch4[fn_mod102]; |
| 92 | } |
| 93 | |
| 94 | if ((subslot == -1) || (d_mode == SPLITTER_SDCCH4 && subslot > 3)) |
| 95 | { |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | std::string port("out"); |
| 100 | |
| 101 | switch (subslot) |
| 102 | { |
| 103 | case 0: |
| 104 | port.append("0"); |
| 105 | break; |
| 106 | case 1: |
| 107 | port.append("1"); |
| 108 | break; |
| 109 | case 2: |
| 110 | port.append("2"); |
| 111 | break; |
| 112 | case 3: |
| 113 | port.append("3"); |
| 114 | break; |
| 115 | case 4: |
| 116 | port.append("4"); |
| 117 | break; |
| 118 | case 5: |
| 119 | port.append("5"); |
| 120 | break; |
| 121 | case 6: |
| 122 | port.append("6"); |
| 123 | break; |
| 124 | case 7: |
| 125 | port.append("7"); |
| 126 | break; |
| 127 | default: |
| 128 | port.append("0"); |
| 129 | break; |
| 130 | } |
| 131 | |
| 132 | message_port_pub(pmt::mp(port), msg); |
| 133 | } |
| 134 | } /* namespace gsm */ |
| 135 | } /* namespace gr */ |