blob: 2014a5bf4f90f725000848beac440a816eb58dc1 [file] [log] [blame]
piotr437f5462014-02-04 17:57:25 +01001/* -*- c++ -*- */
2/*
3 * @file
4 * @author Piotr Krysik <pkrysik@stud.elka.pw.edu.pl>
5 * @section LICENSE
6 *
7 * GNU Radio 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 * GNU Radio 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 GNU Radio; 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 * @section DESCRIPTION
23 * This file contains classes which define gsm_receiver configuration
24 * and the burst_counter which is used to store internal state of the receiver
25 * when it's synchronized
26 */
27#ifndef INCLUDED_GSM_RECEIVER_CONFIG_H
28#define INCLUDED_GSM_RECEIVER_CONFIG_H
29
30#include <vector>
31#include <algorithm>
32#include <math.h>
33#include <stdint.h>
34#include <gsm_constants.h>
35
36class multiframe_configuration
37{
38 private:
39 multiframe_type d_type;
40 std::vector<burst_type> d_burst_types;
41 public:
42 multiframe_configuration() {
43 d_type = unknown;
44 fill(d_burst_types.begin(), d_burst_types.end(), empty);
45 }
46
47 ~multiframe_configuration() {}
48
49 void set_type(multiframe_type type) {
50 if (type == multiframe_26) {
51 d_burst_types.resize(26);
52 } else {
53 d_burst_types.resize(51);
54 }
55
56 d_type = type;
57 }
58
59 void set_burst_type(int nr, burst_type type) {
60 d_burst_types[nr] = type;
61 }
62
63 multiframe_type get_type() {
64 return d_type;
65 }
66
67 burst_type get_burst_type(int nr) {
68 return d_burst_types[nr];
69 }
70};
71
72class burst_counter
73{
74 private:
75 const int d_OSR;
76 uint32_t d_t1, d_t2, d_t3, d_timeslot_nr;
77 double d_offset_fractional;
78 double d_offset_integer;
79 public:
80 burst_counter(int osr):
81 d_OSR(osr),
82 d_t1(0),
83 d_t2(0),
84 d_t3(0),
85 d_timeslot_nr(0),
86 d_offset_fractional(0.0),
87 d_offset_integer(0.0) {
88 }
89
90 burst_counter(int osr, uint32_t t1, uint32_t t2, uint32_t t3, uint32_t timeslot_nr):
91 d_OSR(osr),
92 d_t1(t1),
93 d_t2(t2),
94 d_t3(t3),
95 d_timeslot_nr(timeslot_nr),
96 d_offset_fractional(0.0),
97 d_offset_integer(0.0) {
piotr7f3f3662014-07-08 16:47:53 +020098 d_offset_integer = 0;
99 d_offset_fractional = 0;
piotr437f5462014-02-04 17:57:25 +0100100 }
101
102 burst_counter & operator++(int);
103 void set(uint32_t t1, uint32_t t2, uint32_t t3, uint32_t timeslot_nr);
104
105 uint32_t get_t1() {
106 return d_t1;
107 }
108
109 uint32_t get_t2() {
110 return d_t2;
111 }
112
113 uint32_t get_t3() {
114 return d_t3;
115 }
116
117 uint32_t get_timeslot_nr() {
118 return d_timeslot_nr;
119 }
120
121 uint32_t get_frame_nr() {
122 return (51 * 26 * d_t1) + (51 * (((d_t3 + 26) - d_t2) % 26)) + d_t3;
123 }
124
125 uint32_t get_frame_nr_mod() {
126 return (d_t1 << 11) + (d_t3 << 5) + d_t2;
127 }
128
129 unsigned get_offset() {
130 return (unsigned)d_offset_integer;
131 }
132};
133
134class channel_configuration
135{
136 private:
137 multiframe_configuration d_timeslots_descriptions[TS_PER_FRAME];
138 public:
139 channel_configuration() {
140 for (int i = 0; i < TS_PER_FRAME; i++) {
141 d_timeslots_descriptions[i].set_type(unknown);
142 }
143 }
144
145 void set_multiframe_type(int timeslot_nr, multiframe_type type) {
146 d_timeslots_descriptions[timeslot_nr].set_type(type);
147 }
148
149 void set_burst_types(int timeslot_nr, const unsigned mapping[], unsigned mapping_size, burst_type b_type) {
150 unsigned i;
151 for (i = 0; i < mapping_size; i++) {
152 d_timeslots_descriptions[timeslot_nr].set_burst_type(mapping[i], b_type);
153 }
154 }
155
156 void set_single_burst_type(int timeslot_nr, int burst_nr, burst_type b_type) {
157 d_timeslots_descriptions[timeslot_nr].set_burst_type(burst_nr, b_type);
158 }
159
160 burst_type get_burst_type(burst_counter burst_nr);
161};
162
163#endif /* INCLUDED_GSM_RECEIVER_CONFIG_H */