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.
This commit is contained in:
Janne Huttunen 2014-12-20 17:32:26 +02:00 committed by Uwe Hermann
parent bb983c666a
commit a6413fa58e
1 changed files with 26 additions and 10 deletions

View 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,35 +701,51 @@ 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;
}
if (count > 0)
packet.type = SR_DF_ANALOG;
packet.payload = &analog;
sr_session_send(devc->cb_data, &packet);
}
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)
{