]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/center-3xx/protocol.c
rigol-ds: Add DS1074Z Plus and DS1104Z Plus.
[libsigrok.git] / src / hardware / center-3xx / protocol.c
index a67a884f97a7a31c7ffeb4a7b95af7234f93b1e6..b4d9ed5ba834162cc063e2bc47a9a3579ef0acce 100644 (file)
@@ -25,6 +25,7 @@
 
 struct center_info {
        float temp[NUM_CHANNELS];
+       int digits[NUM_CHANNELS];
        gboolean rec, std, max, min, maxmin, t1t2, rel, hold, lowbat, celsius;
        gboolean memfull, autooff;
        gboolean mode_std, mode_rel, mode_max, mode_min, mode_maxmin;
@@ -97,8 +98,12 @@ static int packet_parse(const uint8_t *buf, int idx, struct center_info *info)
        /* Byte 43: Specifies whether we need to divide the value(s) by 10. */
        for (i = 0; i < NUM_CHANNELS; i++) {
                /* Bit = 0: Divide by 10. Bit = 1: Don't divide by 10. */
-               if ((buf[43] & (1 << i)) == 0)
+               if ((buf[43] & (1 << i)) == 0) {
                        info->temp[i] /= 10;
+                       info->digits[i] = 1;
+               } else {
+                       info->digits[i] = 0;
+               }
        }
 
        /* Bytes 39-42: Overflow/overlimit bits, depending on mode. */
@@ -123,7 +128,10 @@ static int packet_parse(const uint8_t *buf, int idx, struct center_info *info)
 static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
 {
        struct sr_datafeed_packet packet;
-       struct sr_datafeed_analog_old analog;
+       struct sr_datafeed_analog analog;
+       struct sr_analog_encoding encoding;
+       struct sr_analog_meaning meaning;
+       struct sr_analog_spec spec;
        struct dev_context *devc;
        struct center_info info;
        GSList *l;
@@ -131,7 +139,8 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
 
        devc = sdi->priv;
 
-       memset(&analog, 0, sizeof(struct sr_datafeed_analog_old));
+       /* Note: digits/spec_digits will be overridden later. */
+       sr_analog_init(&analog, &encoding, &meaning, &spec, 0);
        memset(&info, 0, sizeof(struct center_info));
 
        ret = packet_parse(buf, idx, &info);
@@ -141,17 +150,19 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
        }
 
        /* Common values for all 4 channels. */
-       packet.type = SR_DF_ANALOG_OLD;
+       packet.type = SR_DF_ANALOG;
        packet.payload = &analog;
-       analog.mq = SR_MQ_TEMPERATURE;
-       analog.unit = (info.celsius) ? SR_UNIT_CELSIUS : SR_UNIT_FAHRENHEIT;
+       analog.meaning->mq = SR_MQ_TEMPERATURE;
+       analog.meaning->unit = (info.celsius) ? SR_UNIT_CELSIUS : SR_UNIT_FAHRENHEIT;
        analog.num_samples = 1;
 
        /* Send the values for T1 - T4. */
        for (i = 0; i < NUM_CHANNELS; i++) {
                l = NULL;
                l = g_slist_append(l, g_slist_nth_data(sdi->channels, i));
-               analog.channels = l;
+               analog.meaning->channels = l;
+               analog.encoding->digits = info.digits[i];
+               analog.spec->spec_digits = info.digits[i];
                analog.data = &(info.temp[i]);
                sr_session_send(sdi, &packet);
                g_slist_free(l);