From 55d7e7f2d27367670a7ef254434b42f0ab592b5a Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Fri, 3 Feb 2017 10:08:41 -0700 Subject: [PATCH 1/6] Standardize device selection options in hackrf-tools Fixes issue #318 --- host/hackrf-tools/src/hackrf_operacake.c | 23 ++++++----------------- host/hackrf-tools/src/hackrf_si5351c.c | 12 ++++++------ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_operacake.c b/host/hackrf-tools/src/hackrf_operacake.c index 91e1e0d2..5162d060 100644 --- a/host/hackrf-tools/src/hackrf_operacake.c +++ b/host/hackrf-tools/src/hackrf_operacake.c @@ -34,7 +34,6 @@ typedef int bool; static void usage() { printf("\nUsage:\n"); printf("\t-h, --help: this help\n"); - printf("\t-s, --serial : specify a particular device by serial number\n"); printf("\t-d, --device : specify a particular device by number\n"); printf("\t-o, --address : specify a particular operacake by address [default: 0x00]\n"); printf("\t-a : set port A connection\n"); @@ -44,7 +43,6 @@ static void usage() { static struct option long_options[] = { { "device", no_argument, 0, 'd' }, - { "serial", no_argument, 0, 's' }, { "address", no_argument, 0, 'o' }, { "list", no_argument, 0, 'v' }, { "help", no_argument, 0, 'h' }, @@ -65,7 +63,6 @@ int parse_int(char* const s, uint16_t* const value) { int main(int argc, char** argv) { int opt; const char* serial_number = NULL; - int device_index = 0; int operacake_address = 0; int port_a = 0; int port_b = 0; @@ -83,13 +80,9 @@ int main(int argc, char** argv) { return -1; } - while( (opt = getopt_long(argc, argv, "d:s:o:a:b:lh?", long_options, &option_index)) != EOF ) { + while( (opt = getopt_long(argc, argv, "d:o:a:b:lh?", long_options, &option_index)) != EOF ) { switch( opt ) { case 'd': - device_index = atoi(optarg); - break; - - case 's': serial_number = optarg; break; @@ -132,15 +125,11 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - if(serial_number != NULL) { - result = hackrf_open_by_serial(serial_number, &device); - } else { - hackrf_device_list_t* device_list = hackrf_device_list(); - if(device_list->devicecount <= 0) { - result = HACKRF_ERROR_NOT_FOUND; - } else { - result = hackrf_device_list_open(device_list, device_index, &device); - } + result = hackrf_open_by_serial(serial_number, &device); + if (result != HACKRF_SUCCESS) { + fprintf(stderr, "hackrf_open() failed: %s (%d)\n", + hackrf_error_name(result), result); + return EXIT_FAILURE; } if( result ) { diff --git a/host/hackrf-tools/src/hackrf_si5351c.c b/host/hackrf-tools/src/hackrf_si5351c.c index c4fc0cdb..7c8712c4 100644 --- a/host/hackrf-tools/src/hackrf_si5351c.c +++ b/host/hackrf-tools/src/hackrf_si5351c.c @@ -38,8 +38,8 @@ static void usage() { printf("\t-n, --register : set register number for read/write operations\n"); printf("\t-r, --read: read register specified by last -n argument, or all registers\n"); printf("\t-w, --write : write register specified by last -n argument with value \n"); - printf("\t-s, --serial : specify a particular device by serial number\n"); - printf("\t-d, --device : specify a particular device by number\n"); + printf("\t-d, --device : specify a particular device by serial number\n"); + printf("\t-D, --device-idx : specify a particular device by number\n"); printf("\nExamples:\n"); printf("\t -n 12 -r # reads from register 12\n"); printf("\t -r # reads all registers\n"); @@ -52,7 +52,7 @@ static struct option long_options[] = { { "write", required_argument, 0, 'w' }, { "read", no_argument, 0, 'r' }, { "device", no_argument, 0, 'd' }, - { "serial", no_argument, 0, 's' }, + { "device-idx", no_argument, 0, 'D' }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; @@ -214,7 +214,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - while( (opt = getopt_long(argc, argv, "d:s:cn:rw:h?", long_options, &option_index)) != EOF ) { + while( (opt = getopt_long(argc, argv, "d:D:cn:rw:h?", long_options, &option_index)) != EOF ) { switch( opt ) { case 'n': result = parse_int(optarg, ®ister_number); @@ -233,11 +233,11 @@ int main(int argc, char** argv) { dump_config = true; break; - case 'd': + case 'D': device_index = atoi(optarg); break; - case 's': + case 'd': serial_number = optarg; break; case 'h': From feeb7a9c95e3bdfb416305b1c70e232fdf5b2fc4 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Fri, 3 Feb 2017 10:20:23 -0700 Subject: [PATCH 2/6] Add selection by device serial number to rffc5071 and max2837 tools --- host/hackrf-tools/src/hackrf_max2837.c | 11 +++++++++-- host/hackrf-tools/src/hackrf_operacake.c | 5 ----- host/hackrf-tools/src/hackrf_rffc5071.c | 10 ++++++++-- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_max2837.c b/host/hackrf-tools/src/hackrf_max2837.c index d09a7557..f52ca9e1 100644 --- a/host/hackrf-tools/src/hackrf_max2837.c +++ b/host/hackrf-tools/src/hackrf_max2837.c @@ -38,6 +38,7 @@ static void usage() { printf("\t-n, --register : set register number for read/write operations\n"); printf("\t-r, --read: read register specified by last -n argument, or all registers\n"); printf("\t-w, --write : write register specified by last -n argument with value \n"); + printf("\t-d, --device : specify a particular device by serial number\n"); printf("\nExamples:\n"); printf("\t -n 12 -r # reads from register 12\n"); printf("\t -r # reads all registers\n"); @@ -48,6 +49,7 @@ static struct option long_options[] = { { "register", required_argument, 0, 'n' }, { "write", required_argument, 0, 'w' }, { "read", no_argument, 0, 'r' }, + { "device", no_argument, 0, 'd' }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; @@ -133,6 +135,7 @@ int main(int argc, char** argv) { int option_index = 0; bool read = false; bool write = false; + const char* serial_number = NULL; int result = hackrf_init(); if( result ) { @@ -140,7 +143,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - while( (opt = getopt_long(argc, argv, "n:rw:h?", long_options, &option_index)) != EOF ) { + while( (opt = getopt_long(argc, argv, "n:rw:d:h?", long_options, &option_index)) != EOF ) { switch( opt ) { case 'n': result = parse_int(optarg, ®ister_number); @@ -155,6 +158,10 @@ int main(int argc, char** argv) { read = true; break; + case 'd': + serial_number = optarg; + break; + case 'h': case '?': usage(); @@ -184,7 +191,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - result = hackrf_open(&device); + result = hackrf_open_by_serial(serial_number, &device); if(result) { printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result); return EXIT_FAILURE; diff --git a/host/hackrf-tools/src/hackrf_operacake.c b/host/hackrf-tools/src/hackrf_operacake.c index 5162d060..649f9902 100644 --- a/host/hackrf-tools/src/hackrf_operacake.c +++ b/host/hackrf-tools/src/hackrf_operacake.c @@ -132,11 +132,6 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - if( result ) { - printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result); - return -1; - } - if(list) { result = hackrf_get_operacake_boards(device, operacakes); if (result != HACKRF_SUCCESS) { diff --git a/host/hackrf-tools/src/hackrf_rffc5071.c b/host/hackrf-tools/src/hackrf_rffc5071.c index 11285d83..867bc379 100644 --- a/host/hackrf-tools/src/hackrf_rffc5071.c +++ b/host/hackrf-tools/src/hackrf_rffc5071.c @@ -39,6 +39,7 @@ static void usage() { printf("\t-n, --register : set register number for read/write operations\n"); printf("\t-r, --read: read register specified by last -n argument, or all registers\n"); printf("\t-w, --write : write register specified by last -n argument with value \n"); + printf("\t-d, --device : specify a particular device by serial number\n"); printf("\nExamples:\n"); printf("\t -n 12 -r # reads from register 12\n"); printf("\t -r # reads all registers\n"); @@ -49,6 +50,7 @@ static struct option long_options[] = { { "register", required_argument, 0, 'n' }, { "write", required_argument, 0, 'w' }, { "read", no_argument, 0, 'r' }, + { "device", no_argument, 0, 'd' }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 }, }; @@ -134,6 +136,7 @@ int main(int argc, char** argv) { int option_index = 0; bool read = false; bool write = false; + const char* serial_number = NULL; int result = hackrf_init(); if( result ) { @@ -141,7 +144,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - while( (opt = getopt_long(argc, argv, "n:rw:h?", long_options, &option_index)) != EOF ) { + while( (opt = getopt_long(argc, argv, "n:rw:d:h?", long_options, &option_index)) != EOF ) { switch( opt ) { case 'n': result = parse_int(optarg, ®ister_number); @@ -153,6 +156,9 @@ int main(int argc, char** argv) { case 'r': read = true; break; + case 'd': + serial_number = optarg; + break; case 'h': case '?': usage(); @@ -182,7 +188,7 @@ int main(int argc, char** argv) { return EXIT_FAILURE; } - result = hackrf_open(&device); + result = hackrf_open_by_serial(serial_number, &device); if(result) { printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result); return EXIT_FAILURE; From 3c468a7a0f6d8fe9d9ffb706a71a50ed7da9be29 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Fri, 3 Feb 2017 12:05:10 -0700 Subject: [PATCH 3/6] Report libusb error messages where possible for USB errors --- host/libhackrf/src/hackrf.c | 48 ++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index ba3e5e0c..c858f66d 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -145,6 +145,7 @@ static const uint16_t hackrf_one_usb_pid = 0x6089; static const uint16_t rad1o_usb_pid = 0xcc15; static libusb_context* g_libusb_context = NULL; +int last_libusb_error = LIBUSB_SUCCESS; static void request_exit(void) { @@ -249,6 +250,7 @@ static int prepare_transfers( error = libusb_submit_transfer(device->transfers[transfer_index]); if( error != 0 ) { + last_libusb_error = error; return HACKRF_ERROR_LIBUSB; } } @@ -269,6 +271,7 @@ static int detach_kernel_drivers(libusb_device_handle* usb_device_handle) result = libusb_get_active_config_descriptor(dev, &config); if( result < 0 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } @@ -282,11 +285,13 @@ static int detach_kernel_drivers(libusb_device_handle* usb_device_handle) if( result == LIBUSB_ERROR_NOT_SUPPORTED ) { return 0; } + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else if( result == 1 ) { result = libusb_detach_kernel_driver(usb_device_handle, i); if( result != 0 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } } @@ -300,6 +305,7 @@ static int set_hackrf_configuration(libusb_device_handle* usb_device, int config result = libusb_get_configuration(usb_device, &curr_config); if( result != 0 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } @@ -313,6 +319,7 @@ static int set_hackrf_configuration(libusb_device_handle* usb_device, int config result = libusb_set_configuration(usb_device, config); if( result != 0 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } } @@ -340,6 +347,7 @@ int ADDCALL hackrf_init(void) libusb_error = libusb_init(&g_libusb_context); if( libusb_error != 0 ) { + last_libusb_error = libusb_error; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -511,6 +519,7 @@ static int hackrf_open_setup(libusb_device_handle* usb_device, hackrf_device** d result = libusb_claim_interface(usb_device, 0); if( result != LIBUSB_SUCCESS ) { + last_libusb_error = result; libusb_close(usb_device); return HACKRF_ERROR_LIBUSB; } @@ -601,7 +610,7 @@ int ADDCALL hackrf_open_by_serial(const char* const desired_serial_number, hackr int ADDCALL hackrf_device_list_open(hackrf_device_list_t *list, int idx, hackrf_device** device) { libusb_device_handle* usb_device; - int i; + int i, result; if( device == NULL || list == NULL || idx < 0 || idx >= list->devicecount ) { @@ -610,8 +619,10 @@ int ADDCALL hackrf_device_list_open(hackrf_device_list_t *list, int idx, hackrf_ i = list->usb_device_index[idx]; - if( libusb_open(list->usb_devices[i], &usb_device) != 0 ) { + result = libusb_open(list->usb_devices[i], &usb_device); + if(result != 0) { usb_device = NULL; + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } @@ -634,6 +645,7 @@ int ADDCALL hackrf_set_transceiver_mode(hackrf_device* device, hackrf_transceive if( result != 0 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -662,6 +674,7 @@ int ADDCALL hackrf_max2837_read(hackrf_device* device, uint8_t register_number, if( result < 2 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -694,6 +707,7 @@ int ADDCALL hackrf_max2837_write(hackrf_device* device, uint8_t register_number, if( result != 0 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -724,6 +738,7 @@ int ADDCALL hackrf_si5351c_read(hackrf_device* device, uint16_t register_number, if( result < 1 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { *value = temp_value; @@ -756,6 +771,7 @@ int ADDCALL hackrf_si5351c_write(hackrf_device* device, uint16_t register_number if( result != 0 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -778,6 +794,7 @@ int ADDCALL hackrf_set_baseband_filter_bandwidth(hackrf_device* device, const ui if( result != 0 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -807,6 +824,7 @@ int ADDCALL hackrf_rffc5071_read(hackrf_device* device, uint8_t register_number, if( result < 2 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -835,6 +853,7 @@ int ADDCALL hackrf_rffc5071_write(hackrf_device* device, uint8_t register_number if( result != 0 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -857,6 +876,7 @@ int ADDCALL hackrf_spiflash_erase(hackrf_device* device) if (result != 0) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -886,6 +906,7 @@ int ADDCALL hackrf_spiflash_write(hackrf_device* device, const uint32_t address, if (result < length) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -915,6 +936,7 @@ int ADDCALL hackrf_spiflash_read(hackrf_device* device, const uint32_t address, if (result < length) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -944,6 +966,7 @@ int ADDCALL hackrf_cpld_write(hackrf_device* device, ); if (result != LIBUSB_SUCCESS) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } } @@ -967,6 +990,7 @@ int ADDCALL hackrf_board_id_read(hackrf_device* device, uint8_t* value) if (result < 1) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -990,6 +1014,7 @@ int ADDCALL hackrf_version_string_read(hackrf_device* device, char* version, if (result < 0) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { version[result] = '\0'; @@ -1005,8 +1030,10 @@ extern ADDAPI int ADDCALL hackrf_usb_api_version_read(hackrf_device* device, struct libusb_device_descriptor desc; dev = libusb_get_device(device->usb_device); result = libusb_get_device_descriptor(dev, &desc); - if (result < 0) + if (result < 0) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; + } *version = desc.bcdDevice; return HACKRF_SUCCESS; @@ -1053,6 +1080,7 @@ int ADDCALL hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz) if (result < length) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -1104,6 +1132,7 @@ int ADDCALL hackrf_set_freq_explicit(hackrf_device* device, if (result < length) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -1145,6 +1174,7 @@ int ADDCALL hackrf_set_sample_rate_manual(hackrf_device* device, if (result < length) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return hackrf_set_baseband_filter_bandwidth(device, @@ -1214,6 +1244,7 @@ int ADDCALL hackrf_set_amp_enable(hackrf_device* device, const uint8_t value) if (result != 0) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -1239,6 +1270,7 @@ int ADDCALL hackrf_board_partid_serialno_read(hackrf_device* device, read_partid if (result < length) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { @@ -1358,6 +1390,7 @@ int ADDCALL hackrf_set_antenna_enable(hackrf_device* device, const uint8_t value if (result != 0) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -1606,6 +1639,10 @@ const char* ADDCALL hackrf_error_name(enum hackrf_error errcode) return "insufficient memory"; case HACKRF_ERROR_LIBUSB: +#if defined(LIBUSB_API_VERSION) && (LIBUSB_API_VERSION >= 0x01000103) + if(last_libusb_error != LIBUSB_SUCCESS) + return libusb_strerror(last_libusb_error); +#endif return "USB error"; case HACKRF_ERROR_THREAD: @@ -1750,6 +1787,7 @@ int ADDCALL hackrf_set_hw_sync_mode(hackrf_device* device, const uint8_t value) if( result != 0 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -1778,6 +1816,7 @@ int ADDCALL hackrf_init_sweep(hackrf_device* device, uint16_t* frequency_list, i ); if (result < size) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -1804,6 +1843,7 @@ int ADDCALL hackrf_get_operacake_boards(hackrf_device* device, uint8_t* boards) if (result < 8) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -1839,6 +1879,7 @@ int ADDCALL hackrf_set_operacake_ports(hackrf_device* device, ); if (result != 0) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; @@ -1859,6 +1900,7 @@ int ADDCALL hackrf_reset(hackrf_device* device) { ); if( result != 0 ) { + last_libusb_error = result; return HACKRF_ERROR_LIBUSB; } else { return HACKRF_SUCCESS; From b8aaee6e720c9267f8a9436f847f1df633b2e609 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Fri, 3 Feb 2017 12:07:07 -0700 Subject: [PATCH 4/6] Correct usage for -d --- host/hackrf-tools/src/hackrf_operacake.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/hackrf-tools/src/hackrf_operacake.c b/host/hackrf-tools/src/hackrf_operacake.c index 649f9902..0b8405b6 100644 --- a/host/hackrf-tools/src/hackrf_operacake.c +++ b/host/hackrf-tools/src/hackrf_operacake.c @@ -34,7 +34,7 @@ typedef int bool; static void usage() { printf("\nUsage:\n"); printf("\t-h, --help: this help\n"); - printf("\t-d, --device : specify a particular device by number\n"); + printf("\t-d, --device : specify a particular device by serial number\n"); printf("\t-o, --address : specify a particular operacake by address [default: 0x00]\n"); printf("\t-a : set port A connection\n"); printf("\t-b : set port B connection\n"); From 38c67f7e8992f4859eaa6297ff700e511c03b856 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Sun, 5 Feb 2017 21:40:57 -0700 Subject: [PATCH 5/6] Add printable libhackrf and hackrf tools version strings --- host/CMakeLists.txt | 18 ++++++++++++++++++ host/hackrf-tools/CMakeLists.txt | 5 +---- host/hackrf-tools/src/hackrf_info.c | 4 ++++ host/libhackrf/CMakeLists.txt | 4 +++- host/libhackrf/src/hackrf.c | 16 ++++++++++++++++ host/libhackrf/src/hackrf.h | 3 +++ 6 files changed, 45 insertions(+), 5 deletions(-) diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 874163f8..96965b7a 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -3,6 +3,24 @@ cmake_minimum_required(VERSION 2.8) project (hackrf_all) +#set(RELEASE "") + +if(NOT DEFINED RELEASE) + execute_process( + COMMAND git log -n 1 --format=%h + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + RESULT_VARIABLE GIT_VERSION_FOUND + ERROR_QUIET + OUTPUT_VARIABLE GIT_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if (GIT_VERSION_FOUND) + set(RELEASE "unknown") + else (GIT_VERSION_FOUND) + set(RELEASE "git-${GIT_VERSION}") + endif (GIT_VERSION_FOUND) +endif() + add_subdirectory(libhackrf) add_subdirectory(hackrf-tools) diff --git a/host/hackrf-tools/CMakeLists.txt b/host/hackrf-tools/CMakeLists.txt index 82ea47d8..18dbf007 100644 --- a/host/hackrf-tools/CMakeLists.txt +++ b/host/hackrf-tools/CMakeLists.txt @@ -23,11 +23,8 @@ cmake_minimum_required(VERSION 2.8) project(hackrf-tools C) -set(MAJOR_VERSION 0) -set(MINOR_VERSION 5) set(PACKAGE hackrf-tools) -set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION}) -set(VERSION ${VERSION_STRING}) +add_definitions(-DTOOL_RELEASE="${RELEASE}") set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake/modules) if(MSVC) diff --git a/host/hackrf-tools/src/hackrf_info.c b/host/hackrf-tools/src/hackrf_info.c index 0049a3e7..abb72887 100644 --- a/host/hackrf-tools/src/hackrf_info.c +++ b/host/hackrf-tools/src/hackrf_info.c @@ -44,6 +44,10 @@ int main(void) hackrf_error_name(result), result); return EXIT_FAILURE; } + + printf("hackrf_info version: %s\n", TOOL_RELEASE); + printf("libhackrf version: %s (%s)\n", hackrf_library_release(), + hackrf_library_version()); list = hackrf_device_list(); diff --git a/host/libhackrf/CMakeLists.txt b/host/libhackrf/CMakeLists.txt index c898d233..c3cd4946 100644 --- a/host/libhackrf/CMakeLists.txt +++ b/host/libhackrf/CMakeLists.txt @@ -24,10 +24,12 @@ cmake_minimum_required(VERSION 2.8) project(libhackrf C) set(MAJOR_VERSION 0) -set(MINOR_VERSION 4) +set(MINOR_VERSION 5) set(PACKAGE libhackrf) set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION}) set(VERSION ${VERSION_STRING}) +add_definitions(-DLIBRARY_VERSION="${VERSION_STRING}") +add_definitions(-DLIBRARY_RELEASE="${RELEASE}") set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake/modules) if(MSVC) diff --git a/host/libhackrf/src/hackrf.c b/host/libhackrf/src/hackrf.c index c858f66d..a6925611 100644 --- a/host/libhackrf/src/hackrf.c +++ b/host/libhackrf/src/hackrf.c @@ -365,6 +365,22 @@ int ADDCALL hackrf_exit(void) return HACKRF_SUCCESS; } +#ifndef LIBRARY_VERSION +#define LIBRARY_VERSION "unknown" +#endif +const char* ADDCALL hackrf_library_version() +{ + return LIBRARY_VERSION; +} + +#ifndef LIBRARY_RELEASE +#define LIBRARY_RELEASE "unknown" +#endif +const char* ADDCALL hackrf_library_release() +{ + return LIBRARY_RELEASE; +} + hackrf_device_list_t* ADDCALL hackrf_device_list() { ssize_t i; diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index d1a57c4d..904207e0 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -133,6 +133,9 @@ extern "C" extern ADDAPI int ADDCALL hackrf_init(); extern ADDAPI int ADDCALL hackrf_exit(); +extern ADDAPI const char* ADDCALL hackrf_library_version(); +extern ADDAPI const char* ADDCALL hackrf_library_release(); + extern ADDAPI hackrf_device_list_t* ADDCALL hackrf_device_list(); extern ADDAPI int ADDCALL hackrf_device_list_open(hackrf_device_list_t *list, int idx, hackrf_device** device); extern ADDAPI void ADDCALL hackrf_device_list_free(hackrf_device_list_t *list); From a44875a7a0f25a25b42f75168e20342212f5a1e2 Mon Sep 17 00:00:00 2001 From: Dominic Spill Date: Mon, 6 Feb 2017 10:57:09 -0700 Subject: [PATCH 6/6] Add dirty flag to host versions --- host/CMakeLists.txt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index 96965b7a..69b0ef31 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -9,16 +9,25 @@ if(NOT DEFINED RELEASE) execute_process( COMMAND git log -n 1 --format=%h WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - RESULT_VARIABLE GIT_VERSION_FOUND + RESULT_VARIABLE GIT_EXIT_VALUE ERROR_QUIET OUTPUT_VARIABLE GIT_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ) - if (GIT_VERSION_FOUND) + if (GIT_EXIT_VALUE) set(RELEASE "unknown") - else (GIT_VERSION_FOUND) - set(RELEASE "git-${GIT_VERSION}") - endif (GIT_VERSION_FOUND) + else (GIT_EXIT_VALUE) + execute_process( + COMMAND git status -s --untracked-files=no + OUTPUT_VARIABLE DIRTY + ) + if ( NOT "${DIRTY}" STREQUAL "" ) + set(DIRTY_FLAG "*") + else() + set(DIRTY_FLAG "") + endif() + set(RELEASE "git-${GIT_VERSION}${DIRTY_FLAG}") + endif (GIT_EXIT_VALUE) endif() add_subdirectory(libhackrf)