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 |
Piotr Krysik | a6268a5 | 2017-08-23 16:02:19 +0200 | [diff] [blame] | 4 | * @author (C) 2009-2017 by Piotr Krysik <ptrkrysik@gmail.com> |
ptrkrysik | 529895b | 2014-12-02 18:07:38 +0100 | [diff] [blame] | 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> |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 29 | |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 30 | #include <algorithm> |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 31 | #include <string.h> |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 32 | #include <iostream> |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 33 | #include <numeric> |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 34 | #include <vector> |
ptrkrysik | 3be74a7 | 2014-12-13 10:11:00 +0100 | [diff] [blame] | 35 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 36 | #include <boost/circular_buffer.hpp> |
| 37 | #include <boost/scoped_ptr.hpp> |
ptrkrysik | 3be74a7 | 2014-12-13 10:11:00 +0100 | [diff] [blame] | 38 | #include <grgsm/endian.h> |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 39 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 40 | #include "receiver_impl.h" |
| 41 | #include "viterbi_detector.h" |
| 42 | #include "sch.h" |
| 43 | |
| 44 | #if 0 |
| 45 | /* Files included for debuging */ |
| 46 | #include "plotting/plotting.hpp" |
| 47 | #include <pthread.h> |
| 48 | #include <iomanip> |
| 49 | #endif |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 50 | |
| 51 | #define SYNC_SEARCH_RANGE 30 |
| 52 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 53 | namespace gr |
| 54 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 55 | namespace gsm |
| 56 | { |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 57 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 58 | /* The public constructor */ |
| 59 | receiver::sptr |
| 60 | receiver::make( |
| 61 | int osr, const std::vector<int> &cell_allocation, |
| 62 | const std::vector<int> &tseq_nums, bool process_uplink) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 63 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 64 | return gnuradio::get_initial_sptr |
| 65 | (new receiver_impl(osr, cell_allocation, |
| 66 | tseq_nums, process_uplink)); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 67 | } |
| 68 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 69 | /* The private constructor */ |
| 70 | receiver_impl::receiver_impl( |
| 71 | int osr, const std::vector<int> &cell_allocation, |
| 72 | const std::vector<int> &tseq_nums, bool process_uplink |
| 73 | ) : gr::sync_block("receiver", |
| 74 | gr::io_signature::make(1, -1, sizeof(gr_complex)), |
| 75 | gr::io_signature::make(0, 0, 0)), |
Piotr Krysik | 96f2ea7 | 2017-10-16 15:47:08 +0200 | [diff] [blame] | 76 | d_samples_consumed(0), |
Piotr Krysik | df97869 | 2017-09-27 21:58:24 +0200 | [diff] [blame] | 77 | d_rx_time_received(false), |
| 78 | d_time_samp_ref(GSM_SYMBOL_RATE * osr), |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 79 | d_OSR(osr), |
| 80 | d_process_uplink(process_uplink), |
| 81 | d_chan_imp_length(CHAN_IMP_RESP_LENGTH), |
Piotr Krysik | df97869 | 2017-09-27 21:58:24 +0200 | [diff] [blame] | 82 | d_counter(0), //TODO: use nitems_read instead of d_counter |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 83 | d_fcch_start_pos(0), |
| 84 | d_freq_offset_setting(0), |
| 85 | d_state(fcch_search), |
| 86 | d_burst_nr(osr), |
| 87 | d_failed_sch(0), |
| 88 | d_signal_dbm(-120), |
| 89 | d_tseq_nums(tseq_nums), |
| 90 | d_cell_allocation(cell_allocation), |
| 91 | d_last_time(0.0) |
ptrkrysik | 32c2116 | 2015-04-04 14:01:52 +0200 | [diff] [blame] | 92 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 93 | /** |
| 94 | * Don't send samples to the receiver |
| 95 | * until there are at least samples for one |
| 96 | */ |
| 97 | set_output_multiple(floor((TS_BITS + 2 * GUARD_PERIOD) * d_OSR)); |
| 98 | |
| 99 | /** |
| 100 | * Prepare SCH sequence bits |
| 101 | * |
| 102 | * (TS_BITS + 2 * GUARD_PERIOD) |
| 103 | * Burst and two guard periods |
| 104 | * (one guard period is an arbitrary overlap) |
| 105 | */ |
| 106 | gmsk_mapper(SYNC_BITS, N_SYNC_BITS, |
| 107 | d_sch_training_seq, gr_complex(0.0, -1.0)); |
| 108 | |
| 109 | /* Prepare bits of training sequences */ |
| 110 | for (int i = 0; i < TRAIN_SEQ_NUM; i++) { |
| 111 | /** |
| 112 | * If first bit of the sequence is 0 |
| 113 | * => first symbol is 1, else -1 |
| 114 | */ |
| 115 | gr_complex startpoint = train_seq[i][0] == 0 ? |
| 116 | gr_complex(1.0, 0.0) : gr_complex(-1.0, 0.0); |
| 117 | gmsk_mapper(train_seq[i], N_TRAIN_BITS, |
| 118 | d_norm_training_seq[i], startpoint); |
| 119 | } |
| 120 | |
| 121 | /* Register output ports */ |
| 122 | message_port_register_out(pmt::mp("C0")); |
| 123 | message_port_register_out(pmt::mp("CX")); |
| 124 | message_port_register_out(pmt::mp("measurements")); |
| 125 | |
| 126 | /** |
| 127 | * Configure the receiver, |
| 128 | * i.e. tell it where to find which burst type |
| 129 | */ |
| 130 | configure_receiver(); |
| 131 | } |
| 132 | |
| 133 | /* Our virtual destructor */ |
| 134 | receiver_impl::~receiver_impl() {} |
| 135 | |
| 136 | int |
| 137 | receiver_impl::work( |
| 138 | int noutput_items, |
| 139 | gr_vector_const_void_star &input_items, |
| 140 | gr_vector_void_star &output_items) |
| 141 | { |
| 142 | gr_complex *input = (gr_complex *) input_items[0]; |
| 143 | uint64_t start = nitems_read(0); |
| 144 | uint64_t stop = start + noutput_items; |
| 145 | d_freq_offset_tag_in_fcch = false; |
| 146 | |
| 147 | #if 0 |
| 148 | /* FIXME: jak zrobić to rzutowanie poprawnie */ |
| 149 | std::vector<const gr_complex *> iii = |
| 150 | (std::vector<const gr_complex *>) input_items; |
| 151 | #endif |
| 152 | |
| 153 | /* Time synchronization loop */ |
| 154 | float current_time = |
| 155 | static_cast<float>(start / (GSM_SYMBOL_RATE * d_OSR)); |
| 156 | if ((current_time - d_last_time) > 0.1) { |
| 157 | pmt::pmt_t msg = pmt::make_tuple(pmt::mp("current_time"), |
| 158 | pmt::from_double(current_time)); |
ptrkrysik | 32c2116 | 2015-04-04 14:01:52 +0200 | [diff] [blame] | 159 | message_port_pub(pmt::mp("measurements"), msg); |
| 160 | d_last_time = current_time; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 161 | } |
ptrkrysik | 32c2116 | 2015-04-04 14:01:52 +0200 | [diff] [blame] | 162 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 163 | /* Frequency correction loop */ |
| 164 | std::vector<tag_t> freq_offset_tags; |
| 165 | pmt::pmt_t key = pmt::string_to_symbol("setting_freq_offset"); |
| 166 | get_tags_in_range(freq_offset_tags, 0, start, stop, key); |
| 167 | |
| 168 | if (!freq_offset_tags.empty()) { |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 169 | tag_t freq_offset_tag = freq_offset_tags[0]; |
Piotr Krysik | 43af70d | 2016-07-20 21:37:24 +0200 | [diff] [blame] | 170 | uint64_t tag_offset = freq_offset_tag.offset - start; |
Piotr Krysik | 43af70d | 2016-07-20 21:37:24 +0200 | [diff] [blame] | 171 | d_freq_offset_setting = pmt::to_double(freq_offset_tag.value); |
piotr | 4089c1a | 2014-08-06 14:10:56 +0200 | [diff] [blame] | 172 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 173 | burst_type b_type = d_channel_conf.get_burst_type(d_burst_nr); |
| 174 | if (d_state == synchronized && b_type == fcch_burst){ |
| 175 | uint64_t last_sample_nr = |
| 176 | ceil((GUARD_PERIOD + 2.0 * TAIL_BITS + 156.25) * d_OSR) + 1; |
| 177 | d_freq_offset_tag_in_fcch = tag_offset < last_sample_nr; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 178 | } |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 179 | } |
Piotr Krysik | df97869 | 2017-09-27 21:58:24 +0200 | [diff] [blame] | 180 | |
| 181 | /* Obtaining current time with use of rx_time tag provided i.e. by UHD devices */ |
| 182 | /* And storing it in time_sample_ref for sample number to time conversion */ |
| 183 | std::vector<tag_t> rx_time_tags; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 184 | |
| 185 | /* Main state machine */ |
Piotr Krysik | 96f2ea7 | 2017-10-16 15:47:08 +0200 | [diff] [blame] | 186 | d_samples_consumed = 0; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 187 | switch (d_state) { |
| 188 | case fcch_search: |
| 189 | fcch_search_handler(input, noutput_items); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 190 | break; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 191 | case sch_search: |
| 192 | sch_search_handler(input, noutput_items); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 193 | break; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 194 | case synchronized: |
| 195 | synchronized_handler(input, input_items, noutput_items); |
| 196 | break; |
| 197 | } |
| 198 | |
Piotr Krysik | 96f2ea7 | 2017-10-16 15:47:08 +0200 | [diff] [blame] | 199 | get_tags_in_window(rx_time_tags, 0, 0, d_samples_consumed, pmt::string_to_symbol("rx_time")); |
| 200 | if(!rx_time_tags.empty()){ |
| 201 | d_rx_time_received = true; |
| 202 | tag_t rx_time_tag = *(rx_time_tags.begin()); |
| 203 | |
| 204 | uint64_t rx_time_full_part = to_uint64(tuple_ref(rx_time_tag.value,0)); |
| 205 | double rx_time_frac_part = to_double(tuple_ref(rx_time_tag.value,1)); |
| 206 | |
| 207 | time_spec_t current_rx_time = time_spec_t(rx_time_full_part, rx_time_frac_part); |
| 208 | uint64_t current_start_offset = rx_time_tag.offset; |
| 209 | d_time_samp_ref.update(current_rx_time, current_start_offset); |
Piotr Krysik | 96f2ea7 | 2017-10-16 15:47:08 +0200 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | return d_samples_consumed; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 213 | } |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 214 | |
| 215 | void |
| 216 | receiver_impl::fcch_search_handler(gr_complex *input, int noutput_items) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 217 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 218 | double freq_offset_tmp; |
ptrkrysik | 5821379 | 2014-10-30 09:05:15 +0100 | [diff] [blame] | 219 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 220 | /* Check if received samples is a FCCN burst */ |
| 221 | if (!find_fcch_burst(input, noutput_items, freq_offset_tmp)) |
| 222 | return; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 223 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 224 | /* We found it, compose a message */ |
| 225 | pmt::pmt_t msg = pmt::make_tuple( |
| 226 | pmt::mp("freq_offset"), |
| 227 | pmt::from_double(freq_offset_tmp - d_freq_offset_setting), |
| 228 | pmt::mp("fcch_search") |
| 229 | ); |
Piotr Krysik | 9bc0fc0 | 2017-01-18 21:53:17 +0100 | [diff] [blame] | 230 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 231 | /* Notify FCCH loop */ |
| 232 | message_port_pub(pmt::mp("measurements"), msg); |
| 233 | |
| 234 | /* Update current state */ |
| 235 | d_state = sch_search; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 236 | } |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 237 | |
| 238 | void |
| 239 | receiver_impl::sch_search_handler(gr_complex *input, int noutput_items) |
| 240 | { |
| 241 | std::vector<gr_complex> channel_imp_resp(CHAN_IMP_RESP_LENGTH * d_OSR); |
| 242 | unsigned char burst_buf[BURST_SIZE]; |
| 243 | int rc, t1, t2, t3; |
| 244 | int burst_start; |
| 245 | |
| 246 | /* Wait until we get a SCH burst */ |
| 247 | if (!reach_sch_burst(noutput_items)) |
| 248 | return; |
| 249 | |
| 250 | /* Get channel impulse response from it */ |
| 251 | burst_start = get_sch_chan_imp_resp(input, &channel_imp_resp[0]); |
| 252 | |
| 253 | /* Detect bits using MLSE detection */ |
| 254 | detect_burst(input, &channel_imp_resp[0], burst_start, burst_buf); |
| 255 | |
| 256 | /* Attempt to decode BSIC and frame number */ |
| 257 | rc = decode_sch(&burst_buf[3], &t1, &t2, &t3, &d_ncc, &d_bcc); |
| 258 | if (rc) { |
| 259 | /** |
| 260 | * There is error in the SCH burst, |
| 261 | * go back to the FCCH search state |
| 262 | */ |
| 263 | d_state = fcch_search; |
| 264 | return; |
| 265 | } |
| 266 | |
| 267 | /* Set counter of bursts value */ |
| 268 | d_burst_nr.set(t1, t2, t3, 0); |
| 269 | d_burst_nr++; |
| 270 | |
| 271 | /* Consume samples up to the next guard period */ |
Piotr Krysik | 96f2ea7 | 2017-10-16 15:47:08 +0200 | [diff] [blame] | 272 | unsigned int to_consume = burst_start + BURST_SIZE * d_OSR + 4 * d_OSR; |
| 273 | // consume_each(to_consume); |
| 274 | d_samples_consumed += to_consume; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 275 | |
| 276 | /* Update current state */ |
| 277 | d_state = synchronized; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 278 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 279 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 280 | void |
| 281 | receiver_impl::synchronized_handler(gr_complex *input, |
| 282 | gr_vector_const_void_star &input_items, int noutput_items) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 283 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 284 | /** |
| 285 | * In this state receiver is synchronized and it processes |
| 286 | * bursts according to burst type for given burst number |
| 287 | */ |
| 288 | std::vector<gr_complex> channel_imp_resp(CHAN_IMP_RESP_LENGTH * d_OSR); |
Piotr Krysik | 3b11689 | 2018-02-27 08:43:30 +0100 | [diff] [blame] | 289 | size_t inputs_to_process = d_cell_allocation.size(); |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 290 | unsigned char output_binary[BURST_SIZE]; |
| 291 | burst_type b_type; |
| 292 | int to_consume = 0; |
| 293 | int offset = 0; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 294 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 295 | if (d_process_uplink) |
| 296 | inputs_to_process *= 2; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 297 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 298 | /* Process all connected inputs */ |
Piotr Krysik | 3b11689 | 2018-02-27 08:43:30 +0100 | [diff] [blame] | 299 | for (size_t input_nr = 0; input_nr < inputs_to_process; input_nr++) { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 300 | input = (gr_complex *) input_items[input_nr]; |
| 301 | double signal_pwr = 0; |
| 302 | |
| 303 | for (int ii = GUARD_PERIOD; ii < TS_BITS; ii++) |
| 304 | signal_pwr += abs(input[ii]) * abs(input[ii]); |
| 305 | |
| 306 | signal_pwr = signal_pwr / (TS_BITS); |
| 307 | d_signal_dbm = round(10 * log10(signal_pwr / 50)); |
| 308 | |
| 309 | if (input_nr == 0) |
| 310 | d_c0_signal_dbm = d_signal_dbm; |
| 311 | |
| 312 | /* Get burst type for given burst number */ |
| 313 | b_type = input_nr == 0 ? |
| 314 | d_channel_conf.get_burst_type(d_burst_nr) : normal_or_noise; |
| 315 | |
| 316 | /* Process burst according to its type */ |
| 317 | switch (b_type) { |
| 318 | case fcch_burst: |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 319 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 320 | if (d_freq_offset_tag_in_fcch) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 321 | break; |
| 322 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 323 | /* Send all-zero sequence message */ |
| 324 | send_burst(d_burst_nr, fc_fb, GSMTAP_BURST_FCCH, input_nr); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 325 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 326 | /* Extract frequency offset */ |
| 327 | const unsigned first_sample = |
| 328 | ceil((GUARD_PERIOD + 2 * TAIL_BITS) * d_OSR) + 1; |
| 329 | const unsigned last_sample = |
| 330 | first_sample + USEFUL_BITS * d_OSR - TAIL_BITS * d_OSR; |
| 331 | double freq_offset_tmp = |
| 332 | compute_freq_offset(input, first_sample, last_sample); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 333 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 334 | /* Frequency correction loop */ |
| 335 | pmt::pmt_t msg = pmt::make_tuple( |
| 336 | pmt::mp("freq_offset"), |
| 337 | pmt::from_double(freq_offset_tmp - d_freq_offset_setting), |
| 338 | pmt::mp("synchronized")); |
| 339 | message_port_pub(pmt::mp("measurements"), msg); |
| 340 | |
| 341 | break; |
| 342 | } |
| 343 | |
| 344 | case sch_burst: |
| 345 | { |
Piotr Krysik | bfb47dc | 2017-11-11 11:12:02 +0100 | [diff] [blame] | 346 | int ncc, bcc; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 347 | int t1, t2, t3; |
| 348 | int rc; |
| 349 | |
| 350 | /* Get channel impulse response */ |
| 351 | d_c0_burst_start = get_sch_chan_imp_resp(input, |
| 352 | &channel_imp_resp[0]); |
| 353 | |
| 354 | /* Perform MLSE detection */ |
| 355 | detect_burst(input, &channel_imp_resp[0], |
| 356 | d_c0_burst_start, output_binary); |
| 357 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 358 | /* Attempt to decode SCH burst */ |
Piotr Krysik | bfb47dc | 2017-11-11 11:12:02 +0100 | [diff] [blame] | 359 | rc = decode_sch(&output_binary[3], &t1, &t2, &t3, &ncc, &bcc); |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 360 | if (rc) { |
| 361 | if (++d_failed_sch >= MAX_SCH_ERRORS) { |
| 362 | /* We have to resynchronize, change state */ |
| 363 | d_state = fcch_search; |
| 364 | |
| 365 | /* Frequency correction loop */ |
| 366 | pmt::pmt_t msg = pmt::make_tuple(pmt::mp("freq_offset"), |
| 367 | pmt::from_double(0.0),pmt::mp("sync_loss")); |
| 368 | message_port_pub(pmt::mp("measurements"), msg); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | break; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 372 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 373 | |
Piotr Krysik | bfb47dc | 2017-11-11 11:12:02 +0100 | [diff] [blame] | 374 | /* Compose a message with GSMTAP header and bits */ |
| 375 | send_burst(d_burst_nr, output_binary, |
| 376 | GSMTAP_BURST_SCH, input_nr, d_c0_burst_start); |
| 377 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 378 | /** |
| 379 | * Decoding was successful, now |
| 380 | * compute offset from burst_start, |
| 381 | * burst should start after a guard period. |
| 382 | */ |
| 383 | offset = d_c0_burst_start - floor((GUARD_PERIOD) * d_OSR); |
| 384 | to_consume += offset; |
| 385 | d_failed_sch = 0; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 386 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 387 | break; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 388 | } |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 389 | |
| 390 | case normal_burst: |
| 391 | { |
| 392 | float normal_corr_max; |
| 393 | /** |
| 394 | * Get channel impulse response for given |
| 395 | * training sequence number - d_bcc |
| 396 | */ |
| 397 | d_c0_burst_start = get_norm_chan_imp_resp(input, |
| 398 | &channel_imp_resp[0], &normal_corr_max, d_bcc); |
| 399 | |
| 400 | /* Perform MLSE detection */ |
| 401 | detect_burst(input, &channel_imp_resp[0], |
| 402 | d_c0_burst_start, output_binary); |
| 403 | |
| 404 | /* Compose a message with GSMTAP header and bits */ |
| 405 | send_burst(d_burst_nr, output_binary, |
Piotr Krysik | df97869 | 2017-09-27 21:58:24 +0200 | [diff] [blame] | 406 | GSMTAP_BURST_NORMAL, input_nr, d_c0_burst_start); |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 407 | |
| 408 | break; |
| 409 | } |
| 410 | |
| 411 | case dummy_or_normal: |
| 412 | { |
| 413 | unsigned int normal_burst_start, dummy_burst_start; |
| 414 | float dummy_corr_max, normal_corr_max; |
| 415 | |
| 416 | dummy_burst_start = get_norm_chan_imp_resp(input, |
| 417 | &channel_imp_resp[0], &dummy_corr_max, TS_DUMMY); |
| 418 | normal_burst_start = get_norm_chan_imp_resp(input, |
| 419 | &channel_imp_resp[0], &normal_corr_max, d_bcc); |
| 420 | |
| 421 | if (normal_corr_max > dummy_corr_max) { |
| 422 | d_c0_burst_start = normal_burst_start; |
| 423 | |
| 424 | /* Perform MLSE detection */ |
| 425 | detect_burst(input, &channel_imp_resp[0], |
| 426 | normal_burst_start, output_binary); |
| 427 | |
| 428 | /* Compose a message with GSMTAP header and bits */ |
| 429 | send_burst(d_burst_nr, output_binary, |
Piotr Krysik | df97869 | 2017-09-27 21:58:24 +0200 | [diff] [blame] | 430 | GSMTAP_BURST_NORMAL, input_nr, normal_burst_start); |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 431 | } else { |
| 432 | d_c0_burst_start = dummy_burst_start; |
| 433 | |
| 434 | /* Compose a message with GSMTAP header and bits */ |
| 435 | send_burst(d_burst_nr, dummy_burst, |
Piotr Krysik | df97869 | 2017-09-27 21:58:24 +0200 | [diff] [blame] | 436 | GSMTAP_BURST_DUMMY, input_nr, dummy_burst_start); |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | break; |
| 440 | } |
| 441 | |
| 442 | case normal_or_noise: |
| 443 | { |
| 444 | std::vector<gr_complex> v(input, input + noutput_items); |
| 445 | float normal_corr_max = -1e6; |
Piotr Krysik | 3b11689 | 2018-02-27 08:43:30 +0100 | [diff] [blame] | 446 | // float normal_corr_max_tmp; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 447 | unsigned int burst_start; |
| 448 | int max_tn, tseq_num; |
| 449 | |
| 450 | if (d_tseq_nums.size() == 0) { |
| 451 | /** |
| 452 | * There is no information about training sequence, |
| 453 | * however the receiver can detect it with use of a |
| 454 | * very simple algorithm based on finding |
| 455 | */ |
| 456 | get_norm_chan_imp_resp(input, &channel_imp_resp[0], |
| 457 | &normal_corr_max, 0); |
| 458 | |
| 459 | float ts_max = normal_corr_max; |
| 460 | int ts_max_num = 0; |
| 461 | |
| 462 | for (int ss = 1; ss <= 7; ss++) { |
| 463 | get_norm_chan_imp_resp(input, &channel_imp_resp[0], |
| 464 | &normal_corr_max, ss); |
| 465 | |
| 466 | if (ts_max < normal_corr_max) { |
| 467 | ts_max = normal_corr_max; |
| 468 | ts_max_num = ss; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | d_tseq_nums.push_back(ts_max_num); |
| 473 | } |
| 474 | |
| 475 | /* Choose proper training sequence number */ |
| 476 | tseq_num = input_nr <= d_tseq_nums.size() ? |
| 477 | d_tseq_nums[input_nr - 1] : d_tseq_nums.back(); |
| 478 | |
| 479 | /* Get channel impulse response */ |
| 480 | burst_start = get_norm_chan_imp_resp(input, &channel_imp_resp[0], |
| 481 | &normal_corr_max, tseq_num); |
| 482 | |
| 483 | /* Perform MLSE detection */ |
| 484 | detect_burst(input, &channel_imp_resp[0], |
| 485 | burst_start, output_binary); |
| 486 | |
| 487 | /* Compose a message with GSMTAP header and bits */ |
Piotr Krysik | df97869 | 2017-09-27 21:58:24 +0200 | [diff] [blame] | 488 | send_burst(d_burst_nr, output_binary, GSMTAP_BURST_NORMAL, input_nr, burst_start); |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 489 | |
| 490 | break; |
| 491 | } |
| 492 | |
| 493 | case dummy: |
| 494 | send_burst(d_burst_nr, dummy_burst, GSMTAP_BURST_DUMMY, input_nr); |
| 495 | break; |
| 496 | |
| 497 | case rach_burst: |
| 498 | case empty: |
| 499 | /* Do nothing */ |
| 500 | break; |
| 501 | } |
| 502 | |
| 503 | if (input_nr == input_items.size() - 1) { |
| 504 | /* Go to the next burst */ |
| 505 | d_burst_nr++; |
| 506 | |
| 507 | /* Consume samples of the burst up to next guard period */ |
| 508 | to_consume += TS_BITS * d_OSR + d_burst_nr.get_offset(); |
Piotr Krysik | 96f2ea7 | 2017-10-16 15:47:08 +0200 | [diff] [blame] | 509 | // consume_each(to_consume); |
| 510 | d_samples_consumed += to_consume; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | bool |
| 516 | receiver_impl::find_fcch_burst(const gr_complex *input, |
| 517 | const int nitems, double &computed_freq_offset) |
| 518 | { |
| 519 | /* Circular buffer used to scan through signal to find */ |
| 520 | boost::circular_buffer<float> |
| 521 | phase_diff_buffer(FCCH_HITS_NEEDED * d_OSR); |
| 522 | boost::circular_buffer<float>::iterator buffer_iter; |
| 523 | |
| 524 | float lowest_max_min_diff; |
| 525 | float phase_diff; /* Best match for FCCH burst */ |
| 526 | float min_phase_diff; |
| 527 | float max_phase_diff; |
| 528 | double best_sum = 0; |
| 529 | gr_complex conjprod; |
| 530 | int start_pos; |
| 531 | int hit_count; |
| 532 | int miss_count; |
| 533 | |
| 534 | int sample_number = 0; |
| 535 | int to_consume = 0; |
| 536 | bool result = false; |
| 537 | bool end = false; |
| 538 | |
| 539 | /* Possible states of FCCH search algorithm */ |
| 540 | enum states |
| 541 | { |
| 542 | init, /* initialize variables */ |
| 543 | search, /* search for positive samples */ |
| 544 | found_something, /* search for FCCH and the best position of it */ |
| 545 | fcch_found, /* when FCCH was found */ |
| 546 | search_fail /* when there is no FCCH in the input vector */ |
| 547 | } fcch_search_state; |
| 548 | |
| 549 | /* Set initial state */ |
| 550 | fcch_search_state = init; |
| 551 | |
| 552 | while (!end) |
| 553 | { |
| 554 | switch (fcch_search_state) { |
| 555 | case init: |
| 556 | { |
| 557 | hit_count = 0; |
| 558 | miss_count = 0; |
| 559 | start_pos = -1; |
| 560 | lowest_max_min_diff = 99999; |
| 561 | phase_diff_buffer.clear(); |
| 562 | |
| 563 | /* Change current state */ |
| 564 | fcch_search_state = search; |
| 565 | |
| 566 | break; |
| 567 | } |
| 568 | |
| 569 | case search: |
| 570 | { |
| 571 | sample_number++; |
| 572 | |
| 573 | if (sample_number > nitems - FCCH_HITS_NEEDED * d_OSR) { |
| 574 | /** |
| 575 | * If it isn't possible to find FCCH, because |
| 576 | * there is too few samples left to look into, |
| 577 | * don't do anything with those samples which are left |
| 578 | * and consume only those which were checked |
| 579 | */ |
| 580 | to_consume = sample_number; |
| 581 | fcch_search_state = search_fail; |
| 582 | break; |
| 583 | } |
| 584 | |
| 585 | phase_diff = compute_phase_diff(input[sample_number], |
| 586 | input[sample_number - 1]); |
| 587 | |
| 588 | /** |
| 589 | * If a positive phase difference was found |
| 590 | * switch to state in which searches for FCCH |
| 591 | */ |
| 592 | if (phase_diff > 0) { |
| 593 | to_consume = sample_number; |
| 594 | fcch_search_state = found_something; |
| 595 | } else { |
| 596 | fcch_search_state = search; |
| 597 | } |
| 598 | |
| 599 | break; |
| 600 | } |
| 601 | |
| 602 | case found_something: |
| 603 | { |
| 604 | if (phase_diff > 0) |
| 605 | hit_count++; |
| 606 | else |
| 607 | miss_count++; |
| 608 | |
| 609 | if ((miss_count >= FCCH_MAX_MISSES * d_OSR) |
| 610 | && (hit_count <= FCCH_HITS_NEEDED * d_OSR)) |
| 611 | { |
| 612 | /* If miss_count exceeds limit before hit_count */ |
| 613 | fcch_search_state = init; |
| 614 | continue; |
| 615 | } |
| 616 | |
| 617 | if (((miss_count >= FCCH_MAX_MISSES * d_OSR) |
| 618 | && (hit_count > FCCH_HITS_NEEDED * d_OSR)) |
| 619 | || (hit_count > 2 * FCCH_HITS_NEEDED * d_OSR)) |
| 620 | { |
| 621 | /** |
| 622 | * If hit_count and miss_count exceeds |
| 623 | * limit then FCCH was found |
| 624 | */ |
| 625 | fcch_search_state = fcch_found; |
| 626 | continue; |
| 627 | } |
| 628 | |
| 629 | if ((miss_count < FCCH_MAX_MISSES * d_OSR) |
| 630 | && (hit_count > FCCH_HITS_NEEDED * d_OSR)) |
| 631 | { |
| 632 | /** |
| 633 | * Find difference between minimal and maximal |
| 634 | * element in the buffer. For FCCH this value |
| 635 | * should be low. This part is searching for |
| 636 | * a region where this value is lowest. |
| 637 | */ |
| 638 | min_phase_diff = *(min_element(phase_diff_buffer.begin(), |
| 639 | phase_diff_buffer.end())); |
| 640 | max_phase_diff = *(max_element(phase_diff_buffer.begin(), |
| 641 | phase_diff_buffer.end())); |
| 642 | |
| 643 | if (lowest_max_min_diff > max_phase_diff - min_phase_diff) { |
| 644 | lowest_max_min_diff = max_phase_diff - min_phase_diff; |
| 645 | start_pos = sample_number - FCCH_HITS_NEEDED |
| 646 | * d_OSR - FCCH_MAX_MISSES * d_OSR; |
| 647 | best_sum = 0; |
| 648 | |
| 649 | for (buffer_iter = phase_diff_buffer.begin(); |
| 650 | buffer_iter != (phase_diff_buffer.end()); |
| 651 | buffer_iter++) { |
| 652 | /* Store best value of phase offset sum */ |
| 653 | best_sum += *buffer_iter - (M_PI / 2) / d_OSR; |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | /* If there is no single sample left to check */ |
| 659 | if (++sample_number >= nitems) { |
| 660 | fcch_search_state = search_fail; |
| 661 | continue; |
| 662 | } |
| 663 | |
| 664 | phase_diff = compute_phase_diff(input[sample_number], |
| 665 | input[sample_number-1]); |
| 666 | phase_diff_buffer.push_back(phase_diff); |
| 667 | fcch_search_state = found_something; |
| 668 | |
| 669 | break; |
| 670 | } |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 671 | |
| 672 | case fcch_found: |
| 673 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 674 | /* Consume one FCCH burst */ |
| 675 | to_consume = start_pos + FCCH_HITS_NEEDED * d_OSR + 1; |
| 676 | d_fcch_start_pos = d_counter + start_pos; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 677 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 678 | /** |
| 679 | * Compute frequency offset |
| 680 | * |
| 681 | * 1625000.0 / 6 - GMSK symbol rate in GSM |
| 682 | */ |
| 683 | double phase_offset = best_sum / FCCH_HITS_NEEDED; |
| 684 | double freq_offset = phase_offset * 1625000.0 / 6 / (2 * M_PI); |
| 685 | computed_freq_offset = freq_offset; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 686 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 687 | end = true; |
| 688 | result = true; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 689 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 690 | break; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 691 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 692 | |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 693 | case search_fail: |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 694 | end = true; |
| 695 | result = false; |
| 696 | break; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 697 | } |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | d_counter += to_consume; |
Piotr Krysik | 96f2ea7 | 2017-10-16 15:47:08 +0200 | [diff] [blame] | 701 | // consume_each(to_consume); |
| 702 | d_samples_consumed += to_consume; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 703 | |
| 704 | return result; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 705 | } |
| 706 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 707 | double |
| 708 | receiver_impl::compute_freq_offset(const gr_complex * input, |
| 709 | unsigned first_sample, unsigned last_sample) |
Piotr Krysik | 654d652 | 2017-01-23 21:53:48 +0100 | [diff] [blame] | 710 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 711 | double phase_sum = 0; |
| 712 | unsigned ii; |
| 713 | |
| 714 | for (ii = first_sample; ii < last_sample; ii++) |
| 715 | { |
| 716 | double phase_diff = compute_phase_diff(input[ii], |
| 717 | input[ii-1]) - (M_PI / 2) / d_OSR; |
Piotr Krysik | 654d652 | 2017-01-23 21:53:48 +0100 | [diff] [blame] | 718 | phase_sum += phase_diff; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | double phase_offset = phase_sum / (last_sample - first_sample); |
| 722 | double freq_offset = phase_offset * 1625000.0 / (12.0 * M_PI); |
| 723 | |
| 724 | return freq_offset; |
Piotr Krysik | 654d652 | 2017-01-23 21:53:48 +0100 | [diff] [blame] | 725 | } |
| 726 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 727 | inline float |
| 728 | receiver_impl::compute_phase_diff(gr_complex val1, gr_complex val2) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 729 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 730 | gr_complex conjprod = val1 * conj(val2); |
| 731 | return fast_atan2f(imag(conjprod), real(conjprod)); |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 732 | } |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 733 | |
| 734 | bool |
| 735 | receiver_impl::reach_sch_burst(const int nitems) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 736 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 737 | /* It just consumes samples to get near to a SCH burst */ |
| 738 | int to_consume = 0; |
| 739 | bool result = false; |
| 740 | unsigned sample_nr = d_fcch_start_pos |
| 741 | + (FRAME_BITS - SAFETY_MARGIN) * d_OSR; |
| 742 | |
| 743 | /* Consume samples until d_counter will be equal to sample_nr */ |
| 744 | if (d_counter < sample_nr) { |
| 745 | to_consume = d_counter + nitems >= sample_nr ? |
| 746 | sample_nr - d_counter : nitems; |
| 747 | } else { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 748 | to_consume = 0; |
| 749 | result = true; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | d_counter += to_consume; |
Piotr Krysik | 96f2ea7 | 2017-10-16 15:47:08 +0200 | [diff] [blame] | 753 | // consume_each(to_consume); |
| 754 | d_samples_consumed += to_consume; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 755 | |
| 756 | return result; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 757 | } |
| 758 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 759 | int |
| 760 | receiver_impl::get_sch_chan_imp_resp(const gr_complex *input, |
| 761 | gr_complex * chan_imp_resp) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 762 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 763 | std::vector<gr_complex> correlation_buffer; |
| 764 | std::vector<float> window_energy_buffer; |
| 765 | std::vector<float> power_buffer; |
| 766 | |
| 767 | int chan_imp_resp_center = 0; |
| 768 | int strongest_window_nr; |
| 769 | int burst_start; |
| 770 | float energy = 0; |
| 771 | |
| 772 | int len = (SYNC_POS + SYNC_SEARCH_RANGE) * d_OSR; |
| 773 | for (int ii = SYNC_POS * d_OSR; ii < len; ii++) { |
| 774 | gr_complex correlation = correlate_sequence(&d_sch_training_seq[5], |
| 775 | N_SYNC_BITS - 10, &input[ii]); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 776 | correlation_buffer.push_back(correlation); |
| 777 | power_buffer.push_back(std::pow(abs(correlation), 2)); |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | /* Compute window energies */ |
| 781 | std::vector<float>::iterator iter = power_buffer.begin(); |
| 782 | while (iter != power_buffer.end()) { |
ptrkrysik | ef5e2db | 2015-01-03 12:10:14 +0100 | [diff] [blame] | 783 | std::vector<float>::iterator iter_ii = iter; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 784 | bool loop_end = false; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 785 | energy = 0; |
| 786 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 787 | for (int ii = 0; ii < (d_chan_imp_length) * d_OSR; ii++, iter_ii++) { |
| 788 | if (iter_ii == power_buffer.end()) { |
| 789 | loop_end = true; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 790 | break; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | energy += (*iter_ii); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 794 | } |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 795 | |
| 796 | if (loop_end) |
| 797 | break; |
| 798 | |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 799 | window_energy_buffer.push_back(energy); |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 800 | iter++; |
| 801 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 802 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 803 | strongest_window_nr = max_element(window_energy_buffer.begin(), |
| 804 | window_energy_buffer.end()) - window_energy_buffer.begin(); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 805 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 806 | #if 0 |
| 807 | d_channel_imp_resp.clear(); |
| 808 | #endif |
| 809 | |
| 810 | float max_correlation = 0; |
| 811 | for (int ii = 0; ii < (d_chan_imp_length) * d_OSR; ii++) { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 812 | gr_complex correlation = correlation_buffer[strongest_window_nr + ii]; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 813 | if (abs(correlation) > max_correlation) { |
| 814 | chan_imp_resp_center = ii; |
| 815 | max_correlation = abs(correlation); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 816 | } |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 817 | |
| 818 | #if 0 |
| 819 | d_channel_imp_resp.push_back(correlation); |
| 820 | #endif |
| 821 | |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 822 | chan_imp_resp[ii] = correlation; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | burst_start = strongest_window_nr + chan_imp_resp_center |
| 826 | - 48 * d_OSR - 2 * d_OSR + 2 + SYNC_POS * d_OSR; |
| 827 | return burst_start; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 828 | } |
| 829 | |
| 830 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 831 | void |
| 832 | receiver_impl::detect_burst(const gr_complex * input, |
| 833 | gr_complex * chan_imp_resp, int burst_start, |
| 834 | unsigned char * output_binary) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 835 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 836 | std::vector<gr_complex> rhh_temp(CHAN_IMP_RESP_LENGTH * d_OSR); |
| 837 | unsigned int stop_states[2] = {4, 12}; |
| 838 | gr_complex filtered_burst[BURST_SIZE]; |
| 839 | gr_complex rhh[CHAN_IMP_RESP_LENGTH]; |
| 840 | float output[BURST_SIZE]; |
| 841 | int start_state = 3; |
| 842 | |
| 843 | autocorrelation(chan_imp_resp, &rhh_temp[0], d_chan_imp_length*d_OSR); |
| 844 | for (int ii = 0; ii < d_chan_imp_length; ii++) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 845 | rhh[ii] = conj(rhh_temp[ii*d_OSR]); |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 846 | |
| 847 | mafi(&input[burst_start], BURST_SIZE, chan_imp_resp, |
| 848 | d_chan_imp_length * d_OSR, filtered_burst); |
| 849 | |
| 850 | viterbi_detector(filtered_burst, BURST_SIZE, rhh, |
| 851 | start_state, stop_states, 2, output); |
| 852 | |
| 853 | for (int i = 0; i < BURST_SIZE; i++) |
| 854 | output_binary[i] = output[i] > 0; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 855 | } |
| 856 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 857 | void |
| 858 | receiver_impl::gmsk_mapper(const unsigned char * input, |
| 859 | int nitems, gr_complex * gmsk_output, gr_complex start_point) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 860 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 861 | gr_complex j = gr_complex(0.0, 1.0); |
| 862 | gmsk_output[0] = start_point; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 863 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 864 | int previous_symbol = 2 * input[0] - 1; |
| 865 | int current_symbol; |
| 866 | int encoded_symbol; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 867 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 868 | for (int i = 1; i < nitems; i++) { |
| 869 | /* Change bits representation to NRZ */ |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 870 | current_symbol = 2 * input[i] - 1; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 871 | |
| 872 | /* Differentially encode */ |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 873 | encoded_symbol = current_symbol * previous_symbol; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 874 | |
| 875 | /* And do GMSK mapping */ |
| 876 | gmsk_output[i] = j * gr_complex(encoded_symbol, 0.0) |
| 877 | * gmsk_output[i-1]; |
| 878 | |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 879 | previous_symbol = current_symbol; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 880 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 881 | } |
| 882 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 883 | gr_complex |
| 884 | receiver_impl::correlate_sequence(const gr_complex * sequence, |
| 885 | int length, const gr_complex * input) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 886 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 887 | gr_complex result(0.0, 0.0); |
| 888 | |
| 889 | for (int ii = 0; ii < length; ii++) |
| 890 | result += sequence[ii] * conj(input[ii * d_OSR]); |
| 891 | |
| 892 | return result / gr_complex(length, 0); |
| 893 | } |
| 894 | |
| 895 | /* Computes autocorrelation for positive arguments */ |
| 896 | inline void |
| 897 | receiver_impl::autocorrelation(const gr_complex * input, |
| 898 | gr_complex * out, int nitems) |
| 899 | { |
| 900 | for (int k = nitems - 1; k >= 0; k--) { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 901 | out[k] = gr_complex(0, 0); |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 902 | for (int i = k; i < nitems; i++) |
| 903 | out[k] += input[i] * conj(input[i - k]); |
| 904 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 905 | } |
| 906 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 907 | inline void |
| 908 | receiver_impl::mafi(const gr_complex * input, int nitems, |
| 909 | gr_complex * filter, int filter_length, gr_complex * output) |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 910 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 911 | for (int n = 0; n < nitems; n++) { |
| 912 | int a = n * d_OSR; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 913 | output[n] = 0; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 914 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 915 | for (int ii = 0; ii < filter_length; ii++) { |
| 916 | if ((a + ii) >= nitems * d_OSR) |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 917 | break; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 918 | |
| 919 | output[n] += input[a + ii] * filter[ii]; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 920 | } |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | |
| 924 | /* Especially computations of strongest_window_nr */ |
| 925 | int |
| 926 | receiver_impl::get_norm_chan_imp_resp(const gr_complex *input, |
| 927 | gr_complex *chan_imp_resp, float *corr_max, int bcc) |
| 928 | { |
| 929 | std::vector<gr_complex> correlation_buffer; |
| 930 | std::vector<float> window_energy_buffer; |
| 931 | std::vector<float> power_buffer; |
| 932 | |
| 933 | int search_center = (int) (TRAIN_POS + GUARD_PERIOD) * d_OSR; |
| 934 | int search_start_pos = search_center + 1 - 5 * d_OSR; |
| 935 | int search_stop_pos = search_center |
| 936 | + d_chan_imp_length * d_OSR + 5 * d_OSR; |
| 937 | |
| 938 | for (int ii = search_start_pos; ii < search_stop_pos; ii++) { |
| 939 | gr_complex correlation = correlate_sequence( |
| 940 | &d_norm_training_seq[bcc][TRAIN_BEGINNING], |
| 941 | N_TRAIN_BITS - 10, &input[ii]); |
| 942 | correlation_buffer.push_back(correlation); |
| 943 | power_buffer.push_back(std::pow(abs(correlation), 2)); |
| 944 | } |
| 945 | |
| 946 | #if 0 |
| 947 | plot(power_buffer); |
| 948 | #endif |
| 949 | |
| 950 | /* Compute window energies */ |
| 951 | std::vector<float>::iterator iter = power_buffer.begin(); |
| 952 | while (iter != power_buffer.end()) { |
| 953 | std::vector<float>::iterator iter_ii = iter; |
| 954 | bool loop_end = false; |
| 955 | float energy = 0; |
| 956 | |
| 957 | int len = d_chan_imp_length * d_OSR; |
| 958 | for (int ii = 0; ii < len; ii++, iter_ii++) { |
| 959 | if (iter_ii == power_buffer.end()) { |
| 960 | loop_end = true; |
| 961 | break; |
| 962 | } |
| 963 | |
| 964 | energy += (*iter_ii); |
| 965 | } |
| 966 | |
| 967 | if (loop_end) |
| 968 | break; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 969 | |
| 970 | window_energy_buffer.push_back(energy); |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 971 | iter++; |
| 972 | } |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 973 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 974 | /* Calculate the strongest window number */ |
| 975 | int strongest_window_nr = max_element(window_energy_buffer.begin(), |
| 976 | window_energy_buffer.end() - d_chan_imp_length * d_OSR) |
| 977 | - window_energy_buffer.begin(); |
| 978 | |
| 979 | if (strongest_window_nr < 0) |
| 980 | strongest_window_nr = 0; |
| 981 | |
| 982 | float max_correlation = 0; |
| 983 | for (int ii = 0; ii < d_chan_imp_length * d_OSR; ii++) { |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 984 | gr_complex correlation = correlation_buffer[strongest_window_nr + ii]; |
piotr | d0bf149 | 2014-02-05 17:27:32 +0100 | [diff] [blame] | 985 | if (abs(correlation) > max_correlation) |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 986 | max_correlation = abs(correlation); |
| 987 | |
| 988 | #if 0 |
| 989 | d_channel_imp_resp.push_back(correlation); |
| 990 | #endif |
| 991 | |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 992 | chan_imp_resp[ii] = correlation; |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | *corr_max = max_correlation; |
| 996 | |
| 997 | /** |
| 998 | * Compute first sample position, which corresponds |
| 999 | * to the first sample of the impulse response |
| 1000 | */ |
| 1001 | return search_start_pos + strongest_window_nr - TRAIN_POS * d_OSR; |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1005 | void |
| 1006 | receiver_impl::send_burst(burst_counter burst_nr, |
| 1007 | const unsigned char * burst_binary, uint8_t burst_type, |
Piotr Krysik | 8a8d41a | 2018-04-16 22:21:29 +0200 | [diff] [blame] | 1008 | size_t input_nr, unsigned int burst_start) |
ptrkrysik | 380dea8 | 2015-08-06 10:11:58 +0200 | [diff] [blame] | 1009 | { |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1010 | /* Buffer for GSMTAP header and burst */ |
| 1011 | uint8_t buf[sizeof(gsmtap_hdr) + BURST_SIZE]; |
| 1012 | uint32_t frame_number; |
| 1013 | uint16_t arfcn; |
| 1014 | uint8_t tn; |
ptrkrysik | 617ba03 | 2014-11-21 10:11:05 +0100 | [diff] [blame] | 1015 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1016 | /* Set pointers to GSMTAP header and burst inside buffer */ |
| 1017 | struct gsmtap_hdr *tap_header = (struct gsmtap_hdr *) buf; |
| 1018 | uint8_t *burst = buf + sizeof(gsmtap_hdr); |
| 1019 | |
| 1020 | tap_header->version = GSMTAP_VERSION; |
| 1021 | tap_header->hdr_len = sizeof(gsmtap_hdr) / 4; |
| 1022 | tap_header->type = GSMTAP_TYPE_UM_BURST; |
| 1023 | tap_header->sub_type = burst_type; |
| 1024 | |
| 1025 | bool dl_burst = !(input_nr >= d_cell_allocation.size()); |
| 1026 | if (dl_burst) { |
| 1027 | tn = static_cast<uint8_t>(d_burst_nr.get_timeslot_nr()); |
| 1028 | frame_number = htobe32(d_burst_nr.get_frame_nr()); |
| 1029 | arfcn = htobe16(d_cell_allocation[input_nr]); |
| 1030 | } else { |
| 1031 | input_nr -= d_cell_allocation.size(); |
| 1032 | tn = static_cast<uint8_t> |
| 1033 | (d_burst_nr.subtract_timeslots(3).get_timeslot_nr()); |
| 1034 | frame_number = htobe32( |
| 1035 | d_burst_nr.subtract_timeslots(3).get_frame_nr()); |
| 1036 | arfcn = htobe16( |
| 1037 | d_cell_allocation[input_nr] | GSMTAP_ARFCN_F_UPLINK); |
| 1038 | } |
| 1039 | |
| 1040 | tap_header->frame_number = frame_number; |
| 1041 | tap_header->timeslot = tn; |
| 1042 | tap_header->arfcn = arfcn; |
| 1043 | |
| 1044 | tap_header->signal_dbm = static_cast<int8_t>(d_signal_dbm); |
| 1045 | tap_header->snr_db = 0; /* FIXME: Can we calculate this? */ |
| 1046 | |
Piotr Krysik | df97869 | 2017-09-27 21:58:24 +0200 | [diff] [blame] | 1047 | pmt::pmt_t pdu_header = pmt::make_dict(); |
| 1048 | |
| 1049 | /* Add timestamp of the first sample - if available */ |
| 1050 | if(d_rx_time_received) { |
| 1051 | time_spec_t time_spec_of_first_sample = d_time_samp_ref.offset_to_time(nitems_read(0)+burst_start); |
| 1052 | uint64_t full = time_spec_of_first_sample.get_full_secs(); |
| 1053 | double frac = time_spec_of_first_sample.get_frac_secs(); |
Piotr Krysik | 96f2ea7 | 2017-10-16 15:47:08 +0200 | [diff] [blame] | 1054 | pdu_header = |
| 1055 | pmt::dict_add(pdu_header, pmt::mp("fn_time"), |
| 1056 | pmt::cons( |
| 1057 | pmt::cons(pmt::from_uint64(be32toh(frame_number)), pmt::from_uint64(tn)), |
| 1058 | pmt::cons(pmt::from_uint64(full), pmt::from_double(frac)))); |
Piotr Krysik | df97869 | 2017-09-27 21:58:24 +0200 | [diff] [blame] | 1059 | } |
| 1060 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1061 | /* Copy burst to the buffer */ |
| 1062 | memcpy(burst, burst_binary, BURST_SIZE); |
| 1063 | |
| 1064 | /* Allocate a new message */ |
| 1065 | pmt::pmt_t blob = pmt::make_blob(buf, sizeof(gsmtap_hdr) + BURST_SIZE); |
Piotr Krysik | 96f2ea7 | 2017-10-16 15:47:08 +0200 | [diff] [blame] | 1066 | pmt::pmt_t msg = pmt::cons(pdu_header, blob); |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1067 | |
| 1068 | /* Send message */ |
| 1069 | if (input_nr == 0) |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 1070 | message_port_pub(pmt::mp("C0"), msg); |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1071 | else |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 1072 | message_port_pub(pmt::mp("CX"), msg); |
| 1073 | } |
piotr | 6d152d9 | 2014-02-21 00:02:44 +0100 | [diff] [blame] | 1074 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1075 | void |
| 1076 | receiver_impl::configure_receiver(void) |
| 1077 | { |
| 1078 | d_channel_conf.set_multiframe_type(TIMESLOT0, multiframe_51); |
| 1079 | d_channel_conf.set_burst_types(TIMESLOT0, TEST51, |
| 1080 | sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
| 1081 | d_channel_conf.set_burst_types(TIMESLOT0, TEST_CCH_FRAMES, |
| 1082 | sizeof(TEST_CCH_FRAMES) / sizeof(unsigned), dummy_or_normal); |
| 1083 | d_channel_conf.set_burst_types(TIMESLOT0, FCCH_FRAMES, |
| 1084 | sizeof(FCCH_FRAMES) / sizeof(unsigned), fcch_burst); |
| 1085 | d_channel_conf.set_burst_types(TIMESLOT0, SCH_FRAMES, |
| 1086 | sizeof(SCH_FRAMES) / sizeof(unsigned), sch_burst); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 1087 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1088 | d_channel_conf.set_multiframe_type(TIMESLOT1, multiframe_51); |
| 1089 | d_channel_conf.set_burst_types(TIMESLOT1, TEST51, |
| 1090 | sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 1091 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1092 | d_channel_conf.set_multiframe_type(TIMESLOT2, multiframe_51); |
| 1093 | d_channel_conf.set_burst_types(TIMESLOT2, TEST51, |
| 1094 | sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 1095 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1096 | d_channel_conf.set_multiframe_type(TIMESLOT3, multiframe_51); |
| 1097 | d_channel_conf.set_burst_types(TIMESLOT3, TEST51, |
| 1098 | sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
ptrkrysik | e518bbf | 2014-11-06 14:50:59 +0100 | [diff] [blame] | 1099 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1100 | d_channel_conf.set_multiframe_type(TIMESLOT4, multiframe_51); |
| 1101 | d_channel_conf.set_burst_types(TIMESLOT4, TEST51, |
| 1102 | sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
piotr | f2b6a1b | 2014-08-04 11:28:59 +0200 | [diff] [blame] | 1103 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1104 | d_channel_conf.set_multiframe_type(TIMESLOT5, multiframe_51); |
| 1105 | d_channel_conf.set_burst_types(TIMESLOT5, TEST51, |
| 1106 | sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 1107 | |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1108 | d_channel_conf.set_multiframe_type(TIMESLOT6, multiframe_51); |
| 1109 | d_channel_conf.set_burst_types(TIMESLOT6, TEST51, |
| 1110 | sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
| 1111 | |
| 1112 | d_channel_conf.set_multiframe_type(TIMESLOT7, multiframe_51); |
| 1113 | d_channel_conf.set_burst_types(TIMESLOT7, TEST51, |
| 1114 | sizeof(TEST51) / sizeof(unsigned), dummy_or_normal); |
| 1115 | } |
| 1116 | |
| 1117 | void |
| 1118 | receiver_impl::set_cell_allocation( |
| 1119 | const std::vector<int> &cell_allocation) |
| 1120 | { |
| 1121 | d_cell_allocation = cell_allocation; |
| 1122 | } |
| 1123 | |
| 1124 | void |
| 1125 | receiver_impl::set_tseq_nums(const std::vector<int> &tseq_nums) |
| 1126 | { |
| 1127 | d_tseq_nums = tseq_nums; |
| 1128 | } |
| 1129 | |
| 1130 | void |
| 1131 | receiver_impl::reset(void) |
| 1132 | { |
| 1133 | d_state = fcch_search; |
| 1134 | } |
Vadim Yanitskiy | cc82cf0 | 2017-07-24 19:21:02 +0700 | [diff] [blame] | 1135 | } /* namespace gsm */ |
piotr | 437f546 | 2014-02-04 17:57:25 +0100 | [diff] [blame] | 1136 | } /* namespace gr */ |