From: Janne Huttunen Date: Sat, 20 Dec 2014 15:32:26 +0000 (+0200) Subject: Use frames to group a single measurement result together. X-Git-Tag: libsigrok-0.4.0~691 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=a6413fa58e455fb4a654720218183e297835226c Use frames to group a single measurement result together. 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. --- diff --git a/src/lcr/es51919.c b/src/lcr/es51919.c index 59dc194c..b1b78853 100644 --- a/src/lcr/es51919.c +++ b/src/lcr/es51919.c @@ -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)