]> sigrok.org Git - libsigrok.git/commitdiff
fluke-dmm: Move device-specific DM handling
authorAndreas Sandberg <redacted>
Thu, 3 Oct 2024 22:51:58 +0000 (23:51 +0100)
committerSoeren Apel <redacted>
Mon, 7 Oct 2024 20:08:25 +0000 (22:08 +0200)
With the exception of the Fluke 28x series, device-specific DM
handling is currently handled in protocol.c. Move this to separate
files for clarity.

Signed-off-by: Andreas Sandberg <redacted>
Makefile.am
src/hardware/fluke-dmm/fluke-18x.c [new file with mode: 0644]
src/hardware/fluke-dmm/fluke-190.c [new file with mode: 0644]
src/hardware/fluke-dmm/protocol.c
src/hardware/fluke-dmm/protocol.h

index ea32cb89c6aeb2d77cee80e9fe564291e3df3d63..e58282ca9c58adce763fbc60607af2f8f6dcda77 100644 (file)
@@ -359,6 +359,8 @@ if HW_FLUKE_DMM
 src_libdrivers_la_SOURCES += \
        src/hardware/fluke-dmm/protocol.h \
        src/hardware/fluke-dmm/protocol.c \
+       src/hardware/fluke-dmm/fluke-18x.c \
+       src/hardware/fluke-dmm/fluke-190.c \
        src/hardware/fluke-dmm/fluke-28x.c \
        src/hardware/fluke-dmm/api.c
 endif
diff --git a/src/hardware/fluke-dmm/fluke-18x.c b/src/hardware/fluke-dmm/fluke-18x.c
new file mode 100644 (file)
index 0000000..55ce2d3
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * This file is part of the libsigrok project.
+ *
+ * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <libsigrok/libsigrok.h>
+#include "libsigrok-internal.h"
+#include "protocol.h"
+
+SR_PRIV void fluke_handle_qm_18x(const struct sr_dev_inst *sdi, char **tokens)
+{
+       struct dev_context *devc;
+       struct sr_datafeed_packet packet;
+       struct sr_datafeed_analog analog;
+       struct sr_analog_encoding encoding;
+       struct sr_analog_meaning meaning;
+       struct sr_analog_spec spec;
+       float fvalue;
+       char *e, *u;
+       gboolean is_oor;
+       int digits;
+       int exponent;
+       enum sr_mq mq;
+       enum sr_unit unit;
+       enum sr_mqflag mqflags;
+
+       devc = sdi->priv;
+
+       if (strcmp(tokens[0], "QM") || !tokens[1])
+               return;
+
+       if ((e = strstr(tokens[1], "Out of range"))) {
+               is_oor = TRUE;
+               fvalue = -1;
+               digits = 0;
+               while (*e && *e != '.')
+                       e++;
+       } else {
+               is_oor = FALSE;
+               /* 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_digits(tokens[1], &fvalue, &digits) != SR_OK) {
+                       /* Happens all the time, when switching modes. */
+                       sr_dbg("Invalid float: '%s'", tokens[1]);
+                       return;
+               }
+       }
+       while (*e && *e == ' ')
+               e++;
+
+       if (is_oor)
+               fvalue = NAN;
+
+       mq = 0;
+       unit = 0;
+       exponent = 0;
+       mqflags = 0;
+       if ((u = strstr(e, "V DC")) || (u = strstr(e, "V AC"))) {
+               mq = SR_MQ_VOLTAGE;
+               unit = SR_UNIT_VOLT;
+               if (!is_oor && e[0] == 'm')
+                       exponent = -3;
+               /* This catches "V AC", "V DC" and "V AC+DC". */
+               if (strstr(u, "AC"))
+                       mqflags |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
+               if (strstr(u, "DC"))
+                       mqflags |= SR_MQFLAG_DC;
+       } else if ((u = strstr(e, "dBV")) || (u = strstr(e, "dBm"))) {
+               mq = SR_MQ_VOLTAGE;
+               if (u[2] == 'm')
+                       unit = SR_UNIT_DECIBEL_MW;
+               else
+                       unit = SR_UNIT_DECIBEL_VOLT;
+               mqflags |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
+       } else if ((u = strstr(e, "Ohms"))) {
+               mq = SR_MQ_RESISTANCE;
+               unit = SR_UNIT_OHM;
+               if (is_oor)
+                       fvalue = INFINITY;
+               else if (e[0] == 'k')
+                       exponent = 3;
+               else if (e[0] == 'M')
+                       exponent = 6;
+       } else if (!strcmp(e, "nS")) {
+               mq = SR_MQ_CONDUCTANCE;
+               unit = SR_UNIT_SIEMENS;
+               exponent = -9;
+       } else if ((u = strstr(e, "Farads"))) {
+               mq = SR_MQ_CAPACITANCE;
+               unit = SR_UNIT_FARAD;
+               if (!is_oor) {
+                       if (e[0] == 'm')
+                               exponent = -3;
+                       else if (e[0] == 'u')
+                               exponent = -6;
+                       else if (e[0] == 'n')
+                               exponent = -9;
+               }
+       } else if ((u = strstr(e, "Deg C")) || (u = strstr(e, "Deg F"))) {
+               mq = SR_MQ_TEMPERATURE;
+               if (u[4] == 'C')
+                       unit = SR_UNIT_CELSIUS;
+               else
+                       unit = SR_UNIT_FAHRENHEIT;
+       } else if ((u = strstr(e, "A AC")) || (u = strstr(e, "A DC"))) {
+               mq = SR_MQ_CURRENT;
+               unit = SR_UNIT_AMPERE;
+               /* This catches "A AC", "A DC" and "A AC+DC". */
+               if (strstr(u, "AC"))
+                       mqflags |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
+               if (strstr(u, "DC"))
+                       mqflags |= SR_MQFLAG_DC;
+               if (!is_oor) {
+                       if (e[0] == 'm')
+                               exponent = -3;
+                       else if (e[0] == 'u')
+                               exponent = -6;
+               }
+       } else if ((u = strstr(e, "Hz"))) {
+               mq = SR_MQ_FREQUENCY;
+               unit = SR_UNIT_HERTZ;
+               if (e[0] == 'k')
+                       exponent = 3;
+       } else if (!strcmp(e, "%")) {
+               mq = SR_MQ_DUTY_CYCLE;
+               unit = SR_UNIT_PERCENTAGE;
+       } else if ((u = strstr(e, "ms"))) {
+               mq = SR_MQ_PULSE_WIDTH;
+               unit = SR_UNIT_SECOND;
+               exponent = -3;
+       }
+
+       if (mq != 0) {
+               /* Got a measurement. */
+               digits -= exponent;
+               fvalue *= pow(10.0f, exponent);
+
+               sr_analog_init(&analog, &encoding, &meaning, &spec, digits);
+               analog.data = &fvalue;
+               analog.num_samples = 1;
+               analog.meaning->unit = unit;
+               analog.meaning->mq = mq;
+               analog.meaning->mqflags = mqflags;
+               analog.meaning->channels = sdi->channels;
+
+               packet.type = SR_DF_ANALOG;
+               packet.payload = &analog;
+               sr_session_send(sdi, &packet);
+               sr_sw_limits_update_samples_read(&devc->limits, 1);
+       }
+}
diff --git a/src/hardware/fluke-dmm/fluke-190.c b/src/hardware/fluke-dmm/fluke-190.c
new file mode 100644 (file)
index 0000000..9dcc153
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ * This file is part of the libsigrok project.
+ *
+ * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
+#include <libsigrok/libsigrok.h>
+#include "libsigrok-internal.h"
+#include "protocol.h"
+
+static void handle_qm_19x_meta(const struct sr_dev_inst *sdi, char **tokens)
+{
+       struct dev_context *devc;
+       int meas_type, meas_unit, meas_char, i;
+
+       /* Make sure we have 7 valid tokens. */
+       for (i = 0; tokens[i] && i < 7; i++);
+       if (i != 7)
+               return;
+
+       if (strcmp(tokens[1], "1"))
+               /* Invalid measurement. */
+               return;
+
+       if (strcmp(tokens[2], "3"))
+               /* Only interested in input from the meter mode source. */
+               return;
+
+       devc = sdi->priv;
+
+       /* Measurement type 11 == absolute, 19 = relative */
+       meas_type = strtol(tokens[0], NULL, 10);
+       if (meas_type != 11 && meas_type != 19)
+               /* Device is in some mode we don't support. */
+               return;
+
+       /* We might get metadata for absolute and relative mode (if the device
+        * is in relative mode). In that case, relative takes precedence. */
+       if (meas_type == 11 && devc->meas_type == 19)
+               return;
+
+       meas_unit = strtol(tokens[3], NULL, 10);
+       if (meas_unit == 0)
+               /* Device is turned off. Really. */
+               return;
+       meas_char = strtol(tokens[4], NULL, 10);
+
+       devc->mq = 0;
+       devc->unit = 0;
+       devc->mqflags = 0;
+
+       switch (meas_unit) {
+       case 1:
+               devc->mq = SR_MQ_VOLTAGE;
+               devc->unit = SR_UNIT_VOLT;
+               if (meas_char == 1)
+                       devc->mqflags |= SR_MQFLAG_DC;
+               else if (meas_char == 2)
+                       devc->mqflags |= SR_MQFLAG_AC;
+               else if (meas_char == 3)
+                       devc->mqflags |= SR_MQFLAG_DC | SR_MQFLAG_AC;
+               else if (meas_char == 15)
+                       devc->mqflags |= SR_MQFLAG_DIODE | SR_MQFLAG_DC;
+               break;
+       case 2:
+               devc->mq = SR_MQ_CURRENT;
+               devc->unit = SR_UNIT_AMPERE;
+               if (meas_char == 1)
+                       devc->mqflags |= SR_MQFLAG_DC;
+               else if (meas_char == 2)
+                       devc->mqflags |= SR_MQFLAG_AC;
+               else if (meas_char == 3)
+                       devc->mqflags |= SR_MQFLAG_DC | SR_MQFLAG_AC;
+               break;
+       case 3:
+               if (meas_char == 1) {
+                       devc->mq = SR_MQ_RESISTANCE;
+                       devc->unit = SR_UNIT_OHM;
+               } else if (meas_char == 16) {
+                       devc->mq = SR_MQ_CONTINUITY;
+                       devc->unit = SR_UNIT_BOOLEAN;
+               }
+               break;
+       case 12:
+               devc->mq = SR_MQ_TEMPERATURE;
+               devc->unit = SR_UNIT_CELSIUS;
+               break;
+       case 13:
+               devc->mq = SR_MQ_TEMPERATURE;
+               devc->unit = SR_UNIT_FAHRENHEIT;
+               break;
+       default:
+               sr_dbg("unknown unit: %d", meas_unit);
+       }
+       if (devc->mq == 0 && devc->unit == 0)
+               return;
+
+       /* If we got here, we know how to interpret the measurement. */
+       devc->meas_type = meas_type;
+       if (meas_type == 11)
+               /* Absolute meter reading. */
+               devc->is_relative = FALSE;
+       else if (!strcmp(tokens[0], "19"))
+               /* Relative meter reading. */
+               devc->is_relative = TRUE;
+
+}
+
+static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens)
+{
+       struct dev_context *devc;
+       struct sr_datafeed_packet packet;
+       struct sr_datafeed_analog analog;
+       struct sr_analog_encoding encoding;
+       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
+                * is rather problematic, we'll cut through this here. */
+               fvalue = NAN;
+       } else {
+               if (sr_atof_ascii_digits(tokens[0], &fvalue, &digits) != SR_OK ||
+                   fvalue == 0.0) {
+                       sr_err("Invalid float '%s'.", tokens[0]);
+                       return;
+               }
+       }
+
+       devc = sdi->priv;
+       if (devc->mq == 0 || devc->unit == 0)
+               /* Don't have valid metadata yet. */
+               return;
+
+       if (devc->mq == SR_MQ_RESISTANCE && isnan(fvalue))
+               fvalue = INFINITY;
+       else if (devc->mq == SR_MQ_CONTINUITY) {
+               if (isnan(fvalue))
+                       fvalue = 0.0;
+               else
+                       fvalue = 1.0;
+       }
+
+       sr_analog_init(&analog, &encoding, &meaning, &spec, digits);
+       analog.meaning->channels = sdi->channels;
+       analog.num_samples = 1;
+       analog.data = &fvalue;
+       analog.meaning->mq = devc->mq;
+       analog.meaning->unit = devc->unit;
+       analog.meaning->mqflags = 0;
+       packet.type = SR_DF_ANALOG;
+       packet.payload = &analog;
+       sr_session_send(sdi, &packet);
+
+       sr_sw_limits_update_samples_read(&devc->limits, 1);
+}
+
+SR_PRIV void fluke_handle_qm_190(const struct sr_dev_inst *sdi, char **tokens)
+{
+       struct dev_context *devc = sdi->priv;
+       int num_tokens, i;
+
+       num_tokens = g_strv_length(tokens);
+       if (num_tokens < 7) {
+               /* Response to QM <n> measurement request. */
+               handle_qm_19x_data(sdi, tokens);
+               return;
+       }
+
+       /*
+        * Response to QM: This is a comma-separated list of
+        * fields with metadata about the measurement. This
+        * format can return multiple sets of metadata,
+        * split into sets of 7 tokens each.
+        */
+       devc->meas_type = 0;
+       for (i = 0; i < num_tokens; i += 7)
+               handle_qm_19x_meta(sdi, tokens + i);
+}
index 5683ffeac881bc964ca82ba9f7cdb590a5f80ed1..59aebaa490483ec9fc80d6f6e1f8be68d38aa2e6 100644 (file)
 #include "libsigrok-internal.h"
 #include "protocol.h"
 
-static void handle_qm_18x(const struct sr_dev_inst *sdi, char **tokens)
-{
-       struct dev_context *devc;
-       struct sr_datafeed_packet packet;
-       struct sr_datafeed_analog analog;
-       struct sr_analog_encoding encoding;
-       struct sr_analog_meaning meaning;
-       struct sr_analog_spec spec;
-       float fvalue;
-       char *e, *u;
-       gboolean is_oor;
-       int digits;
-       int exponent;
-       enum sr_mq mq;
-       enum sr_unit unit;
-       enum sr_mqflag mqflags;
-
-       devc = sdi->priv;
-
-       if (strcmp(tokens[0], "QM") || !tokens[1])
-               return;
-
-       if ((e = strstr(tokens[1], "Out of range"))) {
-               is_oor = TRUE;
-               fvalue = -1;
-               digits = 0;
-               while (*e && *e != '.')
-                       e++;
-       } else {
-               is_oor = FALSE;
-               /* 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_digits(tokens[1], &fvalue, &digits) != SR_OK) {
-                       /* Happens all the time, when switching modes. */
-                       sr_dbg("Invalid float: '%s'", tokens[1]);
-                       return;
-               }
-       }
-       while (*e && *e == ' ')
-               e++;
-
-       if (is_oor)
-               fvalue = NAN;
-
-       mq = 0;
-       unit = 0;
-       exponent = 0;
-       mqflags = 0;
-       if ((u = strstr(e, "V DC")) || (u = strstr(e, "V AC"))) {
-               mq = SR_MQ_VOLTAGE;
-               unit = SR_UNIT_VOLT;
-               if (!is_oor && e[0] == 'm')
-                       exponent = -3;
-               /* This catches "V AC", "V DC" and "V AC+DC". */
-               if (strstr(u, "AC"))
-                       mqflags |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
-               if (strstr(u, "DC"))
-                       mqflags |= SR_MQFLAG_DC;
-       } else if ((u = strstr(e, "dBV")) || (u = strstr(e, "dBm"))) {
-               mq = SR_MQ_VOLTAGE;
-               if (u[2] == 'm')
-                       unit = SR_UNIT_DECIBEL_MW;
-               else
-                       unit = SR_UNIT_DECIBEL_VOLT;
-               mqflags |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
-       } else if ((u = strstr(e, "Ohms"))) {
-               mq = SR_MQ_RESISTANCE;
-               unit = SR_UNIT_OHM;
-               if (is_oor)
-                       fvalue = INFINITY;
-               else if (e[0] == 'k')
-                       exponent = 3;
-               else if (e[0] == 'M')
-                       exponent = 6;
-       } else if (!strcmp(e, "nS")) {
-               mq = SR_MQ_CONDUCTANCE;
-               unit = SR_UNIT_SIEMENS;
-               exponent = -9;
-       } else if ((u = strstr(e, "Farads"))) {
-               mq = SR_MQ_CAPACITANCE;
-               unit = SR_UNIT_FARAD;
-               if (!is_oor) {
-                       if (e[0] == 'm')
-                               exponent = -3;
-                       else if (e[0] == 'u')
-                               exponent = -6;
-                       else if (e[0] == 'n')
-                               exponent = -9;
-               }
-       } else if ((u = strstr(e, "Deg C")) || (u = strstr(e, "Deg F"))) {
-               mq = SR_MQ_TEMPERATURE;
-               if (u[4] == 'C')
-                       unit = SR_UNIT_CELSIUS;
-               else
-                       unit = SR_UNIT_FAHRENHEIT;
-       } else if ((u = strstr(e, "A AC")) || (u = strstr(e, "A DC"))) {
-               mq = SR_MQ_CURRENT;
-               unit = SR_UNIT_AMPERE;
-               /* This catches "A AC", "A DC" and "A AC+DC". */
-               if (strstr(u, "AC"))
-                       mqflags |= SR_MQFLAG_AC | SR_MQFLAG_RMS;
-               if (strstr(u, "DC"))
-                       mqflags |= SR_MQFLAG_DC;
-               if (!is_oor) {
-                       if (e[0] == 'm')
-                               exponent = -3;
-                       else if (e[0] == 'u')
-                               exponent = -6;
-               }
-       } else if ((u = strstr(e, "Hz"))) {
-               mq = SR_MQ_FREQUENCY;
-               unit = SR_UNIT_HERTZ;
-               if (e[0] == 'k')
-                       exponent = 3;
-       } else if (!strcmp(e, "%")) {
-               mq = SR_MQ_DUTY_CYCLE;
-               unit = SR_UNIT_PERCENTAGE;
-       } else if ((u = strstr(e, "ms"))) {
-               mq = SR_MQ_PULSE_WIDTH;
-               unit = SR_UNIT_SECOND;
-               exponent = -3;
-       }
-
-       if (mq != 0) {
-               /* Got a measurement. */
-               digits -= exponent;
-               fvalue *= pow(10.0f, exponent);
-
-               sr_analog_init(&analog, &encoding, &meaning, &spec, digits);
-               analog.data = &fvalue;
-               analog.num_samples = 1;
-               analog.meaning->unit = unit;
-               analog.meaning->mq = mq;
-               analog.meaning->mqflags = mqflags;
-               analog.meaning->channels = sdi->channels;
-
-               packet.type = SR_DF_ANALOG;
-               packet.payload = &analog;
-               sr_session_send(sdi, &packet);
-               sr_sw_limits_update_samples_read(&devc->limits, 1);
-       }
-}
-
-static void handle_qm_19x_meta(const struct sr_dev_inst *sdi, char **tokens)
-{
-       struct dev_context *devc;
-       int meas_type, meas_unit, meas_char, i;
-
-       /* Make sure we have 7 valid tokens. */
-       for (i = 0; tokens[i] && i < 7; i++);
-       if (i != 7)
-               return;
-
-       if (strcmp(tokens[1], "1"))
-               /* Invalid measurement. */
-               return;
-
-       if (strcmp(tokens[2], "3"))
-               /* Only interested in input from the meter mode source. */
-               return;
-
-       devc = sdi->priv;
-
-       /* Measurement type 11 == absolute, 19 = relative */
-       meas_type = strtol(tokens[0], NULL, 10);
-       if (meas_type != 11 && meas_type != 19)
-               /* Device is in some mode we don't support. */
-               return;
-
-       /* We might get metadata for absolute and relative mode (if the device
-        * is in relative mode). In that case, relative takes precedence. */
-       if (meas_type == 11 && devc->meas_type == 19)
-               return;
-
-       meas_unit = strtol(tokens[3], NULL, 10);
-       if (meas_unit == 0)
-               /* Device is turned off. Really. */
-               return;
-       meas_char = strtol(tokens[4], NULL, 10);
-
-       devc->mq = 0;
-       devc->unit = 0;
-       devc->mqflags = 0;
-
-       switch (meas_unit) {
-       case 1:
-               devc->mq = SR_MQ_VOLTAGE;
-               devc->unit = SR_UNIT_VOLT;
-               if (meas_char == 1)
-                       devc->mqflags |= SR_MQFLAG_DC;
-               else if (meas_char == 2)
-                       devc->mqflags |= SR_MQFLAG_AC;
-               else if (meas_char == 3)
-                       devc->mqflags |= SR_MQFLAG_DC | SR_MQFLAG_AC;
-               else if (meas_char == 15)
-                       devc->mqflags |= SR_MQFLAG_DIODE | SR_MQFLAG_DC;
-               break;
-       case 2:
-               devc->mq = SR_MQ_CURRENT;
-               devc->unit = SR_UNIT_AMPERE;
-               if (meas_char == 1)
-                       devc->mqflags |= SR_MQFLAG_DC;
-               else if (meas_char == 2)
-                       devc->mqflags |= SR_MQFLAG_AC;
-               else if (meas_char == 3)
-                       devc->mqflags |= SR_MQFLAG_DC | SR_MQFLAG_AC;
-               break;
-       case 3:
-               if (meas_char == 1) {
-                       devc->mq = SR_MQ_RESISTANCE;
-                       devc->unit = SR_UNIT_OHM;
-               } else if (meas_char == 16) {
-                       devc->mq = SR_MQ_CONTINUITY;
-                       devc->unit = SR_UNIT_BOOLEAN;
-               }
-               break;
-       case 12:
-               devc->mq = SR_MQ_TEMPERATURE;
-               devc->unit = SR_UNIT_CELSIUS;
-               break;
-       case 13:
-               devc->mq = SR_MQ_TEMPERATURE;
-               devc->unit = SR_UNIT_FAHRENHEIT;
-               break;
-       default:
-               sr_dbg("unknown unit: %d", meas_unit);
-       }
-       if (devc->mq == 0 && devc->unit == 0)
-               return;
-
-       /* If we got here, we know how to interpret the measurement. */
-       devc->meas_type = meas_type;
-       if (meas_type == 11)
-               /* Absolute meter reading. */
-               devc->is_relative = FALSE;
-       else if (!strcmp(tokens[0], "19"))
-               /* Relative meter reading. */
-               devc->is_relative = TRUE;
-
-}
-
-static void handle_qm_19x_data(const struct sr_dev_inst *sdi, char **tokens)
-{
-       struct dev_context *devc;
-       struct sr_datafeed_packet packet;
-       struct sr_datafeed_analog analog;
-       struct sr_analog_encoding encoding;
-       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
-                * is rather problematic, we'll cut through this here. */
-               fvalue = NAN;
-       } else {
-               if (sr_atof_ascii_digits(tokens[0], &fvalue, &digits) != SR_OK ||
-                   fvalue == 0.0) {
-                       sr_err("Invalid float '%s'.", tokens[0]);
-                       return;
-               }
-       }
-
-       devc = sdi->priv;
-       if (devc->mq == 0 || devc->unit == 0)
-               /* Don't have valid metadata yet. */
-               return;
-
-       if (devc->mq == SR_MQ_RESISTANCE && isnan(fvalue))
-               fvalue = INFINITY;
-       else if (devc->mq == SR_MQ_CONTINUITY) {
-               if (isnan(fvalue))
-                       fvalue = 0.0;
-               else
-                       fvalue = 1.0;
-       }
-
-       sr_analog_init(&analog, &encoding, &meaning, &spec, digits);
-       analog.meaning->channels = sdi->channels;
-       analog.num_samples = 1;
-       analog.data = &fvalue;
-       analog.meaning->mq = devc->mq;
-       analog.meaning->unit = devc->unit;
-       analog.meaning->mqflags = 0;
-       packet.type = SR_DF_ANALOG;
-       packet.payload = &analog;
-       sr_session_send(sdi, &packet);
-
-       sr_sw_limits_update_samples_read(&devc->limits, 1);
-}
-
 static void handle_line(const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
-       int num_tokens, n, i;
+       int n;
        char cmd[16], **tokens;
        int ret;
 
@@ -354,25 +56,11 @@ static void handle_line(const struct sr_dev_inst *sdi)
                case FLUKE_187:
                case FLUKE_189:
                        devc->expect_response = FALSE;
-                       handle_qm_18x(sdi, tokens);
+                       fluke_handle_qm_18x(sdi, tokens);
                        break;
                case FLUKE_190:
                        devc->expect_response = FALSE;
-                       num_tokens = g_strv_length(tokens);
-                       if (num_tokens < 7) {
-                               /* Response to QM <n> measurement request. */
-                               handle_qm_19x_data(sdi, tokens);
-                               break;
-                       }
-                       /*
-                        * Response to QM: This is a comma-separated list of
-                        * fields with metadata about the measurement. This
-                        * format can return multiple sets of metadata,
-                        * split into sets of 7 tokens each.
-                        */
-                       devc->meas_type = 0;
-                       for (i = 0; i < num_tokens; i += 7)
-                               handle_qm_19x_meta(sdi, tokens + i);
+                       fluke_handle_qm_190(sdi, tokens);
                        if (devc->meas_type) {
                                /*
                                 * Slip the request in now, before the main
index 14adc18e767fa1ecd157a15d27367d153ea68c7b..d419851d4f4b594665f20e3d58ea0aa5d8cc07b6 100644 (file)
@@ -63,6 +63,8 @@ struct dev_context {
        enum sr_mqflag mqflags;
 };
 
+SR_PRIV void fluke_handle_qm_18x(const struct sr_dev_inst *sdi, char **tokens);
+SR_PRIV void fluke_handle_qm_190(const struct sr_dev_inst *sdi, char **tokens);
 SR_PRIV void fluke_handle_qm_28x(const struct sr_dev_inst *sdi, char **tokens);
 
 SR_PRIV int fluke_receive_data(int fd, int revents, void *cb_data);