blob: 5c3363a97fc9a0a08e9f0885f2a51dd5d65a63fe [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#ifdef HAVE_CONFIG_H
23#include "config.h"
24#endif
25
Piotr Krysikeb81b032018-02-27 08:46:17 +010026#include <cmath>
piotr437f5462014-02-04 17:57:25 +010027#include <receiver_config.h>
28
Piotr Krysikeb81b032018-02-27 08:46:17 +010029
piotr437f5462014-02-04 17:57:25 +010030burst_counter & burst_counter::operator++(int)
31{
32 d_timeslot_nr++;
33 if (d_timeslot_nr == TS_PER_FRAME) {
34 d_timeslot_nr = 0;
35
36 if ((d_t2 == 25) && (d_t3 == 50)) {
37 d_t1 = (d_t1 + 1) % (1 << 11);
38 }
39
40 d_t2 = (d_t2 + 1) % 26;
41 d_t3 = (d_t3 + 1) % 51;
42 }
43
44 //update offset - this is integer for d_OSR which is multiple of four
45 d_offset_fractional += GUARD_FRACTIONAL * d_OSR;
46 d_offset_integer = floor(d_offset_fractional);
47 d_offset_fractional = d_offset_fractional - d_offset_integer;
48 return (*this);
49}
50
ptrkrysik202788e2015-08-06 10:09:43 +020051burst_counter burst_counter::subtract_timeslots(unsigned int number_of_timeslots)
52{
53 int timeslot_nr = (int)d_timeslot_nr - (int)number_of_timeslots;
54 int t1,t2,t3;
55 if (timeslot_nr < 0) {
56 timeslot_nr = timeslot_nr + 8;
57
Piotr Krysik6629abc2017-07-23 20:26:49 +020058 t2 = (d_t2+26 - 1) % 26;
59 t3 = (d_t3+51 - 1) % 51;
ptrkrysik202788e2015-08-06 10:09:43 +020060
61 if ((d_t2 == 0) && (d_t3 == 0)) {
62 t1 = (d_t1 - 1) % (1 << 11);
63 } else
64 {
65 t1 = d_t1;
66 }
67 }
68 else
69 {
70 t1 = d_t1;
71 t2 = d_t2;
72 t3 = d_t3;
73 }
74
75 return burst_counter(d_OSR, t1, t2, t3, timeslot_nr);
76}
77
piotr437f5462014-02-04 17:57:25 +010078void burst_counter::set(uint32_t t1, uint32_t t2, uint32_t t3, uint32_t timeslot_nr)
79{
80 d_t1 = t1;
81 d_t2 = t2;
82 d_t3 = t3;
83 d_timeslot_nr = timeslot_nr;
84 double first_sample_position = (get_frame_nr() * 8 + timeslot_nr) * TS_BITS;
85 d_offset_fractional = first_sample_position - floor(first_sample_position);
86 d_offset_integer = 0;
87}
88
89burst_type channel_configuration::get_burst_type(burst_counter burst_nr)
90{
91 uint32_t timeslot_nr = burst_nr.get_timeslot_nr();
92 multiframe_type m_type = d_timeslots_descriptions[timeslot_nr].get_type();
93 uint32_t nr;
94
95 switch (m_type) {
96 case multiframe_26:
97 nr = burst_nr.get_t2();
98 break;
99 case multiframe_51:
100 nr = burst_nr.get_t3();
101 break;
102 default:
103 nr = 0;
104 break;
105 }
106
107 return d_timeslots_descriptions[timeslot_nr].get_burst_type(nr);
108}