]> sigrok.org Git - libsigrok.git/commitdiff
Use frames to group a single measurement result together.
authorJanne Huttunen <redacted>
Sat, 20 Dec 2014 15:32:26 +0000 (17:32 +0200)
committerUwe Hermann <redacted>
Tue, 6 Jan 2015 19:10:17 +0000 (20:10 +0100)
In most, but not all, modes the ES51919 reports two separate
analog values for each measurement sample. These values are
mapped to two separate channels and sent in two separate
packets.

A client program needs a way to determine which results are
parts of the same measurement and also know when a complete
measurement is received so it can process the sample. Use
the frame begin and end packets to separate groups that each
represent a single complete measurement.

src/lcr/es51919.c

index 59dc194c5f4d795db1e6379994746f1a92d852b5..b1b788531a4077c2d7aedccad5c54e16b55e24f0 100644 (file)
@@ -665,7 +665,7 @@ static void handle_packet(struct sr_dev_inst *sdi, const uint8_t *pkt)
        struct dev_context *devc;
        unsigned int val;
        float floatval;
-       int count;
+       gboolean frame;
 
        devc = sdi->priv;
 
@@ -701,34 +701,50 @@ static void handle_packet(struct sr_dev_inst *sdi, const uint8_t *pkt)
                        return;
        }
 
-       count = 0;
+       frame = FALSE;
 
        memset(&analog, 0, sizeof(analog));
 
        analog.num_samples = 1;
        analog.data = &floatval;
 
-       packet.type = SR_DF_ANALOG;
-       packet.payload = &analog;
-
        analog.channels = g_slist_append(NULL, sdi->channels->data);
 
        parse_measurement(pkt, &floatval, &analog, 0);
        if (analog.mq >= 0) {
-               if (sr_session_send(devc->cb_data, &packet) == SR_OK)
-                       count++;
+               if (!frame) {
+                       packet.type = SR_DF_FRAME_BEGIN;
+                       sr_session_send(devc->cb_data, &packet);
+                       frame = TRUE;
+               }
+
+               packet.type = SR_DF_ANALOG;
+               packet.payload = &analog;
+
+               sr_session_send(devc->cb_data, &packet);
        }
 
        analog.channels = g_slist_append(NULL, sdi->channels->next->data);
 
        parse_measurement(pkt, &floatval, &analog, 1);
        if (analog.mq >= 0) {
-               if (sr_session_send(devc->cb_data, &packet) == SR_OK)
-                       count++;
+               if (!frame) {
+                       packet.type = SR_DF_FRAME_BEGIN;
+                       sr_session_send(devc->cb_data, &packet);
+                       frame = TRUE;
+               }
+
+               packet.type = SR_DF_ANALOG;
+               packet.payload = &analog;
+
+               sr_session_send(devc->cb_data, &packet);
        }
 
-       if (count > 0)
+       if (frame) {
+               packet.type = SR_DF_FRAME_END;
+               sr_session_send(devc->cb_data, &packet);
                dev_sample_counter_inc(&devc->sample_count);
+       }
 }
 
 static int handle_new_data(struct sr_dev_inst *sdi)