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.
This commit is contained in:
parent
66b349841a
commit
3f8453b274
|
@ -223,6 +223,7 @@ SR_PRIV int brymen_parse(const uint8_t *buf, float *floatval,
|
||||||
uint8_t *bfunc;
|
uint8_t *bfunc;
|
||||||
const char *txt;
|
const char *txt;
|
||||||
int txtlen;
|
int txtlen;
|
||||||
|
char *unit;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
(void)info;
|
(void)info;
|
||||||
|
@ -236,6 +237,18 @@ SR_PRIV int brymen_parse(const uint8_t *buf, float *floatval,
|
||||||
|
|
||||||
memset(&flags, 0, sizeof(flags));
|
memset(&flags, 0, sizeof(flags));
|
||||||
parse_flags(bfunc, &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);
|
ret = parse_value(txt, txtlen, floatval);
|
||||||
sr_dbg("floatval: %f, ret %d", *floatval, ret);
|
sr_dbg("floatval: %f, ret %d", *floatval, ret);
|
||||||
if (ret != SR_OK)
|
if (ret != SR_OK)
|
||||||
|
|
Loading…
Reference in New Issue