From: Gerhard Sittig Date: Mon, 21 Sep 2020 18:32:21 +0000 (+0200) Subject: brymen-dmm: unbreak temperature response parsing X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3f8453b274d7776ff4f0bb7a869eb6211364c190;p=libsigrok.git brymen-dmm: unbreak temperature response parsing The BM850s temperature function response includes the C/F unit in an unexpected position ("0.0272CE+3") which breaks number conversion. Drop the C/F unit to unbreak the conversion. This was observed with BM859s. Absence of the C/F unit in the response is fatal in this implementation. If other meter firmware versions or models don't suffer from that issue, the removal must be silent and non-fatal. --- diff --git a/src/hardware/brymen-dmm/parser.c b/src/hardware/brymen-dmm/parser.c index 9811012b..40ca6c86 100644 --- a/src/hardware/brymen-dmm/parser.c +++ b/src/hardware/brymen-dmm/parser.c @@ -223,6 +223,7 @@ SR_PRIV int brymen_parse(const uint8_t *buf, float *floatval, uint8_t *bfunc; const char *txt; int txtlen; + char *unit; int ret; (void)info; @@ -236,6 +237,18 @@ SR_PRIV int brymen_parse(const uint8_t *buf, float *floatval, memset(&flags, 0, sizeof(flags)); parse_flags(bfunc, &flags); + if (flags.is_fahrenheit || flags.is_celsius) { + /* + * The value text in temperature mode includes the C/F + * suffix between the mantissa and the exponent, which + * breaks the text to number conversion. Example data: + * " 0.0217CE+3". Remove the C/F unit identifier. + */ + unit = strchr(txt, flags.is_fahrenheit ? 'F' : 'C'); + if (!unit) + return SR_ERR; + *unit = ' '; + } ret = parse_value(txt, txtlen, floatval); sr_dbg("floatval: %f, ret %d", *floatval, ret); if (ret != SR_OK)