X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fdmm%2Ffs9922.c;h=06c8b3c430b29e67011ec6065f7f6fb347f56154;hb=HEAD;hp=9f850c3f36d014dcda06bf93b4d20a6a3fcbf39f;hpb=b02bb45f4cf6378520e5a5b82ff39013cfa270b6;p=libsigrok.git diff --git a/src/dmm/fs9922.c b/src/dmm/fs9922.c index 9f850c3f..06c8b3c4 100644 --- a/src/dmm/fs9922.c +++ b/src/dmm/fs9922.c @@ -14,8 +14,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 . */ /* @@ -86,7 +85,7 @@ static gboolean flags_valid(const struct fs9922_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 sign, intval; float floatval; @@ -140,13 +139,13 @@ static int parse_value(const uint8_t *buf, float *result) return SR_ERR; } if (buf[6] == '0') - floatval /= 1; + *exponent = 0; else if (buf[6] == '1') - floatval /= 1000; + *exponent = -3; else if (buf[6] == '2') - floatval /= 100; + *exponent = -2; else if (buf[6] == '4') - floatval /= 10; + *exponent = -1; /* Apply sign. */ floatval *= sign; @@ -224,19 +223,20 @@ static void parse_flags(const uint8_t *buf, struct fs9922_info *info) } static void handle_flags(struct sr_datafeed_analog *analog, float *floatval, - const struct fs9922_info *info) + int *exponent, const struct fs9922_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 || info->is_diode) { @@ -290,7 +290,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_max) @@ -356,18 +356,21 @@ SR_PRIV gboolean sr_fs9922_packet_valid(const uint8_t *buf) SR_PRIV int sr_fs9922_parse(const uint8_t *buf, float *floatval, struct sr_datafeed_analog *analog, void *info) { - int ret; + int ret, exponent = 0; struct fs9922_info *info_local; - info_local = (struct fs9922_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; } @@ -376,12 +379,12 @@ SR_PRIV void sr_fs9922_z1_diode(struct sr_datafeed_analog *analog, void *info) { struct fs9922_info *info_local; - info_local = (struct fs9922_info *)info; + info_local = info; /* User-defined z1 flag means "diode mode". */ if (info_local->is_z1) { analog->meaning->mq = SR_MQ_VOLTAGE; analog->meaning->unit = SR_UNIT_VOLT; - analog->meaning->mqflags |= SR_MQFLAG_DIODE; + analog->meaning->mqflags |= SR_MQFLAG_DIODE | SR_MQFLAG_DC; } }