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" |
ptrkrysik | 3be74a7 | 2014-12-13 10:11:00 +0100 | [diff] [blame] | 29 | #include <grgsm/endian.h> |
| 30 | #include <grgsm/gsmtap.h> |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 31 | |
| 32 | namespace gr { |
| 33 | namespace gsm { |
| 34 | |
| 35 | universal_ctrl_chans_demapper::sptr |
ptrkrysik | d8d4fbc | 2015-02-07 19:37:42 +0100 | [diff] [blame] | 36 | universal_ctrl_chans_demapper::make(unsigned int timeslot_nr, const std::vector<int> &starts_fn_mod51, const std::vector<int> &channel_types) |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 37 | { |
| 38 | return gnuradio::get_initial_sptr |
ptrkrysik | d8d4fbc | 2015-02-07 19:37:42 +0100 | [diff] [blame] | 39 | (new universal_ctrl_chans_demapper_impl(timeslot_nr, starts_fn_mod51, channel_types)); |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /* |
| 43 | * The private constructor |
| 44 | */ |
ptrkrysik | d8d4fbc | 2015-02-07 19:37:42 +0100 | [diff] [blame] | 45 | universal_ctrl_chans_demapper_impl::universal_ctrl_chans_demapper_impl(unsigned int timeslot_nr, const std::vector<int> &starts_fn_mod51, const std::vector<int> &channel_types) |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 46 | : gr::block("universal_ctrl_chans_demapper", |
| 47 | gr::io_signature::make(0, 0, 0), |
ptrkrysik | d8d4fbc | 2015-02-07 19:37:42 +0100 | [diff] [blame] | 48 | gr::io_signature::make(0, 0, 0)), |
| 49 | d_timeslot(timeslot_nr) |
| 50 | |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 51 | { |
| 52 | |
ptrkrysik | d8d4fbc | 2015-02-07 19:37:42 +0100 | [diff] [blame] | 53 | |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 54 | for(int ii=0; ii<51; ii++) |
| 55 | { |
| 56 | d_starts_fn_mod51[ii]=0; |
| 57 | d_channel_types[ii]=0; |
| 58 | } |
| 59 | |
| 60 | std::vector<int>::const_iterator s; |
| 61 | std::vector<int>::const_iterator ch_type; |
| 62 | |
| 63 | for(s=starts_fn_mod51.begin(), ch_type=channel_types.begin();s != starts_fn_mod51.end(); s++) |
| 64 | { |
| 65 | if((*s > 0) and (*s < (51-4))) |
| 66 | { |
| 67 | for(int ii=0; ii<4; ii++){ |
| 68 | d_starts_fn_mod51[*s+ii] = *s; |
| 69 | if(ch_type!=channel_types.end()) |
| 70 | { |
| 71 | d_channel_types[*s+ii] = *ch_type; |
| 72 | } |
| 73 | } |
| 74 | if(ch_type!=channel_types.end()) |
| 75 | { |
| 76 | ch_type++; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | |
| 82 | message_port_register_in(pmt::mp("bursts")); |
| 83 | set_msg_handler(pmt::mp("bursts"), boost::bind(&universal_ctrl_chans_demapper_impl::filter_ctrl_chans, this, _1)); |
| 84 | message_port_register_out(pmt::mp("bursts")); |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * Our virtual destructor. |
| 89 | */ |
| 90 | universal_ctrl_chans_demapper_impl::~universal_ctrl_chans_demapper_impl() |
| 91 | { |
| 92 | } |
| 93 | |
| 94 | void universal_ctrl_chans_demapper_impl::filter_ctrl_chans(pmt::pmt_t msg) |
| 95 | { |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 96 | pmt::pmt_t header_plus_burst = pmt::cdr(msg); |
| 97 | gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst); |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 98 | |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 99 | uint32_t frame_nr = be32toh(header->frame_number); |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 100 | uint32_t fn_mod51 = frame_nr % 51; |
| 101 | uint32_t fn51_start = d_starts_fn_mod51[fn_mod51]; |
| 102 | uint32_t fn51_stop = fn51_start + 3; |
| 103 | uint32_t ch_type = d_channel_types[fn_mod51]; |
| 104 | header->sub_type = ch_type; |
| 105 | |
| 106 | if(header->timeslot==d_timeslot){ |
| 107 | if(fn_mod51>=fn51_start && fn_mod51<=fn51_stop) |
| 108 | { |
| 109 | uint32_t ii = fn_mod51 - fn51_start; |
| 110 | d_frame_numbers[ii] = frame_nr; |
| 111 | d_bursts[ii] = msg; |
| 112 | } |
| 113 | |
| 114 | if(fn_mod51==fn51_stop) |
| 115 | { |
| 116 | //check for a situation where some bursts were lost |
| 117 | //in this situation frame numbers won't be consecutive |
| 118 | bool frames_are_consecutive = true; |
| 119 | for(int jj=1; jj<4; jj++) |
| 120 | { |
| 121 | if((d_frame_numbers[jj]-d_frame_numbers[jj-1])!=1) |
| 122 | { |
| 123 | frames_are_consecutive = false; |
| 124 | } |
| 125 | } |
| 126 | if(frames_are_consecutive) |
| 127 | { |
| 128 | //send bursts to the output |
| 129 | for(int jj=0; jj<4; jj++) |
| 130 | { |
| 131 | message_port_pub(pmt::mp("bursts"), d_bursts[jj]); |
| 132 | } |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | } /* namespace gsm */ |
| 138 | } /* namespace gr */ |
| 139 | |