rework error handling in Soapy and add statistics

master
Andre Puschmann 7 years ago
parent ecfa685dde
commit 937cb4d7a8

@ -57,6 +57,13 @@ typedef struct {
srslte_rf_info_t info; srslte_rf_info_t info;
double tx_rate; double tx_rate;
size_t rx_mtu, tx_mtu; size_t rx_mtu, tx_mtu;
uint32_t num_time_errors;
uint32_t num_lates;
uint32_t num_overflows;
uint32_t num_underflows;
uint32_t num_other_errors;
uint32_t num_stream_curruption;
} rf_soapy_handler_t; } rf_soapy_handler_t;
@ -354,6 +361,13 @@ int rf_soapy_close(void *h)
SoapySDRDevice_unmake(handler->device); SoapySDRDevice_unmake(handler->device);
free(handler); free(handler);
// print statistics
if (handler->num_lates) printf("#lates=%d\n", handler->num_lates);
if (handler->num_overflows) printf("#overflows=%d\n", handler->num_overflows);
if (handler->num_underflows) printf("#underflows=%d\n", handler->num_underflows);
if (handler->num_time_errors) printf("#time_errors=%d\n", handler->num_time_errors);
if (handler->num_other_errors) printf("#other_errors=%d\n", handler->num_other_errors);
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
@ -542,20 +556,22 @@ int rf_soapy_recv_with_time_multi(void *h,
} }
ret = SoapySDRDevice_readStream(handler->device, handler->rxStream, buffs_ptr, rx_samples, &flags, &timeNs, timeoutUs); ret = SoapySDRDevice_readStream(handler->device, handler->rxStream, buffs_ptr, rx_samples, &flags, &timeNs, timeoutUs);
if(ret < 0) { if (ret == SOAPY_SDR_OVERFLOW || (ret > 0 && (flags & SOAPY_SDR_END_ABRUPT) != 0)) {
// continue when getting overflows and timeouts handler->num_overflows++;
if (ret == SOAPY_SDR_OVERFLOW) { fprintf(stderr, "O");
fprintf(stderr, "O"); fflush(stderr);
fflush(stderr); continue;
continue; } else
} else if (SOAPY_SDR_TIMEOUT) { if (ret == SOAPY_SDR_TIMEOUT) {
fprintf(stderr, "T"); handler->num_time_errors++;
fflush(stderr); fprintf(stderr, "T");
continue; fflush(stderr);
} else { continue;
printf("rx error in soapy, ret=%d, flags=%d, timeNs=%lld\n", ret, flags, timeNs); } else
return SRSLTE_ERROR; if (ret < 0) {
} // unspecific error
printf("SoapySDRDevice_readStream returned %d: %s\n", ret, SoapySDR_errToStr(ret));
handler->num_other_errors++;
} }
// update rx time only for first segment // update rx time only for first segment
@ -680,20 +696,25 @@ int rf_soapy_send_timed_multi(void *h,
timeNs += adv; timeNs += adv;
} }
n += ret; n += ret;
} else }
else
if (ret < 0) { if (ret < 0) {
// An error has occured // An error has occured
switch (ret) { switch (ret) {
case SOAPY_SDR_TIMEOUT: case SOAPY_SDR_TIMEOUT:
handler->num_lates++;
printf("L"); printf("L");
break; break;
case SOAPY_SDR_STREAM_ERROR: case SOAPY_SDR_STREAM_ERROR:
handler->num_stream_curruption++;
printf("E"); printf("E");
break; break;
case SOAPY_SDR_TIME_ERROR: case SOAPY_SDR_TIME_ERROR:
handler->num_time_errors++;
printf("T"); printf("T");
break; break;
case SOAPY_SDR_UNDERFLOW: case SOAPY_SDR_UNDERFLOW:
handler->num_underflows++;
printf("U"); printf("U");
break; break;
default: default:
@ -702,14 +723,12 @@ int rf_soapy_send_timed_multi(void *h,
return SRSLTE_ERROR; return SRSLTE_ERROR;
} }
} }
trials++; trials++;
} while (n < nsamples && trials < 100); } while (n < nsamples && trials < 100);
if (n != nsamples) { if (n != nsamples) {
fprintf(stderr, "Couldn't write all samples.\n"); fprintf(stderr, "Couldn't write all samples after %d trials.\n", trials);
return SRSLTE_ERROR;
} }
return ret; return n;
} }

Loading…
Cancel
Save