+/** Send data packets for current measurements. */
+static void send_data(struct sr_dev_inst *sdi)
+{
+ struct dev_context *devc;
+ struct sr_datafeed_packet packet;
+ struct sr_datafeed_analog analog;
+ int i;
+ float data[MAX_CHANNELS];
+
+ devc = sdi->priv;
+ packet.type = SR_DF_ANALOG;
+ packet.payload = &analog;
+ analog.channels = sdi->channels;
+ analog.num_samples = 1;
+
+ analog.mq = SR_MQ_VOLTAGE;
+ analog.unit = SR_UNIT_VOLT;
+ analog.mqflags = SR_MQFLAG_DC;
+ analog.data = data;
+ for (i = 0; i < devc->model->num_channels; i++)
+ analog.data[i] = devc->channel_status[i].output_voltage_last; /* Value always 3.3 or 5 for channel 3, if present! */
+ sr_session_send(sdi, &packet);
+
+ analog.mq = SR_MQ_CURRENT;
+ analog.unit = SR_UNIT_AMPERE;
+ analog.mqflags = 0;
+ analog.data = data;
+ for (i = 0; i < devc->model->num_channels; i++)
+ analog.data[i] = devc->channel_status[i].output_current_last; /* Value always 0 for channel 3, if present! */
+ sr_session_send(sdi, &packet);
+
+ devc->num_samples++;
+}
+
+/** Process a complete line (without CR/LF) in buf. */
+static void process_line(struct sr_dev_inst *sdi)
+{
+ struct dev_context *devc;
+ double dbl;
+ int auxint;
+
+ devc = sdi->priv;
+
+ switch (devc->acq_req_pending) {
+ case 0: /* Should not happen... */
+ break;
+ case 1: /* Waiting for data reply to request */
+ /* Convert numbers */
+ switch (devc->acq_req) {
+ case AQ_U1: case AQ_U2: case AQ_I1: case AQ_I2:
+ if (sr_atod(devc->buf, &dbl) != SR_OK) {
+ sr_err("Failed to convert '%s' to double, errno=%d %s",
+ devc->buf, errno, strerror(errno));
+ dbl = 0.0;
+ }
+ break;
+ case AQ_STATUS:
+ if (sr_atoi(devc->buf, &auxint) != SR_OK) {
+ sr_err("Failed to convert '%s' to int, errno=%d %s",
+ devc->buf, errno, strerror(errno));
+ auxint = 0;
+ }
+ break;
+ default:
+ break;
+ }
+
+ switch (devc->acq_req) {
+ case AQ_U1:
+ devc->channel_status[0].output_voltage_last = dbl;
+ break;
+ case AQ_I1:
+ devc->channel_status[0].output_current_last = dbl;
+ break;
+ case AQ_U2:
+ devc->channel_status[1].output_voltage_last = dbl;
+ break;
+ case AQ_I2:
+ devc->channel_status[1].output_current_last = dbl;
+ break;
+ case AQ_STATUS: /* Process status and generate data. */
+ if (lps_process_status(sdi, auxint) == SR_OK) {
+ send_data(sdi);
+ }
+ break;
+ default:
+ break;
+ }
+
+ devc->acq_req_pending = 2;
+ break;
+ case 2: /* Waiting for OK after request */
+ if (strcmp(devc->buf, "OK")) {
+ sr_err("Unexpected reply while waiting for OK: '%s'", devc->buf);
+ }
+ devc->acq_req_pending = 0;
+ break;
+ }
+
+ devc->buf[0] = '\0';
+ devc->buflen = 0;
+}
+
+