blob: 181132aa32a2136fa3dd20065bed6e216bf6d8ee [file] [log] [blame]
piotr437f5462014-02-04 17:57:25 +01001/* -*- c++ -*- */
2/*
3 * @file
Piotr Krysika6268a52017-08-23 16:02:19 +02004 * @author (C) 2009-2017 by Piotr Krysik <ptrkrysik@gmail.com>
piotr437f5462014-02-04 17:57:25 +01005 * @section LICENSE
6 *
ptrkrysik529895b2014-12-02 18:07:38 +01007 * Gr-gsm is free software; you can redistribute it and/or modify
piotr437f5462014-02-04 17:57:25 +01008 * 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 *
ptrkrysik529895b2014-12-02 18:07:38 +010012 * Gr-gsm is distributed in the hope that it will be useful,
piotr437f5462014-02-04 17:57:25 +010013 * 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
ptrkrysik529895b2014-12-02 18:07:38 +010018 * along with gr-gsm; see the file COPYING. If not, write to
piotr437f5462014-02-04 17:57:25 +010019 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
piotr437f5462014-02-04 17:57:25 +010021 */
22#ifndef INCLUDED_GSM_RECEIVER_CONFIG_H
23#define INCLUDED_GSM_RECEIVER_CONFIG_H
24
25#include <vector>
26#include <algorithm>
piotr437f5462014-02-04 17:57:25 +010027#include <stdint.h>
Piotr Krysikd7efc052017-11-07 19:33:22 +010028#include <grgsm/gsm_constants.h>
piotr437f5462014-02-04 17:57:25 +010029
30class 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 Yanitskiyc1204222019-01-19 16:33:25 +070044 switch (type) {
45 case multiframe_51:
piotr437f5462014-02-04 17:57:25 +010046 d_burst_types.resize(51);
Vadim Yanitskiyc1204222019-01-19 16:33:25 +070047 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;
piotr437f5462014-02-04 17:57:25 +010058 }
piotr437f5462014-02-04 17:57:25 +010059 }
60
Vadim Yanitskiycdd0c992019-01-19 16:52:20 +070061 void reset(void) {
62 fill(d_burst_types.begin(), d_burst_types.end(), empty);
63 d_burst_types.resize(0);
64 d_type = unknown;
65 }
66
piotr437f5462014-02-04 17:57:25 +010067 void set_burst_type(int nr, burst_type type) {
68 d_burst_types[nr] = type;
69 }
70
71 multiframe_type get_type() {
72 return d_type;
73 }
74
75 burst_type get_burst_type(int nr) {
76 return d_burst_types[nr];
77 }
78};
79
80class burst_counter
81{
82 private:
83 const int d_OSR;
84 uint32_t d_t1, d_t2, d_t3, d_timeslot_nr;
85 double d_offset_fractional;
86 double d_offset_integer;
87 public:
88 burst_counter(int osr):
89 d_OSR(osr),
90 d_t1(0),
91 d_t2(0),
92 d_t3(0),
93 d_timeslot_nr(0),
94 d_offset_fractional(0.0),
95 d_offset_integer(0.0) {
96 }
97
98 burst_counter(int osr, uint32_t t1, uint32_t t2, uint32_t t3, uint32_t timeslot_nr):
99 d_OSR(osr),
100 d_t1(t1),
101 d_t2(t2),
102 d_t3(t3),
103 d_timeslot_nr(timeslot_nr),
104 d_offset_fractional(0.0),
ptrkrysik202788e2015-08-06 10:09:43 +0200105 d_offset_integer(0.0)
106 {
piotr7f3f3662014-07-08 16:47:53 +0200107 d_offset_integer = 0;
108 d_offset_fractional = 0;
piotr437f5462014-02-04 17:57:25 +0100109 }
110
111 burst_counter & operator++(int);
ptrkrysik202788e2015-08-06 10:09:43 +0200112 burst_counter subtract_timeslots(unsigned int number_of_timeslots);
piotr437f5462014-02-04 17:57:25 +0100113 void set(uint32_t t1, uint32_t t2, uint32_t t3, uint32_t timeslot_nr);
114
115 uint32_t get_t1() {
116 return d_t1;
117 }
118
119 uint32_t get_t2() {
120 return d_t2;
121 }
122
123 uint32_t get_t3() {
124 return d_t3;
125 }
126
127 uint32_t get_timeslot_nr() {
128 return d_timeslot_nr;
129 }
130
131 uint32_t get_frame_nr() {
132 return (51 * 26 * d_t1) + (51 * (((d_t3 + 26) - d_t2) % 26)) + d_t3;
133 }
134
135 uint32_t get_frame_nr_mod() {
136 return (d_t1 << 11) + (d_t3 << 5) + d_t2;
137 }
138
139 unsigned get_offset() {
140 return (unsigned)d_offset_integer;
141 }
142};
143
144class channel_configuration
145{
146 private:
147 multiframe_configuration d_timeslots_descriptions[TS_PER_FRAME];
148 public:
149 channel_configuration() {
150 for (int i = 0; i < TS_PER_FRAME; i++) {
151 d_timeslots_descriptions[i].set_type(unknown);
152 }
153 }
154
Vadim Yanitskiycdd0c992019-01-19 16:52:20 +0700155 multiframe_type get_multiframe_type(int timeslot_nr) {
156 return d_timeslots_descriptions[timeslot_nr].get_type();
157 }
158
piotr437f5462014-02-04 17:57:25 +0100159 void set_multiframe_type(int timeslot_nr, multiframe_type type) {
160 d_timeslots_descriptions[timeslot_nr].set_type(type);
161 }
162
163 void set_burst_types(int timeslot_nr, const unsigned mapping[], unsigned mapping_size, burst_type b_type) {
164 unsigned i;
165 for (i = 0; i < mapping_size; i++) {
166 d_timeslots_descriptions[timeslot_nr].set_burst_type(mapping[i], b_type);
167 }
168 }
169
Vadim Yanitskiycdd0c992019-01-19 16:52:20 +0700170 burst_type get_single_burst_type(int timeslot_nr, int burst_nr) {
171 return d_timeslots_descriptions[timeslot_nr].get_burst_type(burst_nr);
172 }
173
piotr437f5462014-02-04 17:57:25 +0100174 void set_single_burst_type(int timeslot_nr, int burst_nr, burst_type b_type) {
175 d_timeslots_descriptions[timeslot_nr].set_burst_type(burst_nr, b_type);
176 }
177
Vadim Yanitskiy4f3fd6d2019-01-19 16:36:09 +0700178 void reset_all(void) {
179 for (int i = 0; i < TS_PER_FRAME; i++)
Vadim Yanitskiycdd0c992019-01-19 16:52:20 +0700180 d_timeslots_descriptions[i].reset();
Vadim Yanitskiy4f3fd6d2019-01-19 16:36:09 +0700181 }
182
piotr437f5462014-02-04 17:57:25 +0100183 burst_type get_burst_type(burst_counter burst_nr);
184};
185
186#endif /* INCLUDED_GSM_RECEIVER_CONFIG_H */