X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fdmm%2Ffs9721.c;h=392e37e75f2ff0d842ace56c59686a86e9f80997;hb=46a36bf0bb2e46f6aee28f629e950fb923c2884f;hp=eaf5b477518de3f0fc10dd02623620556f639f25;hpb=b02bb45f4cf6378520e5a5b82ff39013cfa270b6;p=libsigrok.git diff --git a/src/dmm/fs9721.c b/src/dmm/fs9721.c index eaf5b477..392e37e7 100644 --- a/src/dmm/fs9721.c +++ b/src/dmm/fs9721.c @@ -15,8 +15,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * along with this program; if not, see . */ /* @@ -130,7 +129,7 @@ static gboolean flags_valid(const struct fs9721_info *info) return TRUE; } -static int parse_value(const uint8_t *buf, float *result) +static int parse_value(const uint8_t *buf, float *result, int *exponent) { int i, sign, intval = 0, digits[4]; uint8_t digit_bytes[4]; @@ -179,15 +178,16 @@ static int parse_value(const uint8_t *buf, float *result) /* Decimal point position. */ if ((buf[3] & (1 << 3)) != 0) { - floatval /= 1000; + *exponent = -3; sr_spew("Decimal point after first digit."); } else if ((buf[5] & (1 << 3)) != 0) { - floatval /= 100; + *exponent = -2; sr_spew("Decimal point after second digit."); } else if ((buf[7] & (1 << 3)) != 0) { - floatval /= 10; + *exponent = -1; sr_spew("Decimal point after third digit."); } else { + *exponent = 0; sr_spew("No decimal point in the number."); } @@ -244,19 +244,20 @@ static void parse_flags(const uint8_t *buf, struct fs9721_info *info) } static void handle_flags(struct sr_datafeed_analog *analog, float *floatval, - const struct fs9721_info *info) + int *exponent, const struct fs9721_info *info) { /* Factors */ if (info->is_nano) - *floatval /= 1000000000; + *exponent -= 9; if (info->is_micro) - *floatval /= 1000000; + *exponent -= 6; if (info->is_milli) - *floatval /= 1000; + *exponent -= 3; if (info->is_kilo) - *floatval *= 1000; + *exponent += 3; if (info->is_mega) - *floatval *= 1000000; + *exponent += 6; + *floatval *= powf(10, *exponent); /* Measurement modes */ if (info->is_volt) { @@ -301,7 +302,7 @@ static void handle_flags(struct sr_datafeed_analog *analog, float *floatval, if (info->is_auto) analog->meaning->mqflags |= SR_MQFLAG_AUTORANGE; if (info->is_diode) - analog->meaning->mqflags |= SR_MQFLAG_DIODE; + analog->meaning->mqflags |= SR_MQFLAG_DIODE | SR_MQFLAG_DC; if (info->is_hold) analog->meaning->mqflags |= SR_MQFLAG_HOLD; if (info->is_rel) @@ -349,18 +350,21 @@ SR_PRIV gboolean sr_fs9721_packet_valid(const uint8_t *buf) SR_PRIV int sr_fs9721_parse(const uint8_t *buf, float *floatval, struct sr_datafeed_analog *analog, void *info) { - int ret; + int ret, exponent = 0; struct fs9721_info *info_local; - info_local = (struct fs9721_info *)info; + info_local = info; - if ((ret = parse_value(buf, floatval)) != SR_OK) { + if ((ret = parse_value(buf, floatval, &exponent)) != SR_OK) { sr_dbg("Error parsing value: %d.", ret); return ret; } parse_flags(buf, info_local); - handle_flags(analog, floatval, info_local); + handle_flags(analog, floatval, &exponent, info_local); + + analog->encoding->digits = -exponent; + analog->spec->spec_digits = -exponent; return SR_OK; } @@ -369,7 +373,7 @@ SR_PRIV void sr_fs9721_00_temp_c(struct sr_datafeed_analog *analog, void *info) { struct fs9721_info *info_local; - info_local = (struct fs9721_info *)info; + info_local = info; /* User-defined FS9721_LP3 flag 'c2c1_00' means temperature (C). */ if (info_local->is_c2c1_00) { @@ -382,7 +386,7 @@ SR_PRIV void sr_fs9721_01_temp_c(struct sr_datafeed_analog *analog, void *info) { struct fs9721_info *info_local; - info_local = (struct fs9721_info *)info; + info_local = info; /* User-defined FS9721_LP3 flag 'c2c1_01' means temperature (C). */ if (info_local->is_c2c1_01) { @@ -395,7 +399,7 @@ SR_PRIV void sr_fs9721_10_temp_c(struct sr_datafeed_analog *analog, void *info) { struct fs9721_info *info_local; - info_local = (struct fs9721_info *)info; + info_local = info; /* User-defined FS9721_LP3 flag 'c2c1_10' means temperature (C). */ if (info_local->is_c2c1_10) { @@ -408,7 +412,7 @@ SR_PRIV void sr_fs9721_01_10_temp_f_c(struct sr_datafeed_analog *analog, void *i { struct fs9721_info *info_local; - info_local = (struct fs9721_info *)info; + info_local = info; /* User-defined FS9721_LP3 flag 'c2c1_01' means temperature (F). */ if (info_local->is_c2c1_01) { @@ -427,7 +431,7 @@ SR_PRIV void sr_fs9721_max_c_min(struct sr_datafeed_analog *analog, void *info) { struct fs9721_info *info_local; - info_local = (struct fs9721_info *)info; + info_local = info; /* User-defined FS9721_LP3 flag 'c2c1_00' means MAX. */ if (info_local->is_c2c1_00)