diff --git a/cmake/modules/FindVolk.cmake b/cmake/modules/FindVolk.cmake index f7db6f988..a6b045ecd 100644 --- a/cmake/modules/FindVolk.cmake +++ b/cmake/modules/FindVolk.cmake @@ -27,7 +27,7 @@ FIND_LIBRARY( # Some functions are not defined in old volk versions -IF(${VOLK_FOUND}) +IF(NOT ${VOLK_LIBRARIES} STREQUAL "") SET(CMAKE_REQUIRED_LIBRARIES ${VOLK_LIBRARIES} m) CHECK_FUNCTION_EXISTS_MATH(volk_32f_index_max_16u HAVE_VOLK_MAX_FUNCTION) CHECK_FUNCTION_EXISTS_MATH(volk_32f_accumulator_s32f HAVE_VOLK_ACC_FUNCTION) @@ -129,4 +129,4 @@ IF(${VOLK_FOUND}) INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(VOLK DEFAULT_MSG VOLK_LIBRARIES VOLK_INCLUDE_DIRS) MARK_AS_ADVANCED(VOLK_LIBRARIES VOLK_INCLUDE_DIRS VOLK_DEFINITIONS) -ENDIF(${VOLK_FOUND}) \ No newline at end of file +ENDIF(NOT ${VOLK_LIBRARIES} STREQUAL "") \ No newline at end of file diff --git a/cuhd/lib/cuhd_imp.cpp b/cuhd/lib/cuhd_imp.cpp index 642f3155d..cf0e5b64d 100644 --- a/cuhd/lib/cuhd_imp.cpp +++ b/cuhd/lib/cuhd_imp.cpp @@ -123,6 +123,8 @@ int cuhd_open(char *args, void **h) // handler->usrp = uhd::usrp::multi_usrp::make(_args + ", master_clock_rate=50000000" + ", num_recv_frames=512"); handler->usrp->set_clock_source("internal"); + + uhd::msg::register_handler(my_handler); std::string otw, cpu; otw = "sc16"; @@ -147,16 +149,14 @@ int cuhd_close(void *h) double cuhd_set_rx_srate(void *h, double freq) { cuhd_handler *handler = static_cast < cuhd_handler * >(h); - printf("Changing sampling freq now to %.2f MHz\n", freq/1000000); handler->usrp->set_rx_rate(freq); - printf("Done\n"); - /* + + double ret = handler->usrp->get_rx_rate(); if ((int) ret != (int) freq) { - printf("Got %f!=%f. setting master clock rate to %f\n",ret, freq, freq); handler->usrp->set_master_clock_rate(freq); handler->usrp->set_rx_rate(freq); } - */ + return freq; } @@ -170,9 +170,7 @@ double cuhd_set_rx_gain(void *h, double gain) double cuhd_set_rx_freq(void *h, double freq) { cuhd_handler *handler = static_cast < cuhd_handler * >(h); - printf("Tunning receiver to %.3f MHz\n", (double ) freq/1000000); handler->usrp->set_rx_freq(freq); - printf("Done\n"); return freq; } diff --git a/lte/examples/cell_search.c b/lte/examples/cell_search.c index 30ea2f4bf..6f1072ac8 100644 --- a/lte/examples/cell_search.c +++ b/lte/examples/cell_search.c @@ -55,7 +55,7 @@ int band = -1; int earfcn_start=-1, earfcn_end = -1; -cell_search_cfg_t config = {500, 50, 1.1}; +cell_search_cfg_t config = {100, 10, 16}; float uhd_gain = 60.0; @@ -140,16 +140,15 @@ int main(int argc, char **argv) { exit(-1); } - for (freq=0;freq 0) { + if (udpsource_init(&udp_source, "0.0.0.0", udp_port)) { + fprintf(stderr, "Error creating input UDP socket at port %d\n", udp_port); + exit(-1); + } + + /* + if (udpsource_set_nonblocking(&udp_source)) { + fprintf(stderr, "Error setting non-blocking\n"); + exit(-1); + } + */ + + if (udpsource_set_timeout(&udp_source, 5)) { + fprintf(stderr, "Error setting UDP socket timeout\n"); + exit(-1); + } + + printf("Opened UDP socket at port %d\n", udp_port); + } /* create ifft object */ if (lte_ifft_init(&ifft, CPNORM, cell.nof_prb)) { @@ -232,8 +260,15 @@ void base_free() { cuhd_close(&uhd); #endif } + + if (udp_port > 0) { + udpsource_free(&udp_source); + } + } +uint8_t data[10000], data_unpacked[10000]; + int main(int argc, char **argv) { int nf, sf_idx, N_id_2; cf_t pss_signal[PSS_LEN]; @@ -243,8 +278,8 @@ int main(int argc, char **argv) { ra_pdsch_t ra_dl; ra_prb_t prb_alloc; int i; - uint8_t *data; cf_t *sf_symbols[MAX_PORTS]; + cf_t *slot1_symbols[MAX_PORTS]; dci_msg_t dci_msg; dci_location_t locations[NSUBFRAMES_X_FRAME][10]; uint32_t sfn; @@ -274,17 +309,15 @@ int main(int argc, char **argv) { pss_generate(pss_signal, N_id_2); sss_generate(sss_signal0, sss_signal5, cell.id); - //refsignal_cs_generate(&csr_signal, cell); - /* Generate CRS signals */ if (chest_dl_init(&est, cell)) { fprintf(stderr, "Error initializing equalizer\n"); exit(-1); } - for (i = 0; i < MAX_PORTS; i++) { // now there's only 1 port sf_symbols[i] = sf_buffer; + slot1_symbols[i] = &sf_buffer[SLOT_LEN_RE(cell.nof_prb, cell.cp)]; } #ifndef DISABLE_UHD @@ -317,12 +350,6 @@ int main(int argc, char **argv) { for (i=0;i 0) { + int n = udpsource_read(&udp_source, data_unpacked, 1+(ra_dl.mcs.tbs-1)/8); + if (n > 0) { + bit_pack_vector(data_unpacked, data, n*8); + send_data = true; + } else if (n == 0) { + send_data = false; + } else { + fprintf(stderr, "Error receiving from UDP socket\n"); + exit(-1); + } + } else { + INFO("SF: %d, Generating %d random bits\n", sf_idx, ra_dl.mcs.tbs); + for (i=0;iuhd_args = ""; args->uhd_freq = -1.0; args->uhd_gain = 60.0; + args->udp_port = -1; + args->udp_address = "127.0.0.1"; } void usage(prog_args_t *args, char *prog) { - printf("Usage: %s [agldnrv] -f rx_frequency (in Hz)\n", prog); + printf("Usage: %s [agldnruv] -f rx_frequency (in Hz)\n", prog); printf("\t-a UHD args [Default %s]\n", args->uhd_args); printf("\t-g UHD RX gain [Default %.2f dB]\n", args->uhd_gain); printf("\t-r RNTI [Default 0x%x]\n",args->rnti); @@ -93,13 +97,15 @@ void usage(prog_args_t *args, char *prog) { printf("\t plots are disabled. Graphics library not available\n"); #endif printf("\t-n nof_subframes [Default %d]\n", args->nof_subframes); + printf("\t-u remote UDP port to send data (-1 does nothing with it) [Default %d]\n", args->udp_port); + printf("\t-U remote UDP address to send data [Default %s]\n", args->udp_address); printf("\t-v [set verbose to debug, default none]\n"); } void parse_args(prog_args_t *args, int argc, char **argv) { int opt; args_default(args); - while ((opt = getopt(argc, argv, "agldnvrf")) != -1) { + while ((opt = getopt(argc, argv, "agldnvrfuU")) != -1) { switch (opt) { case 'a': args->uhd_args = argv[optind]; @@ -119,6 +125,12 @@ void parse_args(prog_args_t *args, int argc, char **argv) { case 'l': args->force_N_id_2 = atoi(argv[optind]); break; + case 'u': + args->udp_port = atoi(argv[optind]); + break; + case 'U': + args->udp_address = argv[optind]; + break; case 'd': args->disable_plots = true; break; @@ -138,7 +150,7 @@ void parse_args(prog_args_t *args, int argc, char **argv) { /**********************************************************************/ /* TODO: Do something with the output data */ -uint8_t data[10000], data_unpacked[1000]; +uint8_t data[10000], data_packed[10000]; bool go_exit = false; @@ -156,7 +168,7 @@ int cuhd_recv_wrapper(void *h, void *data, uint32_t nsamples) { extern float mean_exec_time; -enum receiver_state { DECODE_MIB, DECODE_SIB} state; +enum receiver_state { DECODE_MIB, DECODE_PDSCH} state; int main(int argc, char **argv) { @@ -173,9 +185,18 @@ int main(int argc, char **argv) { uint32_t sfn = 0; // system frame number int n; uint8_t bch_payload[BCH_PAYLOAD_LEN], bch_payload_unpacked[BCH_PAYLOAD_LEN]; - uint32_t sfn_offset; + uint32_t sfn_offset; + udpsink_t udp_sink; + parse_args(&prog_args, argc, argv); + if (prog_args.udp_port > 0) { + if (udpsink_init(&udp_sink, prog_args.udp_address, prog_args.udp_port)) { + fprintf(stderr, "Error initiating UDP socket to %s:%d\n", prog_args.udp_address, prog_args.udp_port); + exit(-1); + } + } + printf("Opening UHD device...\n"); if (cuhd_open(prog_args.uhd_args, &uhd)) { fprintf(stderr, "Error opening uhd\n"); @@ -216,7 +237,7 @@ int main(int argc, char **argv) { fprintf(stderr, "Error initiating ue_sync\n"); exit(-1); } - if (ue_dl_init(&ue_dl, cell, 1234)) { // This is the User RNTI + if (ue_dl_init(&ue_dl, cell, prog_args.rnti==SIRNTI?1:prog_args.rnti)) { // This is the User RNTI fprintf(stderr, "Error initiating UE downlink processing module\n"); exit(-1); } @@ -240,14 +261,13 @@ int main(int argc, char **argv) { } #endif - - cuhd_start_rx_stream(uhd); // Variables for measurements uint32_t nframes=0; float rsrp=0.0, rsrq=0.0, snr=0.0; - + bool decode_pdsch; + /* Main loop */ while (!go_exit && (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1)) { @@ -271,19 +291,40 @@ int main(int argc, char **argv) { bcch_bch_unpack(bch_payload, BCH_PAYLOAD_LEN, &cell, &sfn); printf("Decoded MIB. SFN: %d, offset: %d\n", sfn, sfn_offset); sfn = (sfn + sfn_offset)%1024; - state = DECODE_SIB; + state = DECODE_PDSCH; } } break; - case DECODE_SIB: - /* We are looking for SI Blocks, search only in appropiate places */ - if ((ue_sync_get_sfidx(&ue_sync) == 5 && (sfn%2)==0)) { - n = ue_dl_decode_sib(&ue_dl, sf_buffer, data, ue_sync_get_sfidx(&ue_sync), - ((int) ceilf((float)3*(((sfn)/2)%4)/2))%4); + case DECODE_PDSCH: + if (prog_args.rnti != SIRNTI) { + decode_pdsch = true; + } else { + /* We are looking for SIB1 Blocks, search only in appropiate places */ + if ((ue_sync_get_sfidx(&ue_sync) == 5 && (sfn%2)==0)) { + decode_pdsch = true; + } else { + decode_pdsch = false; + } + } + if (decode_pdsch) { + if (prog_args.rnti != SIRNTI) { + n = ue_dl_decode(&ue_dl, sf_buffer, data_packed, ue_sync_get_sfidx(&ue_sync)); + } else { + n = ue_dl_decode_sib(&ue_dl, sf_buffer, data_packed, ue_sync_get_sfidx(&ue_sync), + ((int) ceilf((float)3*(((sfn)/2)%4)/2))%4); + } if (n < 0) { fprintf(stderr, "Error decoding UE DL\n");fflush(stdout); exit(-1); - } + } else if (n > 0) { + /* Send data if socket active */ + if (prog_args.udp_port > 0) { + bit_unpack_vector(data_packed, data, n); + if (udpsink_write(&udp_sink, data, 1+(n-1)/8) < 0) { + fprintf(stderr, "Error sending data through UDP socket\n"); + } + } + } nof_trials++; rsrq = VEC_EMA(chest_dl_get_rsrq(&ue_dl.chest), rsrq, 0.05); @@ -363,12 +404,12 @@ void init_plots() { plot_real_init(&poutfft); plot_real_setTitle(&poutfft, "Output FFT - Magnitude"); plot_real_setLabels(&poutfft, "Index", "dB"); - plot_real_setYAxisScale(&poutfft, -60, 0); + plot_real_setYAxisScale(&poutfft, -40, 40); plot_real_init(&pce); plot_real_setTitle(&pce, "Channel Response - Magnitude"); plot_real_setLabels(&pce, "Index", "dB"); - plot_real_setYAxisScale(&pce, -60, 0); + plot_real_setYAxisScale(&pce, -40, 40); plot_real_init(&p_sync); plot_real_setTitle(&p_sync, "PSS Cross-Corr abs value"); @@ -376,13 +417,13 @@ void init_plots() { plot_scatter_init(&pscatequal); plot_scatter_setTitle(&pscatequal, "PDSCH - Equalized Symbols"); - plot_scatter_setXAxisScale(&pscatequal, -2, 2); - plot_scatter_setYAxisScale(&pscatequal, -2, 2); + plot_scatter_setXAxisScale(&pscatequal, -4, 4); + plot_scatter_setYAxisScale(&pscatequal, -4, 4); plot_scatter_init(&pscatequal_pdcch); plot_scatter_setTitle(&pscatequal_pdcch, "PDCCH - Equalized Symbols"); - plot_scatter_setXAxisScale(&pscatequal_pdcch, -2, 2); - plot_scatter_setYAxisScale(&pscatequal_pdcch, -2, 2); + plot_scatter_setXAxisScale(&pscatequal_pdcch, -4, 4); + plot_scatter_setYAxisScale(&pscatequal_pdcch, -4, 4); } diff --git a/lte/phy/include/liblte/phy/common/phy_common.h b/lte/phy/include/liblte/phy/common/phy_common.h index 4603019ea..59ff15244 100644 --- a/lte/phy/include/liblte/phy/common/phy_common.h +++ b/lte/phy/include/liblte/phy/common/phy_common.h @@ -183,6 +183,8 @@ LIBLTE_API uint32_t lte_voffset(uint32_t symbol_id, LIBLTE_API int lte_cb_size(uint32_t index); +LIBLTE_API bool lte_cb_size_isvalid(uint32_t size); + LIBLTE_API char *lte_cp_string(lte_cp_t cp); LIBLTE_API char *lte_mod_string(lte_mod_t mod); diff --git a/lte/phy/include/liblte/phy/fec/turbodecoder.h b/lte/phy/include/liblte/phy/fec/turbodecoder.h index 9f4b9ea6c..57de9b7ad 100644 --- a/lte/phy/include/liblte/phy/fec/turbodecoder.h +++ b/lte/phy/include/liblte/phy/fec/turbodecoder.h @@ -83,7 +83,7 @@ LIBLTE_API void tdec_decision(tdec_t * h, uint8_t *output, uint32_t long_cb); -LIBLTE_API void tdec_run_all(tdec_t * h, +LIBLTE_API int tdec_run_all(tdec_t * h, llr_t * input, uint8_t *output, uint32_t nof_iterations, diff --git a/lte/phy/include/liblte/phy/io/udpsink.h b/lte/phy/include/liblte/phy/io/udpsink.h index e4ae81957..61b2f000c 100644 --- a/lte/phy/include/liblte/phy/io/udpsink.h +++ b/lte/phy/include/liblte/phy/io/udpsink.h @@ -36,19 +36,22 @@ #include #include "liblte/config.h" -#include "liblte/phy/io/format.h" /* Low-level API */ typedef struct LIBLTE_API { int sockfd; struct sockaddr_in servaddr; - data_type_t type; }udpsink_t; -LIBLTE_API int udpsink_init(udpsink_t *q, char *address, int port, data_type_t type); +LIBLTE_API int udpsink_init(udpsink_t *q, + char *address, + int port); + LIBLTE_API void udpsink_free(udpsink_t *q); -LIBLTE_API int udpsink_write(udpsink_t *q, void *buffer, int nsamples); +LIBLTE_API int udpsink_write(udpsink_t *q, + void *buffer, + int nof_bytes); /* High-level API */ diff --git a/lte/phy/include/liblte/phy/io/udpsource.h b/lte/phy/include/liblte/phy/io/udpsource.h index 77db9346e..e245e33fd 100644 --- a/lte/phy/include/liblte/phy/io/udpsource.h +++ b/lte/phy/include/liblte/phy/io/udpsource.h @@ -29,7 +29,7 @@ #ifndef UDPSOURCE_ #define UDPSOURCE_ - +#include #include #include #include @@ -37,19 +37,27 @@ #include #include "liblte/config.h" -#include "liblte/phy/io/format.h" /* Low-level API */ typedef struct LIBLTE_API { int sockfd; struct sockaddr_in servaddr; - data_type_t type; }udpsource_t; -LIBLTE_API int udpsource_init(udpsource_t *q, char *address, int port, data_type_t type); +LIBLTE_API int udpsource_init(udpsource_t *q, + char *address, + int port); + LIBLTE_API void udpsource_free(udpsource_t *q); -LIBLTE_API int udpsource_read(udpsource_t *q, void *buffer, int nsamples); +LIBLTE_API int udpsource_set_nonblocking(udpsource_t *q); + +LIBLTE_API int udpsource_read(udpsource_t *q, + void *buffer, + int nof_bytes); + +LIBLTE_API int udpsource_set_timeout(udpsource_t *q, + uint32_t microseconds); /* High-level API */ diff --git a/lte/phy/lib/ch_estimation/src/chest_dl.c b/lte/phy/lib/ch_estimation/src/chest_dl.c index e163ac805..9ed12a717 100644 --- a/lte/phy/lib/ch_estimation/src/chest_dl.c +++ b/lte/phy/lib/ch_estimation/src/chest_dl.c @@ -301,8 +301,8 @@ float chest_dl_rssi(chest_dl_t *q, cf_t *input, uint32_t port_id) { float rssi = 0; uint32_t nsymbols = refsignal_cs_nof_symbols(port_id); for (l=0;lcell.cp, port_id) * q->cell.nof_prb * RE_X_RB]; - rssi += vec_dot_prod_conj_ccc(tmp,tmp,q->cell.nof_prb * RE_X_RB); + cf_t *tmp = &input[refsignal_nsymbol(l, q->cell.cp, port_id) * q->cell.nof_prb * RE_X_RB]; + rssi += vec_dot_prod_conj_ccc(tmp, tmp, q->cell.nof_prb * RE_X_RB); } return rssi/nsymbols; } diff --git a/lte/phy/lib/common/src/fft.c b/lte/phy/lib/common/src/fft.c index 3a13782b4..0ba9dd990 100644 --- a/lte/phy/lib/common/src/fft.c +++ b/lte/phy/lib/common/src/fft.c @@ -95,6 +95,8 @@ int lte_ifft_init(lte_fft_t *q, lte_cp_t cp, uint32_t nof_prb) { ret = lte_fft_init_(q, cp, nof_prb, BACKWARD); if (ret == LIBLTE_SUCCESS) { + dft_plan_set_norm(&q->fft_plan, true); + /* set now zeros at CP */ for (i=0;inof_symbols;i++) { bzero(q->tmp, q->nof_guards * sizeof(cf_t)); diff --git a/lte/phy/lib/common/src/phy_common.c b/lte/phy/lib/common/src/phy_common.c index b82580ec3..f6ad8081e 100644 --- a/lte/phy/lib/common/src/phy_common.c +++ b/lte/phy/lib/common/src/phy_common.c @@ -34,7 +34,7 @@ #include "liblte/phy/common/phy_common.h" -const int tc_cb_sizes[NOF_TC_CB_SIZES] = { 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, +const uint32_t tc_cb_sizes[NOF_TC_CB_SIZES] = { 40, 48, 56, 64, 72, 80, 88, 96, 104, 112, 120, 128, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240, 248, 256, 264, 272, 280, 288, 296, 304, 312, 320, 328, 336, 344, 352, 360, 368, 376, 384, 392, 400, 408, 416, 424, 432, 440, 448, 456, @@ -117,12 +117,21 @@ bool lte_N_id_1_isvalid(uint32_t N_id_1) { */ int lte_cb_size(uint32_t index) { if (index < NOF_TC_CB_SIZES) { - return tc_cb_sizes[index]; + return (int) tc_cb_sizes[index]; } else { return LIBLTE_ERROR; } } +bool lte_cb_size_isvalid(uint32_t size) { + for (int i=0;i #include "liblte/phy/phy.h" -#include "turbocoder_test.h" +#include "turbodecoder_test.h" typedef _Complex float cf_t; @@ -46,7 +46,7 @@ float ebno_db = 100.0; uint32_t seed = 0; int K = -1; -#define MAX_ITERATIONS 4 +#define MAX_ITERATIONS 4 int nof_iterations = MAX_ITERATIONS; int test_known_data = 0; int test_errors = 0; diff --git a/lte/phy/lib/fec/test/turbocoder_test.h b/lte/phy/lib/fec/test/turbodecoder_test.h similarity index 100% rename from lte/phy/lib/fec/test/turbocoder_test.h rename to lte/phy/lib/fec/test/turbodecoder_test.h diff --git a/lte/phy/lib/io/src/udpsink.c b/lte/phy/lib/io/src/udpsink.c index 5a5890741..74bf7b9cf 100644 --- a/lte/phy/lib/io/src/udpsink.c +++ b/lte/phy/lib/io/src/udpsink.c @@ -37,16 +37,20 @@ #include "liblte/phy/io/udpsink.h" -int udpsink_init(udpsink_t *q, char *address, int port, data_type_t type) { +int udpsink_init(udpsink_t *q, char *address, int port) { bzero(q, sizeof(udpsink_t)); q->sockfd=socket(AF_INET,SOCK_DGRAM,0); + + if (q->sockfd < 0) { + perror("socket"); + return -1; + } q->servaddr.sin_family = AF_INET; q->servaddr.sin_addr.s_addr=inet_addr(address); q->servaddr.sin_port=htons(port); - q->type = type; return 0; } @@ -57,36 +61,15 @@ void udpsink_free(udpsink_t *q) { bzero(q, sizeof(udpsink_t)); } -int udpsink_write(udpsink_t *q, void *buffer, int nsamples) { - int size; - - switch(q->type) { - case FLOAT: - case COMPLEX_FLOAT: - case COMPLEX_SHORT: - fprintf(stderr, "Not implemented\n"); - return -1; - case FLOAT_BIN: - case COMPLEX_FLOAT_BIN: - case COMPLEX_SHORT_BIN: - if (q->type == FLOAT_BIN) { - size = sizeof(float); - } else if (q->type == COMPLEX_FLOAT_BIN) { - size = sizeof(_Complex float); - } else if (q->type == COMPLEX_SHORT_BIN) { - size = sizeof(_Complex short); - } - return sendto(q->sockfd, buffer, nsamples * size, 0, - &q->servaddr, sizeof(struct sockaddr_in)); - break; - } - return -1; +int udpsink_write(udpsink_t *q, void *buffer, int nof_bytes) { + return sendto(q->sockfd, buffer, nof_bytes, 0, + &q->servaddr, sizeof(struct sockaddr_in)); } int udpsink_initialize(udpsink_hl* h) { - return udpsink_init(&h->obj, h->init.address, h->init.port, h->init.data_type); + return udpsink_init(&h->obj, h->init.address, h->init.port); } int udpsink_work(udpsink_hl* h) { diff --git a/lte/phy/lib/io/src/udpsource.c b/lte/phy/lib/io/src/udpsource.c index a6a39d2ac..cd2bf59ba 100644 --- a/lte/phy/lib/io/src/udpsource.c +++ b/lte/phy/lib/io/src/udpsource.c @@ -29,23 +29,33 @@ #include #include #include +#include #include #include #include +#include #include "liblte/phy/io/udpsource.h" -int udpsource_init(udpsource_t *q, char *address, int port, data_type_t type) { +int udpsource_init(udpsource_t *q, char *address, int port) { bzero(q, sizeof(udpsource_t)); q->sockfd=socket(AF_INET,SOCK_DGRAM,0); + if (q->sockfd < 0) { + perror("socket"); + return -1; + } + q->servaddr.sin_family = AF_INET; q->servaddr.sin_addr.s_addr=inet_addr(address); q->servaddr.sin_port=htons(port); - bind(q->sockfd,(struct sockaddr *)&q->servaddr,sizeof(struct sockaddr_in)); + + if (bind(q->sockfd,(struct sockaddr *)&q->servaddr,sizeof(struct sockaddr_in))) { + perror("bind"); + return -1; + } - q->type = type; return 0; } @@ -56,34 +66,41 @@ void udpsource_free(udpsource_t *q) { bzero(q, sizeof(udpsource_t)); } -int udpsource_read(udpsource_t *q, void *buffer, int nsamples) { - int size; - - switch(q->type) { - case FLOAT: - case COMPLEX_FLOAT: - case COMPLEX_SHORT: - fprintf(stderr, "Not implemented\n"); - return -1; - case FLOAT_BIN: - case COMPLEX_FLOAT_BIN: - case COMPLEX_SHORT_BIN: - if (q->type == FLOAT_BIN) { - size = sizeof(float); - } else if (q->type == COMPLEX_FLOAT_BIN) { - size = sizeof(_Complex float); - } else if (q->type == COMPLEX_SHORT_BIN) { - size = sizeof(_Complex short); +int udpsource_read(udpsource_t *q, void *buffer, int nbytes) { + int n = recv(q->sockfd, buffer, nbytes, 0); + + if (n == -1) { + if (errno == EAGAIN) { + return 0; + } else { + return -1; } - return recv(q->sockfd, buffer, size * nsamples, 0); - break; + } else { + return n; } - return -1; } +int udpsource_set_nonblocking(udpsource_t *q) { + if (fcntl(q->sockfd, F_SETFL, O_NONBLOCK)) { + perror("fcntl"); + return -1; + } + return 0; +} + +int udpsource_set_timeout(udpsource_t *q, uint32_t microseconds) { + struct timeval t; + t.tv_sec = 0; + t.tv_usec = microseconds; + if (setsockopt(q->sockfd, SOL_SOCKET, SO_RCVTIMEO, &t, sizeof(struct timeval))) { + perror("setsockopt"); + return -1; + } + return 0; +} int udpsource_initialize(udpsource_hl* h) { - return udpsource_init(&h->obj, h->init.address, h->init.port, h->init.data_type); + return udpsource_init(&h->obj, h->init.address, h->init.port); } int udpsource_work(udpsource_hl* h) { diff --git a/lte/phy/lib/phch/src/pdsch.c b/lte/phy/lib/phch/src/pdsch.c index 8d7ebc433..42743f6eb 100644 --- a/lte/phy/lib/phch/src/pdsch.c +++ b/lte/phy/lib/phch/src/pdsch.c @@ -204,6 +204,7 @@ int pdsch_init(pdsch_t *q, lte_cell_t cell) { if (precoding_init(&q->precoding, SF_LEN_RE(cell.nof_prb, cell.cp))) { fprintf(stderr, "Error initializing precoding\n"); + goto clean; } for (i = 0; i < 4; i++) { @@ -212,9 +213,11 @@ int pdsch_init(pdsch_t *q, lte_cell_t cell) { } } if (crc_init(&q->crc_tb, LTE_CRC24A, 24)) { + fprintf(stderr, "Error initiating CRC\n"); goto clean; } if (crc_init(&q->crc_cb, LTE_CRC24B, 24)) { + fprintf(stderr, "Error initiating CRC\n"); goto clean; } @@ -224,9 +227,11 @@ int pdsch_init(pdsch_t *q, lte_cell_t cell) { q->rnti_is_set = false; if (tcod_init(&q->encoder, MAX_LONG_CB)) { + fprintf(stderr, "Error initiating Turbo Coder\n"); goto clean; } if (tdec_init(&q->decoder, MAX_LONG_CB)) { + fprintf(stderr, "Error initiating Turbo Decoder\n"); goto clean; } @@ -397,7 +402,7 @@ int pdsch_harq_init(pdsch_harq_t *p, pdsch_t *pdsch) { // We add 50 % larger buffer to the maximum expected bits per subframe // FIXME: Use HARQ buffer limitation based on UE category - p->w_buff_size = p->cell.nof_prb * MAX_PDSCH_RE(p->cell.cp) * 6 * 2 / p->max_cb; + p->w_buff_size = p->cell.nof_prb * MAX_PDSCH_RE(p->cell.cp) * 6 * 2; for (i=0;imax_cb;i++) { p->pdsch_w_buff_f[i] = vec_malloc(sizeof(float) * p->w_buff_size); if (!p->pdsch_w_buff_f[i]) { @@ -851,7 +856,8 @@ int pdsch_encode(pdsch_t *q, uint8_t *data, cf_t *sf_symbols[MAX_PORTS], uint32_ if (q != NULL && data != NULL && subframe < 10 && - harq_process != NULL) + harq_process != NULL && + harq_process->mcs.mod > 0) { if (q->rnti_is_set) { diff --git a/lte/phy/lib/ue/src/ue_dl.c b/lte/phy/lib/ue/src/ue_dl.c index f19557e22..472a6c7f0 100644 --- a/lte/phy/lib/ue/src/ue_dl.c +++ b/lte/phy/lib/ue/src/ue_dl.c @@ -146,7 +146,7 @@ void ue_dl_free(ue_dl_t *q) { void ue_dl_set_rnti(ue_dl_t *q, uint16_t rnti) { q->current_rnti = rnti; - pdsch_set_rnti(&q->pdsch, SIRNTI); + pdsch_set_rnti(&q->pdsch, rnti); } void ue_dl_reset(ue_dl_t *q) { @@ -155,7 +155,7 @@ void ue_dl_reset(ue_dl_t *q) { LIBLTE_API float mean_exec_time=0; -dci_format_t ue_formats[] = {Format1A,Format1}; // Format1B should go here also +dci_format_t ue_formats[] = {Format1,Format1A}; // Format1B should go here also const uint32_t nof_ue_formats = 2; dci_format_t common_formats[] = {Format1A,Format1C}; @@ -253,7 +253,9 @@ int ue_dl_decode_sib(ue_dl_t *q, cf_t *input, uint8_t *data, uint32_t sf_idx, ui } } if (q->harq_process[0].mcs.mod > 0) { - ret = pdsch_decode(&q->pdsch, q->sf_symbols, q->ce, chest_dl_get_noise_estimate(&q->chest), data, sf_idx, + ret = pdsch_decode(&q->pdsch, q->sf_symbols, q->ce, + chest_dl_get_noise_estimate(&q->chest), + data, sf_idx, &q->harq_process[0], rvidx); if (ret == LIBLTE_ERROR) { q->pkt_errors++; diff --git a/lte/phy/lib/ue/src/ue_sync.c b/lte/phy/lib/ue/src/ue_sync.c index d82e5c709..0338b1aba 100644 --- a/lte/phy/lib/ue/src/ue_sync.c +++ b/lte/phy/lib/ue/src/ue_sync.c @@ -100,7 +100,7 @@ int ue_sync_init(ue_sync_t *q, sync_correct_cfo(&q->sfind, true); sync_correct_cfo(&q->strack, true); - sync_set_threshold(&q->sfind, 1.1); + sync_set_threshold(&q->sfind, 1.3); sync_set_em_alpha(&q->sfind, 0.01); q->nof_avg_find_frames = FIND_NOF_AVG_FRAMES; sync_set_threshold(&q->strack, 1.2);