uint32_t iodev_get_sfidx(iodev_t *q) { if (iodev_isfile(q)) { return q->sf_idx; } else { return ue_sync_get_sfidx(&q->sframe); } }
int main(int argc, char **argv) { int ret; cf_t *sf_buffer; iodev_t iodev; prog_args_t prog_args; lte_cell_t cell; ue_dl_t ue_dl; bool ue_dl_initiated = false; int64_t sf_cnt; uint32_t sf_idx; pbch_mib_t mib; bool printed_sib = false; uint32_t rlen; parse_args(&prog_args, argc, argv); if (iodev_init(&iodev, &prog_args.io_config)) { fprintf(stderr, "Error initiating input device\n"); exit(-1); } #ifndef DISABLE_GRAPHICS if (!prog_args.disable_plots) { init_plots(); } #endif /* Setup SIGINT handler */ printf("\n --- Press Ctrl+C to exit --- \n"); signal(SIGINT, sigintHandler); /* Initialize frame and subframe counters */ sf_cnt = 0; sf_idx = 0; /* Main loop */ while (!go_exit && (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1)) { ret = iodev_receive(&iodev, &sf_buffer); if (ret < 0) { fprintf(stderr, "Error reading from input device (%d)\n", ret); break; } /* iodev_receive returns 1 if successfully read 1 aligned subframe */ if (ret == 1) { if (!ue_dl_initiated) { if (iodev_isUSRP(&iodev)) { cell = ue_sync_get_cell(&iodev.sframe); mib = ue_sync_get_mib(&iodev.sframe); } else { cell.id = prog_args.cell_id_file; cell.cp = CPNORM; cell.nof_ports = 1; // TODO: Use prog_args cell.nof_prb = prog_args.nof_prb_file; mib.phich_resources = R_1; mib.phich_length = PHICH_NORM; } if (ue_dl_init(&ue_dl, cell, mib.phich_resources, mib.phich_length, 1234)) { fprintf(stderr, "Error initiating UE downlink processing module\n"); exit(-1); } pdsch_set_rnti(&ue_dl.pdsch, prog_args.rnti); ue_dl_initiated = true; } else { if (iodev_isUSRP(&iodev)) { sf_idx = ue_sync_get_sfidx(&iodev.sframe); } rlen = ue_dl_receive(&ue_dl, sf_buffer, data, sf_idx, ue_sync_get_mib(&iodev.sframe).sfn, prog_args.rnti); if (rlen < 0) { fprintf(stderr, "\nError running receiver\n");fflush(stdout); exit(-1); } if (prog_args.rnti == SIRNTI && !printed_sib && rlen > 0) { printf("\n\nDecoded SIB1 Message: "); vec_fprint_hex(stdout, data, rlen); printf("\n");fflush(stdout); printed_sib = true; } if (!(sf_cnt % 10)) { printf("Cell ID: %3d, RSSI: %+.2f dBm, CFO: %+.4f KHz, SFO: %+.4f Khz, TimeOffset: %4d, Errors: %4d/%4d, BLER: %.1e\r", cell.id, 20*log10f(agc_get_rssi(&iodev.sframe.agc)), iodev.sframe.cur_cfo * 15, iodev.sframe.mean_time_offset / 5, iodev.sframe.peak_idx, (int) ue_dl.pkt_errors, (int) ue_dl.pkts_total, (float) ue_dl.pkt_errors / ue_dl.pkts_total); fflush(stdout); if (VERBOSE_ISINFO()) { printf("\n"); } } #ifndef DISABLE_GRAPHICS if (!prog_args.disable_plots && sf_idx == 5) { do_plots(&ue_dl, sf_idx); } #endif } if (iodev_isfile(&iodev)) { sf_idx++; if (sf_idx == NSUBFRAMES_X_FRAME) { sf_idx = 0; } } } if (prog_args.nof_subframes > 0) { sf_cnt++; } if (iodev_isfile(&iodev)) { usleep(5000); } } if (ue_dl_initiated) { ue_dl_free(&ue_dl); } iodev_free(&iodev); printf("\nBye\n"); exit(0); }