]> sigrok.org Git - libsigrok.git/blobdiff - hardware/fluke-dmm/fluke.c
Replace 'probe' with 'channel' in most places.
[libsigrok.git] / hardware / fluke-dmm / fluke.c
index e5d174a325ca31760d55589a1631a48872dfa76c..edb6734adbd06166a1204cbd02012c16f77e060f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the sigrok project.
+ * This file is part of the libsigrok project.
  *
  * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
  *
@@ -26,7 +26,6 @@
 #include "libsigrok-internal.h"
 #include "fluke-dmm.h"
 
-
 static struct sr_datafeed_analog *handle_qm_18x(const struct sr_dev_inst *sdi,
                char **tokens)
 {
@@ -35,18 +34,23 @@ static struct sr_datafeed_analog *handle_qm_18x(const struct sr_dev_inst *sdi,
        char *e, *u;
        gboolean is_oor;
 
-       (void)sdi;
-
        if (strcmp(tokens[0], "QM") || !tokens[1])
                return NULL;
 
        if ((e = strstr(tokens[1], "Out of range"))) {
                is_oor = TRUE;
                fvalue = -1;
+               while(*e && *e != '.')
+                       e++;
        } else {
                is_oor = FALSE;
-               fvalue = strtof(tokens[1], &e);
-               if (fvalue == 0.0 && e == tokens[1]) {
+               /* Delimit the float, since sr_atof_ascii() wants only
+                * a valid float here. */
+               e = tokens[1];
+               while(*e && *e != ' ')
+                       e++;
+               *e++ = '\0';
+               if (sr_atof_ascii(tokens[1], &fvalue) != SR_OK || fvalue == 0.0) {
                        /* Happens all the time, when switching modes. */
                        sr_dbg("Invalid float.");
                        return NULL;
@@ -55,11 +59,12 @@ static struct sr_datafeed_analog *handle_qm_18x(const struct sr_dev_inst *sdi,
        while(*e && *e == ' ')
                e++;
 
-       /* TODO: Check malloc return value. */
-       analog = g_try_malloc0(sizeof(struct sr_datafeed_analog));
+       if (!(analog = g_try_malloc0(sizeof(struct sr_datafeed_analog))))
+               return NULL;
+       if (!(analog->data = g_try_malloc(sizeof(float))))
+               return NULL;
+       analog->channels = sdi->channels;
        analog->num_samples = 1;
-       /* TODO: Check malloc return value. */
-       analog->data = g_try_malloc(sizeof(float));
        if (is_oor)
                *analog->data = NAN;
        else
@@ -156,24 +161,21 @@ static struct sr_datafeed_analog *handle_qm_28x(const struct sr_dev_inst *sdi,
 {
        struct sr_datafeed_analog *analog;
        float fvalue;
-       char *eptr;
-
-       (void)sdi;
 
        if (!tokens[1])
                return NULL;
 
-       fvalue = strtof(tokens[0], &eptr);
-       if (fvalue == 0.0 && eptr == tokens[0]) {
-               sr_err("Invalid float.");
+       if (sr_atof_ascii(tokens[0], &fvalue) != SR_OK || fvalue == 0.0) {
+               sr_err("Invalid float '%s'.", tokens[0]);
                return NULL;
        }
 
-       /* TODO: Check malloc return value. */
-       analog = g_try_malloc0(sizeof(struct sr_datafeed_analog));
+       if (!(analog = g_try_malloc0(sizeof(struct sr_datafeed_analog))))
+               return NULL;
+       if (!(analog->data = g_try_malloc(sizeof(float))))
+               return NULL;
+       analog->channels = sdi->channels;
        analog->num_samples = 1;
-       /* TODO: Check malloc return value. */
-       analog->data = g_try_malloc(sizeof(float));
        *analog->data = fvalue;
        analog->mq = -1;
 
@@ -366,7 +368,6 @@ static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens)
        struct sr_datafeed_packet packet;
        struct sr_datafeed_analog analog;
        float fvalue;
-       char *eptr;
 
        if (!strcmp(tokens[0], "9.9E+37")) {
                /* An invalid measurement shows up on the display as "OL", but
@@ -374,8 +375,7 @@ static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens)
                 * is rather problematic, we'll cut through this here. */
                fvalue = NAN;
        } else {
-               fvalue = strtof(tokens[0], &eptr);
-               if (fvalue == 0.0 && eptr == tokens[0]) {
+               if (sr_atof_ascii(tokens[0], &fvalue) != SR_OK || fvalue == 0.0) {
                        sr_err("Invalid float '%s'.", tokens[0]);
                        return;
                }
@@ -396,6 +396,7 @@ static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens)
                        fvalue = 1.0;
        }
 
+       analog.channels = sdi->channels;
        analog.num_samples = 1;
        analog.data = &fvalue;
        analog.mq = devc->mq;
@@ -411,12 +412,14 @@ static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens)
 static void handle_line(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
+       struct sr_serial_dev_inst *serial;
        struct sr_datafeed_packet packet;
        struct sr_datafeed_analog *analog;
        int num_tokens, n, i;
        char cmd[16], **tokens;
 
        devc = sdi->priv;
+       serial = sdi->conn;
        sr_spew("Received line '%s' (%d).", devc->buf, devc->buflen);
 
        if (devc->buflen == 1) {
@@ -432,7 +435,7 @@ static void handle_line(const struct sr_dev_inst *sdi)
        analog = NULL;
        tokens = g_strsplit(devc->buf, ",", 0);
        if (tokens[0]) {
-               if (devc->profile->model == FLUKE_187) {
+               if (devc->profile->model == FLUKE_187 || devc->profile->model == FLUKE_189) {
                        devc->expect_response = FALSE;
                        analog = handle_qm_18x(sdi, tokens);
                } else if (devc->profile->model == FLUKE_287) {
@@ -453,7 +456,7 @@ static void handle_line(const struct sr_dev_inst *sdi)
                                        /* Slip the request in now, before the main
                                         * timer loop asks for metadata again. */
                                        n = sprintf(cmd, "QM %d\r", devc->meas_type);
-                                       if (serial_write(devc->serial, cmd, n) == -1)
+                                       if (serial_write(serial, cmd, n) == -1)
                                                sr_err("Unable to send QM (measurement): %s.",
                                                                strerror(errno));
                                }
@@ -482,6 +485,7 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data)
 {
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
+       struct sr_serial_dev_inst *serial;
        int len;
        int64_t now, elapsed;
 
@@ -493,10 +497,11 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data)
        if (!(devc = sdi->priv))
                return TRUE;
 
+       serial = sdi->conn;
        if (revents == G_IO_IN) {
                /* Serial data arrived. */
                while(FLUKEDMM_BUFSIZE - devc->buflen - 1 > 0) {
-                       len = serial_read(devc->serial, devc->buf + devc->buflen, 1);
+                       len = serial_read(serial, devc->buf + devc->buflen, 1);
                        if (len < 1)
                                break;
                        devc->buflen++;
@@ -521,7 +526,7 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data)
         * out-of-sync or temporary disconnect issues. */
        if ((devc->expect_response == FALSE && elapsed > devc->profile->poll_period)
                        || elapsed > devc->profile->timeout) {
-               if (serial_write(devc->serial, "QM\r", 3) == -1)
+               if (serial_write(serial, "QM\r", 3) == -1)
                        sr_err("Unable to send QM: %s.", strerror(errno));
                devc->cmd_sent_at = now;
                devc->expect_response = TRUE;
@@ -529,5 +534,3 @@ SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data)
 
        return TRUE;
 }
-
-