Error codes from libhackrf are not very legible, and in the case of
HACKRF_ERROR_LIBUSB, don't uniquely describe the cause of the error.
Calling hackrf_error_name() provides a human-readable message, and
in the case of libusb errors, identifies the actual cause rather than
just indicating that the error came from libusb.
This came up whilst trying to diagnose a libhackrf bug which showed
up when using libhackrf, via gr-osmosdr, via gqrx:
https://github.com/greatscottgadgets/hackrf/issues/883
---
lib/hackrf/hackrf_source_c.cc | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/hackrf/hackrf_source_c.cc b/lib/hackrf/hackrf_source_c.cc
index 03ea3bd..2826924 100644
--- a/lib/hackrf/hackrf_source_c.cc
+++ b/lib/hackrf/hackrf_source_c.cc
@@ -170,7 +170,8 @@ bool hackrf_source_c::start()
hackrf_common::start();
int ret = hackrf_start_rx( _dev.get(), _hackrf_rx_callback, (void *)this );
if ( ret != HACKRF_SUCCESS ) {
- std::cerr << "Failed to start RX streaming (" << ret <<
")" << std::endl;
+ const char *msg = hackrf_error_name( (enum hackrf_error) ret );
+ std::cerr << "Failed to start RX streaming (" << ret <<
": " << msg << ")" << std::endl;
return false;
}
return true;
@@ -184,7 +185,8 @@ bool hackrf_source_c::stop()
hackrf_common::stop();
int ret = hackrf_stop_rx( _dev.get() );
if ( ret != HACKRF_SUCCESS ) {
- std::cerr << "Failed to stop RX streaming (" << ret <<
")" << std::endl;
+ const char *msg = hackrf_error_name( (enum hackrf_error) ret );
+ std::cerr << "Failed to stop RX streaming (" << ret <<
": " << msg << ")" << std::endl;
return false;
}
return true;
--
2.30.2