From 2d79f6d69fa36adee768c246b1209bd3102e6896 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 17 Oct 2012 20:55:48 -0700 Subject: [PATCH] Added support for hackrf_max2837 utility to accept registers and values as "0x" (base-16) or "0b" (base-2). --- host/libhackrf/examples/hackrf_max2837.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/host/libhackrf/examples/hackrf_max2837.c b/host/libhackrf/examples/hackrf_max2837.c index f4fbdf2e..cac878ff 100644 --- a/host/libhackrf/examples/hackrf_max2837.c +++ b/host/libhackrf/examples/hackrf_max2837.c @@ -22,6 +22,7 @@ #include #include +#include #include #include @@ -43,9 +44,22 @@ static struct option long_options[] = { { 0, 0, 0, 0 }, }; -int parse_int(char* const s, uint16_t* const value) { +int parse_int(char* s, uint16_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 long long_value = strtol(s, &s_end, 10); + const long long_value = strtol(s, &s_end, base); if( (s != s_end) && (*s_end == 0) ) { *value = long_value; return HACKRF_SUCCESS;