Added hackrf_set_amp_enable() in hackrf_transfer.
This commit is contained in:
@ -86,6 +86,30 @@ int parse_u64(char* s, uint64_t* const value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int parse_int(char* s, uint32_t* const value) {
|
||||||
|
uint_fast8_t base = 10;
|
||||||
|
if( strlen(s) > 2 ) {
|
||||||
|
if( s[0] == '0' ) {
|
||||||
|
if( (s[1] == 'x') || (s[1] == 'X') ) {
|
||||||
|
base = 16;
|
||||||
|
s += 2;
|
||||||
|
} else if( (s[1] == 'b') || (s[1] == 'B') ) {
|
||||||
|
base = 2;
|
||||||
|
s += 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char* s_end = s;
|
||||||
|
const unsigned long ulong_value = strtoul(s, &s_end, base);
|
||||||
|
if( (s != s_end) && (*s_end == 0) ) {
|
||||||
|
*value = ulong_value;
|
||||||
|
return HACKRF_SUCCESS;
|
||||||
|
} else {
|
||||||
|
return HACKRF_ERROR_INVALID_PARAM;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FILE* fd = NULL;
|
FILE* fd = NULL;
|
||||||
volatile uint32_t byte_count = 0;
|
volatile uint32_t byte_count = 0;
|
||||||
|
|
||||||
@ -97,6 +121,9 @@ struct timeval t_start;
|
|||||||
bool freq = false;
|
bool freq = false;
|
||||||
uint64_t freq_hz;
|
uint64_t freq_hz;
|
||||||
|
|
||||||
|
bool amp = false;
|
||||||
|
uint32_t amp_enable;
|
||||||
|
|
||||||
int rx_callback(hackrf_transfer* transfer) {
|
int rx_callback(hackrf_transfer* transfer) {
|
||||||
if( fd != NULL )
|
if( fd != NULL )
|
||||||
{
|
{
|
||||||
@ -135,7 +162,8 @@ static void usage() {
|
|||||||
printf("Usage:\n");
|
printf("Usage:\n");
|
||||||
printf("\t-r <filename> # Receive data into file.\n");
|
printf("\t-r <filename> # Receive data into file.\n");
|
||||||
printf("\t-t <filename> # Transmit data from file.\n");
|
printf("\t-t <filename> # Transmit data from file.\n");
|
||||||
printf("\t-f <set_freq_MHz> # Set Frequency in MHz (between [%lld, %lld[).\n", FREQ_MIN_HZ, FREQ_MAX_HZ);
|
printf("\t[-f set_freq_hz] # Set Freq in Hz (between [%lld, %lld[).\n", FREQ_MIN_HZ, FREQ_MAX_HZ);
|
||||||
|
printf("\t[-a set_amp] # Set Amp 1=Enable, 0=Disable.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static hackrf_device* device = NULL;
|
static hackrf_device* device = NULL;
|
||||||
@ -201,7 +229,7 @@ int main(int argc, char** argv) {
|
|||||||
const char* path = NULL;
|
const char* path = NULL;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
while( (opt = getopt(argc, argv, "r:t:f:")) != EOF ) {
|
while( (opt = getopt(argc, argv, "r:t:f:a:")) != EOF ) {
|
||||||
result = HACKRF_SUCCESS;
|
result = HACKRF_SUCCESS;
|
||||||
switch( opt ) {
|
switch( opt ) {
|
||||||
case 'r':
|
case 'r':
|
||||||
@ -219,6 +247,11 @@ int main(int argc, char** argv) {
|
|||||||
result = parse_u64(optarg, &freq_hz);
|
result = parse_u64(optarg, &freq_hz);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'a':
|
||||||
|
amp = true;
|
||||||
|
result = parse_int(optarg, &_enable);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -233,7 +266,20 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
if( freq ) {
|
if( freq ) {
|
||||||
if( (freq_hz >= FREQ_MAX_HZ) || (freq_hz < FREQ_MIN_HZ) )
|
if( (freq_hz >= FREQ_MAX_HZ) || (freq_hz < FREQ_MIN_HZ) )
|
||||||
printf("argument error: frequency shall be between [%lld, %lld[.\n", FREQ_MIN_HZ, FREQ_MAX_HZ);
|
{
|
||||||
|
printf("argument error: set_freq_hz shall be between [%lld, %lld[.\n", FREQ_MIN_HZ, FREQ_MAX_HZ);
|
||||||
|
usage();
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if( amp ) {
|
||||||
|
if( amp_enable > 1 )
|
||||||
|
{
|
||||||
|
printf("argument error: set_amp shall be 0 or 1.\n");
|
||||||
|
usage();
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( transmit == receive )
|
if( transmit == receive )
|
||||||
@ -320,6 +366,15 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( amp ) {
|
||||||
|
printf("call hackrf_set_amp_enable(%ld)\n", amp_enable);
|
||||||
|
result = hackrf_set_amp_enable(device, (uint8_t)amp_enable);
|
||||||
|
if( result != HACKRF_SUCCESS ) {
|
||||||
|
printf("hackrf_set_amp_enable() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gettimeofday(&t_start, NULL);
|
gettimeofday(&t_start, NULL);
|
||||||
gettimeofday(&time_start, NULL);
|
gettimeofday(&time_start, NULL);
|
||||||
|
|
||||||
|
@ -571,26 +571,6 @@ int hackrf_version_string_read(hackrf_device* device, char* version,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int hackrf_set_amp_enable(hackrf_device* device, uint8_t value)
|
|
||||||
{
|
|
||||||
int result = libusb_control_transfer(
|
|
||||||
device->usb_device,
|
|
||||||
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
|
|
||||||
HACKRF_VENDOR_REQUEST_AMP_ENABLE,
|
|
||||||
value,
|
|
||||||
0,
|
|
||||||
NULL,
|
|
||||||
0,
|
|
||||||
0
|
|
||||||
);
|
|
||||||
|
|
||||||
if (result != 0) {
|
|
||||||
return HACKRF_ERROR_LIBUSB;
|
|
||||||
} else {
|
|
||||||
return HACKRF_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t freq_mhz; /* From 30 to 6000MHz */
|
uint32_t freq_mhz; /* From 30 to 6000MHz */
|
||||||
uint32_t freq_hz; /* From 0 to 999999Hz */
|
uint32_t freq_hz; /* From 0 to 999999Hz */
|
||||||
@ -630,6 +610,26 @@ int hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int hackrf_set_amp_enable(hackrf_device* device, const uint8_t value)
|
||||||
|
{
|
||||||
|
int result = libusb_control_transfer(
|
||||||
|
device->usb_device,
|
||||||
|
LIBUSB_ENDPOINT_OUT | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE,
|
||||||
|
HACKRF_VENDOR_REQUEST_AMP_ENABLE,
|
||||||
|
value,
|
||||||
|
0,
|
||||||
|
NULL,
|
||||||
|
0,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result != 0) {
|
||||||
|
return HACKRF_ERROR_LIBUSB;
|
||||||
|
} else {
|
||||||
|
return HACKRF_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void* transfer_threadproc(void* arg) {
|
static void* transfer_threadproc(void* arg) {
|
||||||
hackrf_device* device = (hackrf_device*)arg;
|
hackrf_device* device = (hackrf_device*)arg;
|
||||||
|
|
||||||
|
@ -95,6 +95,8 @@ int hackrf_version_string_read(hackrf_device* device, char* version,
|
|||||||
|
|
||||||
int hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz);
|
int hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz);
|
||||||
|
|
||||||
|
int hackrf_set_amp_enable(hackrf_device* device, const uint8_t value);
|
||||||
|
|
||||||
const char* hackrf_error_name(enum hackrf_error errcode);
|
const char* hackrf_error_name(enum hackrf_error errcode);
|
||||||
const char* hackrf_board_id_name(enum hackrf_board_id board_id);
|
const char* hackrf_board_id_name(enum hackrf_board_id board_id);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user