]> sigrok.org Git - libsigrok.git/blobdiff - hardware/victor-dmm/protocol.c
Replace 'probe' with 'channel' in most places.
[libsigrok.git] / hardware / victor-dmm / protocol.c
index cd92bafb90cbe5cb77ea5b0024579478392b839b..6af51419326694c6241c349b850bb5c04a70a393 100644 (file)
  */
 
 #include <glib.h>
+#include <string.h>
+#include <math.h>
 #include "libsigrok.h"
 #include "libsigrok-internal.h"
 #include "protocol.h"
-#include <string.h>
-#include <math.h>
-
 
 /* Reverse the high nibble into the low nibble */
 static uint8_t decode_digit(uint8_t in)
@@ -41,16 +40,19 @@ static uint8_t decode_digit(uint8_t in)
        return out;
 }
 
-static void decode_buf(struct dev_context *devc, unsigned char *data)
+static void decode_buf(struct sr_dev_inst *sdi, unsigned char *data)
 {
        struct sr_datafeed_packet packet;
        struct sr_datafeed_analog analog;
+       struct dev_context *devc;
        long factor, ivalue;
        uint8_t digits[4];
        gboolean is_duty, is_continuity, is_diode, is_ac, is_dc, is_auto;
        gboolean is_hold, is_max, is_min, is_relative, minus;
        float fvalue;
 
+       devc = sdi->priv;
+
        digits[0] = decode_digit(data[12]);
        digits[1] = decode_digit(data[11]);
        digits[2] = decode_digit(data[10]);
@@ -71,6 +73,7 @@ static void decode_buf(struct dev_context *devc, unsigned char *data)
        }
 
        /* Decimal point position */
+       factor = 0;
        switch (data[7] >> 4) {
        case 0x00:
                factor = 0;
@@ -85,7 +88,8 @@ static void decode_buf(struct dev_context *devc, unsigned char *data)
                factor = 3;
                break;
        default:
-               sr_err("Unknown decimal point value %.2x.", data[7]);
+               sr_err("Unknown decimal point byte: 0x%.2x.", data[7]);
+               break;
        }
 
        /* Minus flag */
@@ -126,14 +130,15 @@ static void decode_buf(struct dev_context *devc, unsigned char *data)
                break;
        case 0x80:
                /* Never seen */
-               sr_dbg("Unknown mode right detail %.2x.", data[4]);
+               sr_dbg("Unknown mode right detail: 0x%.2x.", data[4]);
                break;
        default:
-               sr_dbg("Unknown/invalid mode right detail %.2x.", data[4]);
+               sr_dbg("Unknown/invalid mode right detail: 0x%.2x.", data[4]);
+               break;
        }
 
        /* Scale flags on the right, continued */
-       is_max = is_min = TRUE;
+       is_max = is_min = FALSE;
        if (data[5] & 0x04)
                is_max = TRUE;
        if (data[5] & 0x08)
@@ -169,7 +174,7 @@ static void decode_buf(struct dev_context *devc, unsigned char *data)
                        analog.mq = SR_MQ_DUTY_CYCLE;
                        analog.unit = SR_UNIT_PERCENTAGE;
                } else
-                       sr_dbg("Unknown measurement mode %.2x.", data[3]);
+                       sr_dbg("Unknown measurement mode: %.2x.", data[3]);
                break;
        case 0x01:
                if (is_diode) {
@@ -211,7 +216,7 @@ static void decode_buf(struct dev_context *devc, unsigned char *data)
                break;
        case 0x08:
                /* Never seen */
-               sr_dbg("Unknown measurement mode %.2x.", data[3]);
+               sr_dbg("Unknown measurement mode: 0x%.2x.", data[3]);
                break;
        case 0x10:
                analog.mq = SR_MQ_FREQUENCY;
@@ -230,7 +235,8 @@ static void decode_buf(struct dev_context *devc, unsigned char *data)
                analog.unit = SR_UNIT_FAHRENHEIT;
                break;
        default:
-               sr_dbg("Unknown/invalid measurement mode %.2x.", data[3]);
+               sr_dbg("Unknown/invalid measurement mode: 0x%.2x.", data[3]);
+               break;
        }
        if (analog.mq == -1)
                return;
@@ -246,6 +252,7 @@ static void decode_buf(struct dev_context *devc, unsigned char *data)
        if (is_relative)
                analog.mqflags |= SR_MQFLAG_RELATIVE;
 
+       analog.channels = sdi->channels;
        analog.num_samples = 1;
        analog.data = &fvalue;
        packet.type = SR_DF_ANALOG;
@@ -257,7 +264,6 @@ static void decode_buf(struct dev_context *devc, unsigned char *data)
 
 SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf)
 {
-       struct dev_context *devc;
        GString *dbg;
        int i;
        unsigned char data[DMM_DATA_SIZE];
@@ -266,8 +272,6 @@ SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf)
                6, 13, 5, 11, 2, 7, 9, 8, 3, 10, 12, 0, 4, 1
        };
 
-       devc = sdi->priv;
-
        for (i = 0; i < DMM_DATA_SIZE && buf[i] == 0; i++);
        if (i == DMM_DATA_SIZE) {
                /* This DMM outputs all zeroes from time to time, just ignore it. */
@@ -288,8 +292,7 @@ SR_PRIV int victor_dmm_receive_data(struct sr_dev_inst *sdi, unsigned char *buf)
                g_string_free(dbg, TRUE);
        }
 
-       decode_buf(devc, data);
+       decode_buf(sdi, data);
 
        return SR_OK;
 }
-