Пример #1
0
int srslte_ue_cellsearch_init_multi(srslte_ue_cellsearch_t * q, uint32_t max_frames, 
                              int (recv_callback)(void*, cf_t*[SRSLTE_MAX_PORTS], uint32_t,srslte_timestamp_t*), 
                              uint32_t nof_rx_antennas,
                              void *stream_handler) 
{
  int ret = SRSLTE_ERROR_INVALID_INPUTS;

  if (q != NULL && nof_rx_antennas > 0) {
    ret = SRSLTE_ERROR;
    srslte_cell_t cell;

    bzero(q, sizeof(srslte_ue_cellsearch_t));    
    
    bzero(&cell, sizeof(srslte_cell_t));
    cell.id = SRSLTE_CELL_ID_UNKNOWN; 
    cell.nof_prb = SRSLTE_CS_NOF_PRB; 

    if (srslte_ue_sync_init_multi(&q->ue_sync, cell.nof_prb, true, recv_callback, nof_rx_antennas, stream_handler)) {
      fprintf(stderr, "Error initiating ue_sync\n");
      goto clean_exit; 
    }
    if (srslte_ue_sync_set_cell(&q->ue_sync, cell)) {
      fprintf(stderr, "Error setting cell in ue_sync\n");
      goto clean_exit;
    }

    for (int i=0;i<nof_rx_antennas;i++) {
      q->sf_buffer[i] = srslte_vec_malloc(3*sizeof(cf_t)*SRSLTE_SF_LEN_PRB(100));
    }
    q->nof_rx_antennas = nof_rx_antennas; 
    
    q->candidates = calloc(sizeof(srslte_ue_cellsearch_result_t), max_frames);
    if (!q->candidates) {
      perror("malloc");
      goto clean_exit; 
    }
    q->mode_ntimes = calloc(sizeof(uint32_t), max_frames);
    if (!q->mode_ntimes) {
      perror("malloc");
      goto clean_exit;  
    }
    q->mode_counted = calloc(sizeof(uint8_t), max_frames);
    if (!q->mode_counted) {
      perror("malloc");
      goto clean_exit;  
    }

    q->max_frames = max_frames;
    q->nof_valid_frames = max_frames; 
    
    ret = SRSLTE_SUCCESS;
  }

clean_exit:
  if (ret == SRSLTE_ERROR) {
    srslte_ue_cellsearch_free(q);
  }
  return ret;
}
Пример #2
0
/** This function is simply a wrapper to the ue_cell_search module for rf devices 
 */
int rf_cell_search(srslte_rf_t *rf, uint32_t nof_rx_antennas,
                   cell_search_cfg_t *config, 
                   int force_N_id_2, srslte_cell_t *cell, float *cfo) 
{
  int ret = SRSLTE_ERROR; 
  srslte_ue_cellsearch_t cs; 
  srslte_ue_cellsearch_result_t found_cells[3];

  bzero(found_cells, 3*sizeof(srslte_ue_cellsearch_result_t));
    
  if (srslte_ue_cellsearch_init_multi(&cs, config->max_frames_pss, srslte_rf_recv_wrapper_cs, nof_rx_antennas, (void*) rf)) {
    fprintf(stderr, "Error initiating UE cell detect\n");
    return SRSLTE_ERROR; 
  }
  if (config->nof_valid_pss_frames) {
    srslte_ue_cellsearch_set_nof_valid_frames(&cs, config->nof_valid_pss_frames);
  }

  INFO("Setting sampling frequency %.2f MHz for PSS search\n", SRSLTE_CS_SAMP_FREQ/1000000);
  srslte_rf_set_rx_srate(rf, SRSLTE_CS_SAMP_FREQ);
  
  INFO("Starting receiver...\n");
  srslte_rf_start_rx_stream(rf, false);

  /* Find a cell in the given N_id_2 or go through the 3 of them to find the strongest */
  uint32_t max_peak_cell = 0;
  if (force_N_id_2 >= 0) {
    ret = srslte_ue_cellsearch_scan_N_id_2(&cs, force_N_id_2, &found_cells[force_N_id_2]);
    max_peak_cell = force_N_id_2;
  } else {
    ret = srslte_ue_cellsearch_scan(&cs, found_cells, &max_peak_cell); 
  }
  if (ret < 0) {
    srslte_rf_stop_rx_stream(rf);
    fprintf(stderr, "Error searching cell\n");
    return SRSLTE_ERROR;
  } else if (ret == 0) {
    srslte_rf_stop_rx_stream(rf);
    fprintf(stderr, "Could not find any cell in this frequency\n");
    return SRSLTE_SUCCESS;
  }
  
  for (int i=0;i<3;i++) {
    if (i == max_peak_cell) {
      printf("*");
    } else {
      printf(" ");
    }
    printf("Found Cell_id: %3d CP: %s, DetectRatio=%2.0f%% PSR=%.2f, Power=%.1f dBm\n", 
           found_cells[i].cell_id, srslte_cp_string(found_cells[i].cp), 
           found_cells[i].mode*100,
           found_cells[i].psr, 20*log10(found_cells[i].peak*1000));
  }
  
  // Save result 
  if (cell) {
    cell->id = found_cells[max_peak_cell].cell_id;
    cell->cp = found_cells[max_peak_cell].cp; 
  }

  // Save CFO
  if (cfo) {
    *cfo = found_cells[max_peak_cell].cfo;
  }
  
  srslte_rf_stop_rx_stream(rf);
  srslte_ue_cellsearch_free(&cs);

  return ret; 
}
Пример #3
0
/** This function is simply a wrapper to the ue_cell_search module for cuhd devices 
 */
int cuhd_cell_search(void *uhd, cell_search_cfg_t *config, 
                     int force_N_id_2, srslte_cell_t *cell) 
{
  int ret = SRSLTE_ERROR; 
  srslte_ue_cellsearch_t cs; 
  srslte_ue_cellsearch_result_t found_cells[3];

  bzero(found_cells, 3*sizeof(srslte_ue_cellsearch_result_t));
    
  if (srslte_ue_cellsearch_init(&cs, cuhd_recv_wrapper_cs, uhd)) {
    fprintf(stderr, "Error initiating UE cell detect\n");
    return SRSLTE_ERROR; 
  }
  
  if (config->max_frames_pss) {
    srslte_ue_cellsearch_set_nof_frames_to_scan(&cs, config->max_frames_pss);
  }
  if (config->threshold) {
    srslte_ue_cellsearch_set_threshold(&cs, config->threshold);
  }

  if (config->init_agc > 0) {
    srslte_ue_sync_start_agc(&cs.ue_sync, cuhd_set_rx_gain_th, config->init_agc);
  }
  
  INFO("Setting sampling frequency %.2f MHz for PSS search\n", SRSLTE_CS_SAMP_FREQ/1000000);
  cuhd_set_rx_srate(uhd, SRSLTE_CS_SAMP_FREQ);
  
  INFO("Starting receiver...\n", 0);
  cuhd_start_rx_stream(uhd);

  /* Find a cell in the given N_id_2 or go through the 3 of them to find the strongest */
  uint32_t max_peak_cell = 0;
  if (force_N_id_2 >= 0) {
    ret = srslte_ue_cellsearch_scan_N_id_2(&cs, force_N_id_2, &found_cells[force_N_id_2]);
    max_peak_cell = force_N_id_2;
  } else {
    ret = srslte_ue_cellsearch_scan(&cs, found_cells, &max_peak_cell); 
  }
  if (ret < 0) {
    fprintf(stderr, "Error searching cell\n");
    return SRSLTE_ERROR;
  } else if (ret == 0) {
    fprintf(stderr, "Could not find any cell in this frequency\n");
    return SRSLTE_SUCCESS;
  }
  
  for (int i=0;i<3;i++) {
    if (i == max_peak_cell) {
      printf("*");
    } else {
      printf(" ");
    }
    printf("Found Cell_id: %3d CP: %s, DetectRatio=%2.0f%% PSR=%.2f, Power=%.1f dBm\n", 
           found_cells[i].cell_id, srslte_cp_string(found_cells[i].cp), 
           found_cells[i].mode*100,
           found_cells[i].psr, 20*log10(found_cells[i].peak*1000));
  }
  
  // Save result 
  if (cell) {
    cell->id = found_cells[max_peak_cell].cell_id;
    cell->cp = found_cells[max_peak_cell].cp; 
  }

  // Save AGC value for MIB decoding
  if (config->init_agc > 0) {
    config->init_agc = srslte_agc_get_gain(&cs.ue_sync.agc);
  }
  
  cuhd_stop_rx_stream(uhd);
  srslte_ue_cellsearch_free(&cs);

  return ret; 
}