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