fixing soapy Tx for lime and RTL-SDR

master
yagoda 8 years ago
parent 266f1b08fb
commit 12d58bbb62

@ -43,9 +43,14 @@ typedef struct {
SoapySDRRange *ranges; SoapySDRRange *ranges;
SoapySDRStream *rxStream; SoapySDRStream *rxStream;
SoapySDRStream *txStream; SoapySDRStream *txStream;
bool tx_stream_active;
} rf_soapy_handler_t; } rf_soapy_handler_t;
cf_t zero_mem[64*1024];
int soapy_error(void *h) int soapy_error(void *h)
{ {
return 0; 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) char* rf_soapy_devname(void* h)
{ {
return "soapy"; return "soapy";
@ -121,14 +127,11 @@ int rf_soapy_start_rx_stream(void *h)
int rf_soapy_start_tx_stream(void *h) int rf_soapy_start_tx_stream(void *h)
{ {
rf_soapy_handler_t *handler = (rf_soapy_handler_t*) 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;
}
if(SoapySDRDevice_activateStream(handler->device, handler->txStream, 0, 0, 0) != 0) if(SoapySDRDevice_activateStream(handler->device, handler->txStream, 0, 0, 0) != 0)
return SRSLTE_ERROR; return SRSLTE_ERROR;
handler->tx_stream_active = true;
return SRSLTE_SUCCESS; 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)); bzero(handler, sizeof(rf_soapy_handler_t));
*h = handler; *h = handler;
handler->device = sdr; 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) { if (SoapySDRDevice_setupStream(handler->device, &(handler->rxStream), SOAPY_SDR_RX, SOAPY_SDR_CF32, NULL, 0, NULL) != 0) {
printf("setupStream fail: %s\n", SoapySDRDevice_lastError()); printf("setupStream fail: %s\n", SoapySDRDevice_lastError());
return SRSLTE_ERROR; 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; return SRSLTE_SUCCESS;
} }
@ -300,7 +307,7 @@ double rf_soapy_set_tx_gain(void *h, double gain)
printf("setGain fail: %s\n", SoapySDRDevice_lastError()); printf("setGain fail: %s\n", SoapySDRDevice_lastError());
return SRSLTE_ERROR; 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()); printf("setFrequency fail: %s\n", SoapySDRDevice_lastError());
return SRSLTE_ERROR; return SRSLTE_ERROR;
} }
return SoapySDRDevice_getFrequency(handler->device, SOAPY_SDR_RX, 0); return SoapySDRDevice_getFrequency(handler->device, SOAPY_SDR_TX, 0);
} }
@ -422,14 +429,44 @@ int rf_soapy_send_timed(void *h,
bool is_start_of_burst, bool is_start_of_burst,
bool is_end_of_burst) bool is_end_of_burst)
{ {
int flags; int flags;
long long timeNs; long long timeNs;
int trials = 0;
int ret = 0;
rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h;
timeNs = secs * 1000000000; timeNs = secs * 1000000000;
timeNs = timeNs + (frac_secs * 1000000000); timeNs = timeNs + (frac_secs * 1000000000);
int ret = SoapySDRDevice_writeStream(handler->device, handler->txStream, data, nsamples, &flags, timeNs, 100000); 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) if(ret != nsamples)
return SRSLTE_ERROR; return SRSLTE_ERROR;
return ret; return ret;
} }

Loading…
Cancel
Save