From 958c7421890c62436e198547473ccfcd3d838c46 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Fri, 18 Mar 2022 10:42:40 +0000 Subject: [PATCH 1/3] Remove delays from hackrf_stop_rx_cmd and hackrf_stop_tx_cmd. These were added in #805, as a workaround to prevent their parent functions from returning before transfer cancellations had completed. This has since been fixed properly in #1029. --- host/libhackrf/src/hackrf.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index e6f01563..7b0c0e0e 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -1887,13 +1887,7 @@ int ADDCALL hackrf_start_rx(hackrf_device* device, hackrf_sample_block_cb_fn cal static int hackrf_stop_rx_cmd(hackrf_device* device) { int result; - result = hackrf_set_transceiver_mode(device, HACKRF_TRANSCEIVER_MODE_OFF); -#ifdef _WIN32 - Sleep(10); -#else - usleep(10 * 1000); -#endif return result; } @@ -1935,11 +1929,6 @@ static int hackrf_stop_tx_cmd(hackrf_device* device) { int result; result = hackrf_set_transceiver_mode(device, HACKRF_TRANSCEIVER_MODE_OFF); -#ifdef _WIN32 - Sleep(10); -#else - usleep(10 * 1000); -#endif return result; } From b109a31fd3f2c636783ffd62f68502bf1753a495 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Fri, 18 Mar 2022 10:56:58 +0000 Subject: [PATCH 2/3] Merge hackrf_stop_tx_cmd and hackrf_start_tx_cmd. These both do the same thing: set transceiver mode to OFF. --- host/libhackrf/src/hackrf.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index 7b0c0e0e..b5c1554e 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -1884,7 +1884,7 @@ int ADDCALL hackrf_start_rx(hackrf_device* device, hackrf_sample_block_cb_fn cal return result; } -static int hackrf_stop_rx_cmd(hackrf_device* device) +static int hackrf_stop_cmd(hackrf_device* device) { int result; result = hackrf_set_transceiver_mode(device, HACKRF_TRANSCEIVER_MODE_OFF); @@ -1909,7 +1909,7 @@ int ADDCALL hackrf_stop_rx(hackrf_device* device) return result; } - return hackrf_stop_rx_cmd(device); + return hackrf_stop_cmd(device); } int ADDCALL hackrf_start_tx(hackrf_device* device, hackrf_sample_block_cb_fn callback, void* tx_ctx) @@ -1925,13 +1925,6 @@ int ADDCALL hackrf_start_tx(hackrf_device* device, hackrf_sample_block_cb_fn cal return result; } -static int hackrf_stop_tx_cmd(hackrf_device* device) -{ - int result; - result = hackrf_set_transceiver_mode(device, HACKRF_TRANSCEIVER_MODE_OFF); - return result; -} - /* * Stop any pending transmit. * @@ -1949,7 +1942,7 @@ int ADDCALL hackrf_stop_tx(hackrf_device* device) return result; } - return hackrf_stop_tx_cmd(device); + return hackrf_stop_cmd(device); } int ADDCALL hackrf_close(hackrf_device* device) @@ -1962,8 +1955,8 @@ int ADDCALL hackrf_close(hackrf_device* device) if( device != NULL ) { - result1 = hackrf_stop_rx_cmd(device); - result2 = hackrf_stop_tx_cmd(device); + result1 = hackrf_stop_cmd(device); + result2 = hackrf_stop_cmd(device); /* * Finally kill the transfer thread, which will From f046ed24a393a7379fea8dced9f52fc83f3c6803 Mon Sep 17 00:00:00 2001 From: Martin Ling Date: Fri, 18 Mar 2022 10:57:38 +0000 Subject: [PATCH 3/3] Remove duplicate stop command in hackrf_close(). --- host/libhackrf/src/hackrf.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index b5c1554e..517c6a79 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -1947,22 +1947,20 @@ int ADDCALL hackrf_stop_tx(hackrf_device* device) int ADDCALL hackrf_close(hackrf_device* device) { - int result1, result2, result3; + int result1, result2; result1 = HACKRF_SUCCESS; result2 = HACKRF_SUCCESS; - result3 = HACKRF_SUCCESS; if( device != NULL ) { result1 = hackrf_stop_cmd(device); - result2 = hackrf_stop_cmd(device); /* * Finally kill the transfer thread, which will * also cancel any pending transmit/receive transfers. */ - result3 = kill_transfer_thread(device); + result2 = kill_transfer_thread(device); if( device->usb_device != NULL ) { libusb_release_interface(device->usb_device, 0); @@ -1980,10 +1978,6 @@ int ADDCALL hackrf_close(hackrf_device* device) } open_devices--; - if (result3 != HACKRF_SUCCESS) - { - return result3; - } if (result2 != HACKRF_SUCCESS) { return result2;