piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 1 | /* -*- c++ -*- */ |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 2 | /* |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 3 | * @file |
| 4 | * @author Piotr Krysik <ptrkrysik@gmail.com> |
| 5 | * @section LICENSE |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 6 | * |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 7 | * Gr-gsm is free software; you can redistribute it and/or modify |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 8 | * 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. |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 11 | * |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 12 | * Gr-gsm is distributed in the hope that it will be useful, |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 13 | * 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. |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 16 | * |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU General Public License |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 18 | * along with gr-gsm; see the file COPYING. If not, write to |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 19 | * the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | * Boston, MA 02110-1301, USA. |
| 21 | */ |
| 22 | |
| 23 | #ifdef HAVE_CONFIG_H |
| 24 | #include "config.h" |
| 25 | #endif |
| 26 | |
| 27 | #include <gnuradio/io_signature.h> |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 28 | #include <gnuradio/math.h> |
| 29 | #include <math.h> |
| 30 | #include <boost/circular_buffer.hpp> |
| 31 | #include <algorithm> |
| 32 | #include <numeric> |
David Holm | f2497bd | 2014-12-01 21:22:37 +0100 | [diff] [blame] | 33 | #include <vector> |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 34 | #include <viterbi_detector.h> |
| 35 | #include <string.h> |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 36 | #include <iostream> |
Piotr Krysik | 0a932e6 | 2016-08-29 07:37:30 +0200 | [diff] [blame] | 37 | //#include <iomanip> |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 38 | #include <boost/scoped_ptr.hpp> |
ptrkrysik | 3be74a7 | 2014-12-13 10:11:00 +0100 | [diff] [blame] | 39 | |
| 40 | #include <sch.h> |
| 41 | #include "receiver_impl.h" |
| 42 | #include <grgsm/endian.h> |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 43 | |
ptrkrysik | d85d460 | 2014-11-13 10:11:53 +0100 | [diff] [blame] | 44 | //files included for debuging |
| 45 | //#include "plotting/plotting.hpp" |
| 46 | //#include <pthread.h> |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 47 | |
| 48 | #define SYNC_SEARCH_RANGE 30 |
| 49 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 50 | namespace gr |
| 51 | { |
| 52 | namespace gsm |
| 53 | { |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 54 | receiver::sptr |
ptrkrysik | 380dea8 | 2015-08-06 10:11:58 +0200 | [diff] [blame] | 55 | receiver::make(int osr, const std::vector<int> &cell_allocation, const std::vector<int> &tseq_nums, bool process_uplink) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 56 | { |
| 57 | return gnuradio::get_initial_sptr |
ptrkrysik | 380dea8 | 2015-08-06 10:11:58 +0200 | [diff] [blame] | 58 | (new receiver_impl(osr, cell_allocation, tseq_nums, process_uplink)); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /* |
| 62 | * The private constructor |
| 63 | */ |
ptrkrysik | 380dea8 | 2015-08-06 10:11:58 +0200 | [diff] [blame] | 64 | receiver_impl::receiver_impl(int osr, const std::vector<int> &cell_allocation, const std::vector<int> &tseq_nums, bool process_uplink) |
piotr | c7c249a | 2014-05-02 17:24:08 +0200 | [diff] [blame] | 65 | : gr::sync_block("receiver", |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 66 | gr::io_signature::make(1, -1, sizeof(gr_complex)), |
piotr | 7c82b17 | 2014-02-08 14:15:27 +0100 | [diff] [blame] | 67 | gr::io_signature::make(0, 0, 0)), |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 68 | d_OSR(osr), |
ptrkrysik | 380dea8 | 2015-08-06 10:11:58 +0200 | [diff] [blame] | 69 | d_process_uplink(process_uplink), |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 70 | d_chan_imp_length(CHAN_IMP_RESP_LENGTH), |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 71 | d_counter(0), |
| 72 | d_fcch_start_pos(0), |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 73 | d_freq_offset_setting(0), |
piotr | d6d6687 | 2014-08-06 15:20:33 +0200 | [diff] [blame] | 74 | d_state(fcch_search), |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 75 | d_burst_nr(osr), |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 76 | d_failed_sch(0), |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 77 | d_signal_dbm(-120), |
| 78 | d_tseq_nums(tseq_nums), |
ptrkrysik | 32c2116 | 2015-04-04 14:01:52 +0200 | [diff] [blame] | 79 | d_cell_allocation(cell_allocation), |
| 80 | d_last_time(0.0) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 81 | { |
| 82 | int i; |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 83 | //don't send samples to the receiver until there are at least samples for one |
piotr | 7f3f366 | 2014-07-08 16:47:53 +0200 | [diff] [blame] | 84 | set_output_multiple(floor((TS_BITS + 2 * GUARD_PERIOD) * d_OSR)); // burst and two gurad periods (one gurard period is an arbitrary overlap) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 85 | gmsk_mapper(SYNC_BITS, N_SYNC_BITS, d_sch_training_seq, gr_complex(0.0, -1.0)); |
| 86 | for (i = 0; i < TRAIN_SEQ_NUM; i++) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 87 | { |
piotr | f502e0f | 2014-04-24 10:28:29 +0200 | [diff] [blame] | 88 | 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 |
piotr | 7f3f366 | 2014-07-08 16:47:53 +0200 | [diff] [blame] | 89 | //if first bit of the seqeunce ==1 first symbol ==-1 |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 90 | gmsk_mapper(train_seq[i], N_TRAIN_BITS, d_norm_training_seq[i], startpoint); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 91 | } |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 92 | message_port_register_out(pmt::mp("C0")); |
| 93 | message_port_register_out(pmt::mp("CX")); |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 94 | message_port_register_out(pmt::mp("measurements")); |
piotr | 903b1d6 | 2014-04-17 11:33:27 +0200 | [diff] [blame] | 95 | configure_receiver(); //configure the receiver - tell it where to find which burst type |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 96 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 97 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 98 | /* |
| 99 | * Our virtual destructor. |
| 100 | */ |
| 101 | receiver_impl::~receiver_impl() |
| 102 | { |
| 103 | } |
| 104 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 105 | int |
piotr | c7c249a | 2014-05-02 17:24:08 +0200 | [diff] [blame] | 106 | receiver_impl::work(int noutput_items, |
| 107 | gr_vector_const_void_star &input_items, |
| 108 | gr_vector_void_star &output_items) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 109 | { |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 110 | // std::vector<const gr_complex *> iii = (std::vector<const gr_complex *>) input_items; // jak zrobić to rzutowanie poprawnie |
| 111 | gr_complex * input = (gr_complex *) input_items[0]; |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 112 | std::vector<tag_t> freq_offset_tags; |
| 113 | uint64_t start = nitems_read(0); |
| 114 | uint64_t stop = start + noutput_items; |
piotr | 7c82b17 | 2014-02-08 14:15:27 +0100 | [diff] [blame] | 115 | |
ptrkrysik | 32c2116 | 2015-04-04 14:01:52 +0200 | [diff] [blame] | 116 | float current_time = static_cast<float>(start)/(GSM_SYMBOL_RATE*d_OSR); |
| 117 | if((current_time - d_last_time) > 0.1) |
| 118 | { |
| 119 | pmt::pmt_t msg = pmt::make_tuple(pmt::mp("current_time"),pmt::from_double(current_time)); |
| 120 | message_port_pub(pmt::mp("measurements"), msg); |
| 121 | d_last_time = current_time; |
| 122 | } |
| 123 | |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 124 | pmt::pmt_t key = pmt::string_to_symbol("setting_freq_offset"); |
| 125 | get_tags_in_range(freq_offset_tags, 0, start, stop, key); |
| 126 | bool freq_offset_tag_in_fcch = false; |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 127 | |
| 128 | if(!freq_offset_tags.empty()){ |
| 129 | tag_t freq_offset_tag = freq_offset_tags[0]; |
Piotr Krysik | 43af70d | 2016-07-20 21:37:24 +0200 | [diff] [blame] | 130 | uint64_t tag_offset = freq_offset_tag.offset - start; |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 131 | |
| 132 | burst_type b_type = d_channel_conf.get_burst_type(d_burst_nr); |
| 133 | if(d_state == synchronized && b_type == fcch_burst){ |
| 134 | uint64_t last_sample_nr = ceil((GUARD_PERIOD + 2.0 * TAIL_BITS + 156.25) * d_OSR) + 1; |
| 135 | if(tag_offset < last_sample_nr){ |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 136 | freq_offset_tag_in_fcch = true; |
| 137 | } |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 138 | } |
Piotr Krysik | 43af70d | 2016-07-20 21:37:24 +0200 | [diff] [blame] | 139 | d_freq_offset_setting = pmt::to_double(freq_offset_tag.value); |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 140 | } |
| 141 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 142 | switch (d_state) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 143 | { |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 144 | //bootstrapping |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 145 | case fcch_search: |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 146 | { |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 147 | double freq_offset_tmp; |
| 148 | if (find_fcch_burst(input, noutput_items,freq_offset_tmp)) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 149 | { |
piotr | d6d6687 | 2014-08-06 15:20:33 +0200 | [diff] [blame] | 150 | 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")); |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 151 | message_port_pub(pmt::mp("measurements"), msg); |
| 152 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 153 | d_state = sch_search; |
| 154 | } |
| 155 | else |
| 156 | { |
piotr | d6d6687 | 2014-08-06 15:20:33 +0200 | [diff] [blame] | 157 | d_state = fcch_search; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 158 | } |
| 159 | break; |
| 160 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 161 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 162 | case sch_search: |
| 163 | { |
ptrkrysik | ef5e2db | 2015-01-03 12:10:14 +0100 | [diff] [blame] | 164 | std::vector<gr_complex> channel_imp_resp(CHAN_IMP_RESP_LENGTH*d_OSR); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 165 | int t1, t2, t3; |
| 166 | int burst_start = 0; |
| 167 | unsigned char output_binary[BURST_SIZE]; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 168 | |
piotr | c7c249a | 2014-05-02 17:24:08 +0200 | [diff] [blame] | 169 | if (reach_sch_burst(noutput_items)) //wait for a SCH burst |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 170 | { |
| 171 | burst_start = get_sch_chan_imp_resp(input, &channel_imp_resp[0]); //get channel impulse response from it |
| 172 | detect_burst(input, &channel_imp_resp[0], burst_start, output_binary); //detect bits using MLSE detection |
| 173 | if (decode_sch(&output_binary[3], &t1, &t2, &t3, &d_ncc, &d_bcc) == 0) //decode SCH burst |
| 174 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 175 | d_burst_nr.set(t1, t2, t3, 0); //set counter of bursts value |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 176 | d_burst_nr++; |
| 177 | |
piotr | 7f3f366 | 2014-07-08 16:47:53 +0200 | [diff] [blame] | 178 | consume_each(burst_start + BURST_SIZE * d_OSR + 4*d_OSR); //consume samples up to next guard period |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 179 | d_state = synchronized; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 180 | } |
| 181 | else |
| 182 | { |
piotr | d6d6687 | 2014-08-06 15:20:33 +0200 | [diff] [blame] | 183 | d_state = fcch_search; //if there is error in the sch burst go back to fcch search phase |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 184 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 185 | } |
| 186 | else |
| 187 | { |
| 188 | d_state = sch_search; |
| 189 | } |
| 190 | break; |
| 191 | } |
| 192 | //in this state receiver is synchronized and it processes bursts according to burst type for given burst number |
| 193 | case synchronized: |
| 194 | { |
ptrkrysik | ef5e2db | 2015-01-03 12:10:14 +0100 | [diff] [blame] | 195 | std::vector<gr_complex> channel_imp_resp(CHAN_IMP_RESP_LENGTH*d_OSR); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 196 | int offset = 0; |
| 197 | int to_consume = 0; |
| 198 | unsigned char output_binary[BURST_SIZE]; |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 199 | burst_type b_type; |
ptrkrysik | 380dea8 | 2015-08-06 10:11:58 +0200 | [diff] [blame] | 200 | unsigned int inputs_to_process=d_cell_allocation.size(); |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 201 | |
ptrkrysik | 380dea8 | 2015-08-06 10:11:58 +0200 | [diff] [blame] | 202 | if(d_process_uplink) |
| 203 | { |
| 204 | inputs_to_process = 2*inputs_to_process; |
| 205 | } |
| 206 | |
| 207 | for(int input_nr=0; input_nr<inputs_to_process; input_nr++) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 208 | { |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 209 | double signal_pwr = 0; |
| 210 | input = (gr_complex *)input_items[input_nr]; |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 211 | |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 212 | for(int ii=GUARD_PERIOD;ii<TS_BITS;ii++) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 213 | { |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 214 | signal_pwr += abs(input[ii])*abs(input[ii]); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 215 | } |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 216 | signal_pwr = signal_pwr/(TS_BITS); |
| 217 | d_signal_dbm = round(10*log10(signal_pwr/50)); |
| 218 | if(input_nr==0){ |
| 219 | d_c0_signal_dbm = d_signal_dbm; |
| 220 | } |
| 221 | |
| 222 | if(input_nr==0) //for c0 channel burst type is controlled by channel configuration |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 223 | { |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 224 | b_type = d_channel_conf.get_burst_type(d_burst_nr); //get burst type for given burst number |
| 225 | } |
| 226 | else |
| 227 | { |
| 228 | b_type = normal_or_noise; //for the rest it can be only normal burst or noise (at least at this moment of development) |
| 229 | } |
| 230 | |
| 231 | switch (b_type) |
| 232 | { |
| 233 | case fcch_burst: //if it's FCCH burst |
| 234 | { |
Piotr Krysik | 43af70d | 2016-07-20 21:37:24 +0200 | [diff] [blame] | 235 | if(freq_offset_tag_in_fcch==false) |
| 236 | { |
| 237 | const unsigned first_sample = ceil((GUARD_PERIOD + 2 * TAIL_BITS) * d_OSR) + 1; |
| 238 | const unsigned last_sample = first_sample + USEFUL_BITS * d_OSR - TAIL_BITS * d_OSR; |
| 239 | double freq_offset_tmp = compute_freq_offset(input, first_sample, last_sample); //extract frequency offset from it |
Piotr Krysik | 43af70d | 2016-07-20 21:37:24 +0200 | [diff] [blame] | 240 | send_burst(d_burst_nr, fc_fb, GSMTAP_BURST_FCCH, input_nr); |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 241 | |
Piotr Krysik | 43af70d | 2016-07-20 21:37:24 +0200 | [diff] [blame] | 242 | pmt::pmt_t msg = pmt::make_tuple(pmt::mp("freq_offset"),pmt::from_double(freq_offset_tmp-d_freq_offset_setting),pmt::mp("synchronized")); |
| 243 | message_port_pub(pmt::mp("measurements"), msg); |
| 244 | } |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 245 | break; |
| 246 | } |
| 247 | case sch_burst: //if it's SCH burst |
| 248 | { |
| 249 | int t1, t2, t3, d_ncc, d_bcc; |
| 250 | d_c0_burst_start = get_sch_chan_imp_resp(input, &channel_imp_resp[0]); //get channel impulse response |
| 251 | |
| 252 | detect_burst(input, &channel_imp_resp[0], d_c0_burst_start, output_binary); //MLSE detection of bits |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 253 | send_burst(d_burst_nr, output_binary, GSMTAP_BURST_SCH, input_nr); |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 254 | if (decode_sch(&output_binary[3], &t1, &t2, &t3, &d_ncc, &d_bcc) == 0) //and decode SCH data |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 255 | { |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 256 | // d_burst_nr.set(t1, t2, t3, 0); //but only to check if burst_start value is correct |
| 257 | d_failed_sch = 0; |
| 258 | offset = d_c0_burst_start - floor((GUARD_PERIOD) * d_OSR); //compute offset from burst_start - burst should start after a guard period |
| 259 | to_consume += offset; //adjust with offset number of samples to be consumed |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 260 | } |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 261 | else |
| 262 | { |
| 263 | d_failed_sch++; |
| 264 | if (d_failed_sch >= MAX_SCH_ERRORS) |
| 265 | { |
| 266 | d_state = fcch_search; |
| 267 | pmt::pmt_t msg = pmt::make_tuple(pmt::mp("freq_offset"),pmt::from_double(0.0),pmt::mp("sync_loss")); |
| 268 | message_port_pub(pmt::mp("measurements"), msg); |
ptrkrysik | d57745d | 2014-12-02 19:05:36 +0100 | [diff] [blame] | 269 | //DCOUT("Re-Synchronization!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 270 | } |
| 271 | } |
| 272 | break; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 273 | } |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 274 | case normal_burst: |
| 275 | { |
| 276 | float normal_corr_max; //if it's normal burst |
| 277 | 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 |
| 278 | detect_burst(input, &channel_imp_resp[0], d_c0_burst_start, output_binary); //MLSE detection of bits |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 279 | send_burst(d_burst_nr, output_binary, GSMTAP_BURST_NORMAL, input_nr); |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 280 | break; |
| 281 | } |
| 282 | case dummy_or_normal: |
| 283 | { |
| 284 | unsigned int normal_burst_start, dummy_burst_start; |
| 285 | float dummy_corr_max, normal_corr_max; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 286 | |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 287 | dummy_burst_start = get_norm_chan_imp_resp(input, &channel_imp_resp[0], &dummy_corr_max, TS_DUMMY); |
| 288 | normal_burst_start = get_norm_chan_imp_resp(input, &channel_imp_resp[0], &normal_corr_max, d_bcc); |
Piotr Krysik | 9bc0fc0 | 2017-01-18 21:53:17 +0100 | [diff] [blame] | 289 | |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 290 | if (normal_corr_max > dummy_corr_max) |
| 291 | { |
| 292 | d_c0_burst_start = normal_burst_start; |
| 293 | detect_burst(input, &channel_imp_resp[0], normal_burst_start, output_binary); |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 294 | send_burst(d_burst_nr, output_binary, GSMTAP_BURST_NORMAL, input_nr); |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 295 | } |
| 296 | else |
| 297 | { |
| 298 | d_c0_burst_start = dummy_burst_start; |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 299 | send_burst(d_burst_nr, dummy_burst, GSMTAP_BURST_DUMMY, input_nr); |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 300 | } |
| 301 | break; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 302 | } |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 303 | case rach_burst: |
| 304 | break; |
| 305 | case dummy: |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 306 | send_burst(d_burst_nr, dummy_burst, GSMTAP_BURST_DUMMY, input_nr); |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 307 | break; |
| 308 | case normal_or_noise: |
| 309 | { |
| 310 | unsigned int burst_start; |
| 311 | float normal_corr_max_tmp; |
| 312 | float normal_corr_max=-1e6; |
| 313 | int max_tn; |
| 314 | std::vector<gr_complex> v(input, input + noutput_items); |
Piotr Krysik | f0ec659 | 2016-03-11 09:05:46 +0100 | [diff] [blame] | 315 | //if(d_signal_dbm>=d_c0_signal_dbm-13) |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 316 | { |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 317 | if(d_tseq_nums.size()==0) //there is no information about training sequence |
| 318 | { //however the receiver can detect it |
| 319 | get_norm_chan_imp_resp(input, &channel_imp_resp[0], &normal_corr_max, 0); |
| 320 | float ts_max=normal_corr_max; //with use of a very simple algorithm based on finding |
| 321 | int ts_max_num=0; //maximum correlation |
| 322 | for(int ss=1; ss<=7; ss++) |
| 323 | { |
| 324 | get_norm_chan_imp_resp(input, &channel_imp_resp[0], &normal_corr_max, ss); |
| 325 | if(ts_max<normal_corr_max) |
| 326 | { |
| 327 | ts_max = normal_corr_max; |
| 328 | ts_max_num = ss; |
| 329 | } |
| 330 | } |
| 331 | d_tseq_nums.push_back(ts_max_num); |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 332 | } |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 333 | int tseq_num; |
Piotr Krysik | f0ec659 | 2016-03-11 09:05:46 +0100 | [diff] [blame] | 334 | if(input_nr<=d_tseq_nums.size()) |
| 335 | { |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 336 | tseq_num = d_tseq_nums[input_nr-1]; |
Piotr Krysik | f0ec659 | 2016-03-11 09:05:46 +0100 | [diff] [blame] | 337 | } else |
| 338 | { |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 339 | tseq_num = d_tseq_nums.back(); |
| 340 | } |
| 341 | burst_start = get_norm_chan_imp_resp(input, &channel_imp_resp[0], &normal_corr_max, tseq_num); |
| 342 | // if(abs(d_c0_burst_start-burst_start)<=2){ //unused check/filter based on timing |
Piotr Krysik | f0ec659 | 2016-03-11 09:05:46 +0100 | [diff] [blame] | 343 | // if((normal_corr_max/sqrt(signal_pwr))>=0.9) |
| 344 | { |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 345 | detect_burst(input, &channel_imp_resp[0], burst_start, output_binary); |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 346 | send_burst(d_burst_nr, output_binary, GSMTAP_BURST_NORMAL, input_nr); |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 347 | } |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 348 | } |
| 349 | break; |
| 350 | } |
| 351 | case empty: //if it's empty burst |
| 352 | break; //do nothing |
| 353 | } |
| 354 | |
ptrkrysik | 91c2835 | 2015-06-07 18:36:15 +0200 | [diff] [blame] | 355 | if(input_nr==input_items.size()-1) |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 356 | { |
| 357 | d_burst_nr++; //go to next burst |
| 358 | to_consume += TS_BITS * d_OSR + d_burst_nr.get_offset(); //consume samples of the burst up to next guard period |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 359 | consume_each(to_consume); |
| 360 | } |
| 361 | //and add offset which is introduced by |
| 362 | //0.25 fractional part of a guard period |
| 363 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 364 | } |
| 365 | break; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 366 | } |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 367 | return 0; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 368 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 369 | |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 370 | bool receiver_impl::find_fcch_burst(const gr_complex *input, const int nitems, double & computed_freq_offset) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 371 | { |
ptrkrysik | ef5e2db | 2015-01-03 12:10:14 +0100 | [diff] [blame] | 372 | boost::circular_buffer<float> phase_diff_buffer(FCCH_HITS_NEEDED * d_OSR); //circular buffer used to scan throug signal to find |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 373 | //best match for FCCH burst |
| 374 | float phase_diff = 0; |
| 375 | gr_complex conjprod; |
| 376 | int start_pos = -1; |
| 377 | int hit_count = 0; |
| 378 | int miss_count = 0; |
| 379 | float min_phase_diff; |
| 380 | float max_phase_diff; |
| 381 | double best_sum = 0; |
| 382 | float lowest_max_min_diff = 99999; |
| 383 | |
| 384 | int to_consume = 0; |
| 385 | int sample_number = 0; |
| 386 | bool end = false; |
| 387 | bool result = false; |
ptrkrysik | ef5e2db | 2015-01-03 12:10:14 +0100 | [diff] [blame] | 388 | boost::circular_buffer<float>::iterator buffer_iter; |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 389 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 390 | /**@name Possible states of FCCH search algorithm*/ |
| 391 | //@{ |
| 392 | enum states |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 393 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 394 | init, ///< initialize variables |
| 395 | search, ///< search for positive samples |
| 396 | found_something, ///< search for FCCH and the best position of it |
| 397 | fcch_found, ///< when FCCH was found |
| 398 | search_fail ///< when there is no FCCH in the input vector |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 399 | } fcch_search_state; |
| 400 | //@} |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 401 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 402 | fcch_search_state = init; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 403 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 404 | while (!end) |
| 405 | { |
| 406 | switch (fcch_search_state) |
| 407 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 408 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 409 | case init: //initialize variables |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 410 | hit_count = 0; |
| 411 | miss_count = 0; |
| 412 | start_pos = -1; |
| 413 | lowest_max_min_diff = 99999; |
| 414 | phase_diff_buffer.clear(); |
| 415 | fcch_search_state = search; |
| 416 | |
| 417 | break; |
| 418 | |
piotr | 7c82b17 | 2014-02-08 14:15:27 +0100 | [diff] [blame] | 419 | case search: // search for positive samples |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 420 | sample_number++; |
| 421 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 422 | if (sample_number > nitems - FCCH_HITS_NEEDED * d_OSR) //if it isn't possible to find FCCH because |
| 423 | { |
piotr | 7c82b17 | 2014-02-08 14:15:27 +0100 | [diff] [blame] | 424 | //there's too few samples left to look into, |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 425 | to_consume = sample_number; //don't do anything with those samples which are left |
piotr | 7c82b17 | 2014-02-08 14:15:27 +0100 | [diff] [blame] | 426 | //and consume only those which were checked |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 427 | fcch_search_state = search_fail; |
| 428 | } |
| 429 | else |
| 430 | { |
| 431 | phase_diff = compute_phase_diff(input[sample_number], input[sample_number-1]); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 432 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 433 | if (phase_diff > 0) //if a positive phase difference was found |
| 434 | { |
| 435 | to_consume = sample_number; |
| 436 | fcch_search_state = found_something; //switch to state in which searches for FCCH |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | fcch_search_state = search; |
| 441 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | break; |
| 445 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 446 | case found_something: // search for FCCH and the best position of it |
| 447 | { |
| 448 | if (phase_diff > 0) |
| 449 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 450 | hit_count++; //positive phase differencies increases hits_count |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 451 | } |
| 452 | else |
| 453 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 454 | miss_count++; //negative increases miss_count |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 455 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 456 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 457 | if ((miss_count >= FCCH_MAX_MISSES * d_OSR) && (hit_count <= FCCH_HITS_NEEDED * d_OSR)) |
| 458 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 459 | //if miss_count exceeds limit before hit_count |
| 460 | fcch_search_state = init; //go to init |
| 461 | continue; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 462 | } |
| 463 | else if (((miss_count >= FCCH_MAX_MISSES * d_OSR) && (hit_count > FCCH_HITS_NEEDED * d_OSR)) || (hit_count > 2 * FCCH_HITS_NEEDED * d_OSR)) |
| 464 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 465 | //if hit_count and miss_count exceeds limit then FCCH was found |
| 466 | fcch_search_state = fcch_found; |
| 467 | continue; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 468 | } |
| 469 | else if ((miss_count < FCCH_MAX_MISSES * d_OSR) && (hit_count > FCCH_HITS_NEEDED * d_OSR)) |
| 470 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 471 | //find difference between minimal and maximal element in the buffer |
| 472 | //for FCCH this value should be low |
| 473 | //this part is searching for a region where this value is lowest |
| 474 | min_phase_diff = * (min_element(phase_diff_buffer.begin(), phase_diff_buffer.end())); |
| 475 | max_phase_diff = * (max_element(phase_diff_buffer.begin(), phase_diff_buffer.end())); |
| 476 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 477 | if (lowest_max_min_diff > max_phase_diff - min_phase_diff) |
| 478 | { |
| 479 | lowest_max_min_diff = max_phase_diff - min_phase_diff; |
| 480 | start_pos = sample_number - FCCH_HITS_NEEDED * d_OSR - FCCH_MAX_MISSES * d_OSR; //store start pos |
| 481 | best_sum = 0; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 482 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 483 | for (buffer_iter = phase_diff_buffer.begin(); |
| 484 | buffer_iter != (phase_diff_buffer.end()); |
| 485 | buffer_iter++) |
| 486 | { |
| 487 | best_sum += *buffer_iter - (M_PI / 2) / d_OSR; //store best value of phase offset sum |
| 488 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 489 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 490 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 491 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 492 | sample_number++; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 493 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 494 | if (sample_number >= nitems) //if there's no single sample left to check |
| 495 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 496 | fcch_search_state = search_fail;//FCCH search failed |
| 497 | continue; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 498 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 499 | |
| 500 | phase_diff = compute_phase_diff(input[sample_number], input[sample_number-1]); |
| 501 | phase_diff_buffer.push_back(phase_diff); |
| 502 | fcch_search_state = found_something; |
| 503 | } |
| 504 | break; |
| 505 | |
| 506 | case fcch_found: |
| 507 | { |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 508 | to_consume = start_pos + FCCH_HITS_NEEDED * d_OSR + 1; //consume one FCCH burst |
| 509 | |
| 510 | d_fcch_start_pos = d_counter + start_pos; |
| 511 | |
| 512 | //compute frequency offset |
| 513 | double phase_offset = best_sum / FCCH_HITS_NEEDED; |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 514 | double freq_offset = phase_offset * 1625000.0/6 / (2 * M_PI); //1625000.0/6 - GMSK symbol rate in GSM |
| 515 | computed_freq_offset = freq_offset; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 516 | |
| 517 | end = true; |
| 518 | result = true; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 519 | break; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 520 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 521 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 522 | case search_fail: |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 523 | end = true; |
| 524 | result = false; |
| 525 | break; |
| 526 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 527 | } |
| 528 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 529 | d_counter += to_consume; |
| 530 | consume_each(to_consume); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 531 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 532 | return result; |
| 533 | } |
| 534 | |
Piotr Krysik | d61f85b | 2016-08-29 07:38:25 +0200 | [diff] [blame] | 535 | double receiver_impl::compute_freq_offset(const gr_complex * input, unsigned first_sample, unsigned last_sample) |
| 536 | { |
Piotr Krysik | 654d652 | 2017-01-23 21:53:48 +0100 | [diff] [blame] | 537 | double phase_sum = 0; |
| 538 | unsigned ii; |
| 539 | |
| 540 | for (ii = first_sample; ii < last_sample; ii++) |
| 541 | { |
| 542 | double phase_diff = compute_phase_diff(input[ii], input[ii-1]) - (M_PI / 2) / d_OSR; |
| 543 | phase_sum += phase_diff; |
| 544 | } |
| 545 | |
| 546 | double phase_offset = phase_sum / (last_sample - first_sample); |
| 547 | double freq_offset = phase_offset * 1625000.0 / (12.0 * M_PI); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 548 | return freq_offset; |
| 549 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 550 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 551 | inline float receiver_impl::compute_phase_diff(gr_complex val1, gr_complex val2) |
| 552 | { |
| 553 | gr_complex conjprod = val1 * conj(val2); |
| 554 | return fast_atan2f(imag(conjprod), real(conjprod)); |
| 555 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 556 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 557 | bool receiver_impl::reach_sch_burst(const int nitems) |
| 558 | { |
| 559 | //it just consumes samples to get near to a SCH burst |
| 560 | int to_consume = 0; |
| 561 | bool result = false; |
| 562 | unsigned sample_nr_near_sch_start = d_fcch_start_pos + (FRAME_BITS - SAFETY_MARGIN) * d_OSR; |
| 563 | |
| 564 | //consume samples until d_counter will be equal to sample_nr_near_sch_start |
| 565 | if (d_counter < sample_nr_near_sch_start) |
| 566 | { |
| 567 | if (d_counter + nitems >= sample_nr_near_sch_start) |
| 568 | { |
| 569 | to_consume = sample_nr_near_sch_start - d_counter; |
| 570 | } |
| 571 | else |
| 572 | { |
| 573 | to_consume = nitems; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 574 | } |
| 575 | result = false; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 576 | } |
| 577 | else |
| 578 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 579 | to_consume = 0; |
| 580 | result = true; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 581 | } |
| 582 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 583 | d_counter += to_consume; |
| 584 | consume_each(to_consume); |
| 585 | return result; |
| 586 | } |
| 587 | |
| 588 | int receiver_impl::get_sch_chan_imp_resp(const gr_complex *input, gr_complex * chan_imp_resp) |
| 589 | { |
ptrkrysik | ef5e2db | 2015-01-03 12:10:14 +0100 | [diff] [blame] | 590 | std::vector<gr_complex> correlation_buffer; |
| 591 | std::vector<float> power_buffer; |
| 592 | std::vector<float> window_energy_buffer; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 593 | |
| 594 | int strongest_window_nr; |
| 595 | int burst_start = 0; |
| 596 | int chan_imp_resp_center = 0; |
| 597 | float max_correlation = 0; |
| 598 | float energy = 0; |
| 599 | |
| 600 | for (int ii = SYNC_POS * d_OSR; ii < (SYNC_POS + SYNC_SEARCH_RANGE) *d_OSR; ii++) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 601 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 602 | gr_complex correlation = correlate_sequence(&d_sch_training_seq[5], N_SYNC_BITS - 10, &input[ii]); |
| 603 | correlation_buffer.push_back(correlation); |
| 604 | power_buffer.push_back(std::pow(abs(correlation), 2)); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 605 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 606 | //compute window energies |
ptrkrysik | ef5e2db | 2015-01-03 12:10:14 +0100 | [diff] [blame] | 607 | std::vector<float>::iterator iter = power_buffer.begin(); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 608 | bool loop_end = false; |
| 609 | while (iter != power_buffer.end()) |
| 610 | { |
ptrkrysik | ef5e2db | 2015-01-03 12:10:14 +0100 | [diff] [blame] | 611 | std::vector<float>::iterator iter_ii = iter; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 612 | energy = 0; |
| 613 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 614 | for (int ii = 0; ii < (d_chan_imp_length) *d_OSR; ii++, iter_ii++) |
| 615 | { |
| 616 | if (iter_ii == power_buffer.end()) |
| 617 | { |
| 618 | loop_end = true; |
| 619 | break; |
| 620 | } |
| 621 | energy += (*iter_ii); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 622 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 623 | if (loop_end) |
| 624 | { |
| 625 | break; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 626 | } |
| 627 | iter++; |
| 628 | window_energy_buffer.push_back(energy); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 629 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 630 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 631 | strongest_window_nr = max_element(window_energy_buffer.begin(), window_energy_buffer.end()) - window_energy_buffer.begin(); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 632 | // d_channel_imp_resp.clear(); |
| 633 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 634 | max_correlation = 0; |
| 635 | for (int ii = 0; ii < (d_chan_imp_length) *d_OSR; ii++) |
| 636 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 637 | gr_complex correlation = correlation_buffer[strongest_window_nr + ii]; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 638 | if (abs(correlation) > max_correlation) |
| 639 | { |
| 640 | chan_imp_resp_center = ii; |
| 641 | max_correlation = abs(correlation); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 642 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 643 | // d_channel_imp_resp.push_back(correlation); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 644 | chan_imp_resp[ii] = correlation; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 645 | } |
| 646 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 647 | burst_start = strongest_window_nr + chan_imp_resp_center - 48 * d_OSR - 2 * d_OSR + 2 + SYNC_POS * d_OSR; |
| 648 | return burst_start; |
| 649 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 650 | |
| 651 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 652 | void receiver_impl::detect_burst(const gr_complex * input, gr_complex * chan_imp_resp, int burst_start, unsigned char * output_binary) |
| 653 | { |
| 654 | float output[BURST_SIZE]; |
David Holm | f2497bd | 2014-12-01 21:22:37 +0100 | [diff] [blame] | 655 | std::vector<gr_complex> rhh_temp(CHAN_IMP_RESP_LENGTH*d_OSR); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 656 | gr_complex rhh[CHAN_IMP_RESP_LENGTH]; |
| 657 | gr_complex filtered_burst[BURST_SIZE]; |
| 658 | int start_state = 3; |
| 659 | unsigned int stop_states[2] = {4, 12}; |
| 660 | |
David Holm | f2497bd | 2014-12-01 21:22:37 +0100 | [diff] [blame] | 661 | autocorrelation(chan_imp_resp, &rhh_temp[0], d_chan_imp_length*d_OSR); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 662 | for (int ii = 0; ii < (d_chan_imp_length); ii++) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 663 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 664 | rhh[ii] = conj(rhh_temp[ii*d_OSR]); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 665 | } |
| 666 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 667 | mafi(&input[burst_start], BURST_SIZE, chan_imp_resp, d_chan_imp_length*d_OSR, filtered_burst); |
| 668 | |
| 669 | viterbi_detector(filtered_burst, BURST_SIZE, rhh, start_state, stop_states, 2, output); |
| 670 | |
| 671 | for (int i = 0; i < BURST_SIZE ; i++) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 672 | { |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 673 | output_binary[i] = (output[i] > 0); |
| 674 | } |
| 675 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 676 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 677 | void receiver_impl::gmsk_mapper(const unsigned char * input, int nitems, gr_complex * gmsk_output, gr_complex start_point) |
| 678 | { |
| 679 | gr_complex j = gr_complex(0.0, 1.0); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 680 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 681 | int current_symbol; |
| 682 | int encoded_symbol; |
| 683 | int previous_symbol = 2 * input[0] - 1; |
| 684 | gmsk_output[0] = start_point; |
| 685 | |
| 686 | for (int i = 1; i < nitems; i++) |
| 687 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 688 | //change bits representation to NRZ |
| 689 | current_symbol = 2 * input[i] - 1; |
| 690 | //differentially encode |
| 691 | encoded_symbol = current_symbol * previous_symbol; |
| 692 | //and do gmsk mapping |
| 693 | gmsk_output[i] = j * gr_complex(encoded_symbol, 0.0) * gmsk_output[i-1]; |
| 694 | previous_symbol = current_symbol; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 695 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 696 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 697 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 698 | gr_complex receiver_impl::correlate_sequence(const gr_complex * sequence, int length, const gr_complex * input) |
| 699 | { |
| 700 | gr_complex result(0.0, 0.0); |
| 701 | int sample_number = 0; |
| 702 | |
| 703 | for (int ii = 0; ii < length; ii++) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 704 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 705 | sample_number = (ii * d_OSR) ; |
| 706 | result += sequence[ii] * conj(input[sample_number]); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 707 | } |
| 708 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 709 | result = result / gr_complex(length, 0); |
| 710 | return result; |
| 711 | } |
| 712 | |
| 713 | //computes autocorrelation for positive arguments |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 714 | inline void receiver_impl::autocorrelation(const gr_complex * input, gr_complex * out, int nitems) |
| 715 | { |
| 716 | int i, k; |
| 717 | for (k = nitems - 1; k >= 0; k--) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 718 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 719 | out[k] = gr_complex(0, 0); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 720 | for (i = k; i < nitems; i++) |
| 721 | { |
| 722 | out[k] += input[i] * conj(input[i-k]); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 723 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 724 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 725 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 726 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 727 | inline void receiver_impl::mafi(const gr_complex * input, int nitems, gr_complex * filter, int filter_length, gr_complex * output) |
| 728 | { |
| 729 | int ii = 0, n, a; |
| 730 | |
| 731 | for (n = 0; n < nitems; n++) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 732 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 733 | a = n * d_OSR; |
| 734 | output[n] = 0; |
| 735 | ii = 0; |
| 736 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 737 | while (ii < filter_length) |
| 738 | { |
piotr | da8a066 | 2014-04-24 10:29:38 +0200 | [diff] [blame] | 739 | if ((a + ii) >= nitems*d_OSR){ |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 740 | break; |
piotr | da8a066 | 2014-04-24 10:29:38 +0200 | [diff] [blame] | 741 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 742 | output[n] += input[a+ii] * filter[ii]; |
| 743 | ii++; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 744 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 745 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 746 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 747 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 748 | //especially computations of strongest_window_nr |
piotr | 7e3b0db | 2014-02-05 22:44:30 +0100 | [diff] [blame] | 749 | int receiver_impl::get_norm_chan_imp_resp(const gr_complex *input, gr_complex * chan_imp_resp, float *corr_max, int bcc) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 750 | { |
ptrkrysik | ef5e2db | 2015-01-03 12:10:14 +0100 | [diff] [blame] | 751 | std::vector<gr_complex> correlation_buffer; |
| 752 | std::vector<float> power_buffer; |
| 753 | std::vector<float> window_energy_buffer; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 754 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 755 | int strongest_window_nr; |
| 756 | int burst_start = 0; |
| 757 | int chan_imp_resp_center = 0; |
| 758 | float max_correlation = 0; |
| 759 | float energy = 0; |
piotr | 5c82025 | 2014-04-17 09:43:02 +0200 | [diff] [blame] | 760 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 761 | int search_center = (int)((TRAIN_POS + GUARD_PERIOD) * d_OSR); |
piotr | 7c82b17 | 2014-02-08 14:15:27 +0100 | [diff] [blame] | 762 | int search_start_pos = search_center + 1 - 5*d_OSR; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 763 | // int search_start_pos = search_center - d_chan_imp_length * d_OSR; |
piotr | 5c82025 | 2014-04-17 09:43:02 +0200 | [diff] [blame] | 764 | int search_stop_pos = search_center + d_chan_imp_length * d_OSR + 5 * d_OSR; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 765 | |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 766 | for(int ii = search_start_pos; ii < search_stop_pos; ii++) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 767 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 768 | gr_complex correlation = correlate_sequence(&d_norm_training_seq[bcc][TRAIN_BEGINNING], N_TRAIN_BITS - 10, &input[ii]); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 769 | correlation_buffer.push_back(correlation); |
| 770 | power_buffer.push_back(std::pow(abs(correlation), 2)); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 771 | } |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 772 | // plot(power_buffer); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 773 | //compute window energies |
ptrkrysik | ef5e2db | 2015-01-03 12:10:14 +0100 | [diff] [blame] | 774 | std::vector<float>::iterator iter = power_buffer.begin(); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 775 | bool loop_end = false; |
| 776 | while (iter != power_buffer.end()) |
| 777 | { |
ptrkrysik | ef5e2db | 2015-01-03 12:10:14 +0100 | [diff] [blame] | 778 | std::vector<float>::iterator iter_ii = iter; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 779 | energy = 0; |
| 780 | |
Piotr Krysik | 97d4f8a | 2016-02-11 08:40:44 +0100 | [diff] [blame] | 781 | for (int ii = 0; ii < (d_chan_imp_length)*d_OSR; ii++, iter_ii++) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 782 | { |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 783 | if (iter_ii == power_buffer.end()) |
| 784 | { |
| 785 | loop_end = true; |
| 786 | break; |
| 787 | } |
| 788 | energy += (*iter_ii); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 789 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 790 | if (loop_end) |
| 791 | { |
| 792 | break; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 793 | } |
| 794 | iter++; |
| 795 | |
| 796 | window_energy_buffer.push_back(energy); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 797 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 798 | |
piotr | 5c82025 | 2014-04-17 09:43:02 +0200 | [diff] [blame] | 799 | strongest_window_nr = max_element(window_energy_buffer.begin(), window_energy_buffer.end()-((d_chan_imp_length)*d_OSR)) - window_energy_buffer.begin(); |
| 800 | //strongest_window_nr = strongest_window_nr-d_OSR; |
| 801 | if(strongest_window_nr<0){ |
| 802 | strongest_window_nr = 0; |
| 803 | } |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 804 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 805 | max_correlation = 0; |
| 806 | for (int ii = 0; ii < (d_chan_imp_length)*d_OSR; ii++) |
| 807 | { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 808 | gr_complex correlation = correlation_buffer[strongest_window_nr + ii]; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 809 | if (abs(correlation) > max_correlation) |
| 810 | { |
| 811 | chan_imp_resp_center = ii; |
| 812 | max_correlation = abs(correlation); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 813 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 814 | // d_channel_imp_resp.push_back(correlation); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 815 | chan_imp_resp[ii] = correlation; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 816 | } |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 817 | |
piotr | 7e3b0db | 2014-02-05 22:44:30 +0100 | [diff] [blame] | 818 | *corr_max = max_correlation; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 819 | |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 820 | //DCOUT("strongest_window_nr_new: " << strongest_window_nr); |
piotr | c7c249a | 2014-05-02 17:24:08 +0200 | [diff] [blame] | 821 | 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 |
piotr | 7c82b17 | 2014-02-08 14:15:27 +0100 | [diff] [blame] | 822 | |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 823 | //DCOUT("burst_start: " << burst_start); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 824 | return burst_start; |
| 825 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 826 | |
| 827 | |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 828 | void receiver_impl::send_burst(burst_counter burst_nr, const unsigned char * burst_binary, uint8_t burst_type, unsigned int input_nr) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 829 | { |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 830 | boost::scoped_ptr<gsmtap_hdr> tap_header(new gsmtap_hdr()); |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 831 | |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 832 | tap_header->version = GSMTAP_VERSION; |
ptrkrysik | 7f61c64 | 2014-10-30 08:57:27 +0100 | [diff] [blame] | 833 | tap_header->hdr_len = sizeof(gsmtap_hdr)/4; |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 834 | tap_header->type = GSMTAP_TYPE_UM_BURST; |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 835 | tap_header->sub_type = burst_type; |
ptrkrysik | 380dea8 | 2015-08-06 10:11:58 +0200 | [diff] [blame] | 836 | bool uplink_burst = (input_nr >= d_cell_allocation.size()); |
| 837 | if(!uplink_burst) // downlink burst |
| 838 | { |
| 839 | tap_header->timeslot = static_cast<uint8_t>(d_burst_nr.get_timeslot_nr()); |
| 840 | tap_header->frame_number = htobe32(d_burst_nr.get_frame_nr()); |
| 841 | tap_header->arfcn = htobe16(d_cell_allocation[input_nr]) ; |
| 842 | } |
| 843 | else //uplink burst |
| 844 | { |
| 845 | tap_header->timeslot = static_cast<uint8_t>(d_burst_nr.subtract_timeslots(3).get_timeslot_nr()); |
| 846 | tap_header->frame_number = htobe32(d_burst_nr.subtract_timeslots(3).get_frame_nr()); |
| 847 | input_nr = input_nr - d_cell_allocation.size(); |
| 848 | tap_header->arfcn = htobe16(d_cell_allocation[input_nr] | 0x4000); |
| 849 | } |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 850 | tap_header->signal_dbm = static_cast<int8_t>(d_signal_dbm); |
ptrkrysik | 6f6d46d | 2014-11-12 22:50:18 +0100 | [diff] [blame] | 851 | tap_header->snr_db = 0; |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 852 | |
| 853 | int8_t header_plus_burst[sizeof(gsmtap_hdr)+BURST_SIZE]; |
| 854 | memcpy(header_plus_burst, tap_header.get(), sizeof(gsmtap_hdr)); |
| 855 | memcpy(header_plus_burst+sizeof(gsmtap_hdr), burst_binary, BURST_SIZE); |
| 856 | |
| 857 | pmt::pmt_t blob_header_plus_burst = pmt::make_blob(header_plus_burst,sizeof(gsmtap_hdr)+BURST_SIZE); |
| 858 | pmt::pmt_t msg = pmt::cons(pmt::PMT_NIL, blob_header_plus_burst); |
piotr | f2b6a1b | 2014-08-04 11:28:59 +0200 | [diff] [blame] | 859 | |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 860 | if(input_nr==0){ |
| 861 | message_port_pub(pmt::mp("C0"), msg); |
| 862 | } else { |
| 863 | message_port_pub(pmt::mp("CX"), msg); |
| 864 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 865 | } |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 866 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 867 | void receiver_impl::configure_receiver() |
| 868 | { |
piotr | ce92f98 | 2014-04-17 23:37:18 +0200 | [diff] [blame] | 869 | d_channel_conf.set_multiframe_type(TIMESLOT0, multiframe_51); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 870 | d_channel_conf.set_burst_types(TIMESLOT0, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 871 | |
piotr | ce92f98 | 2014-04-17 23:37:18 +0200 | [diff] [blame] | 872 | d_channel_conf.set_burst_types(TIMESLOT0, TEST_CCH_FRAMES, sizeof(TEST_CCH_FRAMES) / sizeof(unsigned), dummy_or_normal); |
| 873 | d_channel_conf.set_burst_types(TIMESLOT0, FCCH_FRAMES, sizeof(FCCH_FRAMES) / sizeof(unsigned), fcch_burst); |
| 874 | d_channel_conf.set_burst_types(TIMESLOT0, SCH_FRAMES, sizeof(SCH_FRAMES) / sizeof(unsigned), sch_burst); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 875 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 876 | d_channel_conf.set_multiframe_type(TIMESLOT1, multiframe_51); |
| 877 | d_channel_conf.set_burst_types(TIMESLOT1, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
| 878 | d_channel_conf.set_multiframe_type(TIMESLOT2, multiframe_51); |
| 879 | d_channel_conf.set_burst_types(TIMESLOT2, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
| 880 | d_channel_conf.set_multiframe_type(TIMESLOT3, multiframe_51); |
| 881 | d_channel_conf.set_burst_types(TIMESLOT3, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
| 882 | d_channel_conf.set_multiframe_type(TIMESLOT4, multiframe_51); |
| 883 | d_channel_conf.set_burst_types(TIMESLOT4, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
| 884 | d_channel_conf.set_multiframe_type(TIMESLOT5, multiframe_51); |
| 885 | d_channel_conf.set_burst_types(TIMESLOT5, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
| 886 | d_channel_conf.set_multiframe_type(TIMESLOT6, multiframe_51); |
| 887 | d_channel_conf.set_burst_types(TIMESLOT6, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
| 888 | d_channel_conf.set_multiframe_type(TIMESLOT7, multiframe_51); |
| 889 | d_channel_conf.set_burst_types(TIMESLOT7, TEST51, sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 890 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 891 | |
ptrkrysik | 7a7b9b0 | 2014-11-19 11:27:34 +0100 | [diff] [blame] | 892 | void receiver_impl::set_cell_allocation(const std::vector<int> &cell_allocation) |
piotr | f2b6a1b | 2014-08-04 11:28:59 +0200 | [diff] [blame] | 893 | { |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 894 | d_cell_allocation = cell_allocation; |
| 895 | } |
| 896 | |
| 897 | void receiver_impl::set_tseq_nums(const std::vector<int> & tseq_nums) |
| 898 | { |
| 899 | d_tseq_nums = tseq_nums; |
piotr | f2b6a1b | 2014-08-04 11:28:59 +0200 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | void receiver_impl::reset() |
| 903 | { |
piotr | d6d6687 | 2014-08-06 15:20:33 +0200 | [diff] [blame] | 904 | d_state = fcch_search; |
piotr | f2b6a1b | 2014-08-04 11:28:59 +0200 | [diff] [blame] | 905 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 906 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 907 | } /* namespace gsm */ |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 908 | } /* namespace gr */ |
| 909 | |