blob: 500113e57e111790728893e0e59c5a818897d0bd [file] [log] [blame]
piotr437f5462014-02-04 17:57:25 +01001/* -*- c++ -*- */
piotrd0bf1492014-02-05 17:27:32 +01002/*
piotrc1d47df2014-04-17 09:45:50 +02003 * Copyright 2014 Piotr Krysik <pkrysik@elka.pw.edu.pl>.
piotrd0bf1492014-02-05 17:27:32 +01004 *
piotr437f5462014-02-04 17:57:25 +01005 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3, or (at your option)
8 * any later version.
piotrd0bf1492014-02-05 17:27:32 +01009 *
piotr437f5462014-02-04 17:57:25 +010010 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
piotrd0bf1492014-02-05 17:27:32 +010014 *
piotr437f5462014-02-04 17:57:25 +010015 * You should have received a copy of the GNU General Public License
16 * along with this software; see the file COPYING. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifdef HAVE_CONFIG_H
22#include "config.h"
23#endif
24
25#include <gnuradio/io_signature.h>
26#include "receiver_impl.h"
27
28#include <gnuradio/io_signature.h>
29#include <gnuradio/math.h>
30#include <math.h>
31#include <boost/circular_buffer.hpp>
32#include <algorithm>
33#include <numeric>
34#include <viterbi_detector.h>
35#include <string.h>
36#include <sch.h>
37#include <iostream>
38#include <iomanip>
piotr437f5462014-02-04 17:57:25 +010039#include <assert.h>
piotr6d152d92014-02-21 00:02:44 +010040#include <boost/scoped_ptr.hpp>
piotr7f3f3662014-07-08 16:47:53 +020041//#include "plotting/plotting.hpp"
piotr437f5462014-02-04 17:57:25 +010042
43#define SYNC_SEARCH_RANGE 30
44
piotrd0bf1492014-02-05 17:27:32 +010045namespace gr
46{
47namespace gsm
48{
piotr437f5462014-02-04 17:57:25 +010049
piotrd0bf1492014-02-05 17:27:32 +010050typedef std::list<float> list_float;
51typedef std::vector<float> vector_float;
piotr437f5462014-02-04 17:57:25 +010052
piotrd0bf1492014-02-05 17:27:32 +010053typedef boost::circular_buffer<float> circular_buffer_float;
piotr437f5462014-02-04 17:57:25 +010054
piotrd0bf1492014-02-05 17:27:32 +010055receiver::sptr
piotr6d152d92014-02-21 00:02:44 +010056receiver::make(feval_dd * tuner, int osr, int arfcn)
piotrd0bf1492014-02-05 17:27:32 +010057{
58 return gnuradio::get_initial_sptr
piotr6d152d92014-02-21 00:02:44 +010059 (new receiver_impl(tuner, osr, arfcn));
piotrd0bf1492014-02-05 17:27:32 +010060}
61
62/*
63 * The private constructor
64 */
piotr6d152d92014-02-21 00:02:44 +010065receiver_impl::receiver_impl(feval_dd * tuner, int osr, int arfcn)
piotrc7c249a2014-05-02 17:24:08 +020066 : gr::sync_block("receiver",
piotrd0bf1492014-02-05 17:27:32 +010067 gr::io_signature::make(1, 1, sizeof(gr_complex)),
piotr7c82b172014-02-08 14:15:27 +010068 gr::io_signature::make(0, 0, 0)),
piotrd0bf1492014-02-05 17:27:32 +010069 d_OSR(osr),
70 d_chan_imp_length(CHAN_IMP_RESP_LENGTH),
71 d_tuner(tuner),
72 d_counter(0),
73 d_fcch_start_pos(0),
74 d_freq_offset(0),
75 d_state(first_fcch_search),
76 d_burst_nr(osr),
piotr6d152d92014-02-21 00:02:44 +010077 d_failed_sch(0),
78 d_arfcn((int)(arfcn)),
79 d_signal_dbm(-120)
piotrd0bf1492014-02-05 17:27:32 +010080{
81 int i;
piotr7f3f3662014-07-08 16:47:53 +020082 //set_output_multiple(floor((TS_BITS + 2 * GUARD_PERIOD) * d_OSR)); //don't send samples to the receiver until there are at least samples for one
83 set_output_multiple(floor((TS_BITS + 2 * GUARD_PERIOD) * d_OSR)); // burst and two gurad periods (one gurard period is an arbitrary overlap)
piotrd0bf1492014-02-05 17:27:32 +010084 gmsk_mapper(SYNC_BITS, N_SYNC_BITS, d_sch_training_seq, gr_complex(0.0, -1.0));
85 for (i = 0; i < TRAIN_SEQ_NUM; i++)
piotr437f5462014-02-04 17:57:25 +010086 {
piotrf502e0f2014-04-24 10:28:29 +020087 gr_complex startpoint = (train_seq[i][0]==0) ? gr_complex(1.0, 0.0) : gr_complex(-1.0, 0.0); //if first bit of the seqeunce ==0 first symbol ==1
piotr7f3f3662014-07-08 16:47:53 +020088 //if first bit of the seqeunce ==1 first symbol ==-1
piotr437f5462014-02-04 17:57:25 +010089 gmsk_mapper(train_seq[i], N_TRAIN_BITS, d_norm_training_seq[i], startpoint);
piotr437f5462014-02-04 17:57:25 +010090 }
piotr7c82b172014-02-08 14:15:27 +010091 message_port_register_out(pmt::mp("bursts"));
piotr903b1d62014-04-17 11:33:27 +020092 configure_receiver(); //configure the receiver - tell it where to find which burst type
piotrd0bf1492014-02-05 17:27:32 +010093}
piotr437f5462014-02-04 17:57:25 +010094
piotrf2b6a1b2014-08-04 11:28:59 +020095
96
piotrd0bf1492014-02-05 17:27:32 +010097/*
98 * Our virtual destructor.
99 */
100receiver_impl::~receiver_impl()
101{
102}
103
piotrd0bf1492014-02-05 17:27:32 +0100104int
piotrc7c249a2014-05-02 17:24:08 +0200105receiver_impl::work(int noutput_items,
106 gr_vector_const_void_star &input_items,
107 gr_vector_void_star &output_items)
piotrd0bf1492014-02-05 17:27:32 +0100108{
piotrc7c249a2014-05-02 17:24:08 +0200109 //std::cout << noutput_items << std::endl;
piotrd0bf1492014-02-05 17:27:32 +0100110 const gr_complex *input = (const gr_complex *) input_items[0];
piotr7c82b172014-02-08 14:15:27 +0100111
piotrd0bf1492014-02-05 17:27:32 +0100112 switch (d_state)
piotr437f5462014-02-04 17:57:25 +0100113 {
piotrd0bf1492014-02-05 17:27:32 +0100114 //bootstrapping
115 case first_fcch_search:
piotr7e3b0db2014-02-05 22:44:30 +0100116 DCOUT("FCCH search");
piotrc7c249a2014-05-02 17:24:08 +0200117 if (find_fcch_burst(input, noutput_items)) //find frequency correction burst in the input buffer
piotrd0bf1492014-02-05 17:27:32 +0100118 {
piotr5f1e1d32014-02-05 18:10:05 +0100119 //set_frequency(d_freq_offset); //if fcch search is successful set frequency offset
piotr7f3f3662014-07-08 16:47:53 +0200120 DCOUT("Freq offset " << d_freq_offset);
121 DCOUT("PPM: " << d_freq_offset/940e6);
piotr437f5462014-02-04 17:57:25 +0100122 d_state = next_fcch_search;
piotrd0bf1492014-02-05 17:27:32 +0100123 }
124 else
125 {
piotr437f5462014-02-04 17:57:25 +0100126 d_state = first_fcch_search;
piotrd0bf1492014-02-05 17:27:32 +0100127 }
128 break;
piotr437f5462014-02-04 17:57:25 +0100129
piotrd0bf1492014-02-05 17:27:32 +0100130 case next_fcch_search: //this state is used because it takes some time (a bunch of buffered samples)
131 {
piotr7e3b0db2014-02-05 22:44:30 +0100132 DCOUT("NEXT FCCH search");
piotr7f3f3662014-07-08 16:47:53 +0200133 d_prev_freq_offset = d_freq_offset; //before previous set_frequqency cause change
piotrc7c249a2014-05-02 17:24:08 +0200134 if (find_fcch_burst(input, noutput_items))
piotrd0bf1492014-02-05 17:27:32 +0100135 {
piotr7f3f3662014-07-08 16:47:53 +0200136 if (abs(d_prev_freq_offset - d_freq_offset) > FCCH_MAX_FREQ_OFFSET)
piotrd0bf1492014-02-05 17:27:32 +0100137 {
piotr5f1e1d32014-02-05 18:10:05 +0100138 //set_frequency(d_freq_offset); //call set_frequncy only frequency offset change is greater than some value
piotr7f3f3662014-07-08 16:47:53 +0200139 //COUT("Freq offset " << d_freq_offset);
140 DCOUT("PPM: " << d_freq_offset/940);
piotr437f5462014-02-04 17:57:25 +0100141 }
piotrd0bf1492014-02-05 17:27:32 +0100142 d_state = sch_search;
143 }
144 else
145 {
piotrd0bf1492014-02-05 17:27:32 +0100146 d_state = next_fcch_search;
147 }
148 break;
149 }
piotr437f5462014-02-04 17:57:25 +0100150
151
piotrd0bf1492014-02-05 17:27:32 +0100152 case sch_search:
153 {
piotr7c82b172014-02-08 14:15:27 +0100154 DCOUT("SCH search");
piotrd0bf1492014-02-05 17:27:32 +0100155 vector_complex channel_imp_resp(CHAN_IMP_RESP_LENGTH*d_OSR);
156 int t1, t2, t3;
157 int burst_start = 0;
158 unsigned char output_binary[BURST_SIZE];
piotr437f5462014-02-04 17:57:25 +0100159
piotrc7c249a2014-05-02 17:24:08 +0200160 if (reach_sch_burst(noutput_items)) //wait for a SCH burst
piotrd0bf1492014-02-05 17:27:32 +0100161 {
162 burst_start = get_sch_chan_imp_resp(input, &channel_imp_resp[0]); //get channel impulse response from it
163 detect_burst(input, &channel_imp_resp[0], burst_start, output_binary); //detect bits using MLSE detection
164 if (decode_sch(&output_binary[3], &t1, &t2, &t3, &d_ncc, &d_bcc) == 0) //decode SCH burst
165 {
piotr6d152d92014-02-21 00:02:44 +0100166 DCOUT("sch burst_start: " << burst_start);
167 DCOUT("bcc: " << d_bcc << " ncc: " << d_ncc << " t1: " << t1 << " t2: " << t2 << " t3: " << t3);
piotr437f5462014-02-04 17:57:25 +0100168 d_burst_nr.set(t1, t2, t3, 0); //set counter of bursts value
piotr437f5462014-02-04 17:57:25 +0100169 d_burst_nr++;
170
piotr7f3f3662014-07-08 16:47:53 +0200171 consume_each(burst_start + BURST_SIZE * d_OSR + 4*d_OSR); //consume samples up to next guard period
piotr437f5462014-02-04 17:57:25 +0100172 d_state = synchronized;
piotrd0bf1492014-02-05 17:27:32 +0100173 }
174 else
175 {
piotr437f5462014-02-04 17:57:25 +0100176 d_state = next_fcch_search; //if there is error in the sch burst go back to fcch search phase
piotr437f5462014-02-04 17:57:25 +0100177 }
piotrd0bf1492014-02-05 17:27:32 +0100178 }
179 else
180 {
181 d_state = sch_search;
182 }
183 break;
184 }
185 //in this state receiver is synchronized and it processes bursts according to burst type for given burst number
186 case synchronized:
187 {
piotr6d152d92014-02-21 00:02:44 +0100188 DCOUT("Synchronized");
piotrd0bf1492014-02-05 17:27:32 +0100189 vector_complex channel_imp_resp(CHAN_IMP_RESP_LENGTH*d_OSR);
190 int burst_start;
191 int offset = 0;
192 int to_consume = 0;
193 unsigned char output_binary[BURST_SIZE];
piotr437f5462014-02-04 17:57:25 +0100194
piotrd0bf1492014-02-05 17:27:32 +0100195 burst_type b_type = d_channel_conf.get_burst_type(d_burst_nr); //get burst type for given burst number
piotrf2b6a1b2014-08-04 11:28:59 +0200196 double signal_pwr = 0;
piotrc7c249a2014-05-02 17:24:08 +0200197 for(int ii=0;ii<noutput_items;ii++)
piotr6d152d92014-02-21 00:02:44 +0100198 {
199 signal_pwr += abs(input[ii])*abs(input[ii]);
200 }
piotrf2b6a1b2014-08-04 11:28:59 +0200201 d_signal_dbm=static_cast<int8_t>(round(10*log10(signal_pwr/50/noutput_items)));
piotr6d152d92014-02-21 00:02:44 +0100202
piotrd0bf1492014-02-05 17:27:32 +0100203 switch (b_type)
204 {
205 case fcch_burst: //if it's FCCH burst
206 {
207 const unsigned first_sample = ceil((GUARD_PERIOD + 2 * TAIL_BITS) * d_OSR) + 1;
208 const unsigned last_sample = first_sample + USEFUL_BITS * d_OSR - TAIL_BITS * d_OSR;
209 double freq_offset = compute_freq_offset(input, first_sample, last_sample); //extract frequency offset from it
piotr437f5462014-02-04 17:57:25 +0100210
piotrd0bf1492014-02-05 17:27:32 +0100211 d_freq_offset_vals.push_front(freq_offset);
piotr6d152d92014-02-21 00:02:44 +0100212 send_burst(d_burst_nr, fc_fb, b_type);
213
piotrd0bf1492014-02-05 17:27:32 +0100214 if (d_freq_offset_vals.size() >= 10)
215 {
216 double sum = std::accumulate(d_freq_offset_vals.begin(), d_freq_offset_vals.end(), 0);
217 double mean_offset = sum / d_freq_offset_vals.size(); //compute mean
218 d_freq_offset_vals.clear();
piotr7f3f3662014-07-08 16:47:53 +0200219 DCOUT("mean offset" << mean_offset/940);
piotrd0bf1492014-02-05 17:27:32 +0100220 if (abs(mean_offset) > FCCH_MAX_FREQ_OFFSET)
221 {
piotr7c82b172014-02-08 14:15:27 +0100222 //d_freq_offset -= mean_offset; //and adjust frequency if it have changed beyond
piotr5f1e1d32014-02-05 18:10:05 +0100223 //set_frequency(d_freq_offset); //some limit
piotr7e3b0db2014-02-05 22:44:30 +0100224 DCOUT("Adjusting frequency, new frequency offset: " << d_freq_offset << "\n");
piotrd0bf1492014-02-05 17:27:32 +0100225 }
226 }
227 }
228 break;
229 case sch_burst: //if it's SCH burst
230 {
231 int t1, t2, t3, d_ncc, d_bcc;
232 burst_start = get_sch_chan_imp_resp(input, &channel_imp_resp[0]); //get channel impulse response
233 detect_burst(input, &channel_imp_resp[0], burst_start, output_binary); //MLSE detection of bits
piotr6d152d92014-02-21 00:02:44 +0100234 send_burst(d_burst_nr, output_binary, b_type);
piotrd0bf1492014-02-05 17:27:32 +0100235 if (decode_sch(&output_binary[3], &t1, &t2, &t3, &d_ncc, &d_bcc) == 0) //and decode SCH data
236 {
237 // d_burst_nr.set(t1, t2, t3, 0); //but only to check if burst_start value is correct
238 d_failed_sch = 0;
239 DCOUT("bcc: " << d_bcc << " ncc: " << d_ncc << " t1: " << t1 << " t2: " << t2 << " t3: " << t3);
240 offset = burst_start - floor((GUARD_PERIOD) * d_OSR); //compute offset from burst_start - burst should start after a guard period
piotr7c82b172014-02-08 14:15:27 +0100241 DCOUT("offset: "<<offset);
piotrd0bf1492014-02-05 17:27:32 +0100242 to_consume += offset; //adjust with offset number of samples to be consumed
243 }
244 else
245 {
246 d_failed_sch++;
247 if (d_failed_sch >= MAX_SCH_ERRORS)
248 {
piotr54624012014-04-17 23:36:27 +0200249 d_state = next_fcch_search;
piotr437f5462014-02-04 17:57:25 +0100250 d_freq_offset_vals.clear();
piotrd0bf1492014-02-05 17:27:32 +0100251 d_freq_offset=0;
piotr7c82b172014-02-08 14:15:27 +0100252 //set_frequency(0);
piotrf2b6a1b2014-08-04 11:28:59 +0200253 COUT("Re-Synchronization!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
piotr437f5462014-02-04 17:57:25 +0100254 }
piotr437f5462014-02-04 17:57:25 +0100255 }
piotrd0bf1492014-02-05 17:27:32 +0100256 }
257 break;
piotr437f5462014-02-04 17:57:25 +0100258
piotr7e3b0db2014-02-05 22:44:30 +0100259 case normal_burst:
260 {
261 float normal_corr_max; //if it's normal burst
262 burst_start = get_norm_chan_imp_resp(input, &channel_imp_resp[0], &normal_corr_max, d_bcc); //get channel impulse response for given training sequence number - d_bcc
piotrd0bf1492014-02-05 17:27:32 +0100263 detect_burst(input, &channel_imp_resp[0], burst_start, output_binary); //MLSE detection of bits
piotr8dc74a42014-04-17 09:48:46 +0200264 send_burst(d_burst_nr, output_binary, b_type);
piotrd0bf1492014-02-05 17:27:32 +0100265 break;
piotr7e3b0db2014-02-05 22:44:30 +0100266 }
piotrd0bf1492014-02-05 17:27:32 +0100267 case dummy_or_normal:
268 {
piotr7e3b0db2014-02-05 22:44:30 +0100269 unsigned int normal_burst_start;
270 float dummy_corr_max, normal_corr_max;
piotr7c82b172014-02-08 14:15:27 +0100271 DCOUT("Dummy");
piotr7e3b0db2014-02-05 22:44:30 +0100272 get_norm_chan_imp_resp(input, &channel_imp_resp[0], &dummy_corr_max, TS_DUMMY);
piotr7c82b172014-02-08 14:15:27 +0100273 DCOUT("Normal");
piotr7e3b0db2014-02-05 22:44:30 +0100274 normal_burst_start = get_norm_chan_imp_resp(input, &channel_imp_resp[0], &normal_corr_max, d_bcc);
275
piotr7c82b172014-02-08 14:15:27 +0100276 DCOUT("normal_corr_max: " << normal_corr_max << " dummy_corr_max:" << dummy_corr_max);
piotr7e3b0db2014-02-05 22:44:30 +0100277 if (normal_corr_max > dummy_corr_max)
piotrd0bf1492014-02-05 17:27:32 +0100278 {
piotr7e3b0db2014-02-05 22:44:30 +0100279 detect_burst(input, &channel_imp_resp[0], normal_burst_start, output_binary);
piotr8dc74a42014-04-17 09:48:46 +0200280 send_burst(d_burst_nr, output_binary, b_type);
piotrd0bf1492014-02-05 17:27:32 +0100281 }
282 else
283 {
piotr6d152d92014-02-21 00:02:44 +0100284 send_burst(d_burst_nr, dummy_burst, b_type);
piotrd0bf1492014-02-05 17:27:32 +0100285 }
286 }
287 case rach_burst:
piotrd0bf1492014-02-05 17:27:32 +0100288 break;
piotr7e3b0db2014-02-05 22:44:30 +0100289 case dummy:
piotr6d152d92014-02-21 00:02:44 +0100290 send_burst(d_burst_nr, dummy_burst, b_type);
piotrd0bf1492014-02-05 17:27:32 +0100291 break;
292 case empty: //if it's empty burst
293 break; //do nothing
294 }
295
296 d_burst_nr++; //go to next burst
piotrd0bf1492014-02-05 17:27:32 +0100297 to_consume += TS_BITS * d_OSR + d_burst_nr.get_offset(); //consume samples of the burst up to next guard period
298 //and add offset which is introduced by
299 //0.25 fractional part of a guard period
piotrd0bf1492014-02-05 17:27:32 +0100300 consume_each(to_consume);
301 }
302 break;
piotr437f5462014-02-04 17:57:25 +0100303 }
304
piotr6d152d92014-02-21 00:02:44 +0100305 return 0;
piotrd0bf1492014-02-05 17:27:32 +0100306}
piotr437f5462014-02-04 17:57:25 +0100307
piotrd0bf1492014-02-05 17:27:32 +0100308
309bool receiver_impl::find_fcch_burst(const gr_complex *input, const int nitems)
310{
311 circular_buffer_float phase_diff_buffer(FCCH_HITS_NEEDED * d_OSR); //circular buffer used to scan throug signal to find
312 //best match for FCCH burst
313 float phase_diff = 0;
314 gr_complex conjprod;
315 int start_pos = -1;
316 int hit_count = 0;
317 int miss_count = 0;
318 float min_phase_diff;
319 float max_phase_diff;
320 double best_sum = 0;
321 float lowest_max_min_diff = 99999;
322
323 int to_consume = 0;
324 int sample_number = 0;
325 bool end = false;
326 bool result = false;
327 circular_buffer_float::iterator buffer_iter;
piotr6d152d92014-02-21 00:02:44 +0100328
piotrd0bf1492014-02-05 17:27:32 +0100329 /**@name Possible states of FCCH search algorithm*/
330 //@{
331 enum states
piotr437f5462014-02-04 17:57:25 +0100332 {
piotr437f5462014-02-04 17:57:25 +0100333 init, ///< initialize variables
334 search, ///< search for positive samples
335 found_something, ///< search for FCCH and the best position of it
336 fcch_found, ///< when FCCH was found
337 search_fail ///< when there is no FCCH in the input vector
piotrd0bf1492014-02-05 17:27:32 +0100338 } fcch_search_state;
339 //@}
piotr437f5462014-02-04 17:57:25 +0100340
piotrd0bf1492014-02-05 17:27:32 +0100341 fcch_search_state = init;
piotr437f5462014-02-04 17:57:25 +0100342
piotrd0bf1492014-02-05 17:27:32 +0100343 while (!end)
344 {
345 switch (fcch_search_state)
346 {
piotr437f5462014-02-04 17:57:25 +0100347
piotrd0bf1492014-02-05 17:27:32 +0100348 case init: //initialize variables
piotr437f5462014-02-04 17:57:25 +0100349 hit_count = 0;
350 miss_count = 0;
351 start_pos = -1;
352 lowest_max_min_diff = 99999;
353 phase_diff_buffer.clear();
354 fcch_search_state = search;
355
356 break;
357
piotr7c82b172014-02-08 14:15:27 +0100358 case search: // search for positive samples
piotr437f5462014-02-04 17:57:25 +0100359 sample_number++;
360
piotrd0bf1492014-02-05 17:27:32 +0100361 if (sample_number > nitems - FCCH_HITS_NEEDED * d_OSR) //if it isn't possible to find FCCH because
362 {
piotr7c82b172014-02-08 14:15:27 +0100363 //there's too few samples left to look into,
piotrd0bf1492014-02-05 17:27:32 +0100364 to_consume = sample_number; //don't do anything with those samples which are left
piotr7c82b172014-02-08 14:15:27 +0100365 //and consume only those which were checked
piotrd0bf1492014-02-05 17:27:32 +0100366 fcch_search_state = search_fail;
367 }
368 else
369 {
370 phase_diff = compute_phase_diff(input[sample_number], input[sample_number-1]);
piotr437f5462014-02-04 17:57:25 +0100371
piotrd0bf1492014-02-05 17:27:32 +0100372 if (phase_diff > 0) //if a positive phase difference was found
373 {
374 to_consume = sample_number;
375 fcch_search_state = found_something; //switch to state in which searches for FCCH
376 }
377 else
378 {
379 fcch_search_state = search;
380 }
piotr437f5462014-02-04 17:57:25 +0100381 }
382
383 break;
384
piotrd0bf1492014-02-05 17:27:32 +0100385 case found_something: // search for FCCH and the best position of it
386 {
387 if (phase_diff > 0)
388 {
piotr437f5462014-02-04 17:57:25 +0100389 hit_count++; //positive phase differencies increases hits_count
piotrd0bf1492014-02-05 17:27:32 +0100390 }
391 else
392 {
piotr437f5462014-02-04 17:57:25 +0100393 miss_count++; //negative increases miss_count
piotrd0bf1492014-02-05 17:27:32 +0100394 }
piotr437f5462014-02-04 17:57:25 +0100395
piotrd0bf1492014-02-05 17:27:32 +0100396 if ((miss_count >= FCCH_MAX_MISSES * d_OSR) && (hit_count <= FCCH_HITS_NEEDED * d_OSR))
397 {
piotr437f5462014-02-04 17:57:25 +0100398 //if miss_count exceeds limit before hit_count
399 fcch_search_state = init; //go to init
400 continue;
piotrd0bf1492014-02-05 17:27:32 +0100401 }
402 else if (((miss_count >= FCCH_MAX_MISSES * d_OSR) && (hit_count > FCCH_HITS_NEEDED * d_OSR)) || (hit_count > 2 * FCCH_HITS_NEEDED * d_OSR))
403 {
piotr437f5462014-02-04 17:57:25 +0100404 //if hit_count and miss_count exceeds limit then FCCH was found
405 fcch_search_state = fcch_found;
406 continue;
piotrd0bf1492014-02-05 17:27:32 +0100407 }
408 else if ((miss_count < FCCH_MAX_MISSES * d_OSR) && (hit_count > FCCH_HITS_NEEDED * d_OSR))
409 {
piotr437f5462014-02-04 17:57:25 +0100410 //find difference between minimal and maximal element in the buffer
411 //for FCCH this value should be low
412 //this part is searching for a region where this value is lowest
413 min_phase_diff = * (min_element(phase_diff_buffer.begin(), phase_diff_buffer.end()));
414 max_phase_diff = * (max_element(phase_diff_buffer.begin(), phase_diff_buffer.end()));
415
piotrd0bf1492014-02-05 17:27:32 +0100416 if (lowest_max_min_diff > max_phase_diff - min_phase_diff)
417 {
418 lowest_max_min_diff = max_phase_diff - min_phase_diff;
419 start_pos = sample_number - FCCH_HITS_NEEDED * d_OSR - FCCH_MAX_MISSES * d_OSR; //store start pos
420 best_sum = 0;
piotr437f5462014-02-04 17:57:25 +0100421
piotrd0bf1492014-02-05 17:27:32 +0100422 for (buffer_iter = phase_diff_buffer.begin();
423 buffer_iter != (phase_diff_buffer.end());
424 buffer_iter++)
425 {
426 best_sum += *buffer_iter - (M_PI / 2) / d_OSR; //store best value of phase offset sum
427 }
piotr437f5462014-02-04 17:57:25 +0100428 }
piotrd0bf1492014-02-05 17:27:32 +0100429 }
piotr437f5462014-02-04 17:57:25 +0100430
piotrd0bf1492014-02-05 17:27:32 +0100431 sample_number++;
piotr437f5462014-02-04 17:57:25 +0100432
piotrd0bf1492014-02-05 17:27:32 +0100433 if (sample_number >= nitems) //if there's no single sample left to check
434 {
piotr437f5462014-02-04 17:57:25 +0100435 fcch_search_state = search_fail;//FCCH search failed
436 continue;
piotr437f5462014-02-04 17:57:25 +0100437 }
piotrd0bf1492014-02-05 17:27:32 +0100438
439 phase_diff = compute_phase_diff(input[sample_number], input[sample_number-1]);
440 phase_diff_buffer.push_back(phase_diff);
441 fcch_search_state = found_something;
442 }
443 break;
444
445 case fcch_found:
446 {
447 DCOUT("fcch found on position: " << d_counter + start_pos);
448 to_consume = start_pos + FCCH_HITS_NEEDED * d_OSR + 1; //consume one FCCH burst
449
450 d_fcch_start_pos = d_counter + start_pos;
451
452 //compute frequency offset
453 double phase_offset = best_sum / FCCH_HITS_NEEDED;
454 double freq_offset = phase_offset * 1625000.0 / (12.0 * M_PI);
piotr7f3f3662014-07-08 16:47:53 +0200455 //d_freq_offset -= freq_offset;
456 d_freq_offset = freq_offset;
piotrd0bf1492014-02-05 17:27:32 +0100457 DCOUT("freq_offset: " << d_freq_offset);
458
459 end = true;
460 result = true;
piotr437f5462014-02-04 17:57:25 +0100461 break;
piotrd0bf1492014-02-05 17:27:32 +0100462 }
piotr437f5462014-02-04 17:57:25 +0100463
piotrd0bf1492014-02-05 17:27:32 +0100464 case search_fail:
piotr437f5462014-02-04 17:57:25 +0100465 end = true;
466 result = false;
467 break;
468 }
piotr437f5462014-02-04 17:57:25 +0100469 }
470
piotrd0bf1492014-02-05 17:27:32 +0100471 d_counter += to_consume;
472 consume_each(to_consume);
piotr437f5462014-02-04 17:57:25 +0100473
piotrd0bf1492014-02-05 17:27:32 +0100474 return result;
475}
476
piotrd0bf1492014-02-05 17:27:32 +0100477double receiver_impl::compute_freq_offset(const gr_complex * input, unsigned first_sample, unsigned last_sample)
478{
479 double phase_sum = 0;
480 unsigned ii;
481
482 for (ii = first_sample; ii < last_sample; ii++)
piotr437f5462014-02-04 17:57:25 +0100483 {
piotr437f5462014-02-04 17:57:25 +0100484 double phase_diff = compute_phase_diff(input[ii], input[ii-1]) - (M_PI / 2) / d_OSR;
485 phase_sum += phase_diff;
piotr437f5462014-02-04 17:57:25 +0100486 }
487
piotrd0bf1492014-02-05 17:27:32 +0100488 double phase_offset = phase_sum / (last_sample - first_sample);
489 double freq_offset = phase_offset * 1625000.0 / (12.0 * M_PI);
490 return freq_offset;
491}
piotr437f5462014-02-04 17:57:25 +0100492
piotrd0bf1492014-02-05 17:27:32 +0100493void receiver_impl::set_frequency(double freq_offset)
494{
495 d_tuner->calleval(freq_offset);
496}
piotr437f5462014-02-04 17:57:25 +0100497
piotrd0bf1492014-02-05 17:27:32 +0100498inline float receiver_impl::compute_phase_diff(gr_complex val1, gr_complex val2)
499{
500 gr_complex conjprod = val1 * conj(val2);
501 return fast_atan2f(imag(conjprod), real(conjprod));
502}
piotr437f5462014-02-04 17:57:25 +0100503
piotrd0bf1492014-02-05 17:27:32 +0100504bool receiver_impl::reach_sch_burst(const int nitems)
505{
506 //it just consumes samples to get near to a SCH burst
507 int to_consume = 0;
508 bool result = false;
509 unsigned sample_nr_near_sch_start = d_fcch_start_pos + (FRAME_BITS - SAFETY_MARGIN) * d_OSR;
510
511 //consume samples until d_counter will be equal to sample_nr_near_sch_start
512 if (d_counter < sample_nr_near_sch_start)
513 {
514 if (d_counter + nitems >= sample_nr_near_sch_start)
515 {
516 to_consume = sample_nr_near_sch_start - d_counter;
517 }
518 else
519 {
520 to_consume = nitems;
piotr437f5462014-02-04 17:57:25 +0100521 }
522 result = false;
piotrd0bf1492014-02-05 17:27:32 +0100523 }
524 else
525 {
piotr437f5462014-02-04 17:57:25 +0100526 to_consume = 0;
527 result = true;
piotr437f5462014-02-04 17:57:25 +0100528 }
529
piotrd0bf1492014-02-05 17:27:32 +0100530 d_counter += to_consume;
531 consume_each(to_consume);
532 return result;
533}
534
535int receiver_impl::get_sch_chan_imp_resp(const gr_complex *input, gr_complex * chan_imp_resp)
536{
537 vector_complex correlation_buffer;
538 vector_float power_buffer;
539 vector_float window_energy_buffer;
540
541 int strongest_window_nr;
542 int burst_start = 0;
543 int chan_imp_resp_center = 0;
544 float max_correlation = 0;
545 float energy = 0;
546
547 for (int ii = SYNC_POS * d_OSR; ii < (SYNC_POS + SYNC_SEARCH_RANGE) *d_OSR; ii++)
piotr437f5462014-02-04 17:57:25 +0100548 {
piotr437f5462014-02-04 17:57:25 +0100549 gr_complex correlation = correlate_sequence(&d_sch_training_seq[5], N_SYNC_BITS - 10, &input[ii]);
550 correlation_buffer.push_back(correlation);
551 power_buffer.push_back(std::pow(abs(correlation), 2));
piotrd0bf1492014-02-05 17:27:32 +0100552 }
piotr7f3f3662014-07-08 16:47:53 +0200553 //plot(power_buffer);
piotrd0bf1492014-02-05 17:27:32 +0100554 //compute window energies
555 vector_float::iterator iter = power_buffer.begin();
556 bool loop_end = false;
557 while (iter != power_buffer.end())
558 {
piotr437f5462014-02-04 17:57:25 +0100559 vector_float::iterator iter_ii = iter;
560 energy = 0;
561
piotrd0bf1492014-02-05 17:27:32 +0100562 for (int ii = 0; ii < (d_chan_imp_length) *d_OSR; ii++, iter_ii++)
563 {
564 if (iter_ii == power_buffer.end())
565 {
566 loop_end = true;
567 break;
568 }
569 energy += (*iter_ii);
piotr437f5462014-02-04 17:57:25 +0100570 }
piotrd0bf1492014-02-05 17:27:32 +0100571 if (loop_end)
572 {
573 break;
piotr437f5462014-02-04 17:57:25 +0100574 }
575 iter++;
576 window_energy_buffer.push_back(energy);
piotrd0bf1492014-02-05 17:27:32 +0100577 }
piotr437f5462014-02-04 17:57:25 +0100578
piotrd0bf1492014-02-05 17:27:32 +0100579 strongest_window_nr = max_element(window_energy_buffer.begin(), window_energy_buffer.end()) - window_energy_buffer.begin();
piotr437f5462014-02-04 17:57:25 +0100580 // d_channel_imp_resp.clear();
581
piotrd0bf1492014-02-05 17:27:32 +0100582 max_correlation = 0;
583 for (int ii = 0; ii < (d_chan_imp_length) *d_OSR; ii++)
584 {
piotr437f5462014-02-04 17:57:25 +0100585 gr_complex correlation = correlation_buffer[strongest_window_nr + ii];
piotrd0bf1492014-02-05 17:27:32 +0100586 if (abs(correlation) > max_correlation)
587 {
588 chan_imp_resp_center = ii;
589 max_correlation = abs(correlation);
piotr437f5462014-02-04 17:57:25 +0100590 }
piotrd0bf1492014-02-05 17:27:32 +0100591 // d_channel_imp_resp.push_back(correlation);
piotr437f5462014-02-04 17:57:25 +0100592 chan_imp_resp[ii] = correlation;
piotr437f5462014-02-04 17:57:25 +0100593 }
594
piotrd0bf1492014-02-05 17:27:32 +0100595 burst_start = strongest_window_nr + chan_imp_resp_center - 48 * d_OSR - 2 * d_OSR + 2 + SYNC_POS * d_OSR;
596 return burst_start;
597}
piotr437f5462014-02-04 17:57:25 +0100598
599
piotrd0bf1492014-02-05 17:27:32 +0100600
601void receiver_impl::detect_burst(const gr_complex * input, gr_complex * chan_imp_resp, int burst_start, unsigned char * output_binary)
602{
603 float output[BURST_SIZE];
604 gr_complex rhh_temp[CHAN_IMP_RESP_LENGTH*d_OSR];
605 gr_complex rhh[CHAN_IMP_RESP_LENGTH];
606 gr_complex filtered_burst[BURST_SIZE];
607 int start_state = 3;
608 unsigned int stop_states[2] = {4, 12};
609
610 autocorrelation(chan_imp_resp, rhh_temp, d_chan_imp_length*d_OSR);
611 for (int ii = 0; ii < (d_chan_imp_length); ii++)
piotr437f5462014-02-04 17:57:25 +0100612 {
piotr437f5462014-02-04 17:57:25 +0100613 rhh[ii] = conj(rhh_temp[ii*d_OSR]);
piotr437f5462014-02-04 17:57:25 +0100614 }
615
piotrd0bf1492014-02-05 17:27:32 +0100616 mafi(&input[burst_start], BURST_SIZE, chan_imp_resp, d_chan_imp_length*d_OSR, filtered_burst);
617
618 viterbi_detector(filtered_burst, BURST_SIZE, rhh, start_state, stop_states, 2, output);
619
620 for (int i = 0; i < BURST_SIZE ; i++)
piotr437f5462014-02-04 17:57:25 +0100621 {
piotrd0bf1492014-02-05 17:27:32 +0100622 output_binary[i] = (output[i] > 0);
623 }
624}
piotr437f5462014-02-04 17:57:25 +0100625
piotrd0bf1492014-02-05 17:27:32 +0100626//TODO consider placing this funtion in a separate class for signal processing
627void receiver_impl::gmsk_mapper(const unsigned char * input, int nitems, gr_complex * gmsk_output, gr_complex start_point)
628{
629 gr_complex j = gr_complex(0.0, 1.0);
piotr437f5462014-02-04 17:57:25 +0100630
piotrd0bf1492014-02-05 17:27:32 +0100631 int current_symbol;
632 int encoded_symbol;
633 int previous_symbol = 2 * input[0] - 1;
634 gmsk_output[0] = start_point;
635
636 for (int i = 1; i < nitems; i++)
637 {
piotr437f5462014-02-04 17:57:25 +0100638 //change bits representation to NRZ
639 current_symbol = 2 * input[i] - 1;
640 //differentially encode
641 encoded_symbol = current_symbol * previous_symbol;
642 //and do gmsk mapping
643 gmsk_output[i] = j * gr_complex(encoded_symbol, 0.0) * gmsk_output[i-1];
644 previous_symbol = current_symbol;
piotr437f5462014-02-04 17:57:25 +0100645 }
piotrd0bf1492014-02-05 17:27:32 +0100646}
piotr437f5462014-02-04 17:57:25 +0100647
piotrd0bf1492014-02-05 17:27:32 +0100648//TODO consider use of some generalized function for correlation and placing it in a separate class for signal processing
649gr_complex receiver_impl::correlate_sequence(const gr_complex * sequence, int length, const gr_complex * input)
650{
651 gr_complex result(0.0, 0.0);
652 int sample_number = 0;
653
654 for (int ii = 0; ii < length; ii++)
piotr437f5462014-02-04 17:57:25 +0100655 {
piotr437f5462014-02-04 17:57:25 +0100656 sample_number = (ii * d_OSR) ;
657 result += sequence[ii] * conj(input[sample_number]);
piotr437f5462014-02-04 17:57:25 +0100658 }
659
piotrd0bf1492014-02-05 17:27:32 +0100660 result = result / gr_complex(length, 0);
661 return result;
662}
663
664//computes autocorrelation for positive arguments
665//TODO consider placing this funtion in a separate class for signal processing
666inline void receiver_impl::autocorrelation(const gr_complex * input, gr_complex * out, int nitems)
667{
668 int i, k;
669 for (k = nitems - 1; k >= 0; k--)
piotr437f5462014-02-04 17:57:25 +0100670 {
piotr437f5462014-02-04 17:57:25 +0100671 out[k] = gr_complex(0, 0);
piotrd0bf1492014-02-05 17:27:32 +0100672 for (i = k; i < nitems; i++)
673 {
674 out[k] += input[i] * conj(input[i-k]);
piotr437f5462014-02-04 17:57:25 +0100675 }
piotr437f5462014-02-04 17:57:25 +0100676 }
piotrd0bf1492014-02-05 17:27:32 +0100677}
piotr437f5462014-02-04 17:57:25 +0100678
piotrd0bf1492014-02-05 17:27:32 +0100679//TODO consider use of some generalized function for filtering and placing it in a separate class for signal processing
680inline void receiver_impl::mafi(const gr_complex * input, int nitems, gr_complex * filter, int filter_length, gr_complex * output)
681{
682 int ii = 0, n, a;
683
684 for (n = 0; n < nitems; n++)
piotr437f5462014-02-04 17:57:25 +0100685 {
piotr437f5462014-02-04 17:57:25 +0100686 a = n * d_OSR;
687 output[n] = 0;
688 ii = 0;
689
piotrd0bf1492014-02-05 17:27:32 +0100690 while (ii < filter_length)
691 {
piotrda8a0662014-04-24 10:29:38 +0200692 if ((a + ii) >= nitems*d_OSR){
piotrd0bf1492014-02-05 17:27:32 +0100693 break;
piotrda8a0662014-04-24 10:29:38 +0200694 }
piotrd0bf1492014-02-05 17:27:32 +0100695 output[n] += input[a+ii] * filter[ii];
696 ii++;
piotr437f5462014-02-04 17:57:25 +0100697 }
piotr437f5462014-02-04 17:57:25 +0100698 }
piotrd0bf1492014-02-05 17:27:32 +0100699}
piotr437f5462014-02-04 17:57:25 +0100700
piotrd0bf1492014-02-05 17:27:32 +0100701//TODO: get_norm_chan_imp_resp is similar to get_sch_chan_imp_resp - consider joining this two functions
piotrd0bf1492014-02-05 17:27:32 +0100702//especially computations of strongest_window_nr
piotr7e3b0db2014-02-05 22:44:30 +0100703int receiver_impl::get_norm_chan_imp_resp(const gr_complex *input, gr_complex * chan_imp_resp, float *corr_max, int bcc)
piotrd0bf1492014-02-05 17:27:32 +0100704{
705 vector_complex correlation_buffer;
706 vector_float power_buffer;
707 vector_float window_energy_buffer;
piotr437f5462014-02-04 17:57:25 +0100708
piotrd0bf1492014-02-05 17:27:32 +0100709 int strongest_window_nr;
710 int burst_start = 0;
711 int chan_imp_resp_center = 0;
712 float max_correlation = 0;
713 float energy = 0;
piotr5c820252014-04-17 09:43:02 +0200714
piotrd0bf1492014-02-05 17:27:32 +0100715 int search_center = (int)((TRAIN_POS + GUARD_PERIOD) * d_OSR);
piotr7c82b172014-02-08 14:15:27 +0100716 int search_start_pos = search_center + 1 - 5*d_OSR;
piotr437f5462014-02-04 17:57:25 +0100717 // int search_start_pos = search_center - d_chan_imp_length * d_OSR;
piotr5c820252014-04-17 09:43:02 +0200718 int search_stop_pos = search_center + d_chan_imp_length * d_OSR + 5 * d_OSR;
piotr437f5462014-02-04 17:57:25 +0100719
piotrd0bf1492014-02-05 17:27:32 +0100720 for (int ii = search_start_pos; ii < search_stop_pos; ii++)
721 {
piotr437f5462014-02-04 17:57:25 +0100722 gr_complex correlation = correlate_sequence(&d_norm_training_seq[bcc][TRAIN_BEGINNING], N_TRAIN_BITS - 10, &input[ii]);
723
724 correlation_buffer.push_back(correlation);
725 power_buffer.push_back(std::pow(abs(correlation), 2));
piotrd0bf1492014-02-05 17:27:32 +0100726 }
piotr437f5462014-02-04 17:57:25 +0100727
piotrd0bf1492014-02-05 17:27:32 +0100728 //compute window energies
729 vector_float::iterator iter = power_buffer.begin();
730 bool loop_end = false;
731 while (iter != power_buffer.end())
732 {
piotr437f5462014-02-04 17:57:25 +0100733 vector_float::iterator iter_ii = iter;
734 energy = 0;
735
piotrd0bf1492014-02-05 17:27:32 +0100736 for (int ii = 0; ii < (d_chan_imp_length - 2)*d_OSR; ii++, iter_ii++)
737 {
piotrd0bf1492014-02-05 17:27:32 +0100738 if (iter_ii == power_buffer.end())
739 {
740 loop_end = true;
741 break;
742 }
743 energy += (*iter_ii);
piotr437f5462014-02-04 17:57:25 +0100744 }
piotrd0bf1492014-02-05 17:27:32 +0100745 if (loop_end)
746 {
747 break;
piotr437f5462014-02-04 17:57:25 +0100748 }
749 iter++;
750
751 window_energy_buffer.push_back(energy);
piotrd0bf1492014-02-05 17:27:32 +0100752 }
piotr437f5462014-02-04 17:57:25 +0100753
piotr5c820252014-04-17 09:43:02 +0200754 strongest_window_nr = max_element(window_energy_buffer.begin(), window_energy_buffer.end()-((d_chan_imp_length)*d_OSR)) - window_energy_buffer.begin();
755 //strongest_window_nr = strongest_window_nr-d_OSR;
756 if(strongest_window_nr<0){
757 strongest_window_nr = 0;
758 }
piotr6d152d92014-02-21 00:02:44 +0100759
piotrd0bf1492014-02-05 17:27:32 +0100760 max_correlation = 0;
761 for (int ii = 0; ii < (d_chan_imp_length)*d_OSR; ii++)
762 {
piotr437f5462014-02-04 17:57:25 +0100763 gr_complex correlation = correlation_buffer[strongest_window_nr + ii];
piotrd0bf1492014-02-05 17:27:32 +0100764 if (abs(correlation) > max_correlation)
765 {
766 chan_imp_resp_center = ii;
767 max_correlation = abs(correlation);
piotr437f5462014-02-04 17:57:25 +0100768 }
piotrd0bf1492014-02-05 17:27:32 +0100769 // d_channel_imp_resp.push_back(correlation);
piotr437f5462014-02-04 17:57:25 +0100770 chan_imp_resp[ii] = correlation;
piotr437f5462014-02-04 17:57:25 +0100771 }
piotr7c82b172014-02-08 14:15:27 +0100772
piotr7e3b0db2014-02-05 22:44:30 +0100773 *corr_max = max_correlation;
piotrd0bf1492014-02-05 17:27:32 +0100774
piotr7c82b172014-02-08 14:15:27 +0100775 DCOUT("strongest_window_nr_new: " << strongest_window_nr);
piotrc7c249a2014-05-02 17:24:08 +0200776 burst_start = search_start_pos + strongest_window_nr - TRAIN_POS * d_OSR; //compute first sample posiiton which corresponds to the first sample of the impulse response
777 //TRAIN_POS=3+57+1+6
778 //TODO: describe this part in detail in documentation as this is crucial part for synchronization
piotr7c82b172014-02-08 14:15:27 +0100779
780 DCOUT("burst_start: " << burst_start);
piotrd0bf1492014-02-05 17:27:32 +0100781 return burst_start;
782}
piotr437f5462014-02-04 17:57:25 +0100783
784
piotr6d152d92014-02-21 00:02:44 +0100785void receiver_impl::send_burst(burst_counter burst_nr, const unsigned char * burst_binary, burst_type b_type)
piotrd0bf1492014-02-05 17:27:32 +0100786{
piotr7c82b172014-02-08 14:15:27 +0100787
piotr6d152d92014-02-21 00:02:44 +0100788 boost::scoped_ptr<gsmtap_hdr> tap_header(new gsmtap_hdr());
789
790 tap_header->version = GSMTAP_VERSION;
791 tap_header->hdr_len = BURST_SIZE/4;
792 tap_header->type = GSMTAP_TYPE_UM_BURST;
793 tap_header->timeslot = static_cast<uint8_t>(d_burst_nr.get_timeslot_nr());
794 tap_header->frame_number = d_burst_nr.get_frame_nr();
795 tap_header->sub_type = static_cast<uint8_t>(b_type);
796 tap_header->arfcn = d_arfcn;
797 tap_header->signal_dbm = static_cast<int8_t>(d_signal_dbm);
798 pmt::pmt_t header_blob=pmt::make_blob(tap_header.get(),sizeof(gsmtap_hdr));
799 pmt::pmt_t burst_binary_blob=pmt::make_blob(burst_binary,BURST_SIZE);
800 pmt::pmt_t msg = pmt::cons(header_blob, burst_binary_blob);
piotrf2b6a1b2014-08-04 11:28:59 +0200801
piotr6d152d92014-02-21 00:02:44 +0100802 message_port_pub(pmt::mp("bursts"), msg);
piotrd0bf1492014-02-05 17:27:32 +0100803}
piotr6d152d92014-02-21 00:02:44 +0100804
piotrd0bf1492014-02-05 17:27:32 +0100805void receiver_impl::configure_receiver()
806{
piotrce92f982014-04-17 23:37:18 +0200807 d_channel_conf.set_multiframe_type(TIMESLOT0, multiframe_51);
piotrd0bf1492014-02-05 17:27:32 +0100808 d_channel_conf.set_burst_types(TIMESLOT0, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
piotr437f5462014-02-04 17:57:25 +0100809
piotrce92f982014-04-17 23:37:18 +0200810 d_channel_conf.set_burst_types(TIMESLOT0, TEST_CCH_FRAMES, sizeof(TEST_CCH_FRAMES) / sizeof(unsigned), dummy_or_normal);
811 d_channel_conf.set_burst_types(TIMESLOT0, FCCH_FRAMES, sizeof(FCCH_FRAMES) / sizeof(unsigned), fcch_burst);
812 d_channel_conf.set_burst_types(TIMESLOT0, SCH_FRAMES, sizeof(SCH_FRAMES) / sizeof(unsigned), sch_burst);
piotr437f5462014-02-04 17:57:25 +0100813
814 // d_channel_conf.set_multiframe_type(TIMESLOT1, multiframe_26);
815 // d_channel_conf.set_burst_types(TIMESLOT1, TRAFFIC_CHANNEL_F, sizeof(TRAFFIC_CHANNEL_F) / sizeof(unsigned), dummy_or_normal);
816 // d_channel_conf.set_multiframe_type(TIMESLOT2, multiframe_26);
817 // d_channel_conf.set_burst_types(TIMESLOT2, TRAFFIC_CHANNEL_F, sizeof(TRAFFIC_CHANNEL_F) / sizeof(unsigned), dummy_or_normal);
818 // d_channel_conf.set_multiframe_type(TIMESLOT3, multiframe_26);
819 // d_channel_conf.set_burst_types(TIMESLOT3, TRAFFIC_CHANNEL_F, sizeof(TRAFFIC_CHANNEL_F) / sizeof(unsigned), dummy_or_normal);
820 // d_channel_conf.set_multiframe_type(TIMESLOT4, multiframe_26);
821 // d_channel_conf.set_burst_types(TIMESLOT4, TRAFFIC_CHANNEL_F, sizeof(TRAFFIC_CHANNEL_F) / sizeof(unsigned), dummy_or_normal);
822 // d_channel_conf.set_multiframe_type(TIMESLOT5, multiframe_26);
823 // d_channel_conf.set_burst_types(TIMESLOT5, TRAFFIC_CHANNEL_F, sizeof(TRAFFIC_CHANNEL_F) / sizeof(unsigned), dummy_or_normal);
824 // d_channel_conf.set_multiframe_type(TIMESLOT6, multiframe_26);
825 // d_channel_conf.set_burst_types(TIMESLOT6, TRAFFIC_CHANNEL_F, sizeof(TRAFFIC_CHANNEL_F) / sizeof(unsigned), dummy_or_normal);
826 // d_channel_conf.set_multiframe_type(TIMESLOT7, multiframe_26);
827 // d_channel_conf.set_burst_types(TIMESLOT7, TRAFFIC_CHANNEL_F, sizeof(TRAFFIC_CHANNEL_F) / sizeof(unsigned), dummy_or_normal);
piotr7e3b0db2014-02-05 22:44:30 +0100828
piotrd0bf1492014-02-05 17:27:32 +0100829 d_channel_conf.set_multiframe_type(TIMESLOT1, multiframe_51);
830 d_channel_conf.set_burst_types(TIMESLOT1, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
831 d_channel_conf.set_multiframe_type(TIMESLOT2, multiframe_51);
832 d_channel_conf.set_burst_types(TIMESLOT2, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
833 d_channel_conf.set_multiframe_type(TIMESLOT3, multiframe_51);
834 d_channel_conf.set_burst_types(TIMESLOT3, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
835 d_channel_conf.set_multiframe_type(TIMESLOT4, multiframe_51);
836 d_channel_conf.set_burst_types(TIMESLOT4, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
837 d_channel_conf.set_multiframe_type(TIMESLOT5, multiframe_51);
838 d_channel_conf.set_burst_types(TIMESLOT5, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
839 d_channel_conf.set_multiframe_type(TIMESLOT6, multiframe_51);
840 d_channel_conf.set_burst_types(TIMESLOT6, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
841 d_channel_conf.set_multiframe_type(TIMESLOT7, multiframe_51);
842 d_channel_conf.set_burst_types(TIMESLOT7, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
piotrd0bf1492014-02-05 17:27:32 +0100843}
piotr437f5462014-02-04 17:57:25 +0100844
piotrf2b6a1b2014-08-04 11:28:59 +0200845void receiver_impl::set_arfcn(int arfcn) //!!
846{
847 d_arfcn = arfcn;
848// std::cout << "set arfcn:"<<arfcn << std::endl;
849}
850
851void receiver_impl::reset()
852{
853 d_state = first_fcch_search;
854}
piotr437f5462014-02-04 17:57:25 +0100855
piotrd0bf1492014-02-05 17:27:32 +0100856} /* namespace gsm */
piotr437f5462014-02-04 17:57:25 +0100857} /* namespace gr */
858