hackrf_operacake: simplify frequency range parsing

This commit is contained in:
Mike Walters
2021-09-03 19:29:30 +01:00
parent 07a9dd73d8
commit 0e68be7771

View File

@ -129,29 +129,22 @@ int parse_port(char* str, uint8_t* port) {
} }
int parse_range(char* s, hackrf_oc_range* range) { int parse_range(char* s, hackrf_oc_range* range) {
char port[16];
float min;
float max;
int result; 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, ':'); // Read frequency as a float here to support scientific notation (e.g: 1e6)
if (!sep2) if (sscanf(s, "%15[^:]:%f:%f", port, &min, &max) == 3) {
return HACKRF_ERROR_INVALID_PARAM; result = parse_port(port, &(range->port));
// Replace : separator to null terminate string for strtol() if (result != HACKRF_SUCCESS)
*sep2 = 0; return result;
sep2++; // Skip past the separator
result = parse_port(s, &(range->port)); range->freq_min = min;
if (result != HACKRF_SUCCESS) range->freq_max = max;
return result; return HACKRF_SUCCESS;
result = parse_uint16(sep, &range->freq_min); }
if (result != HACKRF_SUCCESS) return HACKRF_ERROR_INVALID_PARAM;
return result;
result = parse_uint16(sep2, &range->freq_max);
return result;
} }
int parse_dwell(char* s, hackrf_operacake_dwell_time* dwell_time) { int parse_dwell(char* s, hackrf_operacake_dwell_time* dwell_time) {