Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 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 |
| 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. |
| 11 | * |
| 12 | * Gr-gsm is distributed in the hope that it will be useful, |
| 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. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with gr-gsm; see the file COPYING. If not, write to |
| 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 "tch_f_chans_demapper_impl.h" |
| 29 | #include <grgsm/endian.h> |
| 30 | #include <grgsm/gsmtap.h> |
| 31 | |
| 32 | namespace gr { |
| 33 | namespace gsm { |
| 34 | |
| 35 | tch_f_chans_demapper::sptr |
| 36 | tch_f_chans_demapper::make(unsigned int timeslot_nr) |
| 37 | { |
| 38 | return gnuradio::get_initial_sptr |
| 39 | (new tch_f_chans_demapper_impl(timeslot_nr)); |
| 40 | } |
| 41 | |
| 42 | /* |
| 43 | * The private constructor |
| 44 | * |
| 45 | */ |
| 46 | tch_f_chans_demapper_impl::tch_f_chans_demapper_impl(unsigned int timeslot_nr) |
| 47 | : gr::block("tch_f_chans_demapper", |
| 48 | gr::io_signature::make(0, 0, 0), |
| 49 | gr::io_signature::make(0, 0, 0)), |
| 50 | d_timeslot(timeslot_nr) |
| 51 | |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 52 | { |
| 53 | for (int ii=0; ii<3; ii++) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 54 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 55 | d_bursts_stolen[ii] = false; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 56 | } |
| 57 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 58 | message_port_register_in(pmt::mp("bursts")); |
| 59 | set_msg_handler(pmt::mp("bursts"), boost::bind(&tch_f_chans_demapper_impl::filter_tch_chans, this, _1)); |
| 60 | message_port_register_out(pmt::mp("tch_bursts")); |
| 61 | message_port_register_out(pmt::mp("acch_bursts")); |
| 62 | } |
| 63 | |
| 64 | /* |
| 65 | * Our virtual destructor. |
| 66 | */ |
| 67 | tch_f_chans_demapper_impl::~tch_f_chans_demapper_impl() |
| 68 | { |
| 69 | } |
| 70 | |
| 71 | void tch_f_chans_demapper_impl::filter_tch_chans(pmt::pmt_t msg) |
| 72 | { |
| 73 | pmt::pmt_t header_plus_burst = pmt::cdr(msg); |
| 74 | gsmtap_hdr * header = (gsmtap_hdr *)pmt::blob_data(header_plus_burst); |
| 75 | |
| 76 | uint32_t frame_nr = be32toh(header->frame_number); |
| 77 | uint32_t fn_mod26 = frame_nr % 26; |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 78 | uint32_t fn_mod13 = frame_nr % 13; |
| 79 | bool frames_are_consecutive = true; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 80 | int8_t * burst_bits = (int8_t *)(pmt::blob_data(header_plus_burst))+sizeof(gsmtap_hdr); |
| 81 | |
| 82 | if(header->timeslot == d_timeslot){ |
| 83 | header->sub_type = GSMTAP_CHANNEL_TCH_F; |
| 84 | |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 85 | if (fn_mod13 == 12) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 86 | { |
| 87 | header->sub_type = GSMTAP_CHANNEL_ACCH|GSMTAP_CHANNEL_TCH_F; |
| 88 | |
| 89 | // position of SACCH burst based on timeslot |
| 90 | // see specification gsm 05.02 |
| 91 | uint32_t index; |
| 92 | bool is_sacch = false; |
| 93 | |
| 94 | if (d_timeslot % 2 == 0 && fn_mod26 == 12) |
| 95 | { |
| 96 | index = (((frame_nr - 12) / 26) - (d_timeslot / 2)) % 4; |
| 97 | is_sacch = true; |
| 98 | } |
| 99 | else if (d_timeslot % 2 == 1 && fn_mod26 == 25) |
| 100 | { |
| 101 | index = (((frame_nr - 25) / 26) - ((d_timeslot - 1) / 2)) % 4; |
| 102 | is_sacch = true; |
| 103 | } |
| 104 | |
| 105 | if (is_sacch) |
| 106 | { |
| 107 | d_bursts_sacch[index] = msg; |
| 108 | d_frame_numbers_sacch[index] = frame_nr; |
| 109 | |
| 110 | if (index == 3) |
| 111 | { |
| 112 | //check for a situation where some bursts were lost |
| 113 | //in this situation frame numbers won't be consecutive |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 114 | frames_are_consecutive = true; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 115 | for(int jj=1; jj<4; jj++) |
| 116 | { |
| 117 | if((d_frame_numbers_sacch[jj]-d_frame_numbers_sacch[jj-1]) != 26) |
| 118 | { |
| 119 | frames_are_consecutive = false; |
| 120 | } |
| 121 | } |
| 122 | if(frames_are_consecutive) |
| 123 | { |
| 124 | //send bursts to the output |
| 125 | for(int jj=0; jj<4; jj++) |
| 126 | { |
| 127 | message_port_pub(pmt::mp("acch_bursts"), d_bursts_sacch[jj]); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | else |
| 134 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 135 | if (fn_mod13 <= 3) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 136 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 137 | // add to b1 and b3 |
| 138 | d_bursts[0][fn_mod13] = msg; |
| 139 | d_bursts[2][fn_mod13 + 4] = msg; |
| 140 | |
| 141 | // set framenumber |
| 142 | d_frame_numbers[0][fn_mod13] = frame_nr; |
| 143 | d_frame_numbers[2][fn_mod13 + 4] = frame_nr; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 144 | |
| 145 | // check if stealing bits are set |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 146 | // see 4.2.5 in gsm 05.03 |
| 147 | if (static_cast<int>(burst_bits[60]) == 1) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 148 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 149 | d_bursts_stolen[2] = true; |
| 150 | } |
| 151 | if (static_cast<int>(burst_bits[87]) == 1) |
| 152 | { |
| 153 | d_bursts_stolen[0] = true; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 154 | } |
| 155 | } |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 156 | else if (fn_mod13 >= 4 && fn_mod13 <= 7) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 157 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 158 | // add to b1 and b2 |
| 159 | d_bursts[0][fn_mod13] = msg; |
| 160 | d_bursts[1][fn_mod13 - 4] = msg; |
| 161 | |
| 162 | // set framenumber |
| 163 | d_frame_numbers[0][fn_mod13] = frame_nr; |
| 164 | d_frame_numbers[1][fn_mod13 - 4] = frame_nr; |
| 165 | |
| 166 | // check if stealing bits are set |
| 167 | // see 4.2.5 in gsm 05.03 |
| 168 | if (static_cast<int>(burst_bits[60]) == 1) |
| 169 | { |
| 170 | d_bursts_stolen[0] = true; |
| 171 | } |
| 172 | if (static_cast<int>(burst_bits[87]) == 1) |
| 173 | { |
| 174 | d_bursts_stolen[1] = true; |
| 175 | } |
| 176 | } |
| 177 | else if (fn_mod13 >= 8 && fn_mod13 <= 11) |
| 178 | { |
| 179 | // add to b2 and b3 |
| 180 | d_bursts[1][fn_mod13 - 4] = msg; |
| 181 | d_bursts[2][fn_mod13 - 8] = msg; |
| 182 | |
| 183 | // set framenumber |
| 184 | d_frame_numbers[1][fn_mod13 - 4] = frame_nr; |
| 185 | d_frame_numbers[2][fn_mod13 - 8] = frame_nr; |
| 186 | |
| 187 | // check if stealing bits are set |
| 188 | // see 4.2.5 in gsm 05.03 |
| 189 | if (static_cast<int>(burst_bits[60]) == 1) |
| 190 | { |
| 191 | d_bursts_stolen[1] = true; |
| 192 | } |
| 193 | if (static_cast<int>(burst_bits[87]) == 1) |
| 194 | { |
| 195 | d_bursts_stolen[2] = true; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | // send burst 1 or burst 2 to output |
| 200 | if (fn_mod13 == 3 || fn_mod13 == 7 || fn_mod13 == 11) |
| 201 | { |
| 202 | int tch_burst_nr = 0; |
| 203 | |
| 204 | if (fn_mod13 == 11) |
| 205 | { |
| 206 | tch_burst_nr = 1; |
| 207 | } |
| 208 | else if (fn_mod13 == 3) |
| 209 | { |
| 210 | tch_burst_nr = 2; |
| 211 | } |
| 212 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 213 | //check for a situation where some bursts were lost |
| 214 | //in this situation frame numbers won't be consecutive |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 215 | frames_are_consecutive = true; |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 216 | |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 217 | for(int jj=1; jj<8; jj++) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 218 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 219 | if((d_frame_numbers[tch_burst_nr][jj] - d_frame_numbers[tch_burst_nr][jj-1]) != 1) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 220 | { |
| 221 | frames_are_consecutive = false; |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 222 | // burst 3 has 1 sacch burst in between |
| 223 | if (tch_burst_nr == 2 && jj == 4 |
| 224 | && d_frame_numbers[tch_burst_nr][jj] - d_frame_numbers[tch_burst_nr][jj - 1] == 2) |
| 225 | { |
| 226 | frames_are_consecutive = true; |
| 227 | } |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 228 | } |
| 229 | } |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 230 | |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 231 | if(frames_are_consecutive) |
| 232 | { |
| 233 | //send bursts to the output |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 234 | for(int jj=0; jj<8; jj++) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 235 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 236 | if (d_bursts_stolen[tch_burst_nr]) |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 237 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 238 | message_port_pub(pmt::mp("acch_bursts"), d_bursts[tch_burst_nr][jj]); |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 239 | } |
| 240 | else |
| 241 | { |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 242 | message_port_pub(pmt::mp("tch_bursts"), d_bursts[tch_burst_nr][jj]); |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 243 | } |
| 244 | } |
Roman Khassraf | 155a744 | 2015-05-08 19:52:01 +0200 | [diff] [blame] | 245 | d_bursts_stolen[tch_burst_nr] = false; |
| 246 | } |
Roman Khassraf | fb6bc50 | 2015-04-14 15:44:40 +0200 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | } /* namespace gsm */ |
| 252 | } /* namespace gr */ |
| 253 | |