add rf error handler in soapy

This commit is contained in:
Andre Puschmann 2018-07-06 11:09:56 +02:00
parent a38abfbd47
commit d7e4797f3f
1 changed files with 44 additions and 10 deletions

View File

@ -62,6 +62,8 @@ typedef struct {
double tx_rate; double tx_rate;
size_t rx_mtu, tx_mtu; size_t rx_mtu, tx_mtu;
srslte_rf_error_handler_t soapy_error_handler;
uint32_t num_time_errors; uint32_t num_time_errors;
uint32_t num_lates; uint32_t num_lates;
uint32_t num_overflows; uint32_t num_overflows;
@ -74,6 +76,41 @@ typedef struct {
cf_t zero_mem[64*1024]; cf_t zero_mem[64*1024];
static void log_overflow(rf_soapy_handler_t *h) {
if (h->soapy_error_handler) {
srslte_rf_error_t error;
bzero(&error, sizeof(srslte_rf_error_t));
error.type = SRSLTE_RF_ERROR_OVERFLOW;
h->soapy_error_handler(error);
} else {
h->num_overflows++;
}
}
static void log_late(rf_soapy_handler_t *h, bool is_rx) {
if (h->soapy_error_handler) {
srslte_rf_error_t error;
bzero(&error, sizeof(srslte_rf_error_t));
error.opt = is_rx?1:0;
error.type = SRSLTE_RF_ERROR_LATE;
h->soapy_error_handler(error);
} else {
h->num_lates++;
}
}
static void log_underflow(rf_soapy_handler_t *h) {
if (h->soapy_error_handler) {
srslte_rf_error_t error;
bzero(&error, sizeof(srslte_rf_error_t));
error.type = SRSLTE_RF_ERROR_UNDERFLOW;
h->soapy_error_handler(error);
} else {
h->num_underflows++;
}
}
int soapy_error(void *h) int soapy_error(void *h)
{ {
return 0; return 0;
@ -104,9 +141,10 @@ void rf_soapy_suppress_stdout(void *h)
} }
void rf_soapy_register_error_handler(void *notused, srslte_rf_error_handler_t new_handler) void rf_soapy_register_error_handler(void *h, srslte_rf_error_handler_t new_handler)
{ {
// not supported rf_soapy_handler_t *handler = (rf_soapy_handler_t*) h;
handler->soapy_error_handler = new_handler;
} }
@ -647,15 +685,11 @@ 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 == SOAPY_SDR_OVERFLOW || (ret > 0 && (flags & SOAPY_SDR_END_ABRUPT) != 0)) { if (ret == SOAPY_SDR_OVERFLOW || (ret > 0 && (flags & SOAPY_SDR_END_ABRUPT) != 0)) {
handler->num_overflows++; log_overflow(handler);
fprintf(stderr, "O");
fflush(stderr);
continue; continue;
} else } else
if (ret == SOAPY_SDR_TIMEOUT) { if (ret == SOAPY_SDR_TIMEOUT) {
handler->num_time_errors++; log_late(handler, true);
fprintf(stderr, "T");
fflush(stderr);
continue; continue;
} else } else
if (ret < 0) { if (ret < 0) {
@ -792,7 +826,7 @@ int rf_soapy_send_timed_multi(void *h,
// An error has occured // An error has occured
switch (ret) { switch (ret) {
case SOAPY_SDR_TIMEOUT: case SOAPY_SDR_TIMEOUT:
handler->num_lates++; log_late(handler, false);
printf("L"); printf("L");
break; break;
case SOAPY_SDR_STREAM_ERROR: case SOAPY_SDR_STREAM_ERROR:
@ -804,7 +838,7 @@ int rf_soapy_send_timed_multi(void *h,
printf("T"); printf("T");
break; break;
case SOAPY_SDR_UNDERFLOW: case SOAPY_SDR_UNDERFLOW:
handler->num_underflows++; log_underflow(handler);
printf("U"); printf("U");
break; break;
default: default: