From d6d226bbba41162ae8ce69b9a14576300c69abd1 Mon Sep 17 00:00:00 2001 From: Kenji Rikitake Date: Thu, 2 Apr 2020 15:23:50 +0900 Subject: [PATCH 1/8] airspyhf_info.c: add airspyhf_get_calibration() --- tools/src/airspyhf_info.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/src/airspyhf_info.c b/tools/src/airspyhf_info.c index e9e3ac3..40ad2c6 100644 --- a/tools/src/airspyhf_info.c +++ b/tools/src/airspyhf_info.c @@ -43,6 +43,7 @@ void print_receiver_data (struct airspyhf_device* pd) airspyhf_read_partid_serialno_t read_partid_serialno; unsigned nsrates; char vstr[255]; // the size of buffer length has to be restricted to 1 byte + int32_t ppb; if (airspyhf_board_partid_serialno_read(pd, &read_partid_serialno) == AIRSPYHF_SUCCESS) { printf("S/N: 0x%08X%08X\n", @@ -58,6 +59,12 @@ void print_receiver_data (struct airspyhf_device* pd) else fprintf(stderr, "airspyhf_version_string_read() failed\n"); + if (airspyhf_get_calibration(pd, &ppb) == AIRSPYHF_SUCCESS) { + printf("Calibration = %d\n", ppb); + } else { + fprintf(stderr, "airspyhf_get_calibration() failed\n"); + } + if (airspyhf_get_samplerates(pd, &nsrates, 0) == AIRSPYHF_SUCCESS) { uint32_t *samplerates; @@ -105,7 +112,7 @@ int main(const int argc, char * const *argv) switch (opt) { case 's': - if (sscanf(optarg, "0x%Lx", &sn) == 1) { + if (sscanf(optarg, "0x%llx", &sn) == 1) { sn_msb = (uint32_t)(sn >> 32); sn_lsb = (uint32_t)(sn & 0xFFFFFFFF); printf("Receiver serial number to be opened: 0x%08X%08X\n", @@ -150,7 +157,7 @@ int main(const int argc, char * const *argv) print_receiver_data (dev); return EXIT_SUCCESS; } else { - fprintf (stderr, "Unable to open device with S/N 0x%16LX\n", sn); + fprintf (stderr, "Unable to open device with S/N 0x%16llX\n", sn); return EXIT_FAILURE; } } else { From ccd08ecab48adac74a4fc702857307649fe063c6 Mon Sep 17 00:00:00 2001 From: Kenji Rikitake Date: Thu, 2 Apr 2020 15:25:21 +0900 Subject: [PATCH 2/8] airspyhf_gpio.c: fix printf %Lx ambiguity --- tools/src/airspyhf_gpio.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/src/airspyhf_gpio.c b/tools/src/airspyhf_gpio.c index 6e04d10..4600b8e 100644 --- a/tools/src/airspyhf_gpio.c +++ b/tools/src/airspyhf_gpio.c @@ -91,7 +91,7 @@ int main (const int argc, char **argv) break; case 's': - if (sscanf(optarg, "0x%Lx", &sn) == 1) { + if (sscanf(optarg, "0x%llx", &sn) == 1) { sn_msb = (uint32_t)(sn >> 32); sn_lsb = (uint32_t)(sn & 0xFFFFFFFF); printf("Receiver serial number to be opened: 0x%08X%08X\n", @@ -126,7 +126,7 @@ int main (const int argc, char **argv) if(serial_number) { if (airspyhf_open_sn(&dev, sn) != AIRSPYHF_SUCCESS) { - fprintf (stderr, "Unable to open device with S/N 0x%16LX\n", sn); + fprintf (stderr, "Unable to open device with S/N 0x%16llX\n", sn); goto exit_error; } } else { From 9f17c44713b79a1d734f6a6141df22fb2f90b7dd Mon Sep 17 00:00:00 2001 From: Kenji Rikitake Date: Thu, 2 Apr 2020 15:26:27 +0900 Subject: [PATCH 3/8] airspyhf_rx.c: enable rate output only in verbose mode --- tools/src/airspyhf_rx.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/src/airspyhf_rx.c b/tools/src/airspyhf_rx.c index 1e21285..c727e11 100644 --- a/tools/src/airspyhf_rx.c +++ b/tools/src/airspyhf_rx.c @@ -748,9 +748,11 @@ int main(int argc, char** argv) char buf [64]; float average_rate_now = average_rate * 1e-6f; - snprintf(buf, sizeof(buf),"%2.3f", average_rate_now); - //average_rate_now = 9.5f; - fprintf(stderr, "Streaming at %5s MS/s\n", buf); + if (verbose) { + snprintf(buf, sizeof(buf),"%2.3f", average_rate_now); + //average_rate_now = 9.5f; + fprintf(stderr, "Streaming at %5s MS/s\n", buf); + } if ((limit_num_samples == true) && (bytes_to_xfer == 0)) do_exit = true; else From ddb500e5f8ee22fe07215c98b62fb6a2dbfcfdcf Mon Sep 17 00:00:00 2001 From: Kenji Rikitake Date: Thu, 2 Apr 2020 16:14:40 +0900 Subject: [PATCH 4/8] Add airspyhf_calibrate.c (no value updating yet) --- tools/src/CMakeLists.txt | 4 + tools/src/airspyhf_calibrate.c | 138 +++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 tools/src/airspyhf_calibrate.c diff --git a/tools/src/CMakeLists.txt b/tools/src/CMakeLists.txt index 0941f62..0c873e6 100644 --- a/tools/src/CMakeLists.txt +++ b/tools/src/CMakeLists.txt @@ -42,6 +42,9 @@ install(TARGETS airspyhf_rx RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR}) add_executable(airspyhf_gpio airspyhf_gpio.c) install(TARGETS airspyhf_gpio RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR}) +add_executable(airspyhf_calibrate airspyhf_calibrate.c) +install(TARGETS airspyhf_calibrate RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR}) + if(NOT libairspyhf_SOURCE_DIR) include_directories(${LIBAIRSPYHF_INCLUDE_DIR}) LIST(APPEND TOOLS_LINK_LIBS ${LIBAIRSPYHF_LIBRARIES}) @@ -59,3 +62,4 @@ target_link_libraries(airspyhf_lib_version ${TOOLS_LINK_LIBS}) target_link_libraries(airspyhf_info ${TOOLS_LINK_LIBS}) target_link_libraries(airspyhf_rx ${TOOLS_LINK_LIBS}) target_link_libraries(airspyhf_gpio ${TOOLS_LINK_LIBS}) +target_link_libraries(airspyhf_calibrate ${TOOLS_LINK_LIBS}) diff --git a/tools/src/airspyhf_calibrate.c b/tools/src/airspyhf_calibrate.c new file mode 100644 index 0000000..670d10c --- /dev/null +++ b/tools/src/airspyhf_calibrate.c @@ -0,0 +1,138 @@ +/* + * Copyright 2012 Jared Boone + * Copyright 2013 Michael Ossmann + * Copyright 2013/2014 Benjamin Vernoux + * Copyright 2018 Andrea Montefusco IW0HDV + * Copyright 2020 Kenji Rikitake JJ1BDX + * + * This file is part of AirSpyHF+ (based on HackRF project). + * + * Compile with: + * + * gcc -Wall airspyhf_info.c -lairspyhf -o airspyhf_info -lm + * + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + + +#include +#include +#include +#include +#include + +/* + * print all the receiver data available from libairspyhf + */ +void print_receiver_data (struct airspyhf_device* pd) +{ + if (pd) { + airspyhf_read_partid_serialno_t read_partid_serialno; + unsigned nsrates; + char vstr[255]; // the size of buffer length has to be restricted to 1 byte + int32_t ppb; + + if (airspyhf_board_partid_serialno_read(pd, &read_partid_serialno) == AIRSPYHF_SUCCESS) { + printf("S/N: 0x%08X%08X / ", + read_partid_serialno.serial_no[0], + read_partid_serialno.serial_no[1] + ); + printf("Part ID: 0x%08X / ", read_partid_serialno.part_id); + } else { + fprintf(stderr, "airspyhf_board_partid_serialno_read() failed\n"); + } + if (airspyhf_version_string_read(pd, vstr, sizeof(vstr)) == AIRSPYHF_SUCCESS) + printf("Firmware Version: %s\n", vstr); + else + fprintf(stderr, "airspyhf_version_string_read() failed\n"); + + if (airspyhf_get_calibration(pd, &ppb) == AIRSPYHF_SUCCESS) { + printf("Calibration = %d\n", ppb); + } else { + fprintf(stderr, "airspyhf_get_calibration() failed\n"); + } + } +} + +static void usage(void) +{ + printf("Usage:\n"); + printf("\t-s serial number: open receiver with specified 64-bit serial number (required).\n"); +} + + + +int main(const int argc, char * const *argv) +{ + int opt; + airspyhf_lib_version_t libv; + unsigned serial_number = 0; + unsigned long long sn; + unsigned ndev; + + // scan command line options + while( (opt = getopt(argc, argv, "?hs:")) != EOF ) { + + uint32_t sn_msb; + uint32_t sn_lsb; + + switch (opt) { + case 's': + if (sscanf(optarg, "0x%llx", &sn) == 1) { + sn_msb = (uint32_t)(sn >> 32); + sn_lsb = (uint32_t)(sn & 0xFFFFFFFF); + serial_number = 1; + } else { + fprintf(stderr, "argument error: '-%c %s'\n", opt, optarg); + usage(); + return EXIT_FAILURE; + } + break; + + default: + fprintf(stderr, "unknown argument '-%c'\n", opt); + + case 'h': + case '?': + usage(); + return EXIT_FAILURE; + } + } + + // scan all devices, return how many are attached + ndev = airspyhf_list_devices(0, 0); + + if (ndev <= 0) { + fprintf (stderr, "No devices attached.\n"); + return EXIT_FAILURE; + } + + if (serial_number) { + struct airspyhf_device *dev; + + if (airspyhf_open_sn(&dev, sn) == AIRSPYHF_SUCCESS) { + print_receiver_data (dev); + return EXIT_SUCCESS; + } else { + fprintf (stderr, "Unable to open device with S/N 0x%16llX\n", sn); + return EXIT_FAILURE; + } + } else { + usage(); + return EXIT_FAILURE; + } +} From d1fb0d2eb1076d4d0e42ec24fbb2e6243ff98135 Mon Sep 17 00:00:00 2001 From: Kenji Rikitake Date: Thu, 2 Apr 2020 16:48:50 +0900 Subject: [PATCH 5/8] airspyhf_calibrate.c: add -c option to set ppb value to flash --- tools/src/airspyhf_calibrate.c | 35 ++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/tools/src/airspyhf_calibrate.c b/tools/src/airspyhf_calibrate.c index 670d10c..a18c31b 100644 --- a/tools/src/airspyhf_calibrate.c +++ b/tools/src/airspyhf_calibrate.c @@ -42,7 +42,6 @@ void print_receiver_data (struct airspyhf_device* pd) { if (pd) { airspyhf_read_partid_serialno_t read_partid_serialno; - unsigned nsrates; char vstr[255]; // the size of buffer length has to be restricted to 1 byte int32_t ppb; @@ -71,21 +70,36 @@ void print_receiver_data (struct airspyhf_device* pd) static void usage(void) { printf("Usage:\n"); - printf("\t-s serial number: open receiver with specified 64-bit serial number (required).\n"); + printf("\t-s : open receiver with specified 64-bit serial number (required).\n"); + printf("\t-c : set receiver with specified new calibration value (optional, signed decimal).\n"); } +void write_new_calibration_value (struct airspyhf_device *pd, int32_t new_ppb) +{ + if (airspyhf_set_calibration(pd, new_ppb) == AIRSPYHF_SUCCESS) { + printf("New Calibration = %d\n", new_ppb); + } else { + fprintf(stderr, "airspyhf_set_calibration() failed\n"); + } + if (airspyhf_flash_calibration(pd) == AIRSPYHF_SUCCESS) { + printf("Flash Calibration successfully done\n"); + } else { + fprintf(stderr, "airspyhf_flash_calibration() failed\n"); + } +} int main(const int argc, char * const *argv) { int opt; - airspyhf_lib_version_t libv; unsigned serial_number = 0; unsigned long long sn; unsigned ndev; + unsigned set_calibration = 0; + int32_t new_ppb; // scan command line options - while( (opt = getopt(argc, argv, "?hs:")) != EOF ) { + while( (opt = getopt(argc, argv, "?hs:c:")) != EOF ) { uint32_t sn_msb; uint32_t sn_lsb; @@ -103,6 +117,16 @@ int main(const int argc, char * const *argv) } break; + case 'c': + if (sscanf(optarg, "%d", &new_ppb) == 1) { + set_calibration = 1; + } else { + fprintf(stderr, "argument error: '-%c %s'\n", opt, optarg); + usage(); + return EXIT_FAILURE; + } + break; + default: fprintf(stderr, "unknown argument '-%c'\n", opt); @@ -126,6 +150,9 @@ int main(const int argc, char * const *argv) if (airspyhf_open_sn(&dev, sn) == AIRSPYHF_SUCCESS) { print_receiver_data (dev); + if (set_calibration) { + write_new_calibration_value(dev, new_ppb); + } return EXIT_SUCCESS; } else { fprintf (stderr, "Unable to open device with S/N 0x%16llX\n", sn); From 351c4bfdea92cae97b06570fdd7d573e01855fff Mon Sep 17 00:00:00 2001 From: Kenji Rikitake Date: Thu, 2 Apr 2020 17:05:22 +0900 Subject: [PATCH 6/8] airspyhf_info.c: remove airspyhf_get_calibration() * Function is moved into airspyhf_calibrate.c --- tools/src/airspyhf_info.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tools/src/airspyhf_info.c b/tools/src/airspyhf_info.c index 40ad2c6..e5d0e83 100644 --- a/tools/src/airspyhf_info.c +++ b/tools/src/airspyhf_info.c @@ -43,7 +43,6 @@ void print_receiver_data (struct airspyhf_device* pd) airspyhf_read_partid_serialno_t read_partid_serialno; unsigned nsrates; char vstr[255]; // the size of buffer length has to be restricted to 1 byte - int32_t ppb; if (airspyhf_board_partid_serialno_read(pd, &read_partid_serialno) == AIRSPYHF_SUCCESS) { printf("S/N: 0x%08X%08X\n", @@ -59,12 +58,6 @@ void print_receiver_data (struct airspyhf_device* pd) else fprintf(stderr, "airspyhf_version_string_read() failed\n"); - if (airspyhf_get_calibration(pd, &ppb) == AIRSPYHF_SUCCESS) { - printf("Calibration = %d\n", ppb); - } else { - fprintf(stderr, "airspyhf_get_calibration() failed\n"); - } - if (airspyhf_get_samplerates(pd, &nsrates, 0) == AIRSPYHF_SUCCESS) { uint32_t *samplerates; From e0951066a67a566e88c8676a9adcac5e9891c407 Mon Sep 17 00:00:00 2001 From: Kenji Rikitake Date: Thu, 2 Apr 2020 18:36:20 +0900 Subject: [PATCH 7/8] airspyhf_calibrate.c: remove unnecessary messages --- tools/src/airspyhf_calibrate.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tools/src/airspyhf_calibrate.c b/tools/src/airspyhf_calibrate.c index a18c31b..aa35702 100644 --- a/tools/src/airspyhf_calibrate.c +++ b/tools/src/airspyhf_calibrate.c @@ -9,8 +9,7 @@ * * Compile with: * - * gcc -Wall airspyhf_info.c -lairspyhf -o airspyhf_info -lm - * + * gcc -Wall airspyhf_calibrate.c -lairspyhf -o airspyhf_calibrate -lm * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,7 +35,7 @@ #include /* - * print all the receiver data available from libairspyhf + * print the receiver calibration data */ void print_receiver_data (struct airspyhf_device* pd) { @@ -46,18 +45,13 @@ void print_receiver_data (struct airspyhf_device* pd) int32_t ppb; if (airspyhf_board_partid_serialno_read(pd, &read_partid_serialno) == AIRSPYHF_SUCCESS) { - printf("S/N: 0x%08X%08X / ", + printf("S/N: 0x%08X%08X\n", read_partid_serialno.serial_no[0], read_partid_serialno.serial_no[1] ); - printf("Part ID: 0x%08X / ", read_partid_serialno.part_id); } else { fprintf(stderr, "airspyhf_board_partid_serialno_read() failed\n"); } - if (airspyhf_version_string_read(pd, vstr, sizeof(vstr)) == AIRSPYHF_SUCCESS) - printf("Firmware Version: %s\n", vstr); - else - fprintf(stderr, "airspyhf_version_string_read() failed\n"); if (airspyhf_get_calibration(pd, &ppb) == AIRSPYHF_SUCCESS) { printf("Calibration = %d\n", ppb); From 9cb272c56faf86af10c2a8e258da22edd84a24f2 Mon Sep 17 00:00:00 2001 From: Kenji Rikitake Date: Fri, 3 Apr 2020 08:08:02 +0900 Subject: [PATCH 8/8] airspyhf_calibrate.c: remove unused variables --- tools/src/airspyhf_calibrate.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tools/src/airspyhf_calibrate.c b/tools/src/airspyhf_calibrate.c index aa35702..2252bf2 100644 --- a/tools/src/airspyhf_calibrate.c +++ b/tools/src/airspyhf_calibrate.c @@ -41,7 +41,6 @@ void print_receiver_data (struct airspyhf_device* pd) { if (pd) { airspyhf_read_partid_serialno_t read_partid_serialno; - char vstr[255]; // the size of buffer length has to be restricted to 1 byte int32_t ppb; if (airspyhf_board_partid_serialno_read(pd, &read_partid_serialno) == AIRSPYHF_SUCCESS) { @@ -95,14 +94,9 @@ int main(const int argc, char * const *argv) // scan command line options while( (opt = getopt(argc, argv, "?hs:c:")) != EOF ) { - uint32_t sn_msb; - uint32_t sn_lsb; - switch (opt) { case 's': if (sscanf(optarg, "0x%llx", &sn) == 1) { - sn_msb = (uint32_t)(sn >> 32); - sn_lsb = (uint32_t)(sn & 0xFFFFFFFF); serial_number = 1; } else { fprintf(stderr, "argument error: '-%c %s'\n", opt, optarg);