From 182c9958bbf21dc2824157d4f2ec016f4f06296e Mon Sep 17 00:00:00 2001 From: ismagom Date: Sat, 2 Aug 2014 03:05:54 +0200 Subject: [PATCH] Cell search example looks for 3 cells per frequency --- lte/phy/examples/cell_search.c | 30 ++++++++++++++++++------------ lte/phy/lib/sync/src/sync.c | 4 ++-- lte/phy/lib/ue/src/ue_celldetect.c | 2 +- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/lte/phy/examples/cell_search.c b/lte/phy/examples/cell_search.c index 501568bd5..7d1feeaa2 100644 --- a/lte/phy/examples/cell_search.c +++ b/lte/phy/examples/cell_search.c @@ -53,7 +53,7 @@ int band = -1; int earfcn_start=-1, earfcn_end = -1; int nof_frames_total = 50; int nof_frames_detected = 10; -float threshold = -1; +float threshold = CS_FIND_THRESHOLD; float uhd_gain = 60.0; @@ -171,7 +171,7 @@ int decode_pbch(void *uhd, cf_t *buffer, ue_celldetect_result_t *found_cell) return LIBLTE_SUCCESS; } -int find_cell(void *uhd, ue_celldetect_t *s, cf_t *buffer, ue_celldetect_result_t *found_cell) +int find_cell(void *uhd, ue_celldetect_t *s, cf_t *buffer, ue_celldetect_result_t found_cell[3]) { int n; @@ -190,7 +190,7 @@ int find_cell(void *uhd, ue_celldetect_t *s, cf_t *buffer, ue_celldetect_result_ return LIBLTE_ERROR; } - n = ue_celldetect_scan(s, buffer, flen, found_cell); + n = ue_celldetect_scan(s, buffer, flen, &found_cell[nof_scanned_cells]); switch(n) { case CS_FRAME_UNALIGNED: printf("Realigning frame\n"); @@ -200,10 +200,12 @@ int find_cell(void *uhd, ue_celldetect_t *s, cf_t *buffer, ue_celldetect_result_ } return LIBLTE_ERROR; case CS_CELL_DETECTED: - if (found_cell->peak > 0) { + if (found_cell[nof_scanned_cells].peak > 0) { printf("\n\tCELL ID: %d, CP: %s, Peak: %.2f, Mode: %d/%d\n", - found_cell->cell_id, lte_cp_string(found_cell->cp), - found_cell->peak, found_cell->mode, s->nof_frames_detected); + found_cell[nof_scanned_cells].cell_id, + lte_cp_string(found_cell[nof_scanned_cells].cp), + found_cell[nof_scanned_cells].peak, found_cell[nof_scanned_cells].mode, + s->nof_frames_detected); } nof_scanned_cells++; @@ -216,7 +218,7 @@ int find_cell(void *uhd, ue_celldetect_t *s, cf_t *buffer, ue_celldetect_result_ fprintf(stderr, "Error calling cellsearch_scan()\n"); return LIBLTE_ERROR; } - } while(nof_scanned_cells < 3 && n != CS_CELL_DETECTED); + } while(nof_scanned_cells < 3); INFO("Stopping receiver...\n", 0); cuhd_stop_rx_stream(uhd); @@ -229,7 +231,7 @@ int main(int argc, char **argv) { int n; void *uhd; ue_celldetect_t s; - ue_celldetect_result_t found_cell; + ue_celldetect_result_t found_cells[3]; cf_t *buffer; int nof_freqs; lte_earfcn_t channels[MAX_EARFCN]; @@ -286,15 +288,19 @@ int main(int argc, char **argv) { printf("\n"); } - n = find_cell(uhd, &s, buffer, &found_cell); + n = find_cell(uhd, &s, buffer, found_cells); if (n < 0) { fprintf(stderr, "Error searching cell\n"); exit(-1); } if (n == CS_CELL_DETECTED) { - if (decode_pbch(uhd, buffer, &found_cell)) { - fprintf(stderr, "Error decoding PBCH\n"); - exit(-1); + for (int i=0;i<3;i++) { + if (found_cells[i].peak > threshold/2) { + if (decode_pbch(uhd, buffer, &found_cells[i])) { + fprintf(stderr, "Error decoding PBCH\n"); + exit(-1); + } + } } } } diff --git a/lte/phy/lib/sync/src/sync.c b/lte/phy/lib/sync/src/sync.c index ba9b1194b..9d06a8616 100644 --- a/lte/phy/lib/sync/src/sync.c +++ b/lte/phy/lib/sync/src/sync.c @@ -280,8 +280,8 @@ int sync_find(sync_t *q, cf_t *input, uint32_t find_offset, uint32_t *peak_posit ret = LIBLTE_SUCCESS; } - INFO("SYNC ret=%d pos=%d peak=%.2f energy=%.3f threshold=%.2f sf_idx=%d\n", - ret, peak_pos, q->peak_value, energy, q->threshold, q->sf_idx); + INFO("SYNC ret=%d N_id_2=%d pos=%d peak=%.2f energy=%.3f threshold=%.2f sf_idx=%d\n", + ret, q->N_id_2, peak_pos, q->peak_value, energy, q->threshold, q->sf_idx); } else if (lte_N_id_2_isvalid(q->N_id_2)) { fprintf(stderr, "Must call sync_set_N_id_2() first!\n"); diff --git a/lte/phy/lib/ue/src/ue_celldetect.c b/lte/phy/lib/ue/src/ue_celldetect.c index fbb61c2cc..27cd1b5f8 100644 --- a/lte/phy/lib/ue/src/ue_celldetect.c +++ b/lte/phy/lib/ue/src/ue_celldetect.c @@ -211,7 +211,7 @@ int ue_celldetect_scan(ue_celldetect_t * q, for (uint32_t nf=0;nfsfind, q->current_N_id_2); - printf("[%3d/%3d]: Searching cells with N_id_2=%d. %d frames\n", + DEBUG("[%3d/%3d]: Searching cells with N_id_2=%d. %d frames\n", q->current_nof_detected, q->current_nof_total, q->current_N_id_2, nof_input_frames); /* Find peak and cell id */