From: Gerhard Sittig Date: Sat, 1 Dec 2018 11:23:54 +0000 (+0100) Subject: decode: add support for float option data type X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4c1a29f449343e258bdaa556d0a2469fcd3725df;p=sigrok-cli.git decode: add support for float option data type Accept decoder options where the value is a floating point number. This fixes bug #1247 (the "unsupported type" issue reported for sigrok-cli). --- diff --git a/decode.c b/decode.c index 2b95f23..2935286 100644 --- a/decode.c +++ b/decode.c @@ -38,6 +38,7 @@ static int opts_to_gvar(struct srd_decoder *dec, GHashTable *hash, GSList *optl; GVariant *gvar; gint64 val_int; + double val_dbl; int ret; char *val_str, *conv; @@ -61,6 +62,16 @@ static int opts_to_gvar(struct srd_decoder *dec, GHashTable *hash, break; } gvar = g_variant_new_int64(val_int); + } else if (g_variant_is_of_type(o->def, G_VARIANT_TYPE_DOUBLE)) { + conv = NULL; + val_dbl = strtod(val_str, &conv); + if (!conv || conv == val_str || *conv) { + g_critical("Protocol decoder '%s' option '%s' requires a float number.", + dec->name, o->id); + ret = FALSE; + break; + } + gvar = g_variant_new_double(val_dbl); } else { g_critical("Unsupported type for option '%s' (%s)", o->id, g_variant_get_type_string(o->def));