* Modified API hackrf_is_streaming() now it returns an int HACKRF_TRUE when streaming is running.

* Added new hackrf_error especially for streaming to return more details.
* Adding management of usb transfer cancelled for hackrf_stop_rx()/hackrf_stop_tx().
* Added robustness on hackrf_close() to correctly close libusb related stuff even if USB device is removed or other problems.
* Fixed threading problems (start, stop() then start() ...).
* Cleanup the whole code.
This commit is contained in:
TitanMKD
2013-05-08 15:03:30 +02:00
parent 9749466512
commit 5225477164
3 changed files with 446 additions and 277 deletions

View File

@ -572,8 +572,8 @@ int main(int argc, char** argv) {
gettimeofday(&time_start, NULL); gettimeofday(&time_start, NULL);
printf("Stop with Ctrl-C\n"); printf("Stop with Ctrl-C\n");
while( (hackrf_is_streaming(device)) && while( (hackrf_is_streaming(device) == HACKRF_TRUE) &&
(do_exit == false) ) (do_exit == false) )
{ {
sleep(1); sleep(1);
@ -596,11 +596,14 @@ int main(int argc, char** argv) {
break; break;
} }
} }
if (do_exit) result = hackrf_is_streaming(device);
printf("\nUser cancel, exiting...\n"); if (do_exit)
else {
printf("\nExiting...\n"); printf("\nUser cancel, exiting...\n");
} else {
printf("\nExiting... hackrf_is_streaming() result: %s (%d)\n", hackrf_error_name(result), result);
}
struct timeval t_end; struct timeval t_end;
gettimeofday(&t_end, NULL); gettimeofday(&t_end, NULL);

File diff suppressed because it is too large Load Diff

View File

@ -49,12 +49,16 @@
enum hackrf_error { enum hackrf_error {
HACKRF_SUCCESS = 0, HACKRF_SUCCESS = 0,
HACKRF_TRUE = 1,
HACKRF_ERROR_INVALID_PARAM = -2, HACKRF_ERROR_INVALID_PARAM = -2,
HACKRF_ERROR_NOT_FOUND = -5, HACKRF_ERROR_NOT_FOUND = -5,
HACKRF_ERROR_BUSY = -6, HACKRF_ERROR_BUSY = -6,
HACKRF_ERROR_NO_MEM = -11, HACKRF_ERROR_NO_MEM = -11,
HACKRF_ERROR_LIBUSB = -1000, HACKRF_ERROR_LIBUSB = -1000,
HACKRF_ERROR_THREAD = -1001, HACKRF_ERROR_THREAD = -1001,
HACKRF_ERROR_STREAMING_THREAD_ERR = -1002,
HACKRF_ERROR_STREAMING_STOPPED = -1003,
HACKRF_ERROR_STREAMING_EXIT_CALLED = -1004,
HACKRF_ERROR_OTHER = -9999, HACKRF_ERROR_OTHER = -9999,
}; };
@ -98,8 +102,9 @@ extern ADDAPI int ADDCALL hackrf_stop_rx(hackrf_device* device);
extern ADDAPI int ADDCALL hackrf_start_tx(hackrf_device* device, hackrf_sample_block_cb_fn callback, void* tx_ctx); extern ADDAPI int ADDCALL hackrf_start_tx(hackrf_device* device, hackrf_sample_block_cb_fn callback, void* tx_ctx);
extern ADDAPI int ADDCALL hackrf_stop_tx(hackrf_device* device); extern ADDAPI int ADDCALL hackrf_stop_tx(hackrf_device* device);
extern ADDAPI bool ADDCALL hackrf_is_streaming(hackrf_device* device); /* return HACKRF_TRUE if success */
extern ADDAPI int ADDCALL hackrf_is_streaming(hackrf_device* device);
extern ADDAPI int ADDCALL hackrf_max2837_read(hackrf_device* device, uint8_t register_number, uint16_t* value); extern ADDAPI int ADDCALL hackrf_max2837_read(hackrf_device* device, uint8_t register_number, uint16_t* value);
extern ADDAPI int ADDCALL hackrf_max2837_write(hackrf_device* device, uint8_t register_number, uint16_t value); extern ADDAPI int ADDCALL hackrf_max2837_write(hackrf_device* device, uint8_t register_number, uint16_t value);