|
|
|
@ -40,7 +40,6 @@
|
|
|
|
|
#include "liblte/phy/phy.h"
|
|
|
|
|
|
|
|
|
|
#include "liblte/cuhd/cuhd.h"
|
|
|
|
|
void *uhd;
|
|
|
|
|
|
|
|
|
|
int nof_frames_total = CS_DEFAULT_NOFFRAMES_TOTAL;
|
|
|
|
|
int nof_frames_detected = CS_DEFAULT_NOFFRAMES_DETECTED;
|
|
|
|
@ -95,83 +94,96 @@ void parse_args(int argc, char **argv) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void input_init() {
|
|
|
|
|
|
|
|
|
|
printf("Opening UHD device...\n");
|
|
|
|
|
if (cuhd_open(uhd_args, &uhd)) {
|
|
|
|
|
fprintf(stderr, "Error opening uhd\n");
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
cuhd_set_rx_gain(uhd, uhd_gain);
|
|
|
|
|
|
|
|
|
|
/* set uhd_freq */
|
|
|
|
|
cuhd_set_rx_freq(uhd, (double) uhd_freq);
|
|
|
|
|
cuhd_rx_wait_lo_locked(uhd);
|
|
|
|
|
DEBUG("Set uhd_freq to %.3f MHz\n", (double ) uhd_freq/1000000);
|
|
|
|
|
|
|
|
|
|
INFO("Setting sampling frequency 960 KHz for PSS search\n", 0);
|
|
|
|
|
cuhd_set_rx_srate(uhd, 960000.0);
|
|
|
|
|
|
|
|
|
|
DEBUG("Starting receiver...\n", 0);
|
|
|
|
|
cuhd_start_rx_stream(uhd);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
ue_cellsearch_t s;
|
|
|
|
|
int decode_pbch(void *uhd, cf_t *buffer, ue_celldetect_result_t *found_cell)
|
|
|
|
|
{
|
|
|
|
|
ue_mib_t uemib;
|
|
|
|
|
ue_cellsearch_result_t found_cell;
|
|
|
|
|
pbch_mib_t mib;
|
|
|
|
|
uint32_t flen;
|
|
|
|
|
cf_t *buffer;
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
parse_args(argc, argv);
|
|
|
|
|
uint32_t nof_frames = 0;
|
|
|
|
|
uint32_t flen = MIB_FRAME_SIZE;
|
|
|
|
|
|
|
|
|
|
if (ue_mib_init(&uemib, found_cell->cell_id, found_cell->cp)) {
|
|
|
|
|
fprintf(stderr, "Error initiating PBCH decoder\n");
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INFO("Setting sampling frequency 1.92 MHz for PBCH decoding\n", 0);
|
|
|
|
|
cuhd_set_rx_srate(uhd, 1920000.0);
|
|
|
|
|
INFO("Starting receiver...\n", 0);
|
|
|
|
|
cuhd_start_rx_stream(uhd);
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
if (cuhd_recv(uhd, buffer, flen, 1)<0) {
|
|
|
|
|
fprintf(stderr, "Error receiving from USRP\n");
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
input_init();
|
|
|
|
|
INFO("Calling ue_mib_decode() %d/%d\n", nof_frames, nof_frames_total);
|
|
|
|
|
|
|
|
|
|
// allocate for the maximum size (10 ms at 1.92 MHz for PBCH decoding)
|
|
|
|
|
buffer = vec_malloc(sizeof(cf_t) * 19200*30);
|
|
|
|
|
if (!buffer) {
|
|
|
|
|
perror("malloc");
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ue_cellsearch_init(&s)) {
|
|
|
|
|
fprintf(stderr, "Error initiating UE sync module\n");
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
if (threshold > 0) {
|
|
|
|
|
ue_cellsearch_set_threshold(&s, threshold);
|
|
|
|
|
n = ue_mib_decode(&uemib, buffer, flen, &mib);
|
|
|
|
|
if (n == LIBLTE_ERROR || n == LIBLTE_ERROR_INVALID_INPUTS) {
|
|
|
|
|
fprintf(stderr, "Error calling ue_mib_decode()\n");
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
}
|
|
|
|
|
if (n == MIB_FRAME_UNALIGNED) {
|
|
|
|
|
printf("Realigning frame\n");
|
|
|
|
|
if (cuhd_recv(uhd, buffer, flen/2, 1)<0) {
|
|
|
|
|
fprintf(stderr, "Error receiving from USRP\n");
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
nof_frames++;
|
|
|
|
|
} while (n != MIB_FOUND && nof_frames < nof_frames_total);
|
|
|
|
|
if (n == MIB_FOUND) {
|
|
|
|
|
printf("\n\nMIB decoded in %d ms (%d half frames)\n", nof_frames*5, nof_frames);
|
|
|
|
|
pbch_mib_fprint(stdout, &mib, found_cell->cell_id);
|
|
|
|
|
} else {
|
|
|
|
|
printf("\nCould not decode MIB\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cuhd_stop_rx_stream(uhd);
|
|
|
|
|
cuhd_flush_buffer(uhd);
|
|
|
|
|
|
|
|
|
|
ue_mib_free(&uemib);
|
|
|
|
|
|
|
|
|
|
if (nof_frames_total > 0) {
|
|
|
|
|
ue_cellsearch_set_nof_frames_total(&s, nof_frames_total);
|
|
|
|
|
}
|
|
|
|
|
if (nof_frames_detected > 0) {
|
|
|
|
|
ue_cellsearch_set_nof_frames_detected(&s, nof_frames_detected);
|
|
|
|
|
}
|
|
|
|
|
return LIBLTE_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int find_cell(void *uhd, ue_celldetect_t *s, cf_t *buffer, ue_celldetect_result_t *found_cell)
|
|
|
|
|
{
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
INFO("Setting sampling frequency 960 KHz for PSS search\n", 0);
|
|
|
|
|
cuhd_set_rx_srate(uhd, 960000.0);
|
|
|
|
|
INFO("Starting receiver...\n", 0);
|
|
|
|
|
cuhd_start_rx_stream(uhd);
|
|
|
|
|
|
|
|
|
|
uint32_t nof_scanned_cells = 0;
|
|
|
|
|
flen = 4800;
|
|
|
|
|
|
|
|
|
|
uint32_t flen = 4800;
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
|
|
if (cuhd_recv(uhd, buffer, flen, 1)<0) {
|
|
|
|
|
fprintf(stderr, "Error receiving from USRP\n");
|
|
|
|
|
exit(-1);
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n = ue_cellsearch_scan(&s, buffer, flen, &found_cell);
|
|
|
|
|
n = ue_celldetect_scan(s, buffer, flen, found_cell);
|
|
|
|
|
switch(n) {
|
|
|
|
|
case CS_FRAME_UNALIGNED:
|
|
|
|
|
fprintf(stderr, "Unaliged frame!! Exiting\n");
|
|
|
|
|
exit(-1);
|
|
|
|
|
printf("Realigning frame\n");
|
|
|
|
|
if (cuhd_recv(uhd, buffer, flen/2, 1)<0) {
|
|
|
|
|
fprintf(stderr, "Error receiving from USRP\n");
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
}
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
case CS_CELL_DETECTED:
|
|
|
|
|
printf("\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);
|
|
|
|
|
|
|
|
|
|
if (found_cell->peak > 0) {
|
|
|
|
|
printf("\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);
|
|
|
|
|
}
|
|
|
|
|
nof_scanned_cells++;
|
|
|
|
|
break;
|
|
|
|
|
case CS_CELL_NOT_DETECTED:
|
|
|
|
@ -180,65 +192,72 @@ int main(int argc, char **argv) {
|
|
|
|
|
case LIBLTE_ERROR:
|
|
|
|
|
case LIBLTE_ERROR_INVALID_INPUTS:
|
|
|
|
|
fprintf(stderr, "Error calling cellsearch_scan()\n");
|
|
|
|
|
exit(-1);
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
}
|
|
|
|
|
} while(nof_scanned_cells < 3 && n != CS_CELL_DETECTED);
|
|
|
|
|
|
|
|
|
|
INFO("Stopping receiver...\n", 0);
|
|
|
|
|
cuhd_stop_rx_stream(uhd);
|
|
|
|
|
cuhd_flush_buffer(uhd);
|
|
|
|
|
|
|
|
|
|
if (n == CS_CELL_DETECTED) {
|
|
|
|
|
INFO("Stopping receiver...\n", 0);
|
|
|
|
|
cuhd_stop_rx_stream(uhd);
|
|
|
|
|
|
|
|
|
|
cuhd_flush_buffer(uhd);
|
|
|
|
|
|
|
|
|
|
if (ue_mib_init(&uemib, found_cell.cell_id, found_cell.cp)) {
|
|
|
|
|
fprintf(stderr, "Error initiating PBCH decoder\n");
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INFO("Setting sampling frequency 1.92 MHz for PBCH decoding\n", 0);
|
|
|
|
|
cuhd_set_rx_srate(uhd, 1920000.0);
|
|
|
|
|
INFO("Starting receiver...\n", 0);
|
|
|
|
|
cuhd_start_rx_stream(uhd);
|
|
|
|
|
|
|
|
|
|
usleep(50000);
|
|
|
|
|
|
|
|
|
|
uint32_t nof_frames = 0;
|
|
|
|
|
flen = MIB_FRAME_SIZE;
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
int n;
|
|
|
|
|
void *uhd;
|
|
|
|
|
ue_celldetect_t s;
|
|
|
|
|
ue_celldetect_result_t found_cell;
|
|
|
|
|
cf_t *buffer;
|
|
|
|
|
|
|
|
|
|
parse_args(argc, argv);
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
if (cuhd_recv(uhd, buffer, flen, 1)<0) {
|
|
|
|
|
fprintf(stderr, "Error receiving from USRP\n");
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
INFO("Calling ue_mib_decode() %d/%d\n", nof_frames, nof_frames_total);
|
|
|
|
|
|
|
|
|
|
n = ue_mib_decode(&uemib, buffer, flen, &mib);
|
|
|
|
|
if (n == LIBLTE_ERROR || n == LIBLTE_ERROR_INVALID_INPUTS) {
|
|
|
|
|
fprintf(stderr, "Error calling ue_mib_decode()\n");
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
if (n == MIB_FRAME_UNALIGNED) {
|
|
|
|
|
printf("Realigning frame\n");
|
|
|
|
|
if (cuhd_recv(uhd, buffer, flen/2, 1)<0) {
|
|
|
|
|
fprintf(stderr, "Error receiving from USRP\n");
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
nof_frames++;
|
|
|
|
|
} while (n != MIB_FOUND && nof_frames < nof_frames_total);
|
|
|
|
|
if (n == MIB_FOUND) {
|
|
|
|
|
printf("\n\nMIB decoded in %d ms (%d half frames)\n", nof_frames*5, nof_frames);
|
|
|
|
|
pbch_mib_fprint(stdout, &mib, found_cell.cell_id);
|
|
|
|
|
} else {
|
|
|
|
|
printf("\nCould not decode MIB\n");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
printf("Opening UHD device...\n");
|
|
|
|
|
if (cuhd_open(uhd_args, &uhd)) {
|
|
|
|
|
fprintf(stderr, "Error opening uhd\n");
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
cuhd_set_rx_gain(uhd, uhd_gain);
|
|
|
|
|
|
|
|
|
|
/* set uhd_freq */
|
|
|
|
|
cuhd_set_rx_freq(uhd, (double) uhd_freq);
|
|
|
|
|
cuhd_rx_wait_lo_locked(uhd);
|
|
|
|
|
DEBUG("Set uhd_freq to %.3f MHz\n", (double ) uhd_freq/1000000);
|
|
|
|
|
|
|
|
|
|
buffer = vec_malloc(sizeof(cf_t) * 96000);
|
|
|
|
|
if (!buffer) {
|
|
|
|
|
perror("malloc");
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ue_mib_free(&uemib);
|
|
|
|
|
ue_cellsearch_free(&s);
|
|
|
|
|
if (ue_celldetect_init(&s)) {
|
|
|
|
|
fprintf(stderr, "Error initiating UE sync module\n");
|
|
|
|
|
exit(-1);
|
|
|
|
|
}
|
|
|
|
|
if (threshold > 0) {
|
|
|
|
|
ue_celldetect_set_threshold(&s, threshold);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nof_frames_total > 0) {
|
|
|
|
|
ue_celldetect_set_nof_frames_total(&s, nof_frames_total);
|
|
|
|
|
}
|
|
|
|
|
if (nof_frames_detected > 0) {
|
|
|
|
|
ue_celldetect_set_nof_frames_detected(&s, nof_frames_detected);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n = find_cell(uhd, &s, buffer, &found_cell);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ue_celldetect_free(&s);
|
|
|
|
|
cuhd_close(uhd);
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|