blob: ec2bf252b8f466e274af18a8a72026efcbfd0c73 [file] [log] [blame]
Piotr Krysikb7cce892018-05-11 11:37:21 +02001/* -*- c++ -*- */
2/* @file
3 * @author Piotr Krysik <ptrkrysik@gmail.com>
4 * @section LICENSE
5 *
6 * Gr-gsm is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3, or (at your option)
9 * any later version.
10 *
11 * Gr-gsm is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with gr-gsm; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23//#include "grgsm/misc_utils/freq_hopping_utils.h"
24#include <cmath>
25
26namespace gr {
27 namespace gsm {
28 unsigned char RNTABLE[114] = {
29 48, 98, 63, 1, 36, 95, 78, 102, 94, 73, \
30 0, 64, 25, 81, 76, 59, 124, 23, 104, 100, \
31 101, 47, 118, 85, 18, 56, 96, 86, 54, 2, \
32 80, 34, 127, 13, 6, 89, 57, 103, 12, 74, \
33 55, 111, 75, 38, 109, 71, 112, 29, 11, 88, \
34 87, 19, 3, 68, 110, 26, 33, 31, 8, 45, \
35 82, 58, 40, 107, 32, 5, 106, 92, 62, 67, \
36 77, 108, 122, 37, 60, 66, 121, 42, 51, 126, \
37 117, 114, 4, 90, 43, 52, 53, 113, 120, 72, \
38 16, 49, 7, 79, 119, 61, 22, 84, 9, 97, \
39 91, 15, 21, 24, 46, 39, 93, 105, 65, 70, \
40 125, 99, 17, 123 \
41 };
42
43 int calculate_ma_sfh(int maio, int hsn, int n, int fn)
44 {
45 int mai = 0;
46 int s = 0;
47 int nbin = floor(log2(n) + 1);
48 int t1 = fn / 1326;
49 int t2 = fn % 26;
50 int t3 = fn % 51;
51
52 if (hsn == 0){
53 mai = (fn + maio) % n;
54 } else {
55 int t1r = t1 % 64;
56 int m = t2 + RNTABLE[(hsn ^ t1r) + t3];
57 int mprim = m % (1 << nbin);
58 int tprim = t3 % (1 << nbin);
59
60 if (mprim < n){
61 s = mprim;
62 } else {
63 s = (mprim + tprim) % n;
64 }
65 mai = (s + maio) % n;
66 }
Piotr Krysik6463dc72018-06-18 14:43:50 +020067 return (mai);
Piotr Krysikb7cce892018-05-11 11:37:21 +020068 }
69 } // namespace gsm
70} // namespace gr