From 12d58bbb625395cc276e04e99a59ccfde94c24c4 Mon Sep 17 00:00:00 2001 From: yagoda Date: Thu, 13 Jul 2017 15:14:22 +0100 Subject: [PATCH] fixing soapy Tx for lime and RTL-SDR --- lib/src/phy/rf/rf_soapy_imp.c | 95 ++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 29 deletions(-) diff --git a/lib/src/phy/rf/rf_soapy_imp.c b/lib/src/phy/rf/rf_soapy_imp.c index 8fcf57c24..760b9b880 100644 --- a/lib/src/phy/rf/rf_soapy_imp.c +++ b/lib/src/phy/rf/rf_soapy_imp.c @@ -43,9 +43,14 @@ typedef struct { SoapySDRRange *ranges; SoapySDRStream *rxStream; SoapySDRStream *txStream; + bool tx_stream_active; } rf_soapy_handler_t; +cf_t zero_mem[64*1024]; + + + int soapy_error(void *h) { return 0; @@ -82,6 +87,7 @@ void rf_soapy_register_error_handler(void *notused, srslte_rf_error_handler_t ne } + char* rf_soapy_devname(void* h) { return "soapy"; @@ -120,15 +126,12 @@ int rf_soapy_start_rx_stream(void *h) int rf_soapy_start_tx_stream(void *h) { - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - if (SoapySDRDevice_setupStream(handler->device, &(handler->txStream), SOAPY_SDR_TX, SOAPY_SDR_CF32, NULL, 0, NULL) != 0) { - printf("setupStream fail: %s\n", SoapySDRDevice_lastError()); - return SRSLTE_ERROR; - } - +rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; if(SoapySDRDevice_activateStream(handler->device, handler->txStream, 0, 0, 0) != 0) return SRSLTE_ERROR; + handler->tx_stream_active = true; + return SRSLTE_SUCCESS; } @@ -210,12 +213,16 @@ int rf_soapy_open_multi(char *args, void **h, uint32_t nof_rx_antennas) bzero(handler, sizeof(rf_soapy_handler_t)); *h = handler; handler->device = sdr; - + handler->tx_stream_active = false; if (SoapySDRDevice_setupStream(handler->device, &(handler->rxStream), SOAPY_SDR_RX, SOAPY_SDR_CF32, NULL, 0, NULL) != 0) { printf("setupStream fail: %s\n", SoapySDRDevice_lastError()); return SRSLTE_ERROR; } - + + if (SoapySDRDevice_setupStream(handler->device, &(handler->txStream), SOAPY_SDR_TX, SOAPY_SDR_CF32, NULL, 0, NULL) != 0) { + printf("setupStream fail: %s\n", SoapySDRDevice_lastError()); + return SRSLTE_ERROR; + } return SRSLTE_SUCCESS; } @@ -300,7 +307,7 @@ double rf_soapy_set_tx_gain(void *h, double gain) printf("setGain fail: %s\n", SoapySDRDevice_lastError()); return SRSLTE_ERROR; } - return rf_soapy_get_rx_gain(h); + return rf_soapy_get_tx_gain(h); } @@ -338,7 +345,7 @@ double rf_soapy_set_tx_freq(void *h, double freq) printf("setFrequency fail: %s\n", SoapySDRDevice_lastError()); return SRSLTE_ERROR; } - return SoapySDRDevice_getFrequency(handler->device, SOAPY_SDR_RX, 0); + return SoapySDRDevice_getFrequency(handler->device, SOAPY_SDR_TX, 0); } @@ -413,23 +420,53 @@ int rf_soapy_recv_with_time(void *h, int rf_soapy_send_timed(void *h, - void *data, - int nsamples, - time_t secs, - double frac_secs, - bool has_time_spec, - bool blocking, - bool is_start_of_burst, - bool is_end_of_burst) -{ - int flags; - long long timeNs; - rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; - timeNs = secs * 1000000000; - timeNs = timeNs + (frac_secs * 1000000000); - int ret = SoapySDRDevice_writeStream(handler->device, handler->txStream, data, nsamples, &flags, timeNs, 100000); - if(ret != nsamples) - return SRSLTE_ERROR; - - return ret; + void *data, + int nsamples, + time_t secs, + double frac_secs, + bool has_time_spec, + bool blocking, + bool is_start_of_burst, + bool is_end_of_burst) +{ + + int flags; + long long timeNs; + int trials = 0; + int ret = 0; + rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; + timeNs = secs * 1000000000; + timeNs = timeNs + (frac_secs * 1000000000); + int num_channels = 1; + int n = 0; + + if(!handler->tx_stream_active){ + rf_soapy_start_tx_stream(h); + } + + + cf_t *data_c = (cf_t*) data; + do{ + size_t tx_samples = nsamples; + if (tx_samples > nsamples - n) + { + tx_samples = nsamples - n; + } + void *buff = (void*) &data_c[n]; + const void *buffs_ptr[1] = {buff}; + ret = SoapySDRDevice_writeStream(handler->device, handler->txStream, buffs_ptr, tx_samples, &flags, timeNs, 10000); + if(ret < 0) + return SRSLTE_ERROR; + n += ret; + trials++; + }while (n < nsamples && trials < 100); + + + if(ret != nsamples) + return SRSLTE_ERROR; + + + + return ret; + }