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 | #ifndef INCLUDED_GSM_RECEIVER_CONFIG_H |
| 23 | #define INCLUDED_GSM_RECEIVER_CONFIG_H |
| 24 | |
| 25 | #include <vector> |
| 26 | #include <algorithm> |
| 27 | #include <math.h> |
| 28 | #include <stdint.h> |
| 29 | #include <gsm_constants.h> |
| 30 | |
| 31 | class multiframe_configuration |
| 32 | { |
| 33 | private: |
| 34 | multiframe_type d_type; |
| 35 | std::vector<burst_type> d_burst_types; |
| 36 | public: |
| 37 | multiframe_configuration() { |
| 38 | d_type = unknown; |
| 39 | fill(d_burst_types.begin(), d_burst_types.end(), empty); |
| 40 | } |
| 41 | |
| 42 | ~multiframe_configuration() {} |
| 43 | |
| 44 | void set_type(multiframe_type type) { |
| 45 | if (type == multiframe_26) { |
| 46 | d_burst_types.resize(26); |
| 47 | } else { |
| 48 | d_burst_types.resize(51); |
| 49 | } |
| 50 | |
| 51 | d_type = type; |
| 52 | } |
| 53 | |
| 54 | void set_burst_type(int nr, burst_type type) { |
| 55 | d_burst_types[nr] = type; |
| 56 | } |
| 57 | |
| 58 | multiframe_type get_type() { |
| 59 | return d_type; |
| 60 | } |
| 61 | |
| 62 | burst_type get_burst_type(int nr) { |
| 63 | return d_burst_types[nr]; |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | class burst_counter |
| 68 | { |
| 69 | private: |
| 70 | const int d_OSR; |
| 71 | uint32_t d_t1, d_t2, d_t3, d_timeslot_nr; |
| 72 | double d_offset_fractional; |
| 73 | double d_offset_integer; |
| 74 | public: |
| 75 | burst_counter(int osr): |
| 76 | d_OSR(osr), |
| 77 | d_t1(0), |
| 78 | d_t2(0), |
| 79 | d_t3(0), |
| 80 | d_timeslot_nr(0), |
| 81 | d_offset_fractional(0.0), |
| 82 | d_offset_integer(0.0) { |
| 83 | } |
| 84 | |
| 85 | burst_counter(int osr, uint32_t t1, uint32_t t2, uint32_t t3, uint32_t timeslot_nr): |
| 86 | d_OSR(osr), |
| 87 | d_t1(t1), |
| 88 | d_t2(t2), |
| 89 | d_t3(t3), |
| 90 | d_timeslot_nr(timeslot_nr), |
| 91 | d_offset_fractional(0.0), |
ptrkrysik | 202788e | 2015-08-06 10:09:43 +0200 | [diff] [blame] | 92 | d_offset_integer(0.0) |
| 93 | { |
piotr | 7f3f366 | 2014-07-08 16:47:53 +0200 | [diff] [blame] | 94 | d_offset_integer = 0; |
| 95 | d_offset_fractional = 0; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | burst_counter & operator++(int); |
ptrkrysik | 202788e | 2015-08-06 10:09:43 +0200 | [diff] [blame] | 99 | burst_counter subtract_timeslots(unsigned int number_of_timeslots); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 100 | void set(uint32_t t1, uint32_t t2, uint32_t t3, uint32_t timeslot_nr); |
| 101 | |
| 102 | uint32_t get_t1() { |
| 103 | return d_t1; |
| 104 | } |
| 105 | |
| 106 | uint32_t get_t2() { |
| 107 | return d_t2; |
| 108 | } |
| 109 | |
| 110 | uint32_t get_t3() { |
| 111 | return d_t3; |
| 112 | } |
| 113 | |
| 114 | uint32_t get_timeslot_nr() { |
| 115 | return d_timeslot_nr; |
| 116 | } |
| 117 | |
| 118 | uint32_t get_frame_nr() { |
| 119 | return (51 * 26 * d_t1) + (51 * (((d_t3 + 26) - d_t2) % 26)) + d_t3; |
| 120 | } |
| 121 | |
| 122 | uint32_t get_frame_nr_mod() { |
| 123 | return (d_t1 << 11) + (d_t3 << 5) + d_t2; |
| 124 | } |
| 125 | |
| 126 | unsigned get_offset() { |
| 127 | return (unsigned)d_offset_integer; |
| 128 | } |
| 129 | }; |
| 130 | |
| 131 | class channel_configuration |
| 132 | { |
| 133 | private: |
| 134 | multiframe_configuration d_timeslots_descriptions[TS_PER_FRAME]; |
| 135 | public: |
| 136 | channel_configuration() { |
| 137 | for (int i = 0; i < TS_PER_FRAME; i++) { |
| 138 | d_timeslots_descriptions[i].set_type(unknown); |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | void set_multiframe_type(int timeslot_nr, multiframe_type type) { |
| 143 | d_timeslots_descriptions[timeslot_nr].set_type(type); |
| 144 | } |
| 145 | |
| 146 | void set_burst_types(int timeslot_nr, const unsigned mapping[], unsigned mapping_size, burst_type b_type) { |
| 147 | unsigned i; |
| 148 | for (i = 0; i < mapping_size; i++) { |
| 149 | d_timeslots_descriptions[timeslot_nr].set_burst_type(mapping[i], b_type); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void set_single_burst_type(int timeslot_nr, int burst_nr, burst_type b_type) { |
| 154 | d_timeslots_descriptions[timeslot_nr].set_burst_type(burst_nr, b_type); |
| 155 | } |
| 156 | |
| 157 | burst_type get_burst_type(burst_counter burst_nr); |
| 158 | }; |
| 159 | |
| 160 | #endif /* INCLUDED_GSM_RECEIVER_CONFIG_H */ |