fix for soapy

master
Ismael Gomez 8 years ago
commit dd5822077b

@ -44,6 +44,7 @@ typedef struct {
SoapySDRStream *rxStream; SoapySDRStream *rxStream;
SoapySDRStream *txStream; SoapySDRStream *txStream;
bool tx_stream_active; bool tx_stream_active;
bool rx_stream_active;
} rf_soapy_handler_t; } rf_soapy_handler_t;
@ -116,22 +117,23 @@ void rf_soapy_set_rx_cal(void *h, srslte_rf_cal_t *cal)
int rf_soapy_start_rx_stream(void *h) int rf_soapy_start_rx_stream(void *h)
{ {
rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h;
if(handler->rx_stream_active == false){
if (SoapySDRDevice_activateStream(handler->device, handler->rxStream, 0, 0, 0) != 0) if(SoapySDRDevice_activateStream(handler->device, handler->rxStream, 0, 0, 0) != 0)
return SRSLTE_ERROR; return SRSLTE_ERROR;
handler->rx_stream_active = true;
}
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
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_activateStream(handler->device, handler->txStream, 0, 0, 0) != 0) if(handler->tx_stream_active == false){
return SRSLTE_ERROR; if(SoapySDRDevice_activateStream(handler->device, handler->txStream, 0, 0, 0) != 0)
return SRSLTE_ERROR;
handler->tx_stream_active = true; handler->tx_stream_active = true;
}
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
@ -142,6 +144,7 @@ int rf_soapy_stop_rx_stream(void *h)
if (SoapySDRDevice_deactivateStream(handler->device, handler->rxStream, 0, 0) != 0) if (SoapySDRDevice_deactivateStream(handler->device, handler->rxStream, 0, 0) != 0)
return SRSLTE_ERROR; return SRSLTE_ERROR;
handler->rx_stream_active = false;
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
@ -152,6 +155,8 @@ int rf_soapy_stop_tx_stream(void *h)
if(SoapySDRDevice_deactivateStream(handler->device, handler->txStream, 0, 0) != 0) if(SoapySDRDevice_deactivateStream(handler->device, handler->txStream, 0, 0) != 0)
return SRSLTE_ERROR; return SRSLTE_ERROR;
handler->tx_stream_active = false;
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
@ -214,15 +219,25 @@ int rf_soapy_open_multi(char *args, void **h, uint32_t nof_rx_antennas)
*h = handler; *h = handler;
handler->device = sdr; handler->device = sdr;
handler->tx_stream_active = false; handler->tx_stream_active = false;
if (SoapySDRDevice_setupStream(handler->device, &(handler->rxStream), SOAPY_SDR_RX, SOAPY_SDR_CF32, NULL, 0, NULL) != 0) { handler->rx_stream_active = false;
printf("setupStream fail: %s\n", SoapySDRDevice_lastError());
return SRSLTE_ERROR;
if(SoapySDRDevice_getNumChannels(handler->device,SOAPY_SDR_RX) > 0){
printf("setting up RX stream\n");
if(SoapySDRDevice_setupStream(handler->device, &(handler->rxStream), SOAPY_SDR_RX, SOAPY_SDR_CF32, NULL, 0, NULL) != 0) {
printf("Rx 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) { if(SoapySDRDevice_getNumChannels(handler->device,SOAPY_SDR_TX) > 0){
printf("setupStream fail: %s\n", SoapySDRDevice_lastError()); printf("setting up TX stream\n");
return SRSLTE_ERROR; if (SoapySDRDevice_setupStream(handler->device, &(handler->txStream), SOAPY_SDR_TX, SOAPY_SDR_CF32, NULL, 0, NULL) != 0) {
printf("Tx setupStream fail: %s\n", SoapySDRDevice_lastError());
return SRSLTE_ERROR;
}
} }
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
@ -362,10 +377,7 @@ int rf_soapy_recv_with_time_multi(void *h,
double *frac_secs) double *frac_secs)
{ {
rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h; rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h;
//void *buffs[] = {buff}; //array of buffers
int flags; //flags set by receive operation int flags; //flags set by receive operation
int num_channels = 1; // temp int num_channels = 1; // temp
int trials = 0; int trials = 0;
@ -375,16 +387,14 @@ int rf_soapy_recv_with_time_multi(void *h,
do { do {
size_t rx_samples = nsamples; size_t rx_samples = nsamples;
if (rx_samples > nsamples - n) if (rx_samples > nsamples - n){
{
rx_samples = nsamples - n; rx_samples = nsamples - n;
} }
void *buffs_ptr[4]; void *buffs_ptr[4];
for (int i=0; i<num_channels; i++) for (int i=0; i<num_channels; i++){
{
cf_t *data_c = (cf_t*) data[i]; cf_t *data_c = (cf_t*) data[i];
buffs_ptr[i] = &data_c[n]; buffs_ptr[i] = &data_c[n];
} //(void*)(&data) }
ret = SoapySDRDevice_readStream(handler->device, handler->rxStream, buffs_ptr , rx_samples, &flags, &timeNs, 1000000); ret = SoapySDRDevice_readStream(handler->device, handler->rxStream, buffs_ptr , rx_samples, &flags, &timeNs, 1000000);
if(ret < 0) { if(ret < 0) {
// continue when getting overflows // continue when getting overflows
@ -446,27 +456,24 @@ int rf_soapy_send_timed(void *h,
cf_t *data_c = (cf_t*) data; cf_t *data_c = (cf_t*) data;
do{ do{
size_t tx_samples = nsamples; size_t tx_samples = nsamples;
if (tx_samples > nsamples - n) if (tx_samples > nsamples - n) {
{
tx_samples = nsamples - n; tx_samples = nsamples - n;
} }
void *buff = (void*) &data_c[n]; void *buff = (void*) &data_c[n];
const void *buffs_ptr[1] = {buff}; const void *buffs_ptr[1] = {buff};
ret = SoapySDRDevice_writeStream(handler->device, handler->txStream, buffs_ptr, tx_samples, &flags, timeNs, 10000); ret = SoapySDRDevice_writeStream(handler->device, handler->txStream, buffs_ptr, tx_samples, &flags, timeNs, 10000);
if(ret < 0) if(ret < 0)
return SRSLTE_ERROR; return SRSLTE_ERROR;
n += ret; n += ret;
trials++; trials++;
}while (n < nsamples && trials < 100); }while (n < nsamples && trials < 100);
if(ret != nsamples) if(ret != nsamples)
return SRSLTE_ERROR; return SRSLTE_ERROR;
return ret; return ret;
} }

Loading…
Cancel
Save