Skip to content

Commit 52e3ecb

Browse files
committed
updated to new libhackrf version
1 parent f1c08be commit 52e3ecb

File tree

2 files changed

+186
-5
lines changed

2 files changed

+186
-5
lines changed

python_hackrf/libhackrf/hackrf.c

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
2727
#include <string.h>
2828
#ifndef _WIN32
2929
#include <unistd.h>
30+
#include <signal.h>
3031
#endif
3132
#include <libusb.h>
3233

@@ -103,6 +104,7 @@ typedef enum {
103104
HACKRF_VENDOR_REQUEST_BOARD_REV_READ = 45,
104105
HACKRF_VENDOR_REQUEST_SUPPORTED_PLATFORM_READ = 46,
105106
HACKRF_VENDOR_REQUEST_SET_LEDS = 47,
107+
HACKRF_VENDOR_REQUEST_SET_USER_BIAS_T_OPTS = 48,
106108
} hackrf_vendor_request;
107109

108110
#define USB_CONFIG_STANDARD 0x1
@@ -507,6 +509,7 @@ int ADDCALL hackrf_init(void)
507509
}
508510
}
509511

512+
510513
int ADDCALL hackrf_exit(void)
511514
{
512515
if (open_devices == 0) {
@@ -777,7 +780,7 @@ static int hackrf_open_setup(libusb_device_handle* usb_device, hackrf_device** d
777780
return HACKRF_SUCCESS;
778781
}
779782

780-
int ADDCALL hackrf_android_init(int fileDescriptor, hackrf_device** device)
783+
int ADDCALL hackrf_init_on_android(int fileDescriptor, hackrf_device** device)
781784
{
782785
int libusb_error;
783786
if (device == NULL) {
@@ -1790,6 +1793,20 @@ static void* transfer_threadproc(void* arg)
17901793
int error;
17911794
struct timeval timeout = {0, 500000};
17921795

1796+
/*
1797+
* hackrf_transfer uses pause() and SIGALRM to print statistics and
1798+
* POSIX doesn't specify which thread must recieve the signal, block all
1799+
* signals here, so we don't interrupt their reception by
1800+
* hackrf_transfer or any other app which uses the library (#1323)
1801+
*/
1802+
#ifndef _WIN32
1803+
sigset_t signal_mask;
1804+
sigfillset(&signal_mask);
1805+
if (pthread_sigmask(SIG_BLOCK, &signal_mask, NULL) != 0) {
1806+
return NULL;
1807+
}
1808+
#endif
1809+
17931810
while (device->do_exit == false) {
17941811
error = libusb_handle_events_timeout(g_libusb_context, &timeout);
17951812
if ((error != 0) && (error != LIBUSB_ERROR_INTERRUPTED)) {
@@ -2982,6 +2999,52 @@ int ADDCALL hackrf_set_leds(hackrf_device* device, const uint8_t state)
29822999
}
29833000
}
29843001

3002+
int ADDCALL hackrf_set_user_bias_t_opts(
3003+
hackrf_device* device,
3004+
hackrf_bias_t_user_settting_req* req)
3005+
{
3006+
USB_API_REQUIRED(device, 0x0108)
3007+
uint16_t state = 0; // Assume no modifications
3008+
if (req->off.do_update) {
3009+
state |= 0x4;
3010+
if (req->off.change_on_mode_entry) {
3011+
state |= 0x2 + req->off.enabled;
3012+
}
3013+
}
3014+
3015+
if (req->rx.do_update) {
3016+
state |= 0x20;
3017+
if (req->rx.change_on_mode_entry) {
3018+
state |= 0x10 + (req->rx.enabled << 3);
3019+
}
3020+
}
3021+
3022+
if (req->tx.do_update) {
3023+
state |= 0x100;
3024+
if (req->tx.change_on_mode_entry) {
3025+
state |= 0x80 + (req->tx.enabled << 6);
3026+
}
3027+
}
3028+
3029+
int result = libusb_control_transfer(
3030+
device->usb_device,
3031+
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR |
3032+
LIBUSB_RECIPIENT_DEVICE,
3033+
HACKRF_VENDOR_REQUEST_SET_USER_BIAS_T_OPTS,
3034+
state,
3035+
0,
3036+
NULL,
3037+
0,
3038+
0);
3039+
3040+
if (result != 0) {
3041+
last_libusb_error = result;
3042+
return HACKRF_ERROR_LIBUSB;
3043+
} else {
3044+
return HACKRF_SUCCESS;
3045+
}
3046+
}
3047+
29853048
#ifdef __cplusplus
29863049
} // __cplusplus defined.
29873050
#endif

0 commit comments

Comments
 (0)