piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
| 2 | /* |
| 3 | * @file |
Piotr Krysik | a6268a5 | 2017-08-23 16:02:19 +0200 | [diff] [blame] | 4 | * @author (C) 2009-2017 by Piotr Krysik <ptrkrysik@gmail.com> |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 5 | * @section LICENSE |
| 6 | * |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 7 | * Gr-gsm is free software; you can redistribute it and/or modify |
piotr | 437f546 | 2014-02-04 17:57:25 +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. |
| 11 | * |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 12 | * Gr-gsm is distributed in the hope that it will be useful, |
piotr | 437f546 | 2014-02-04 17:57:25 +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. |
| 16 | * |
| 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 |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 19 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | * Boston, MA 02110-1301, USA. |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 21 | */ |
| 22 | #ifdef HAVE_CONFIG_H |
| 23 | #include "config.h" |
| 24 | #endif |
| 25 | |
| 26 | #include <receiver_config.h> |
| 27 | |
| 28 | burst_counter & burst_counter::operator++(int) |
| 29 | { |
| 30 | d_timeslot_nr++; |
| 31 | if (d_timeslot_nr == TS_PER_FRAME) { |
| 32 | d_timeslot_nr = 0; |
| 33 | |
| 34 | if ((d_t2 == 25) && (d_t3 == 50)) { |
| 35 | d_t1 = (d_t1 + 1) % (1 << 11); |
| 36 | } |
| 37 | |
| 38 | d_t2 = (d_t2 + 1) % 26; |
| 39 | d_t3 = (d_t3 + 1) % 51; |
| 40 | } |
| 41 | |
| 42 | //update offset - this is integer for d_OSR which is multiple of four |
| 43 | d_offset_fractional += GUARD_FRACTIONAL * d_OSR; |
| 44 | d_offset_integer = floor(d_offset_fractional); |
| 45 | d_offset_fractional = d_offset_fractional - d_offset_integer; |
| 46 | return (*this); |
| 47 | } |
| 48 | |
ptrkrysik | 202788e | 2015-08-06 10:09:43 +0200 | [diff] [blame] | 49 | burst_counter burst_counter::subtract_timeslots(unsigned int number_of_timeslots) |
| 50 | { |
| 51 | int timeslot_nr = (int)d_timeslot_nr - (int)number_of_timeslots; |
| 52 | int t1,t2,t3; |
| 53 | if (timeslot_nr < 0) { |
| 54 | timeslot_nr = timeslot_nr + 8; |
| 55 | |
Piotr Krysik | 6629abc | 2017-07-23 20:26:49 +0200 | [diff] [blame] | 56 | t2 = (d_t2+26 - 1) % 26; |
| 57 | t3 = (d_t3+51 - 1) % 51; |
ptrkrysik | 202788e | 2015-08-06 10:09:43 +0200 | [diff] [blame] | 58 | |
| 59 | if ((d_t2 == 0) && (d_t3 == 0)) { |
| 60 | t1 = (d_t1 - 1) % (1 << 11); |
| 61 | } else |
| 62 | { |
| 63 | t1 = d_t1; |
| 64 | } |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | t1 = d_t1; |
| 69 | t2 = d_t2; |
| 70 | t3 = d_t3; |
| 71 | } |
| 72 | |
| 73 | return burst_counter(d_OSR, t1, t2, t3, timeslot_nr); |
| 74 | } |
| 75 | |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 76 | void burst_counter::set(uint32_t t1, uint32_t t2, uint32_t t3, uint32_t timeslot_nr) |
| 77 | { |
| 78 | d_t1 = t1; |
| 79 | d_t2 = t2; |
| 80 | d_t3 = t3; |
| 81 | d_timeslot_nr = timeslot_nr; |
| 82 | double first_sample_position = (get_frame_nr() * 8 + timeslot_nr) * TS_BITS; |
| 83 | d_offset_fractional = first_sample_position - floor(first_sample_position); |
| 84 | d_offset_integer = 0; |
| 85 | } |
| 86 | |
| 87 | burst_type channel_configuration::get_burst_type(burst_counter burst_nr) |
| 88 | { |
| 89 | uint32_t timeslot_nr = burst_nr.get_timeslot_nr(); |
| 90 | multiframe_type m_type = d_timeslots_descriptions[timeslot_nr].get_type(); |
| 91 | uint32_t nr; |
| 92 | |
| 93 | switch (m_type) { |
| 94 | case multiframe_26: |
| 95 | nr = burst_nr.get_t2(); |
| 96 | break; |
| 97 | case multiframe_51: |
| 98 | nr = burst_nr.get_t3(); |
| 99 | break; |
| 100 | default: |
| 101 | nr = 0; |
| 102 | break; |
| 103 | } |
| 104 | |
| 105 | return d_timeslots_descriptions[timeslot_nr].get_burst_type(nr); |
| 106 | } |