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; |
Roman Khassraf | e571e96 | 2015-04-12 15:35:41 +0200 | [diff] [blame] | 58 | d_subslots[ii] = 0; |
| 59 | d_subslots[ii+51] = 0; |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | std::vector<int>::const_iterator s; |
| 63 | std::vector<int>::const_iterator ch_type; |
| 64 | |
| 65 | for(s=starts_fn_mod51.begin(), ch_type=channel_types.begin();s != starts_fn_mod51.end(); s++) |
| 66 | { |
Roman Khassraf | 939edef | 2015-04-12 15:20:38 +0200 | [diff] [blame] | 67 | if((*s >= 0) and (*s <= (51-4))) |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 68 | { |
| 69 | for(int ii=0; ii<4; ii++){ |
| 70 | d_starts_fn_mod51[*s+ii] = *s; |
| 71 | if(ch_type!=channel_types.end()) |
| 72 | { |
| 73 | d_channel_types[*s+ii] = *ch_type; |
| 74 | } |
| 75 | } |
| 76 | if(ch_type!=channel_types.end()) |
| 77 | { |
| 78 | ch_type++; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
Roman Khassraf | e571e96 | 2015-04-12 15:35:41 +0200 | [diff] [blame] | 83 | std::set<int> distinct_channels(channel_types.begin(), channel_types.end()); |
| 84 | std::set<int>::iterator it; |
| 85 | unsigned int subslot; |
| 86 | |
| 87 | for (it=distinct_channels.begin(); it != distinct_channels.end(); it++) |
| 88 | { |
| 89 | subslot = 0; |
| 90 | for(s=starts_fn_mod51.begin();s != starts_fn_mod51.end(); s++) |
| 91 | { |
| 92 | if ((d_channel_types[*s] == *it) and (*s >= 0) and (*s <= (51-4))) |
| 93 | { |
| 94 | for(int ii=0; ii<4; ii++) |
| 95 | { |
| 96 | d_subslots[*s+ii] = subslot; |
| 97 | d_subslots[*s+ii+51] = subslot; |
| 98 | } |
| 99 | subslot++; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | if (*it == GSMTAP_CHANNEL_ACCH or |
| 104 | *it == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_SDCCH) or |
| 105 | *it == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_SDCCH4) or |
| 106 | *it == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_SDCCH8) or |
| 107 | *it == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_TCH_F) or |
| 108 | *it == (GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_TCH_H) |
| 109 | ) |
| 110 | { |
| 111 | for(s=starts_fn_mod51.begin();s != starts_fn_mod51.end(); s++) |
| 112 | { |
| 113 | if ((d_channel_types[*s] == *it) and (*s >= 0) and (*s <= (51-4))) |
| 114 | { |
| 115 | for(int ii=0; ii<4; ii++) |
| 116 | { |
| 117 | d_subslots[*s+ii+51] = subslot; |
| 118 | } |
| 119 | subslot++; |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 125 | |
| 126 | message_port_register_in(pmt::mp("bursts")); |
| 127 | set_msg_handler(pmt::mp("bursts"), boost::bind(&universal_ctrl_chans_demapper_impl::filter_ctrl_chans, this, _1)); |
| 128 | message_port_register_out(pmt::mp("bursts")); |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * Our virtual destructor. |
| 133 | */ |
| 134 | universal_ctrl_chans_demapper_impl::~universal_ctrl_chans_demapper_impl() |
| 135 | { |
| 136 | } |
| 137 | |
| 138 | void universal_ctrl_chans_demapper_impl::filter_ctrl_chans(pmt::pmt_t msg) |
| 139 | { |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 140 | pmt::pmt_t header_plus_burst = pmt::cdr(msg); |
| 141 | gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst); |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 142 | |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 143 | uint32_t frame_nr = be32toh(header->frame_number); |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 144 | uint32_t fn_mod51 = frame_nr % 51; |
| 145 | uint32_t fn51_start = d_starts_fn_mod51[fn_mod51]; |
| 146 | uint32_t fn51_stop = fn51_start + 3; |
| 147 | uint32_t ch_type = d_channel_types[fn_mod51]; |
Roman Khassraf | 275a087 | 2015-04-12 15:17:47 +0200 | [diff] [blame] | 148 | |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 149 | if(header->timeslot==d_timeslot){ |
Roman Khassraf | 275a087 | 2015-04-12 15:17:47 +0200 | [diff] [blame] | 150 | header->sub_type = ch_type; |
Roman Khassraf | e571e96 | 2015-04-12 15:35:41 +0200 | [diff] [blame] | 151 | header->sub_slot = d_subslots[fn_mod51 + (51 * (frame_nr % 2))]; |
Roman Khassraf | 275a087 | 2015-04-12 15:17:47 +0200 | [diff] [blame] | 152 | |
ptrkrysik | 6dded65 | 2014-11-19 11:32:05 +0100 | [diff] [blame] | 153 | if(fn_mod51>=fn51_start && fn_mod51<=fn51_stop) |
| 154 | { |
| 155 | uint32_t ii = fn_mod51 - fn51_start; |
| 156 | d_frame_numbers[ii] = frame_nr; |
| 157 | d_bursts[ii] = msg; |
| 158 | } |
| 159 | |
| 160 | if(fn_mod51==fn51_stop) |
| 161 | { |
| 162 | //check for a situation where some bursts were lost |
| 163 | //in this situation frame numbers won't be consecutive |
| 164 | bool frames_are_consecutive = true; |
| 165 | for(int jj=1; jj<4; jj++) |
| 166 | { |
| 167 | if((d_frame_numbers[jj]-d_frame_numbers[jj-1])!=1) |
| 168 | { |
| 169 | frames_are_consecutive = false; |
| 170 | } |
| 171 | } |
| 172 | if(frames_are_consecutive) |
| 173 | { |
| 174 | //send bursts to the output |
| 175 | for(int jj=0; jj<4; jj++) |
| 176 | { |
| 177 | message_port_pub(pmt::mp("bursts"), d_bursts[jj]); |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | } |
| 183 | } /* namespace gsm */ |
| 184 | } /* namespace gr */ |
| 185 | |