#include "libsigrok-internal.h"
#include "protocol.h"
+static int count_digits(const char *str) {
+ int digits;
+
+ while (*str && *str != ' ' && *str != ',' && *str != '.')
+ str++;
+
+ digits = 0;
+ if (*str == '.') {
+ str++;
+ while (*str && *str != ' ' && *str != ',') {
+ str++;
+ digits++;
+ }
+ }
+
+ return digits;
+}
+
static void handle_qm_18x(const struct sr_dev_inst *sdi, char **tokens)
{
struct dev_context *devc;
float fvalue;
char *e, *u;
gboolean is_oor;
+ int digits;
devc = sdi->priv;
if ((e = strstr(tokens[1], "Out of range"))) {
is_oor = TRUE;
fvalue = -1;
+ digits = 0;
while (*e && *e != '.')
e++;
} else {
while (*e && *e != ' ')
e++;
*e++ = '\0';
- if (sr_atof_ascii(tokens[1], &fvalue) != SR_OK || fvalue == 0.0) {
+ if (sr_atof_ascii(tokens[1], &fvalue) != SR_OK) {
/* Happens all the time, when switching modes. */
- sr_dbg("Invalid float.");
+ sr_dbg("Invalid float: '%s'", tokens[1]);
return;
}
+ digits = count_digits(tokens[1]);
}
while (*e && *e == ' ')
e++;
- /* TODO: Use proper 'digits' value for this device (and its modes). */
- sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
+ sr_analog_init(&analog, &encoding, &meaning, &spec, digits);
analog.data = &fvalue;
analog.meaning->channels = sdi->channels;
analog.num_samples = 1;
struct sr_analog_meaning meaning;
struct sr_analog_spec spec;
float fvalue;
+ int digits;
devc = sdi->priv;
if (!tokens[1])
return;
- if (sr_atof_ascii(tokens[0], &fvalue) != SR_OK || fvalue == 0.0) {
+ if (sr_atof_ascii(tokens[0], &fvalue) != SR_OK) {
sr_err("Invalid float '%s'.", tokens[0]);
return;
}
+ digits = count_digits(tokens[0]);
- /* TODO: Use proper 'digits' value for this device (and its modes). */
- sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
+ sr_analog_init(&analog, &encoding, &meaning, &spec, digits);
analog.data = &fvalue;
analog.meaning->channels = sdi->channels;
analog.num_samples = 1;
struct sr_analog_meaning meaning;
struct sr_analog_spec spec;
float fvalue;
+ int digits;
+ digits = 2;
if (!strcmp(tokens[0], "9.9E+37")) {
/* An invalid measurement shows up on the display as "OL", but
* comes through like this. Since comparing 38-digit floats
sr_err("Invalid float '%s'.", tokens[0]);
return;
}
+ digits = count_digits(tokens[0]);
}
devc = sdi->priv;
fvalue = 1.0;
}
- /* TODO: Use proper 'digits' value for this device (and its modes). */
- sr_analog_init(&analog, &encoding, &meaning, &spec, 2);
+ sr_analog_init(&analog, &encoding, &meaning, &spec, digits);
analog.meaning->channels = sdi->channels;
analog.num_samples = 1;
analog.data = &fvalue;
tokens = g_strsplit(devc->buf, ",", 0);
if (tokens[0]) {
- if (devc->profile->model == FLUKE_187 || devc->profile->model == FLUKE_189) {
+ if (devc->profile->model == FLUKE_87 || devc->profile->model == FLUKE_89 ||
+ devc->profile->model == FLUKE_187 || devc->profile->model == FLUKE_189) {
devc->expect_response = FALSE;
handle_qm_18x(sdi, tokens);
} else if (devc->profile->model == FLUKE_287 || devc->profile->model == FLUKE_289) {