From 0e68be7771371c396e261fd872d0cf5bb04833a5 Mon Sep 17 00:00:00 2001 From: Mike Walters Date: Fri, 3 Sep 2021 19:29:30 +0100 Subject: [PATCH] hackrf_operacake: simplify frequency range parsing --- host/hackrf-tools/src/hackrf_operacake.c | 33 ++++++++++-------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/host/hackrf-tools/src/hackrf_operacake.c b/host/hackrf-tools/src/hackrf_operacake.c index 9a1fb808..da4df9fc 100644 --- a/host/hackrf-tools/src/hackrf_operacake.c +++ b/host/hackrf-tools/src/hackrf_operacake.c @@ -129,29 +129,22 @@ int parse_port(char* str, uint8_t* port) { } int parse_range(char* s, hackrf_oc_range* range) { + char port[16]; + float min; + float max; int result; - char *sep = strchr(s, ':'); - if (!sep) - return HACKRF_ERROR_INVALID_PARAM; - // Replace : separator to null terminate string for strtol() - *sep = 0; - sep++; // Skip past the separator - char *sep2 = strchr(sep, ':'); - if (!sep2) - return HACKRF_ERROR_INVALID_PARAM; - // Replace : separator to null terminate string for strtol() - *sep2 = 0; - sep2++; // Skip past the separator + // Read frequency as a float here to support scientific notation (e.g: 1e6) + if (sscanf(s, "%15[^:]:%f:%f", port, &min, &max) == 3) { + result = parse_port(port, &(range->port)); + if (result != HACKRF_SUCCESS) + return result; - result = parse_port(s, &(range->port)); - if (result != HACKRF_SUCCESS) - return result; - result = parse_uint16(sep, &range->freq_min); - if (result != HACKRF_SUCCESS) - return result; - result = parse_uint16(sep2, &range->freq_max); - return result; + range->freq_min = min; + range->freq_max = max; + return HACKRF_SUCCESS; + } + return HACKRF_ERROR_INVALID_PARAM; } int parse_dwell(char* s, hackrf_operacake_dwell_time* dwell_time) {