ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame^] | 2 | /* |
| 3 | * @file |
| 4 | * @author Piotr Krysik <ptrkrysik@gmail.com> |
| 5 | * @section LICENSE |
| 6 | * |
| 7 | * Gr-gsm is free software; you can redistribute it and/or modify |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3, or (at your option) |
| 10 | * any later version. |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame^] | 11 | * |
| 12 | * Gr-gsm is distributed in the hope that it will be useful, |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame^] | 16 | * |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU General Public License |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame^] | 18 | * along with gr-gsm; see the file COPYING. If not, write to |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 19 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | * Boston, MA 02110-1301, USA. |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_H |
| 24 | #include "config.h" |
| 25 | #endif |
| 26 | |
| 27 | #include <gnuradio/io_signature.h> |
| 28 | #include "universal_ctrl_chans_demapper_impl.h" |
| 29 | #include <gsm/gsmtap.h> |
| 30 | |
| 31 | namespace gr { |
| 32 | namespace gsm { |
| 33 | |
| 34 | universal_ctrl_chans_demapper::sptr |
| 35 | universal_ctrl_chans_demapper::make(const std::vector<int> &starts_fn_mod51, const std::vector<int> &channel_types) |
| 36 | { |
| 37 | return gnuradio::get_initial_sptr |
| 38 | (new universal_ctrl_chans_demapper_impl(starts_fn_mod51, channel_types)); |
| 39 | } |
| 40 | |
| 41 | /* |
| 42 | * The private constructor |
| 43 | */ |
| 44 | universal_ctrl_chans_demapper_impl::universal_ctrl_chans_demapper_impl(const std::vector<int> &starts_fn_mod51, const std::vector<int> &channel_types) |
| 45 | : gr::block("universal_ctrl_chans_demapper", |
| 46 | gr::io_signature::make(0, 0, 0), |
| 47 | gr::io_signature::make(0, 0, 0)) |
| 48 | { |
| 49 | |
| 50 | d_timeslot=0; |
| 51 | for(int ii=0; ii<51; ii++) |
| 52 | { |
| 53 | d_starts_fn_mod51[ii]=0; |
| 54 | d_channel_types[ii]=0; |
| 55 | } |
| 56 | |
| 57 | std::vector<int>::const_iterator s; |
| 58 | std::vector<int>::const_iterator ch_type; |
| 59 | |
| 60 | for(s=starts_fn_mod51.begin(), ch_type=channel_types.begin();s != starts_fn_mod51.end(); s++) |
| 61 | { |
| 62 | if((*s > 0) and (*s < (51-4))) |
| 63 | { |
| 64 | for(int ii=0; ii<4; ii++){ |
| 65 | d_starts_fn_mod51[*s+ii] = *s; |
| 66 | if(ch_type!=channel_types.end()) |
| 67 | { |
| 68 | d_channel_types[*s+ii] = *ch_type; |
| 69 | } |
| 70 | } |
| 71 | if(ch_type!=channel_types.end()) |
| 72 | { |
| 73 | ch_type++; |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | |
| 79 | message_port_register_in(pmt::mp("bursts")); |
| 80 | set_msg_handler(pmt::mp("bursts"), boost::bind(&universal_ctrl_chans_demapper_impl::filter_ctrl_chans, this, _1)); |
| 81 | message_port_register_out(pmt::mp("bursts")); |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | * Our virtual destructor. |
| 86 | */ |
| 87 | universal_ctrl_chans_demapper_impl::~universal_ctrl_chans_demapper_impl() |
| 88 | { |
| 89 | } |
| 90 | |
| 91 | void universal_ctrl_chans_demapper_impl::filter_ctrl_chans(pmt::pmt_t msg) |
| 92 | { |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 93 | pmt::pmt_t header_plus_burst = pmt::cdr(msg); |
| 94 | gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst); |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 95 | |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 96 | uint32_t frame_nr = be32toh(header->frame_number); |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 97 | uint32_t fn_mod51 = frame_nr % 51; |
| 98 | uint32_t fn51_start = d_starts_fn_mod51[fn_mod51]; |
| 99 | uint32_t fn51_stop = fn51_start + 3; |
| 100 | uint32_t ch_type = d_channel_types[fn_mod51]; |
| 101 | header->sub_type = ch_type; |
| 102 | |
| 103 | if(header->timeslot==d_timeslot){ |
| 104 | if(fn_mod51>=fn51_start && fn_mod51<=fn51_stop) |
| 105 | { |
| 106 | uint32_t ii = fn_mod51 - fn51_start; |
| 107 | d_frame_numbers[ii] = frame_nr; |
| 108 | d_bursts[ii] = msg; |
| 109 | } |
| 110 | |
| 111 | if(fn_mod51==fn51_stop) |
| 112 | { |
| 113 | //check for a situation where some bursts were lost |
| 114 | //in this situation frame numbers won't be consecutive |
| 115 | bool frames_are_consecutive = true; |
| 116 | for(int jj=1; jj<4; jj++) |
| 117 | { |
| 118 | if((d_frame_numbers[jj]-d_frame_numbers[jj-1])!=1) |
| 119 | { |
| 120 | frames_are_consecutive = false; |
| 121 | } |
| 122 | } |
| 123 | if(frames_are_consecutive) |
| 124 | { |
| 125 | //send bursts to the output |
| 126 | for(int jj=0; jj<4; jj++) |
| 127 | { |
| 128 | message_port_pub(pmt::mp("bursts"), d_bursts[jj]); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | } /* namespace gsm */ |
| 135 | } /* namespace gr */ |
| 136 | |