blob: bc1c2e4ec5d277cfc1cdd5f9a9ca0d8c158653b8 [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>
ptrkrysik58213792014-10-30 09:05:15 +010041
42#include "plotting/plotting.hpp"
43#include <pthread.h>
piotr437f5462014-02-04 17:57:25 +010044
45#define SYNC_SEARCH_RANGE 30
46
piotrd0bf1492014-02-05 17:27:32 +010047namespace gr
48{
49namespace gsm
50{
piotr437f5462014-02-04 17:57:25 +010051
piotrd0bf1492014-02-05 17:27:32 +010052typedef std::list<float> list_float;
53typedef std::vector<float> vector_float;
piotr437f5462014-02-04 17:57:25 +010054
piotrd0bf1492014-02-05 17:27:32 +010055typedef boost::circular_buffer<float> circular_buffer_float;
piotr437f5462014-02-04 17:57:25 +010056
piotrd0bf1492014-02-05 17:27:32 +010057receiver::sptr
ptrkrysike518bbf2014-11-06 14:50:59 +010058receiver::make(int osr, const std::vector<float> &cell_allocation, const std::vector<int> &tseq_nums)
piotrd0bf1492014-02-05 17:27:32 +010059{
60 return gnuradio::get_initial_sptr
ptrkrysike518bbf2014-11-06 14:50:59 +010061 (new receiver_impl(osr, cell_allocation, tseq_nums));
piotrd0bf1492014-02-05 17:27:32 +010062}
63
64/*
65 * The private constructor
66 */
ptrkrysike518bbf2014-11-06 14:50:59 +010067receiver_impl::receiver_impl(int osr, const std::vector<float> &cell_allocation, const std::vector<int> &tseq_nums)
piotrc7c249a2014-05-02 17:24:08 +020068 : gr::sync_block("receiver",
ptrkrysik58213792014-10-30 09:05:15 +010069 gr::io_signature::make(1, -1, sizeof(gr_complex)),
piotr7c82b172014-02-08 14:15:27 +010070 gr::io_signature::make(0, 0, 0)),
piotrd0bf1492014-02-05 17:27:32 +010071 d_OSR(osr),
72 d_chan_imp_length(CHAN_IMP_RESP_LENGTH),
piotrd0bf1492014-02-05 17:27:32 +010073 d_counter(0),
74 d_fcch_start_pos(0),
piotr4089c1a2014-08-06 14:10:56 +020075 d_freq_offset_setting(0),
piotrd6d66872014-08-06 15:20:33 +020076 d_state(fcch_search),
piotrd0bf1492014-02-05 17:27:32 +010077 d_burst_nr(osr),
piotr6d152d92014-02-21 00:02:44 +010078 d_failed_sch(0),
ptrkrysike518bbf2014-11-06 14:50:59 +010079 d_signal_dbm(-120),
80 d_tseq_nums(tseq_nums),
81 d_cell_allocation(cell_allocation)
piotrd0bf1492014-02-05 17:27:32 +010082{
83 int i;
piotr4089c1a2014-08-06 14:10:56 +020084 //don't send samples to the receiver until there are at least samples for one
piotr7f3f3662014-07-08 16:47:53 +020085 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 +010086 gmsk_mapper(SYNC_BITS, N_SYNC_BITS, d_sch_training_seq, gr_complex(0.0, -1.0));
87 for (i = 0; i < TRAIN_SEQ_NUM; i++)
piotr437f5462014-02-04 17:57:25 +010088 {
piotrf502e0f2014-04-24 10:28:29 +020089 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 +020090 //if first bit of the seqeunce ==1 first symbol ==-1
piotr437f5462014-02-04 17:57:25 +010091 gmsk_mapper(train_seq[i], N_TRAIN_BITS, d_norm_training_seq[i], startpoint);
piotr437f5462014-02-04 17:57:25 +010092 }
ptrkrysike518bbf2014-11-06 14:50:59 +010093 message_port_register_out(pmt::mp("C0"));
94 message_port_register_out(pmt::mp("CX"));
piotr4089c1a2014-08-06 14:10:56 +020095 message_port_register_out(pmt::mp("measurements"));
piotr903b1d62014-04-17 11:33:27 +020096 configure_receiver(); //configure the receiver - tell it where to find which burst type
piotrd0bf1492014-02-05 17:27:32 +010097}
piotr437f5462014-02-04 17:57:25 +010098
piotrd0bf1492014-02-05 17:27:32 +010099/*
100 * Our virtual destructor.
101 */
102receiver_impl::~receiver_impl()
103{
104}
105
piotrd0bf1492014-02-05 17:27:32 +0100106int
piotrc7c249a2014-05-02 17:24:08 +0200107receiver_impl::work(int noutput_items,
108 gr_vector_const_void_star &input_items,
109 gr_vector_void_star &output_items)
piotrd0bf1492014-02-05 17:27:32 +0100110{
ptrkrysik58213792014-10-30 09:05:15 +0100111// std::vector<const gr_complex *> iii = (std::vector<const gr_complex *>) input_items; // jak zrobić to rzutowanie poprawnie
112 gr_complex * input = (gr_complex *) input_items[0];
piotr4089c1a2014-08-06 14:10:56 +0200113 std::vector<tag_t> freq_offset_tags;
114 uint64_t start = nitems_read(0);
115 uint64_t stop = start + noutput_items;
piotr7c82b172014-02-08 14:15:27 +0100116
piotr4089c1a2014-08-06 14:10:56 +0200117 pmt::pmt_t key = pmt::string_to_symbol("setting_freq_offset");
118 get_tags_in_range(freq_offset_tags, 0, start, stop, key);
119 bool freq_offset_tag_in_fcch = false;
120 uint64_t tag_offset=-1; //-1 - just some clearly invalid value
121
122 if(!freq_offset_tags.empty()){
123 tag_t freq_offset_tag = freq_offset_tags[0];
124 tag_offset = freq_offset_tag.offset - start;
125
126 burst_type b_type = d_channel_conf.get_burst_type(d_burst_nr);
127 if(d_state == synchronized && b_type == fcch_burst){
128 uint64_t last_sample_nr = ceil((GUARD_PERIOD + 2.0 * TAIL_BITS + 156.25) * d_OSR) + 1;
129 if(tag_offset < last_sample_nr){
piotr4089c1a2014-08-06 14:10:56 +0200130 freq_offset_tag_in_fcch = true;
131 }
132 d_freq_offset_setting = pmt::to_double(freq_offset_tag.value);
133 } else {
134 d_freq_offset_setting = pmt::to_double(freq_offset_tag.value);
135 }
136 }
137
piotrd0bf1492014-02-05 17:27:32 +0100138 switch (d_state)
piotr437f5462014-02-04 17:57:25 +0100139 {
piotrd0bf1492014-02-05 17:27:32 +0100140 //bootstrapping
ptrkrysik58213792014-10-30 09:05:15 +0100141 case fcch_search:
piotrd0bf1492014-02-05 17:27:32 +0100142 {
piotr4089c1a2014-08-06 14:10:56 +0200143 double freq_offset_tmp;
144 if (find_fcch_burst(input, noutput_items,freq_offset_tmp))
piotrd0bf1492014-02-05 17:27:32 +0100145 {
piotrd6d66872014-08-06 15:20:33 +0200146 pmt::pmt_t msg = pmt::make_tuple(pmt::mp("freq_offset"),pmt::from_double(freq_offset_tmp-d_freq_offset_setting),pmt::mp("fcch_search"));
piotr4089c1a2014-08-06 14:10:56 +0200147 message_port_pub(pmt::mp("measurements"), msg);
148
piotrd0bf1492014-02-05 17:27:32 +0100149 d_state = sch_search;
150 }
151 else
152 {
piotrd6d66872014-08-06 15:20:33 +0200153 d_state = fcch_search;
piotrd0bf1492014-02-05 17:27:32 +0100154 }
155 break;
156 }
piotr437f5462014-02-04 17:57:25 +0100157
piotrd0bf1492014-02-05 17:27:32 +0100158 case sch_search:
159 {
piotrd0bf1492014-02-05 17:27:32 +0100160 vector_complex channel_imp_resp(CHAN_IMP_RESP_LENGTH*d_OSR);
161 int t1, t2, t3;
162 int burst_start = 0;
163 unsigned char output_binary[BURST_SIZE];
piotr437f5462014-02-04 17:57:25 +0100164
piotrc7c249a2014-05-02 17:24:08 +0200165 if (reach_sch_burst(noutput_items)) //wait for a SCH burst
piotrd0bf1492014-02-05 17:27:32 +0100166 {
167 burst_start = get_sch_chan_imp_resp(input, &channel_imp_resp[0]); //get channel impulse response from it
168 detect_burst(input, &channel_imp_resp[0], burst_start, output_binary); //detect bits using MLSE detection
169 if (decode_sch(&output_binary[3], &t1, &t2, &t3, &d_ncc, &d_bcc) == 0) //decode SCH burst
170 {
piotr437f5462014-02-04 17:57:25 +0100171 d_burst_nr.set(t1, t2, t3, 0); //set counter of bursts value
piotr437f5462014-02-04 17:57:25 +0100172 d_burst_nr++;
173
piotr7f3f3662014-07-08 16:47:53 +0200174 consume_each(burst_start + BURST_SIZE * d_OSR + 4*d_OSR); //consume samples up to next guard period
piotr437f5462014-02-04 17:57:25 +0100175 d_state = synchronized;
piotrd0bf1492014-02-05 17:27:32 +0100176 }
177 else
178 {
piotrd6d66872014-08-06 15:20:33 +0200179 d_state = fcch_search; //if there is error in the sch burst go back to fcch search phase
piotr437f5462014-02-04 17:57:25 +0100180 }
piotrd0bf1492014-02-05 17:27:32 +0100181 }
182 else
183 {
184 d_state = sch_search;
185 }
186 break;
187 }
188 //in this state receiver is synchronized and it processes bursts according to burst type for given burst number
189 case synchronized:
190 {
piotrd0bf1492014-02-05 17:27:32 +0100191 vector_complex channel_imp_resp(CHAN_IMP_RESP_LENGTH*d_OSR);
piotrd0bf1492014-02-05 17:27:32 +0100192 int offset = 0;
193 int to_consume = 0;
194 unsigned char output_binary[BURST_SIZE];
piotr437f5462014-02-04 17:57:25 +0100195
ptrkrysik58213792014-10-30 09:05:15 +0100196 burst_type b_type;
piotr6d152d92014-02-21 00:02:44 +0100197
ptrkrysike518bbf2014-11-06 14:50:59 +0100198 for(int input_nr=0; input_nr<d_cell_allocation.size(); input_nr++)
piotrd0bf1492014-02-05 17:27:32 +0100199 {
ptrkrysik58213792014-10-30 09:05:15 +0100200 double signal_pwr = 0;
201 input = (gr_complex *)input_items[input_nr];
piotr4089c1a2014-08-06 14:10:56 +0200202
ptrkrysik58213792014-10-30 09:05:15 +0100203 for(int ii=GUARD_PERIOD;ii<TS_BITS;ii++)
piotrd0bf1492014-02-05 17:27:32 +0100204 {
ptrkrysik58213792014-10-30 09:05:15 +0100205 signal_pwr += abs(input[ii])*abs(input[ii]);
piotrd0bf1492014-02-05 17:27:32 +0100206 }
ptrkrysik58213792014-10-30 09:05:15 +0100207 signal_pwr = signal_pwr/(TS_BITS);
208 d_signal_dbm = round(10*log10(signal_pwr/50));
209 if(input_nr==0){
210 d_c0_signal_dbm = d_signal_dbm;
211 }
212
213 if(input_nr==0) //for c0 channel burst type is controlled by channel configuration
piotrd0bf1492014-02-05 17:27:32 +0100214 {
ptrkrysik58213792014-10-30 09:05:15 +0100215 b_type = d_channel_conf.get_burst_type(d_burst_nr); //get burst type for given burst number
216 }
217 else
218 {
219 b_type = normal_or_noise; //for the rest it can be only normal burst or noise (at least at this moment of development)
220 }
221
222 switch (b_type)
223 {
224 case fcch_burst: //if it's FCCH burst
225 {
226 const unsigned first_sample = ceil((GUARD_PERIOD + 2 * TAIL_BITS) * d_OSR) + 1;
227 const unsigned last_sample = first_sample + USEFUL_BITS * d_OSR - TAIL_BITS * d_OSR;
228 double freq_offset_tmp = compute_freq_offset(input, first_sample, last_sample); //extract frequency offset from it
229
ptrkrysike518bbf2014-11-06 14:50:59 +0100230 send_burst(d_burst_nr, fc_fb, b_type, input_nr);
ptrkrysik58213792014-10-30 09:05:15 +0100231
232 pmt::pmt_t msg = pmt::make_tuple(pmt::mp("freq_offset"),pmt::from_double(freq_offset_tmp-d_freq_offset_setting),pmt::mp("synchronized"));
233 message_port_pub(pmt::mp("measurements"), msg);
234 break;
235 }
236 case sch_burst: //if it's SCH burst
237 {
238 int t1, t2, t3, d_ncc, d_bcc;
239 d_c0_burst_start = get_sch_chan_imp_resp(input, &channel_imp_resp[0]); //get channel impulse response
240
241 detect_burst(input, &channel_imp_resp[0], d_c0_burst_start, output_binary); //MLSE detection of bits
ptrkrysike518bbf2014-11-06 14:50:59 +0100242 send_burst(d_burst_nr, output_binary, b_type, input_nr);
ptrkrysik58213792014-10-30 09:05:15 +0100243 if (decode_sch(&output_binary[3], &t1, &t2, &t3, &d_ncc, &d_bcc) == 0) //and decode SCH data
piotrd0bf1492014-02-05 17:27:32 +0100244 {
ptrkrysik58213792014-10-30 09:05:15 +0100245 // d_burst_nr.set(t1, t2, t3, 0); //but only to check if burst_start value is correct
246 d_failed_sch = 0;
247 offset = d_c0_burst_start - floor((GUARD_PERIOD) * d_OSR); //compute offset from burst_start - burst should start after a guard period
248 to_consume += offset; //adjust with offset number of samples to be consumed
piotr437f5462014-02-04 17:57:25 +0100249 }
ptrkrysik58213792014-10-30 09:05:15 +0100250 else
251 {
252 d_failed_sch++;
253 if (d_failed_sch >= MAX_SCH_ERRORS)
254 {
255 d_state = fcch_search;
256 pmt::pmt_t msg = pmt::make_tuple(pmt::mp("freq_offset"),pmt::from_double(0.0),pmt::mp("sync_loss"));
257 message_port_pub(pmt::mp("measurements"), msg);
258 DCOUT("Re-Synchronization!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
259 }
260 }
261 break;
piotr437f5462014-02-04 17:57:25 +0100262 }
ptrkrysik58213792014-10-30 09:05:15 +0100263 case normal_burst:
264 {
265 float normal_corr_max; //if it's normal burst
266 d_c0_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
267 detect_burst(input, &channel_imp_resp[0], d_c0_burst_start, output_binary); //MLSE detection of bits
ptrkrysike518bbf2014-11-06 14:50:59 +0100268 send_burst(d_burst_nr, output_binary, b_type, input_nr);
ptrkrysik58213792014-10-30 09:05:15 +0100269 break;
270 }
271 case dummy_or_normal:
272 {
273 unsigned int normal_burst_start, dummy_burst_start;
274 float dummy_corr_max, normal_corr_max;
piotr437f5462014-02-04 17:57:25 +0100275
ptrkrysik58213792014-10-30 09:05:15 +0100276 dummy_burst_start = get_norm_chan_imp_resp(input, &channel_imp_resp[0], &dummy_corr_max, TS_DUMMY);
277 normal_burst_start = get_norm_chan_imp_resp(input, &channel_imp_resp[0], &normal_corr_max, d_bcc);
278
279 if (normal_corr_max > dummy_corr_max)
280 {
281 d_c0_burst_start = normal_burst_start;
282 detect_burst(input, &channel_imp_resp[0], normal_burst_start, output_binary);
ptrkrysike518bbf2014-11-06 14:50:59 +0100283 send_burst(d_burst_nr, output_binary, b_type, input_nr);
ptrkrysik58213792014-10-30 09:05:15 +0100284 }
285 else
286 {
287 d_c0_burst_start = dummy_burst_start;
ptrkrysike518bbf2014-11-06 14:50:59 +0100288 send_burst(d_burst_nr, dummy_burst, b_type, input_nr);
ptrkrysik58213792014-10-30 09:05:15 +0100289 }
290 break;
piotrd0bf1492014-02-05 17:27:32 +0100291 }
ptrkrysik58213792014-10-30 09:05:15 +0100292 case rach_burst:
293 break;
294 case dummy:
ptrkrysike518bbf2014-11-06 14:50:59 +0100295 send_burst(d_burst_nr, dummy_burst, b_type, input_nr);
ptrkrysik58213792014-10-30 09:05:15 +0100296 break;
297 case normal_or_noise:
298 {
299 unsigned int burst_start;
300 float normal_corr_max_tmp;
301 float normal_corr_max=-1e6;
302 int max_tn;
303 std::vector<gr_complex> v(input, input + noutput_items);
304 if(d_signal_dbm>=d_c0_signal_dbm-13)
305 {
ptrkrysike518bbf2014-11-06 14:50:59 +0100306 if(d_tseq_nums.size()==0) //there is no information about training sequence
307 { //however the receiver can detect it
308 get_norm_chan_imp_resp(input, &channel_imp_resp[0], &normal_corr_max, 0);
309 float ts_max=normal_corr_max; //with use of a very simple algorithm based on finding
310 int ts_max_num=0; //maximum correlation
311 for(int ss=1; ss<=7; ss++)
312 {
313 get_norm_chan_imp_resp(input, &channel_imp_resp[0], &normal_corr_max, ss);
314 if(ts_max<normal_corr_max)
315 {
316 ts_max = normal_corr_max;
317 ts_max_num = ss;
318 }
319 }
320 d_tseq_nums.push_back(ts_max_num);
ptrkrysik58213792014-10-30 09:05:15 +0100321 }
ptrkrysike518bbf2014-11-06 14:50:59 +0100322 int tseq_num;
323 if(input_nr<=d_tseq_nums.size()){
324 tseq_num = d_tseq_nums[input_nr-1];
325 } else {
326 tseq_num = d_tseq_nums.back();
327 }
328 burst_start = get_norm_chan_imp_resp(input, &channel_imp_resp[0], &normal_corr_max, tseq_num);
329// if(abs(d_c0_burst_start-burst_start)<=2){ //unused check/filter based on timing
330 if((normal_corr_max/sqrt(signal_pwr))>=0.9){
331 detect_burst(input, &channel_imp_resp[0], burst_start, output_binary);
332 send_burst(d_burst_nr, output_binary, b_type, input_nr);
333 }
ptrkrysik58213792014-10-30 09:05:15 +0100334 }
335 break;
336 }
337 case empty: //if it's empty burst
338 break; //do nothing
339 }
340
341 if(input_nr==0)
342 {
343 d_burst_nr++; //go to next burst
344 to_consume += TS_BITS * d_OSR + d_burst_nr.get_offset(); //consume samples of the burst up to next guard period
345 }
346
347 if(input_nr==input_items.size()-1)
348 {
349 consume_each(to_consume);
350 }
351 //and add offset which is introduced by
352 //0.25 fractional part of a guard period
353 }
piotrd0bf1492014-02-05 17:27:32 +0100354 }
355 break;
piotr437f5462014-02-04 17:57:25 +0100356 }
piotr6d152d92014-02-21 00:02:44 +0100357 return 0;
piotrd0bf1492014-02-05 17:27:32 +0100358}
piotr437f5462014-02-04 17:57:25 +0100359
piotr4089c1a2014-08-06 14:10:56 +0200360bool receiver_impl::find_fcch_burst(const gr_complex *input, const int nitems, double & computed_freq_offset)
piotrd0bf1492014-02-05 17:27:32 +0100361{
362 circular_buffer_float phase_diff_buffer(FCCH_HITS_NEEDED * d_OSR); //circular buffer used to scan throug signal to find
363 //best match for FCCH burst
364 float phase_diff = 0;
365 gr_complex conjprod;
366 int start_pos = -1;
367 int hit_count = 0;
368 int miss_count = 0;
369 float min_phase_diff;
370 float max_phase_diff;
371 double best_sum = 0;
372 float lowest_max_min_diff = 99999;
373
374 int to_consume = 0;
375 int sample_number = 0;
376 bool end = false;
377 bool result = false;
378 circular_buffer_float::iterator buffer_iter;
piotr6d152d92014-02-21 00:02:44 +0100379
piotrd0bf1492014-02-05 17:27:32 +0100380 /**@name Possible states of FCCH search algorithm*/
381 //@{
382 enum states
piotr437f5462014-02-04 17:57:25 +0100383 {
piotr437f5462014-02-04 17:57:25 +0100384 init, ///< initialize variables
385 search, ///< search for positive samples
386 found_something, ///< search for FCCH and the best position of it
387 fcch_found, ///< when FCCH was found
388 search_fail ///< when there is no FCCH in the input vector
piotrd0bf1492014-02-05 17:27:32 +0100389 } fcch_search_state;
390 //@}
piotr437f5462014-02-04 17:57:25 +0100391
piotrd0bf1492014-02-05 17:27:32 +0100392 fcch_search_state = init;
piotr437f5462014-02-04 17:57:25 +0100393
piotrd0bf1492014-02-05 17:27:32 +0100394 while (!end)
395 {
396 switch (fcch_search_state)
397 {
piotr437f5462014-02-04 17:57:25 +0100398
piotrd0bf1492014-02-05 17:27:32 +0100399 case init: //initialize variables
piotr437f5462014-02-04 17:57:25 +0100400 hit_count = 0;
401 miss_count = 0;
402 start_pos = -1;
403 lowest_max_min_diff = 99999;
404 phase_diff_buffer.clear();
405 fcch_search_state = search;
406
407 break;
408
piotr7c82b172014-02-08 14:15:27 +0100409 case search: // search for positive samples
piotr437f5462014-02-04 17:57:25 +0100410 sample_number++;
411
piotrd0bf1492014-02-05 17:27:32 +0100412 if (sample_number > nitems - FCCH_HITS_NEEDED * d_OSR) //if it isn't possible to find FCCH because
413 {
piotr7c82b172014-02-08 14:15:27 +0100414 //there's too few samples left to look into,
piotrd0bf1492014-02-05 17:27:32 +0100415 to_consume = sample_number; //don't do anything with those samples which are left
piotr7c82b172014-02-08 14:15:27 +0100416 //and consume only those which were checked
piotrd0bf1492014-02-05 17:27:32 +0100417 fcch_search_state = search_fail;
418 }
419 else
420 {
421 phase_diff = compute_phase_diff(input[sample_number], input[sample_number-1]);
piotr437f5462014-02-04 17:57:25 +0100422
piotrd0bf1492014-02-05 17:27:32 +0100423 if (phase_diff > 0) //if a positive phase difference was found
424 {
425 to_consume = sample_number;
426 fcch_search_state = found_something; //switch to state in which searches for FCCH
427 }
428 else
429 {
430 fcch_search_state = search;
431 }
piotr437f5462014-02-04 17:57:25 +0100432 }
433
434 break;
435
piotrd0bf1492014-02-05 17:27:32 +0100436 case found_something: // search for FCCH and the best position of it
437 {
438 if (phase_diff > 0)
439 {
piotr437f5462014-02-04 17:57:25 +0100440 hit_count++; //positive phase differencies increases hits_count
piotrd0bf1492014-02-05 17:27:32 +0100441 }
442 else
443 {
piotr437f5462014-02-04 17:57:25 +0100444 miss_count++; //negative increases miss_count
piotrd0bf1492014-02-05 17:27:32 +0100445 }
piotr437f5462014-02-04 17:57:25 +0100446
piotrd0bf1492014-02-05 17:27:32 +0100447 if ((miss_count >= FCCH_MAX_MISSES * d_OSR) && (hit_count <= FCCH_HITS_NEEDED * d_OSR))
448 {
piotr437f5462014-02-04 17:57:25 +0100449 //if miss_count exceeds limit before hit_count
450 fcch_search_state = init; //go to init
451 continue;
piotrd0bf1492014-02-05 17:27:32 +0100452 }
453 else if (((miss_count >= FCCH_MAX_MISSES * d_OSR) && (hit_count > FCCH_HITS_NEEDED * d_OSR)) || (hit_count > 2 * FCCH_HITS_NEEDED * d_OSR))
454 {
piotr437f5462014-02-04 17:57:25 +0100455 //if hit_count and miss_count exceeds limit then FCCH was found
456 fcch_search_state = fcch_found;
457 continue;
piotrd0bf1492014-02-05 17:27:32 +0100458 }
459 else if ((miss_count < FCCH_MAX_MISSES * d_OSR) && (hit_count > FCCH_HITS_NEEDED * d_OSR))
460 {
piotr437f5462014-02-04 17:57:25 +0100461 //find difference between minimal and maximal element in the buffer
462 //for FCCH this value should be low
463 //this part is searching for a region where this value is lowest
464 min_phase_diff = * (min_element(phase_diff_buffer.begin(), phase_diff_buffer.end()));
465 max_phase_diff = * (max_element(phase_diff_buffer.begin(), phase_diff_buffer.end()));
466
piotrd0bf1492014-02-05 17:27:32 +0100467 if (lowest_max_min_diff > max_phase_diff - min_phase_diff)
468 {
469 lowest_max_min_diff = max_phase_diff - min_phase_diff;
470 start_pos = sample_number - FCCH_HITS_NEEDED * d_OSR - FCCH_MAX_MISSES * d_OSR; //store start pos
471 best_sum = 0;
piotr437f5462014-02-04 17:57:25 +0100472
piotrd0bf1492014-02-05 17:27:32 +0100473 for (buffer_iter = phase_diff_buffer.begin();
474 buffer_iter != (phase_diff_buffer.end());
475 buffer_iter++)
476 {
477 best_sum += *buffer_iter - (M_PI / 2) / d_OSR; //store best value of phase offset sum
478 }
piotr437f5462014-02-04 17:57:25 +0100479 }
piotrd0bf1492014-02-05 17:27:32 +0100480 }
piotr437f5462014-02-04 17:57:25 +0100481
piotrd0bf1492014-02-05 17:27:32 +0100482 sample_number++;
piotr437f5462014-02-04 17:57:25 +0100483
piotrd0bf1492014-02-05 17:27:32 +0100484 if (sample_number >= nitems) //if there's no single sample left to check
485 {
piotr437f5462014-02-04 17:57:25 +0100486 fcch_search_state = search_fail;//FCCH search failed
487 continue;
piotr437f5462014-02-04 17:57:25 +0100488 }
piotrd0bf1492014-02-05 17:27:32 +0100489
490 phase_diff = compute_phase_diff(input[sample_number], input[sample_number-1]);
491 phase_diff_buffer.push_back(phase_diff);
492 fcch_search_state = found_something;
493 }
494 break;
495
496 case fcch_found:
497 {
piotrd0bf1492014-02-05 17:27:32 +0100498 to_consume = start_pos + FCCH_HITS_NEEDED * d_OSR + 1; //consume one FCCH burst
499
500 d_fcch_start_pos = d_counter + start_pos;
501
502 //compute frequency offset
503 double phase_offset = best_sum / FCCH_HITS_NEEDED;
piotr4089c1a2014-08-06 14:10:56 +0200504 double freq_offset = phase_offset * 1625000.0/6 / (2 * M_PI); //1625000.0/6 - GMSK symbol rate in GSM
505 computed_freq_offset = freq_offset;
piotrd0bf1492014-02-05 17:27:32 +0100506
507 end = true;
508 result = true;
piotr437f5462014-02-04 17:57:25 +0100509 break;
piotrd0bf1492014-02-05 17:27:32 +0100510 }
piotr437f5462014-02-04 17:57:25 +0100511
piotrd0bf1492014-02-05 17:27:32 +0100512 case search_fail:
piotr437f5462014-02-04 17:57:25 +0100513 end = true;
514 result = false;
515 break;
516 }
piotr437f5462014-02-04 17:57:25 +0100517 }
518
piotrd0bf1492014-02-05 17:27:32 +0100519 d_counter += to_consume;
520 consume_each(to_consume);
piotr437f5462014-02-04 17:57:25 +0100521
piotrd0bf1492014-02-05 17:27:32 +0100522 return result;
523}
524
piotrd0bf1492014-02-05 17:27:32 +0100525double receiver_impl::compute_freq_offset(const gr_complex * input, unsigned first_sample, unsigned last_sample)
526{
527 double phase_sum = 0;
528 unsigned ii;
529
530 for (ii = first_sample; ii < last_sample; ii++)
piotr437f5462014-02-04 17:57:25 +0100531 {
piotr437f5462014-02-04 17:57:25 +0100532 double phase_diff = compute_phase_diff(input[ii], input[ii-1]) - (M_PI / 2) / d_OSR;
533 phase_sum += phase_diff;
piotr437f5462014-02-04 17:57:25 +0100534 }
535
piotrd0bf1492014-02-05 17:27:32 +0100536 double phase_offset = phase_sum / (last_sample - first_sample);
537 double freq_offset = phase_offset * 1625000.0 / (12.0 * M_PI);
538 return freq_offset;
539}
piotr437f5462014-02-04 17:57:25 +0100540
piotrd0bf1492014-02-05 17:27:32 +0100541inline float receiver_impl::compute_phase_diff(gr_complex val1, gr_complex val2)
542{
543 gr_complex conjprod = val1 * conj(val2);
544 return fast_atan2f(imag(conjprod), real(conjprod));
545}
piotr437f5462014-02-04 17:57:25 +0100546
piotrd0bf1492014-02-05 17:27:32 +0100547bool receiver_impl::reach_sch_burst(const int nitems)
548{
549 //it just consumes samples to get near to a SCH burst
550 int to_consume = 0;
551 bool result = false;
552 unsigned sample_nr_near_sch_start = d_fcch_start_pos + (FRAME_BITS - SAFETY_MARGIN) * d_OSR;
553
554 //consume samples until d_counter will be equal to sample_nr_near_sch_start
555 if (d_counter < sample_nr_near_sch_start)
556 {
557 if (d_counter + nitems >= sample_nr_near_sch_start)
558 {
559 to_consume = sample_nr_near_sch_start - d_counter;
560 }
561 else
562 {
563 to_consume = nitems;
piotr437f5462014-02-04 17:57:25 +0100564 }
565 result = false;
piotrd0bf1492014-02-05 17:27:32 +0100566 }
567 else
568 {
piotr437f5462014-02-04 17:57:25 +0100569 to_consume = 0;
570 result = true;
piotr437f5462014-02-04 17:57:25 +0100571 }
572
piotrd0bf1492014-02-05 17:27:32 +0100573 d_counter += to_consume;
574 consume_each(to_consume);
575 return result;
576}
577
578int receiver_impl::get_sch_chan_imp_resp(const gr_complex *input, gr_complex * chan_imp_resp)
579{
580 vector_complex correlation_buffer;
581 vector_float power_buffer;
582 vector_float window_energy_buffer;
583
584 int strongest_window_nr;
585 int burst_start = 0;
586 int chan_imp_resp_center = 0;
587 float max_correlation = 0;
588 float energy = 0;
589
590 for (int ii = SYNC_POS * d_OSR; ii < (SYNC_POS + SYNC_SEARCH_RANGE) *d_OSR; ii++)
piotr437f5462014-02-04 17:57:25 +0100591 {
piotr437f5462014-02-04 17:57:25 +0100592 gr_complex correlation = correlate_sequence(&d_sch_training_seq[5], N_SYNC_BITS - 10, &input[ii]);
593 correlation_buffer.push_back(correlation);
594 power_buffer.push_back(std::pow(abs(correlation), 2));
piotrd0bf1492014-02-05 17:27:32 +0100595 }
piotrd0bf1492014-02-05 17:27:32 +0100596 //compute window energies
597 vector_float::iterator iter = power_buffer.begin();
598 bool loop_end = false;
599 while (iter != power_buffer.end())
600 {
piotr437f5462014-02-04 17:57:25 +0100601 vector_float::iterator iter_ii = iter;
602 energy = 0;
603
piotrd0bf1492014-02-05 17:27:32 +0100604 for (int ii = 0; ii < (d_chan_imp_length) *d_OSR; ii++, iter_ii++)
605 {
606 if (iter_ii == power_buffer.end())
607 {
608 loop_end = true;
609 break;
610 }
611 energy += (*iter_ii);
piotr437f5462014-02-04 17:57:25 +0100612 }
piotrd0bf1492014-02-05 17:27:32 +0100613 if (loop_end)
614 {
615 break;
piotr437f5462014-02-04 17:57:25 +0100616 }
617 iter++;
618 window_energy_buffer.push_back(energy);
piotrd0bf1492014-02-05 17:27:32 +0100619 }
piotr437f5462014-02-04 17:57:25 +0100620
piotrd0bf1492014-02-05 17:27:32 +0100621 strongest_window_nr = max_element(window_energy_buffer.begin(), window_energy_buffer.end()) - window_energy_buffer.begin();
piotr437f5462014-02-04 17:57:25 +0100622 // d_channel_imp_resp.clear();
623
piotrd0bf1492014-02-05 17:27:32 +0100624 max_correlation = 0;
625 for (int ii = 0; ii < (d_chan_imp_length) *d_OSR; ii++)
626 {
piotr437f5462014-02-04 17:57:25 +0100627 gr_complex correlation = correlation_buffer[strongest_window_nr + ii];
piotrd0bf1492014-02-05 17:27:32 +0100628 if (abs(correlation) > max_correlation)
629 {
630 chan_imp_resp_center = ii;
631 max_correlation = abs(correlation);
piotr437f5462014-02-04 17:57:25 +0100632 }
piotrd0bf1492014-02-05 17:27:32 +0100633 // d_channel_imp_resp.push_back(correlation);
piotr437f5462014-02-04 17:57:25 +0100634 chan_imp_resp[ii] = correlation;
piotr437f5462014-02-04 17:57:25 +0100635 }
636
piotrd0bf1492014-02-05 17:27:32 +0100637 burst_start = strongest_window_nr + chan_imp_resp_center - 48 * d_OSR - 2 * d_OSR + 2 + SYNC_POS * d_OSR;
638 return burst_start;
639}
piotr437f5462014-02-04 17:57:25 +0100640
641
piotrd0bf1492014-02-05 17:27:32 +0100642void receiver_impl::detect_burst(const gr_complex * input, gr_complex * chan_imp_resp, int burst_start, unsigned char * output_binary)
643{
644 float output[BURST_SIZE];
645 gr_complex rhh_temp[CHAN_IMP_RESP_LENGTH*d_OSR];
646 gr_complex rhh[CHAN_IMP_RESP_LENGTH];
647 gr_complex filtered_burst[BURST_SIZE];
648 int start_state = 3;
649 unsigned int stop_states[2] = {4, 12};
650
651 autocorrelation(chan_imp_resp, rhh_temp, d_chan_imp_length*d_OSR);
652 for (int ii = 0; ii < (d_chan_imp_length); ii++)
piotr437f5462014-02-04 17:57:25 +0100653 {
piotr437f5462014-02-04 17:57:25 +0100654 rhh[ii] = conj(rhh_temp[ii*d_OSR]);
piotr437f5462014-02-04 17:57:25 +0100655 }
656
piotrd0bf1492014-02-05 17:27:32 +0100657 mafi(&input[burst_start], BURST_SIZE, chan_imp_resp, d_chan_imp_length*d_OSR, filtered_burst);
658
659 viterbi_detector(filtered_burst, BURST_SIZE, rhh, start_state, stop_states, 2, output);
660
661 for (int i = 0; i < BURST_SIZE ; i++)
piotr437f5462014-02-04 17:57:25 +0100662 {
piotrd0bf1492014-02-05 17:27:32 +0100663 output_binary[i] = (output[i] > 0);
664 }
665}
piotr437f5462014-02-04 17:57:25 +0100666
piotrd0bf1492014-02-05 17:27:32 +0100667void receiver_impl::gmsk_mapper(const unsigned char * input, int nitems, gr_complex * gmsk_output, gr_complex start_point)
668{
669 gr_complex j = gr_complex(0.0, 1.0);
piotr437f5462014-02-04 17:57:25 +0100670
piotrd0bf1492014-02-05 17:27:32 +0100671 int current_symbol;
672 int encoded_symbol;
673 int previous_symbol = 2 * input[0] - 1;
674 gmsk_output[0] = start_point;
675
676 for (int i = 1; i < nitems; i++)
677 {
piotr437f5462014-02-04 17:57:25 +0100678 //change bits representation to NRZ
679 current_symbol = 2 * input[i] - 1;
680 //differentially encode
681 encoded_symbol = current_symbol * previous_symbol;
682 //and do gmsk mapping
683 gmsk_output[i] = j * gr_complex(encoded_symbol, 0.0) * gmsk_output[i-1];
684 previous_symbol = current_symbol;
piotr437f5462014-02-04 17:57:25 +0100685 }
piotrd0bf1492014-02-05 17:27:32 +0100686}
piotr437f5462014-02-04 17:57:25 +0100687
piotrd0bf1492014-02-05 17:27:32 +0100688gr_complex receiver_impl::correlate_sequence(const gr_complex * sequence, int length, const gr_complex * input)
689{
690 gr_complex result(0.0, 0.0);
691 int sample_number = 0;
692
693 for (int ii = 0; ii < length; ii++)
piotr437f5462014-02-04 17:57:25 +0100694 {
piotr437f5462014-02-04 17:57:25 +0100695 sample_number = (ii * d_OSR) ;
696 result += sequence[ii] * conj(input[sample_number]);
piotr437f5462014-02-04 17:57:25 +0100697 }
698
piotrd0bf1492014-02-05 17:27:32 +0100699 result = result / gr_complex(length, 0);
700 return result;
701}
702
703//computes autocorrelation for positive arguments
piotrd0bf1492014-02-05 17:27:32 +0100704inline void receiver_impl::autocorrelation(const gr_complex * input, gr_complex * out, int nitems)
705{
706 int i, k;
707 for (k = nitems - 1; k >= 0; k--)
piotr437f5462014-02-04 17:57:25 +0100708 {
piotr437f5462014-02-04 17:57:25 +0100709 out[k] = gr_complex(0, 0);
piotrd0bf1492014-02-05 17:27:32 +0100710 for (i = k; i < nitems; i++)
711 {
712 out[k] += input[i] * conj(input[i-k]);
piotr437f5462014-02-04 17:57:25 +0100713 }
piotr437f5462014-02-04 17:57:25 +0100714 }
piotrd0bf1492014-02-05 17:27:32 +0100715}
piotr437f5462014-02-04 17:57:25 +0100716
piotrd0bf1492014-02-05 17:27:32 +0100717inline void receiver_impl::mafi(const gr_complex * input, int nitems, gr_complex * filter, int filter_length, gr_complex * output)
718{
719 int ii = 0, n, a;
720
721 for (n = 0; n < nitems; n++)
piotr437f5462014-02-04 17:57:25 +0100722 {
piotr437f5462014-02-04 17:57:25 +0100723 a = n * d_OSR;
724 output[n] = 0;
725 ii = 0;
726
piotrd0bf1492014-02-05 17:27:32 +0100727 while (ii < filter_length)
728 {
piotrda8a0662014-04-24 10:29:38 +0200729 if ((a + ii) >= nitems*d_OSR){
piotrd0bf1492014-02-05 17:27:32 +0100730 break;
piotrda8a0662014-04-24 10:29:38 +0200731 }
piotrd0bf1492014-02-05 17:27:32 +0100732 output[n] += input[a+ii] * filter[ii];
733 ii++;
piotr437f5462014-02-04 17:57:25 +0100734 }
piotr437f5462014-02-04 17:57:25 +0100735 }
piotrd0bf1492014-02-05 17:27:32 +0100736}
piotr437f5462014-02-04 17:57:25 +0100737
piotrd0bf1492014-02-05 17:27:32 +0100738//especially computations of strongest_window_nr
piotr7e3b0db2014-02-05 22:44:30 +0100739int 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 +0100740{
741 vector_complex correlation_buffer;
742 vector_float power_buffer;
743 vector_float window_energy_buffer;
piotr437f5462014-02-04 17:57:25 +0100744
piotrd0bf1492014-02-05 17:27:32 +0100745 int strongest_window_nr;
746 int burst_start = 0;
747 int chan_imp_resp_center = 0;
748 float max_correlation = 0;
749 float energy = 0;
piotr5c820252014-04-17 09:43:02 +0200750
piotrd0bf1492014-02-05 17:27:32 +0100751 int search_center = (int)((TRAIN_POS + GUARD_PERIOD) * d_OSR);
piotr7c82b172014-02-08 14:15:27 +0100752 int search_start_pos = search_center + 1 - 5*d_OSR;
piotr437f5462014-02-04 17:57:25 +0100753 // int search_start_pos = search_center - d_chan_imp_length * d_OSR;
piotr5c820252014-04-17 09:43:02 +0200754 int search_stop_pos = search_center + d_chan_imp_length * d_OSR + 5 * d_OSR;
piotr437f5462014-02-04 17:57:25 +0100755
ptrkrysik58213792014-10-30 09:05:15 +0100756 for(int ii = search_start_pos; ii < search_stop_pos; ii++)
piotrd0bf1492014-02-05 17:27:32 +0100757 {
piotr437f5462014-02-04 17:57:25 +0100758 gr_complex correlation = correlate_sequence(&d_norm_training_seq[bcc][TRAIN_BEGINNING], N_TRAIN_BITS - 10, &input[ii]);
piotr437f5462014-02-04 17:57:25 +0100759 correlation_buffer.push_back(correlation);
760 power_buffer.push_back(std::pow(abs(correlation), 2));
piotrd0bf1492014-02-05 17:27:32 +0100761 }
ptrkrysike518bbf2014-11-06 14:50:59 +0100762// plot(power_buffer);
piotrd0bf1492014-02-05 17:27:32 +0100763 //compute window energies
764 vector_float::iterator iter = power_buffer.begin();
765 bool loop_end = false;
766 while (iter != power_buffer.end())
767 {
piotr437f5462014-02-04 17:57:25 +0100768 vector_float::iterator iter_ii = iter;
769 energy = 0;
770
piotrd0bf1492014-02-05 17:27:32 +0100771 for (int ii = 0; ii < (d_chan_imp_length - 2)*d_OSR; ii++, iter_ii++)
772 {
piotrd0bf1492014-02-05 17:27:32 +0100773 if (iter_ii == power_buffer.end())
774 {
775 loop_end = true;
776 break;
777 }
778 energy += (*iter_ii);
piotr437f5462014-02-04 17:57:25 +0100779 }
piotrd0bf1492014-02-05 17:27:32 +0100780 if (loop_end)
781 {
782 break;
piotr437f5462014-02-04 17:57:25 +0100783 }
784 iter++;
785
786 window_energy_buffer.push_back(energy);
piotrd0bf1492014-02-05 17:27:32 +0100787 }
piotr437f5462014-02-04 17:57:25 +0100788
piotr5c820252014-04-17 09:43:02 +0200789 strongest_window_nr = max_element(window_energy_buffer.begin(), window_energy_buffer.end()-((d_chan_imp_length)*d_OSR)) - window_energy_buffer.begin();
790 //strongest_window_nr = strongest_window_nr-d_OSR;
791 if(strongest_window_nr<0){
792 strongest_window_nr = 0;
793 }
piotr6d152d92014-02-21 00:02:44 +0100794
piotrd0bf1492014-02-05 17:27:32 +0100795 max_correlation = 0;
796 for (int ii = 0; ii < (d_chan_imp_length)*d_OSR; ii++)
797 {
piotr437f5462014-02-04 17:57:25 +0100798 gr_complex correlation = correlation_buffer[strongest_window_nr + ii];
piotrd0bf1492014-02-05 17:27:32 +0100799 if (abs(correlation) > max_correlation)
800 {
801 chan_imp_resp_center = ii;
802 max_correlation = abs(correlation);
piotr437f5462014-02-04 17:57:25 +0100803 }
piotrd0bf1492014-02-05 17:27:32 +0100804 // d_channel_imp_resp.push_back(correlation);
piotr437f5462014-02-04 17:57:25 +0100805 chan_imp_resp[ii] = correlation;
piotr437f5462014-02-04 17:57:25 +0100806 }
ptrkrysike518bbf2014-11-06 14:50:59 +0100807
piotr7e3b0db2014-02-05 22:44:30 +0100808 *corr_max = max_correlation;
piotrd0bf1492014-02-05 17:27:32 +0100809
ptrkrysik58213792014-10-30 09:05:15 +0100810 //DCOUT("strongest_window_nr_new: " << strongest_window_nr);
piotrc7c249a2014-05-02 17:24:08 +0200811 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
piotr7c82b172014-02-08 14:15:27 +0100812
ptrkrysik58213792014-10-30 09:05:15 +0100813 //DCOUT("burst_start: " << burst_start);
piotrd0bf1492014-02-05 17:27:32 +0100814 return burst_start;
815}
piotr437f5462014-02-04 17:57:25 +0100816
817
ptrkrysike518bbf2014-11-06 14:50:59 +0100818void receiver_impl::send_burst(burst_counter burst_nr, const unsigned char * burst_binary, burst_type b_type, unsigned int input_nr)
piotrd0bf1492014-02-05 17:27:32 +0100819{
piotr6d152d92014-02-21 00:02:44 +0100820 boost::scoped_ptr<gsmtap_hdr> tap_header(new gsmtap_hdr());
821
822 tap_header->version = GSMTAP_VERSION;
ptrkrysik7f61c642014-10-30 08:57:27 +0100823 tap_header->hdr_len = sizeof(gsmtap_hdr)/4;
piotr6d152d92014-02-21 00:02:44 +0100824 tap_header->type = GSMTAP_TYPE_UM_BURST;
825 tap_header->timeslot = static_cast<uint8_t>(d_burst_nr.get_timeslot_nr());
826 tap_header->frame_number = d_burst_nr.get_frame_nr();
827 tap_header->sub_type = static_cast<uint8_t>(b_type);
ptrkrysike518bbf2014-11-06 14:50:59 +0100828 tap_header->arfcn = d_cell_allocation[input_nr];
piotr6d152d92014-02-21 00:02:44 +0100829 tap_header->signal_dbm = static_cast<int8_t>(d_signal_dbm);
830 pmt::pmt_t header_blob=pmt::make_blob(tap_header.get(),sizeof(gsmtap_hdr));
831 pmt::pmt_t burst_binary_blob=pmt::make_blob(burst_binary,BURST_SIZE);
832 pmt::pmt_t msg = pmt::cons(header_blob, burst_binary_blob);
piotrf2b6a1b2014-08-04 11:28:59 +0200833
ptrkrysike518bbf2014-11-06 14:50:59 +0100834 if(input_nr==0){
835 message_port_pub(pmt::mp("C0"), msg);
836 } else {
837 message_port_pub(pmt::mp("CX"), msg);
838 }
piotrd0bf1492014-02-05 17:27:32 +0100839}
piotr6d152d92014-02-21 00:02:44 +0100840
piotrd0bf1492014-02-05 17:27:32 +0100841void receiver_impl::configure_receiver()
842{
piotrce92f982014-04-17 23:37:18 +0200843 d_channel_conf.set_multiframe_type(TIMESLOT0, multiframe_51);
piotrd0bf1492014-02-05 17:27:32 +0100844 d_channel_conf.set_burst_types(TIMESLOT0, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
piotr437f5462014-02-04 17:57:25 +0100845
piotrce92f982014-04-17 23:37:18 +0200846 d_channel_conf.set_burst_types(TIMESLOT0, TEST_CCH_FRAMES, sizeof(TEST_CCH_FRAMES) / sizeof(unsigned), dummy_or_normal);
847 d_channel_conf.set_burst_types(TIMESLOT0, FCCH_FRAMES, sizeof(FCCH_FRAMES) / sizeof(unsigned), fcch_burst);
848 d_channel_conf.set_burst_types(TIMESLOT0, SCH_FRAMES, sizeof(SCH_FRAMES) / sizeof(unsigned), sch_burst);
piotr437f5462014-02-04 17:57:25 +0100849
piotrd0bf1492014-02-05 17:27:32 +0100850 d_channel_conf.set_multiframe_type(TIMESLOT1, multiframe_51);
851 d_channel_conf.set_burst_types(TIMESLOT1, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
852 d_channel_conf.set_multiframe_type(TIMESLOT2, multiframe_51);
853 d_channel_conf.set_burst_types(TIMESLOT2, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
854 d_channel_conf.set_multiframe_type(TIMESLOT3, multiframe_51);
855 d_channel_conf.set_burst_types(TIMESLOT3, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
856 d_channel_conf.set_multiframe_type(TIMESLOT4, multiframe_51);
857 d_channel_conf.set_burst_types(TIMESLOT4, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
858 d_channel_conf.set_multiframe_type(TIMESLOT5, multiframe_51);
859 d_channel_conf.set_burst_types(TIMESLOT5, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
860 d_channel_conf.set_multiframe_type(TIMESLOT6, multiframe_51);
861 d_channel_conf.set_burst_types(TIMESLOT6, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
862 d_channel_conf.set_multiframe_type(TIMESLOT7, multiframe_51);
863 d_channel_conf.set_burst_types(TIMESLOT7, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal);
piotrd0bf1492014-02-05 17:27:32 +0100864}
piotr437f5462014-02-04 17:57:25 +0100865
ptrkrysike518bbf2014-11-06 14:50:59 +0100866void receiver_impl::set_cell_allocation(const std::vector<float> &cell_allocation)
piotrf2b6a1b2014-08-04 11:28:59 +0200867{
ptrkrysike518bbf2014-11-06 14:50:59 +0100868 d_cell_allocation = cell_allocation;
869}
870
871void receiver_impl::set_tseq_nums(const std::vector<int> & tseq_nums)
872{
873 d_tseq_nums = tseq_nums;
piotrf2b6a1b2014-08-04 11:28:59 +0200874}
875
876void receiver_impl::reset()
877{
piotrd6d66872014-08-06 15:20:33 +0200878 d_state = fcch_search;
piotrf2b6a1b2014-08-04 11:28:59 +0200879}
piotr437f5462014-02-04 17:57:25 +0100880
piotrd0bf1492014-02-05 17:27:32 +0100881} /* namespace gsm */
piotr437f5462014-02-04 17:57:25 +0100882} /* namespace gr */
883