@@ -124,6 +124,9 @@ typedef enum {
124124 HACKRF_VENDOR_REQUEST_OPEN = 63 ,
125125 HACKRF_VENDOR_REQUEST_CLOSE = 64 ,
126126 HACKRF_VENDOR_REQUEST_RADIO_SET_MODE = 65 ,
127+ HACKRF_VENDOR_REQUEST_RADIO_SET_FREQUENCY = 66 ,
128+ HACKRF_VENDOR_REQUEST_RADIO_SET_FREQUENCY_EXPLICIT = 67 ,
129+ HACKRF_VENDOR_REQUEST_RADIO_SET_SAMPLE_RATE = 68 ,
127130} hackrf_vendor_request ;
128131
129132#define USB_CONFIG_STANDARD 0x1
@@ -3702,6 +3705,159 @@ int ADDCALL hackrf_radio_set_mode(hackrf_device* device, const enum radio_config
37023705 return HACKRF_SUCCESS ;
37033706}
37043707
3708+ int ADDCALL hackrf_str_to_fp64 (const uint8_t Qn , const char * str , uint64_t * const value )
3709+ {
3710+ uint64_t m = 0 ;
3711+ uint64_t n = 0 ;
3712+ uint64_t div = 1 ;
3713+ uint64_t div_max = ceil ((double ) Qn * log10 (2.0 )) * 10 ;
3714+
3715+ // validate input
3716+ char * endptr ;
3717+ strtod (str , & endptr );
3718+ if (endptr == str || * endptr != '\0' ) {
3719+ return HACKRF_ERROR_INVALID_PARAM ;
3720+ }
3721+
3722+ // parse integer component
3723+ for (; (* str >= '0' ) && (* str <= '9' ); str ++ ) {
3724+ m = (m * 10 ) + (* str - '0' );
3725+ }
3726+ * value = (m << Qn );
3727+
3728+ if (* str != '.' ) {
3729+ return HACKRF_SUCCESS ;
3730+ }
3731+ str ++ ;
3732+
3733+ // parse fractional component
3734+ for (; (* str >= '0' ) && (* str <= '9' ) && (div < div_max ); str ++ ) {
3735+ n = (n * 10 ) + (* str - '0' );
3736+ div *= 10 ;
3737+ }
3738+
3739+ if (div == 1 ) {
3740+ return HACKRF_SUCCESS ;
3741+ }
3742+
3743+ * value += ((n << Qn ) + (div / 2 )) / div ;
3744+
3745+ return HACKRF_SUCCESS ;
3746+ }
3747+
3748+ int ADDCALL hackrf_radio_set_frequency (hackrf_device * device , const fp_40_24_t freq_hz )
3749+ {
3750+ USB_API_REQUIRED (device , 0x0113 );
3751+ uint64_t set_freq_fp_param ;
3752+ uint8_t length ;
3753+ int result ;
3754+
3755+ // serialize parameters
3756+ set_freq_fp_param = TO_LE64 (freq_hz );
3757+ length = sizeof (uint64_t );
3758+
3759+ result = libusb_control_transfer (
3760+ device -> usb_device ,
3761+ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR |
3762+ LIBUSB_RECIPIENT_DEVICE ,
3763+ HACKRF_VENDOR_REQUEST_RADIO_SET_FREQUENCY ,
3764+ 0 ,
3765+ 0 ,
3766+ (unsigned char * ) & set_freq_fp_param ,
3767+ length ,
3768+ DEFAULT_REQUEST_TIMEOUT );
3769+
3770+ if (result < length ) {
3771+ last_libusb_error = result ;
3772+ return HACKRF_ERROR_LIBUSB ;
3773+ }
3774+
3775+ return HACKRF_SUCCESS ;
3776+ }
3777+
3778+ int ADDCALL hackrf_radio_set_frequency_explicit (
3779+ hackrf_device * device ,
3780+ const fp_40_24_t if_freq_hz ,
3781+ const fp_40_24_t lo_freq_hz ,
3782+ const enum rf_path_filter path )
3783+ {
3784+ struct {
3785+ fp_40_24_t if_freq_hz ;
3786+ fp_40_24_t lo_freq_hz ;
3787+ uint8_t path ;
3788+ } params ;
3789+
3790+ uint8_t length ;
3791+ int result ;
3792+
3793+ // TODO are these values still correct for HackRF Pro ?
3794+ if (FP_FREQ_HZ (if_freq_hz ) < 2000000000 || FP_FREQ_HZ (if_freq_hz ) > 3000000000 ) {
3795+ return HACKRF_ERROR_INVALID_PARAM ;
3796+ }
3797+
3798+ // TODO are these values still correct for HackRF Pro ?
3799+ if ((path != RF_PATH_FILTER_BYPASS ) &&
3800+ (FP_FREQ_HZ (lo_freq_hz ) < 84375000 || FP_FREQ_HZ (lo_freq_hz ) > 5400000000 )) {
3801+ return HACKRF_ERROR_INVALID_PARAM ;
3802+ }
3803+
3804+ if (path > 2 ) {
3805+ return HACKRF_ERROR_INVALID_PARAM ;
3806+ }
3807+
3808+ params .if_freq_hz = TO_LE (if_freq_hz );
3809+ params .lo_freq_hz = TO_LE (lo_freq_hz );
3810+ params .path = (uint8_t ) path ;
3811+ length = sizeof (params );
3812+
3813+ result = libusb_control_transfer (
3814+ device -> usb_device ,
3815+ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR |
3816+ LIBUSB_RECIPIENT_DEVICE ,
3817+ HACKRF_VENDOR_REQUEST_RADIO_SET_FREQUENCY_EXPLICIT ,
3818+ 0 ,
3819+ 0 ,
3820+ (unsigned char * ) & params ,
3821+ length ,
3822+ DEFAULT_REQUEST_TIMEOUT );
3823+
3824+ if (result < length ) {
3825+ last_libusb_error = result ;
3826+ return HACKRF_ERROR_LIBUSB ;
3827+ } else {
3828+ return HACKRF_SUCCESS ;
3829+ }
3830+ }
3831+
3832+ int ADDCALL hackrf_radio_set_sample_rate (hackrf_device * device , const fp_28_36_t freq_hz )
3833+ {
3834+ USB_API_REQUIRED (device , 0x0113 );
3835+ uint64_t set_sr_fp_param ;
3836+ uint8_t length ;
3837+ int result ;
3838+
3839+ set_sr_fp_param = TO_LE64 (freq_hz );
3840+ length = sizeof (uint64_t );
3841+
3842+ result = libusb_control_transfer (
3843+ device -> usb_device ,
3844+ LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR |
3845+ LIBUSB_RECIPIENT_DEVICE ,
3846+ HACKRF_VENDOR_REQUEST_RADIO_SET_SAMPLE_RATE ,
3847+ 0 ,
3848+ 0 ,
3849+ (unsigned char * ) & set_sr_fp_param ,
3850+ length ,
3851+ DEFAULT_REQUEST_TIMEOUT );
3852+
3853+ if (result < length ) {
3854+ last_libusb_error = result ;
3855+ return HACKRF_ERROR_LIBUSB ;
3856+ }
3857+
3858+ return HACKRF_SUCCESS ;
3859+ }
3860+
37053861#ifdef __cplusplus
37063862} // __cplusplus defined.
37073863#endif
0 commit comments