Commit 09d8031227c1db7667d4df91909e7a43d6ce6908

Authored by Nicola Bui
1 parent c820dbce
Exists in master

OWL update based on srsLTE_v1.3

srslte/examples/CMakeLists.txt
... ... @@ -82,9 +82,6 @@ if(RF_FOUND)
82 82 add_executable(usrp_capture_sync usrp_capture_sync.c)
83 83 target_link_libraries(usrp_capture_sync srslte)
84 84  
85   - add_executable(imdea_online_decoder_tuned imdea_online_decoder_tuned.c)
86   - target_link_libraries(imdea_online_decoder_tuned srslte)
87   -
88 85 add_executable(imdea_capture_sync imdea_capture_sync.c)
89 86 target_link_libraries(imdea_capture_sync srslte)
90 87  
... ...
srslte/examples/imdea_online_decoder_tuned.c
... ... @@ -1,443 +0,0 @@
1   -/**
2   - *
3   - * \section COPYRIGHT
4   - *
5   - * Copyright 2013-2015 Software Radio Systems Limited
6   - * Copyright 2016 IMDEA Networks Institute
7   - *
8   - * \section LICENSE
9   - *
10   - * This file is part of OWL, which extends the srsLTE library.
11   - *
12   - * srsLTE is free software: you can redistribute it and/or modify
13   - * it under the terms of the GNU Affero General Public License as
14   - * published by the Free Software Foundation, either version 3 of
15   - * the License, or (at your option) any later version.
16   - *
17   - * srsLTE is distributed in the hope that it will be useful,
18   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
19   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20   - * GNU Affero General Public License for more details.
21   - *
22   - * A copy of the GNU Affero General Public License can be found in
23   - * the LICENSE file in the top-level directory of this distribution
24   - * and at http://www.gnu.org/licenses/.
25   - *
26   - */
27   -
28   -#include <stdio.h>
29   -#include <signal.h>
30   -#include <stdlib.h>
31   -#include <string.h>
32   -#include <strings.h>
33   -#include <unistd.h>
34   -#include <math.h>
35   -#include <time.h>
36   -
37   -#include <stdbool.h>
38   -
39   -#include "srslte/srslte.h"
40   -#include "srslte/rf/rf.h"
41   -#include "srslte/rf/rf_utils.h"
42   -
43   -#define ENABLE_AGC_DEFAULT
44   -//#define CORRECT_SAMPLE_OFFSET
45   -//#define FINE_TUNING
46   -#define OWL_PATH "~/Software/OWL/OWL-master/srsLTE/build/srslte/examples"
47   -//#define OWL_PATH "/home/bui/Documents/Software/srsLTE/newsrsLTE/build/srslte/examples"
48   -
49   -char *output_file_name = NULL;
50   -char *rf_args="";
51   -float rf_gain=60.0, rf_freq=-1.0;
52   -int nof_prb = 6;
53   -int nof_subframes = -1;
54   -int N_id_2 = -1;
55   -bool disable_cfo = false;
56   -
57   -cell_search_cfg_t cell_detect_config = {
58   - SRSLTE_DEFAULT_MAX_FRAMES_PBCH,
59   - SRSLTE_DEFAULT_MAX_FRAMES_PSS,
60   - SRSLTE_DEFAULT_NOF_VALID_PSS_FRAMES,
61   - 0
62   -};
63   -
64   -enum receiver_state { DECODE_MIB } state;
65   -
66   -bool go_exit = false;
67   -void sig_int_handler(int signo)
68   -{
69   - printf("SIGINT received. Exiting...\n");
70   - if (signo == SIGINT) {
71   - go_exit = true;
72   - }
73   -}
74   -
75   -void usage(char *prog) {
76   - printf("Usage: %s [aCgpnv] -l N_id_2 -f rx_frequency_hz -o working directory (is it in RAM?)\n", prog);
77   - printf("\t-a RF args [Default %s]\n", rf_args);
78   - printf("\t-C disable cfo correction [Default %s]\n", rf_args);
79   - printf("\t-g RF Gain [Default %.2f dB]\n", rf_gain);
80   - printf("\t-p nof_prb [Default %d]\n", nof_prb);
81   - printf("\t-n nof_subframes [Default %d]\n", nof_subframes);
82   - printf("\t-v verbose\n");
83   -}
84   -
85   -void parse_args(int argc, char **argv) {
86   - int opt;
87   - while ((opt = getopt(argc, argv, "agpnvfol")) != -1) {
88   - switch (opt) {
89   - case 'o':
90   - output_file_name = argv[optind];
91   - break;
92   - case 'a':
93   - rf_args = argv[optind];
94   - break;
95   - case 'C':
96   - disable_cfo = true;
97   - break;
98   - case 'g':
99   - rf_gain = atof(argv[optind]);
100   - break;
101   - case 'p':
102   - nof_prb = atoi(argv[optind]);
103   - break;
104   - case 'f':
105   - rf_freq = atof(argv[optind]);
106   - break;
107   - case 'n':
108   - nof_subframes = atoi(argv[optind]);
109   - break;
110   - case 'l':
111   - N_id_2 = atoi(argv[optind]);
112   - break;
113   - case 'v':
114   - srslte_verbose++;
115   - break;
116   - default:
117   - usage(argv[0]);
118   - exit(-1);
119   - }
120   - }
121   - if (&rf_freq < 0 || output_file_name == NULL) {
122   - usage(argv[0]);
123   - exit(-1);
124   - }
125   -}
126   -
127   -int srslte_rf_recv_wrapper(void *h, void *data, uint32_t nsamples, srslte_timestamp_t *t) {
128   - DEBUG(" ---- Receive %d samples ---- \n", nsamples);
129   - return srslte_rf_recv(h, data, nsamples, 1);
130   -}
131   -
132   -double srslte_rf_set_rx_gain_th_wrapper(void *h, double f) {
133   - return srslte_rf_set_rx_gain_th((srslte_rf_t*) h, f);
134   -}
135   -
136   -int main(int argc, char **argv) {
137   - int n, ret;
138   - srslte_rf_t rf;
139   - srslte_filesink_t sink;
140   - srslte_ue_sync_t ue_sync;
141   - srslte_cell_t cell;
142   - int64_t sf_cnt, sf_guard;
143   - srslte_ue_mib_t ue_mib;
144   - uint8_t bch_payload[SRSLTE_BCH_PAYLOAD_LEN];
145   - int sfn_offset;
146   - bool fstart = 0;
147   - float cfo = 0;
148   - char cwd[1024];
149   - sprintf(cwd,OWL_PATH);
150   -
151   - srslte_ue_dl_t ue_dl;
152   -
153   - uint32_t sfn = 0; // system frame number
154   - cf_t *sf_buffer = NULL;
155   -
156   - parse_args(argc, argv);
157   -
158   - printf("Opening RF device...\n");
159   - if (srslte_rf_open(&rf, rf_args)) {
160   - fprintf(stderr, "Error opening rf\n");
161   - exit(-1);
162   - }
163   - srslte_rf_set_master_clock_rate(&rf, 30.72e6);
164   -
165   - // The new version disables the AGC by default (let's see if it is good or not)
166   - /* Set receiver gain */
167   - if (rf_gain > 0) {
168   - srslte_rf_set_rx_gain(&rf, rf_gain);
169   - } else {
170   - printf("Starting AGC thread...\n");
171   - if (srslte_rf_start_gain_thread(&rf, false)) {
172   - fprintf(stderr, "Error opening rf\n");
173   - exit(-1);
174   - }
175   - srslte_rf_set_rx_gain(&rf, 50);
176   - cell_detect_config.init_agc = 50;
177   - }
178   -
179   - sigset_t sigset;
180   - sigemptyset(&sigset);
181   - sigaddset(&sigset, SIGINT);
182   - sigprocmask(SIG_UNBLOCK, &sigset, NULL);
183   - signal(SIGINT, sig_int_handler);
184   -
185   - /* set receiver frequency and gain*/
186   - printf("Set RX freq: %.6f MHz\n", srslte_rf_set_rx_freq(&rf, rf_freq) / 1000000);
187   - printf("Set RX gain: %.1f dB\n", srslte_rf_set_rx_gain(&rf, rf_gain));
188   - int srate = srslte_sampling_freq_hz(nof_prb);
189   - if (srate != -1) {
190   - if (srate < 10e6) {
191   - srslte_rf_set_master_clock_rate(&rf, 4*srate);
192   - } else {
193   - srslte_rf_set_master_clock_rate(&rf, srate);
194   - }
195   - printf("Setting sampling rate %.2f MHz\n", (float) srate/1000000);
196   - float srate_rf = srslte_rf_set_rx_srate(&rf, (double) srate);
197   - if (srate_rf != srate) {
198   - fprintf(stderr, "Could not set sampling rate\n");
199   - exit(-1);
200   - }
201   - } else {
202   - fprintf(stderr, "Invalid number of PRB %d\n", nof_prb);
203   - exit(-1);
204   - }
205   - srslte_rf_rx_wait_lo_locked(&rf);
206   - srslte_rf_start_rx_stream(&rf);
207   -
208   - uint32_t ntrial=0;
209   - uint32_t max_trial=3;
210   - do {
211   - ret = rf_search_and_decode_mib(&rf, &cell_detect_config, N_id_2, &cell, &cfo);
212   - if (ret < 0) {
213   - fprintf(stderr, "Error searching for cell\n");
214   - exit(-1);
215   - } else if (ret == 0 && !go_exit) {
216   - printf("Cell not found after %d trials. Trying again (Press Ctrl+C to exit)\n", ntrial++);
217   - }
218   - if (ntrial >= max_trial) go_exit = true;
219   - } while (ret == 0 && !go_exit);
220   -
221   - if (go_exit) {
222   - exit(-1);
223   - }
224   -
225   - /* set sampling frequency */
226   - srate = srslte_sampling_freq_hz(cell.nof_prb);
227   - if (srate != -1) {
228   - if (srate < 10e6) {
229   - srslte_rf_set_master_clock_rate(&rf, 4*srate);
230   - } else {
231   - srslte_rf_set_master_clock_rate(&rf, srate);
232   - }
233   - printf("Setting sampling rate %.2f MHz\n", (float) srate/1000000);
234   - float srate_rf = srslte_rf_set_rx_srate(&rf, (double) srate);
235   - if (srate_rf != srate) {
236   - fprintf(stderr, "Could not set sampling rate\n");
237   - exit(-1);
238   - }
239   - } else {
240   - fprintf(stderr, "Invalid number of PRB %d\n", cell.nof_prb);
241   - exit(-1);
242   - }
243   -
244   - INFO("Stopping RF and flushing buffer...\r",0);
245   - srslte_rf_stop_rx_stream(&rf);
246   - srslte_rf_flush_buffer(&rf);
247   -
248   - /* If reading from file, go straight to PDSCH decoding. Otherwise, decode MIB first */
249   - if (srslte_ue_sync_init(&ue_sync, cell, srslte_rf_recv_wrapper, (void*) &rf)) {
250   - fprintf(stderr, "Error initiating ue_sync\n");
251   - exit(-1);
252   - }
253   -
254   - state = DECODE_MIB;
255   -
256   - if (srslte_ue_mib_init(&ue_mib, cell)) {
257   - fprintf(stderr, "Error initaiting UE MIB decoder\n");
258   - exit(-1);
259   - }
260   -
261   - if (srslte_ue_dl_init(&ue_dl, cell)) { // This is the User RNTI
262   - fprintf(stderr, "Error initiating UE downlink processing module\n");
263   - exit(-1);
264   - }
265   -
266   - /* Initialize subframe counter */
267   - sf_cnt = 0;
268   - sf_guard = 0;
269   - int pipeline_depth = 4;
270   - int file_in_use = 0;
271   - int trace_len = 1000; // one second trace with 1000 subframes
272   - char tmp_str[1024];
273   - sprintf(tmp_str, "%s/scan%d.bin", output_file_name, file_in_use);
274   - srslte_filesink_init(&sink, tmp_str, SRSLTE_COMPLEX_FLOAT_BIN);
275   -
276   - srslte_rf_start_rx_stream(&rf);
277   -
278   - if (rf_gain < 0) {
279   - srslte_ue_sync_start_agc(&ue_sync, srslte_rf_set_rx_gain_th_wrapper, cell_detect_config.init_agc);
280   - }
281   -#ifdef PRINT_CHANGE_SCHEDULIGN
282   - srslte_ra_dl_dci_t old_dl_dci;
283   - bzero(&old_dl_dci, sizeof(srslte_ra_dl_dci_t));
284   -#endif
285   -
286   - ue_sync.correct_cfo = !disable_cfo;
287   -
288   - srslte_pbch_decode_reset(&ue_mib.pbch);
289   -
290   - INFO("\nEntering main loop...\n\n", 0);
291   - /* Main loop */
292   - while (!go_exit && (sf_cnt < nof_subframes || nof_subframes == -1)) {
293   -
294   - ret = srslte_ue_sync_get_buffer(&ue_sync, &sf_buffer);
295   - if (ret < 0) {
296   - fprintf(stderr, "Error calling srslte_ue_sync_work()\n");
297   - go_exit = true;
298   - }
299   -
300   - /* srslte_ue_sync_get_buffer returns 1 if successfully read 1 aligned subframe */
301   - if (ret == 1) {
302   - switch (state) {
303   - case DECODE_MIB:
304   - if (srslte_ue_sync_get_sfidx(&ue_sync) == 0) {
305   - n = srslte_ue_mib_decode(&ue_mib, sf_buffer, bch_payload, NULL, &sfn_offset);
306   - if (n < 0) {
307   - fprintf(stderr, "Error decoding UE MIB\n");
308   - exit(-1);
309   - } else if (n == SRSLTE_UE_MIB_FOUND) {
310   - srslte_pbch_mib_unpack(bch_payload, &cell, &sfn);
311   - //srslte_cell_fprint(stdout, &cell, sfn);
312   - fprintf(stderr,"Decoded MIB. SFN: %d, offset: %d\n", sfn, sfn_offset);
313   - //exit(0);
314   - if (!fstart) {
315   - fprintf(stderr,"*************************\n*************************\nRecording started: %d\n*************************\n*************************\n", sfn, sfn_offset);
316   - sfn = (sfn + sfn_offset)%1024;
317   - fstart = 1;
318   - }
319   - } else {
320   - fprintf(stderr,"MIB not decoded. SFN: %d, offset: %d\n", sfn, sfn_offset);
321   - }
322   - }
323   - break;
324   - }
325   - if (srslte_ue_sync_get_sfidx(&ue_sync) == 9) {
326   - sfn++;
327   - }
328   - if (fstart) srslte_filesink_write(&sink, sf_buffer, SRSLTE_SF_LEN_PRB(cell.nof_prb));
329   - } else if (ret == 0) {
330   - if (fstart) {
331   - fprintf(stderr,"Sync loss at %d\n", sfn);
332   - go_exit = true; // let's think about this
333   - } else {
334   - fprintf(stderr,"Finding PSS... Peak: %8.1f, FrameCnt: %d, State: %d\n",
335   - srslte_sync_get_peak_value(&ue_sync.sfind),
336   - ue_sync.frame_total_cnt, ue_sync.state);
337   - }
338   -
339   - }
340   -
341   - if (fstart) {
342   - sf_cnt++;
343   - if (sf_cnt%trace_len==0) {
344   - // file swap
345   - if (file_in_use == 0) {
346   - printf("file swap at %d, old file was scan%d.bin; now recording scan%d.bin\n",sf_cnt,file_in_use, (file_in_use+1)%pipeline_depth);
347   - if (file_in_use > 100*pipeline_depth) {
348   - file_in_use = file_in_use%pipeline_depth + pipeline_depth;
349   - }
350   - file_in_use++;
351   - sprintf(tmp_str,"%s/scan%d.bin",output_file_name, file_in_use%pipeline_depth);
352   - srslte_filesink_init(&sink, tmp_str, SRSLTE_COMPLEX_FLOAT_BIN);
353   - sprintf(tmp_str,"%s/imdea_cc_decoder"
354   - " -i %s/scan%d.bin -l %d -c %d -P %d -p %d -z rnti%d.list 1>output%d.txt 2>output%d.fix &",
355   - cwd, output_file_name, (file_in_use-1)%pipeline_depth,
356   - ue_sync.cell.id%3, ue_sync.cell.id, ue_sync.cell.nof_ports, ue_sync.cell.nof_prb,
357   - (file_in_use-1)%pipeline_depth,
358   - (file_in_use-1)%pipeline_depth, (file_in_use-1)%pipeline_depth);
359   - //system(tmp_str);
360   - //printf("%s\n",tmp_str);
361   - } else if (file_in_use > 0 && file_in_use < pipeline_depth-1 ) {
362   - printf("file swap at %d, old file was scan%d.bin; now recording scan%d.bin\n",sf_cnt,file_in_use, (file_in_use+1)%pipeline_depth);
363   - if (file_in_use > 100*pipeline_depth) {
364   - file_in_use = file_in_use%pipeline_depth + pipeline_depth;
365   - }
366   - file_in_use++;
367   - sprintf(tmp_str,"%s/scan%d.bin",output_file_name, file_in_use%pipeline_depth);
368   - srslte_filesink_init(&sink, tmp_str, SRSLTE_COMPLEX_FLOAT_BIN);
369   - sprintf(tmp_str,"%s/imdea_cc_decoder"
370   - " -i %s/scan%d.bin -l %d -c %d -P %d -p %d -Z %s/rnti%d.list -z %s/rnti%d.list 1>%s/output%d.txt 2>%s/output%d.fix &",
371   - cwd, output_file_name, (file_in_use-1)%pipeline_depth,
372   - ue_sync.cell.id%3, ue_sync.cell.id, ue_sync.cell.nof_ports, ue_sync.cell.nof_prb,
373   - output_file_name, (file_in_use-2)%pipeline_depth, output_file_name, (file_in_use-1)%pipeline_depth,
374   - output_file_name, (file_in_use-1)%pipeline_depth, output_file_name, (file_in_use-1)%pipeline_depth);
375   - system(tmp_str);
376   - //printf("%s\n",tmp_str);
377   -#ifdef FINE_TUNING
378   - sprintf(tmp_str,"timeout %f %s/imdea_fine_tuner"
379   - " -i %s/scan%d.bin -l %d -c %d -P %d -p %d -Z %s/rnti%d.list -z %s/output%d.fix 1>%s/output%db.txt 2>/dev/null &",
380   - (pipeline_depth-2)*0.6, cwd, output_file_name, (file_in_use-2)%pipeline_depth,
381   - ue_sync.cell.id%3, ue_sync.cell.id, ue_sync.cell.nof_ports, ue_sync.cell.nof_prb,
382   - output_file_name, (file_in_use-2)%pipeline_depth, output_file_name, (file_in_use-2)%pipeline_depth, output_file_name, (file_in_use-2)%pipeline_depth);
383   - //printf("%s\n",tmp_str);
384   - system(tmp_str);
385   -#endif
386   - } else if (file_in_use >= pipeline_depth-1) {
387   - printf("file swap at %d, old file was scan%d.bin; now recording scan%d.bin\n",sf_cnt,file_in_use, (file_in_use+1)%pipeline_depth);
388   - if (file_in_use > 100*pipeline_depth) {
389   - file_in_use = file_in_use%pipeline_depth + 2*pipeline_depth;
390   - }
391   - file_in_use++;
392   - sprintf(tmp_str,"%s/scan%d.bin",output_file_name, file_in_use%pipeline_depth);
393   - srslte_filesink_init(&sink, tmp_str, SRSLTE_COMPLEX_FLOAT_BIN);
394   - sprintf(tmp_str,"%s/imdea_cc_decoder"
395   - " -i %s/scan%d.bin -l %d -c %d -P %d -p %d -Z %s/rnti%d.list -z %s/rnti%d.list 1>%s/output%d.txt 2>%s/output%d.fix &",
396   - cwd, output_file_name, (file_in_use-1)%pipeline_depth,
397   - ue_sync.cell.id%3, ue_sync.cell.id, ue_sync.cell.nof_ports, ue_sync.cell.nof_prb,
398   - output_file_name, (file_in_use-2)%pipeline_depth, output_file_name, (file_in_use-1)%pipeline_depth,
399   - output_file_name, (file_in_use-1)%pipeline_depth, output_file_name, (file_in_use-1)%pipeline_depth);
400   - system(tmp_str);
401   - //printf("%s\n",tmp_str);
402   -#ifdef FINE_TUNING
403   - sprintf(tmp_str,"timeout %f %s/imdea_fine_tuner"
404   - " -i %s/scan%d.bin -l %d -c %d -P %d -p %d -Z %s/rnti%d.list -z %s/output%d.fix 1>%s/output%db.txt 2>/dev/null &",
405   - (pipeline_depth-2)*0.6, cwd, output_file_name, (file_in_use-2)%pipeline_depth,
406   - ue_sync.cell.id%3, ue_sync.cell.id, ue_sync.cell.nof_ports, ue_sync.cell.nof_prb,
407   - output_file_name, (file_in_use-2)%pipeline_depth, output_file_name, (file_in_use-2)%pipeline_depth, output_file_name, (file_in_use-2)%pipeline_depth);
408   - //printf("%s\n",tmp_str);
409   - system(tmp_str);
410   - sprintf(tmp_str,"sort -u %s/output%d.txt %s/output%db.txt -o ../results/$(date +%%Y%%m%%d%%H%%M%%S)_output.txt &",
411   - output_file_name, (file_in_use)%pipeline_depth, output_file_name, (file_in_use)%pipeline_depth);
412   - //printf("%s\n",tmp_str);
413   - system(tmp_str);
414   -#else
415   - system(tmp_str);
416   - sprintf(tmp_str,"sort -u %s/output%d.txt -o ../results/$(date +%%Y%%m%%d%%H%%M%%S)_output.txt &",
417   - output_file_name, (file_in_use)%pipeline_depth);
418   - //printf("%s\n",tmp_str);
419   - system(tmp_str);
420   -#endif
421   - }
422   - }
423   - }
424   - sf_guard++;
425   -// if (sf_guard > nof_subframes + 10000) {
426   -// fprintf(stderr,"watchdog exit\n");
427   -// go_exit = true;
428   -// }
429   - } // Main loop
430   -
431   - srslte_ue_dl_free(&ue_dl);
432   - srslte_ue_sync_free(&ue_sync);
433   -
434   - srslte_ue_mib_free(&ue_mib);
435   - srslte_rf_close(&rf);
436   -// printf("\nBye\n");
437   - if (go_exit) {
438   - exit(-1);
439   - } else {
440   - exit(0);
441   - }
442   -}
443   -