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