X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fdmm%2Fut372.c;h=ce21273b688a9f63a9f11a942bb5a545dd3e68da;hb=830e24b68f87f51d4bdc8067704219e0956fba90;hp=d2fd8bc9e8b5643d8996a87d62737b17af868836;hpb=c1aae90038456a61d0f9313d34e6107c3440d3e7;p=libsigrok.git
diff --git a/src/dmm/ut372.c b/src/dmm/ut372.c
index d2fd8bc9..ce21273b 100644
--- a/src/dmm/ut372.c
+++ b/src/dmm/ut372.c
@@ -14,14 +14,14 @@
* 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 .
*/
/*
* UNI-T UT372 protocol parser.
*/
+#include
#include
#include
#include
@@ -89,8 +89,9 @@ SR_PRIV gboolean sr_ut372_packet_valid(const uint8_t *buf)
SR_PRIV int sr_ut372_parse(const uint8_t *buf, float *floatval,
struct sr_datafeed_analog *analog, void *info)
{
- unsigned int i, j, value, divisor;
+ unsigned int i, j, value;
uint8_t segments, flags1, flags2;
+ int exponent;
(void) info;
@@ -98,24 +99,24 @@ SR_PRIV int sr_ut372_parse(const uint8_t *buf, float *floatval,
flags2 = decode_pair(buf + 23);
if (flags2 & FLAGS2_RPM_MASK) {
- analog->mq = SR_MQ_FREQUENCY;
- analog->unit = SR_UNIT_REVOLUTIONS_PER_MINUTE;
+ analog->meaning->mq = SR_MQ_FREQUENCY;
+ analog->meaning->unit = SR_UNIT_REVOLUTIONS_PER_MINUTE;
} else if (flags2 & FLAGS2_COUNT_MASK) {
- analog->mq = SR_MQ_COUNT;
- analog->unit = SR_UNIT_UNITLESS;
+ analog->meaning->mq = SR_MQ_COUNT;
+ analog->meaning->unit = SR_UNIT_UNITLESS;
}
if (flags1 & FLAGS1_HOLD_MASK)
- analog->mqflags |= SR_MQFLAG_HOLD;
+ analog->meaning->mqflags |= SR_MQFLAG_HOLD;
if (flags2 & FLAGS2_MIN_MASK)
- analog->mqflags |= SR_MQFLAG_MIN;
+ analog->meaning->mqflags |= SR_MQFLAG_MIN;
if (flags2 & FLAGS2_MAX_MASK)
- analog->mqflags |= SR_MQFLAG_MAX;
+ analog->meaning->mqflags |= SR_MQFLAG_MAX;
if (flags2 & FLAGS2_AVG_MASK)
- analog->mqflags |= SR_MQFLAG_AVG;
+ analog->meaning->mqflags |= SR_MQFLAG_AVG;
value = 0;
- divisor = 1;
+ exponent = 0;
for (i = 0; i < 5; i++) {
segments = decode_pair(buf + 1 + (2 * i));
@@ -126,10 +127,13 @@ SR_PRIV int sr_ut372_parse(const uint8_t *buf, float *floatval,
}
}
if (segments & DECIMAL_POINT_MASK)
- divisor = pow(10, i);
+ exponent = -i;
}
- *floatval = (float) value / divisor;
+ *floatval = (float) value * powf(10, exponent);
+
+ analog->encoding->digits = -exponent;
+ analog->spec->spec_digits = -exponent;
return SR_OK;
}