int filesource_work(filesource_hl* h) { h->out_len = filesource_read(&h->obj, h->output, h->ctrl_in.nsamples); if (h->out_len < 0) { return -1; } return 0; }
int main(int argc, char **argv) { uint32_t cfi; float cfi_corr; int n; if (argc < 3) { usage(argv[0]); exit(-1); } parse_args(argc,argv); if (base_init()) { fprintf(stderr, "Error initializing receiver\n"); exit(-1); } n = filesource_read(&fsrc, input_buffer, flen); lte_fft_run_sf(&fft, input_buffer, fft_buffer); if (fmatlab) { fprintf(fmatlab, "infft="); vec_fprint_c(fmatlab, input_buffer, flen); fprintf(fmatlab, ";\n"); fprintf(fmatlab, "outfft="); vec_sc_prod_cfc(fft_buffer, 1000.0, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB); vec_fprint_c(fmatlab, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB); fprintf(fmatlab, ";\n"); vec_sc_prod_cfc(fft_buffer, 0.001, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB); } /* Get channel estimates for each port */ chest_dl_estimate(&chest, fft_buffer, ce, 0); INFO("Decoding PCFICH\n", 0); n = pcfich_decode(&pcfich, fft_buffer, ce, chest_dl_get_noise_estimate(&chest), 0, &cfi, &cfi_corr); printf("cfi: %d, distance: %f\n", cfi, cfi_corr); base_free(); if (n < 0) { fprintf(stderr, "Error decoding PCFICH\n"); exit(-1); } else if (n == 0) { printf("Could not decode PCFICH\n"); exit(-1); } else { if (cfi_corr > 2.8 && cfi == 1) { exit(0); } else { exit(-1); } } }
int main(int argc, char **argv) { pbch_mib_t mib; int n; if (argc < 3) { usage(argv[0]); exit(-1); } parse_args(argc,argv); if (base_init()) { fprintf(stderr, "Error initializing receiver\n"); exit(-1); } n = filesource_read(&fsrc, input_buffer, FLEN); lte_fft_run_sf(&fft, input_buffer, fft_buffer); if (fmatlab) { fprintf(fmatlab, "outfft="); vec_sc_prod_cfc(fft_buffer, 1000.0, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB); vec_fprint_c(fmatlab, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB); fprintf(fmatlab, ";\n"); vec_sc_prod_cfc(fft_buffer, 0.001, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB); } /* Get channel estimates for each port */ chest_ce_sf(&chest, fft_buffer, ce, 0); INFO("Decoding PBCH\n", 0); n = pbch_decode(&pbch, fft_buffer, ce, &mib); base_free(); if (n < 0) { fprintf(stderr, "Error decoding PBCH\n"); exit(-1); } else if (n == 0) { printf("Could not decode PBCH\n"); exit(-1); } else { if (mib.nof_ports == 2 && mib.nof_prb == 50 && mib.phich_length == PHICH_NORM && mib.phich_resources == R_1 && mib.sfn == 28) { pbch_mib_fprint(stdout, &mib, cell.id); printf("This is the signal.1.92M.dat file\n"); exit(0); } else { pbch_mib_fprint(stdout, &mib, cell.id); printf("This is an unknown file\n"); exit(-1); } } }
/* Receive samples from the USRP or read from file */ int iodev_receive(iodev_t *q, cf_t **buffer) { int n; if (q->mode == FILESOURCE) { INFO(" ----- READING %d SAMPLES ---- \n", q->sf_len); n = filesource_read(&q->fsrc, q->input_buffer_file, q->sf_len); *buffer = q->input_buffer_file; if (n == -1) { fprintf(stderr, "Error reading file\n"); /* wrap file if arrive to end */ } else if (n < q->sf_len) { DEBUG("Read %d from file. Seeking to 0\n",n); filesource_seek(&q->fsrc, 0); n = filesource_read(&q->fsrc, q->input_buffer_file, q->sf_len); if (n == -1) { fprintf(stderr, "Error reading file\n"); /* wrap file if arrive to end */ } else { n = 1; } } else { n = 1; } q->sf_idx++; if (q->sf_idx == 10) { q->sf_idx = 0; } usleep(5000); } else { /* Use ue_sync_work which returns a synchronized buffer of subframe samples */ #ifndef DISABLE_UHD n = ue_sync_get_buffer(&q->sframe, buffer); if (n < 0) { fprintf(stderr, "Error calling ue_sync_work()\n"); } #endif } return n; }
int main(int argc, char **argv) { ra_pdsch_t ra_dl; int i; int nof_frames; int ret; char *data; dci_location_t locations[10]; uint32_t nof_locations; dci_msg_t dci_msg; data = malloc(10000); if (argc < 3) { usage(argv[0]); exit(-1); } parse_args(argc,argv); if (base_init()) { fprintf(stderr, "Error initializing memory\n"); exit(-1); } if (rnti == SIRNTI) { INFO("Initializing common search space for SI-RNTI\n",0); nof_locations = pdcch_common_locations(&pdcch, locations, 10, cfi); } else { // For ue-specific, generate locations for subframe 5 INFO("Initializing user-specific search space for RNTI: 0x%x\n", rnti); nof_locations = pdcch_ue_locations(&pdcch, locations, 10, 5, cfi, rnti); } ret = -1; nof_frames = 0; do { filesource_read(&fsrc, input_buffer, flen); if (nof_frames == 5) { INFO("Reading %d samples sub-frame %d\n", flen, nof_frames); lte_fft_run_sf(&fft, input_buffer, fft_buffer); if (fmatlab) { fprintf(fmatlab, "infft%d=", nof_frames); vec_fprint_c(fmatlab, input_buffer, flen); fprintf(fmatlab, ";\n"); fprintf(fmatlab, "outfft%d=", nof_frames); vec_sc_prod_cfc(fft_buffer, 1000.0, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB); vec_fprint_c(fmatlab, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB); fprintf(fmatlab, ";\n"); vec_sc_prod_cfc(fft_buffer, 0.001, fft_buffer, CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB); } /* Get channel estimates for each port */ for (i=0;i<cell.nof_ports;i++) { chest_ce_slot_port(&chest, fft_buffer, ce[i], 2*nof_frames, i); chest_ce_slot_port(&chest, &fft_buffer[CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB], &ce[i][CP_NSYMB(cell.cp) * cell.nof_prb * RE_X_RB], 2*nof_frames+1, i); if (fmatlab) { chest_fprint(&chest, fmatlab, 2*nof_frames+1, i); } } uint16_t crc_rem = 0; for (i=0;i<nof_locations && crc_rem != rnti;i++) { if (pdcch_extract_llr(&pdcch, fft_buffer, ce, locations[i], nof_frames, cfi)) { fprintf(stderr, "Error extracting LLRs\n"); return -1; } if (pdcch_decode_msg(&pdcch, &dci_msg, Format1A, &crc_rem)) { fprintf(stderr, "Error decoding DCI msg\n"); return -1; } } if (crc_rem == rnti) { if (dci_msg_to_ra_dl(&dci_msg, rnti, 1234, cell, cfi, &ra_dl)) { fprintf(stderr, "Error unpacking PDSCH scheduling DCI message\n"); goto goout; } if (pdsch_harq_setup(&harq_process, ra_dl.mcs, &ra_dl.prb_alloc)) { fprintf(stderr, "Error configuring HARQ process\n"); goto goout; } if (pdsch_decode(&pdsch, fft_buffer, ce, data, nof_frames%10, &harq_process, ra_dl.rv_idx)) { fprintf(stderr, "Error decoding PDSCH\n"); goto goout; } else { printf("PDSCH Decoded OK!\n"); } } } nof_frames++; } while (nof_frames <= max_frames); ret = 0; goout: base_free(); exit(ret); }
int main(int argc, char **argv) { int distance; int i, n; int ngroup, nseq, max_nseq; char ack_rx; if (argc < 3) { usage(argv[0]); exit(-1); } parse_args(argc,argv); max_nseq = CP_ISNORM(cp)?PHICH_NORM_NSEQUENCES:PHICH_EXT_NSEQUENCES; if (base_init()) { fprintf(stderr, "Error initializing memory\n"); exit(-1); } n = filesource_read(&fsrc, input_buffer, flen); lte_fft_run(&fft, input_buffer, fft_buffer); if (fmatlab) { fprintf(fmatlab, "infft="); vec_fprint_c(fmatlab, input_buffer, flen); fprintf(fmatlab, ";\n"); fprintf(fmatlab, "outfft="); vec_fprint_c(fmatlab, fft_buffer, CP_NSYMB(cp) * nof_prb * RE_X_RB); fprintf(fmatlab, ";\n"); } /* Get channel estimates for each port */ for (i=0;i<nof_ports;i++) { chest_ce_slot_port(&chest, fft_buffer, ce[i], 0, i); if (fmatlab) { chest_fprint(&chest, fmatlab, 0, i); } } INFO("Decoding PHICH\n", 0); /* Receive all PHICH groups and sequence numbers */ for (ngroup=0;ngroup<phich_ngroups(&phich);ngroup++) { for (nseq=0;nseq<max_nseq;nseq++) { if (phich_decode(&phich, fft_buffer, ce, ngroup, nseq, numsubframe, &ack_rx, &distance)<0) { printf("Error decoding ACK\n"); exit(-1); } INFO("%d/%d, ack_rx: %d, ns: %d, distance: %d\n", ngroup, nseq, ack_rx, numsubframe, distance); } } base_free(); fftwf_cleanup(); if (n < 0) { fprintf(stderr, "Error decoding phich\n"); exit(-1); } else if (n == 0) { printf("Could not decode phich\n"); exit(-1); } else { exit(0); } }
int main(int argc, char **argv) { ra_pdsch_t ra_dl; int i; int frame_cnt; int ret; dci_location_t locations[MAX_CANDIDATES]; uint32_t nof_locations; dci_msg_t dci_msg; if (argc < 3) { usage(argv[0]); exit(-1); } parse_args(argc,argv); if (base_init()) { fprintf(stderr, "Error initializing memory\n"); exit(-1); } ret = -1; frame_cnt = 0; do { filesource_read(&fsrc, input_buffer, flen); INFO("Reading %d samples sub-frame %d\n", flen, frame_cnt); lte_fft_run_sf(&fft, input_buffer, fft_buffer); /* Get channel estimates for each port */ chest_dl_estimate(&chest, fft_buffer, ce, frame_cnt %10); uint16_t crc_rem = 0; if (pdcch_extract_llr(&pdcch, fft_buffer, ce, chest_dl_get_noise_estimate(&chest), frame_cnt %10, cfi)) { fprintf(stderr, "Error extracting LLRs\n"); return -1; } if (rnti == SIRNTI) { INFO("Initializing common search space for SI-RNTI\n",0); nof_locations = pdcch_common_locations(&pdcch, locations, MAX_CANDIDATES, cfi); } else { INFO("Initializing user-specific search space for RNTI: 0x%x\n", rnti); nof_locations = pdcch_ue_locations(&pdcch, locations, MAX_CANDIDATES, frame_cnt %10, cfi, rnti); } for (i=0;i<nof_locations && crc_rem != rnti;i++) { if (pdcch_decode_msg(&pdcch, &dci_msg, &locations[i], dci_format, &crc_rem)) { fprintf(stderr, "Error decoding DCI msg\n"); return -1; } } if (crc_rem == rnti) { dci_msg_type_t type; if (dci_msg_get_type(&dci_msg, &type, cell.nof_prb, rnti, 1234)) { fprintf(stderr, "Can't get DCI message type\n"); exit(-1); } printf("MSG %d: ",i); dci_msg_type_fprint(stdout, type); switch(type.type) { case PDSCH_SCHED: bzero(&ra_dl, sizeof(ra_pdsch_t)); if (dci_msg_unpack_pdsch(&dci_msg, &ra_dl, cell.nof_prb, rnti != SIRNTI)) { fprintf(stderr, "Can't unpack PDSCH message\n"); } else { ra_pdsch_fprint(stdout, &ra_dl, cell.nof_prb); if (ra_dl.alloc_type == alloc_type2 && ra_dl.type2_alloc.mode == t2_loc && ra_dl.type2_alloc.riv == 11 && ra_dl.rv_idx == 0 && ra_dl.harq_process == 0 && ra_dl.mcs_idx == 2) { printf("This is the file signal.1.92M.amar.dat\n"); ret = 0; } } break; default: fprintf(stderr, "Unsupported message type\n"); break; } } frame_cnt++; } while (frame_cnt <= max_frames); base_free(); exit(ret); }