#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 {
sr_dbg("Invalid float.");
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;
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;