]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/motech-lps-30x/protocol.c
std_init(): Drop check if pass in driver is non-NULL
[libsigrok.git] / src / hardware / motech-lps-30x / protocol.c
index 6daa5d9ffe6087fe2b8edd525bfd3bc2bf4abf79..1a3c75dc591954cbd4a4dfeec3ad0b917063fabc 100644 (file)
@@ -23,6 +23,7 @@
  *  @internal
  */
 
+#include <config.h>
 #include <errno.h>
 #include <string.h>
 #include "protocol.h"
@@ -32,12 +33,12 @@ static void send_data(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
        struct sr_datafeed_packet packet;
-       struct sr_datafeed_analog analog;
+       struct sr_datafeed_analog_old analog;
        int i;
        float data[MAX_CHANNELS];
 
        devc = sdi->priv;
-       packet.type = SR_DF_ANALOG;
+       packet.type = SR_DF_ANALOG_OLD;
        packet.payload = &analog;
        analog.channels = sdi->channels;
        analog.num_samples = 1;
@@ -58,7 +59,7 @@ static void send_data(struct sr_dev_inst *sdi)
                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++;
+       sr_sw_limits_update_samples_read(&devc->limits, 1);
 }
 
 /** Process a complete line (without CR/LF) in buf. */
@@ -82,14 +83,14 @@ static void process_line(struct sr_dev_inst *sdi)
                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));
+                                       devc->buf, errno, g_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));
+                                       devc->buf, errno, g_strerror(errno));
                                auxint = 0;
                        }
                        break;
@@ -139,7 +140,6 @@ SR_PRIV int motech_lps_30x_receive_data(int fd, int revents, void *cb_data)
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
        int len;
-       gdouble elapsed_s;
 
        (void)fd;
 
@@ -178,24 +178,18 @@ SR_PRIV int motech_lps_30x_receive_data(int fd, int revents, void *cb_data)
                }
        }
 
-       /* If number of samples or time limit reached, stop acquisition. */
-       if (devc->limit_samples && (devc->num_samples >= devc->limit_samples))
-               sdi->driver->dev_acquisition_stop(sdi, cb_data);
-
-       if (devc->limit_msec) {
-               elapsed_s = g_timer_elapsed(devc->elapsed_msec, NULL);
-               if ((elapsed_s * 1000) >= devc->limit_msec)
-                       sdi->driver->dev_acquisition_stop(sdi, cb_data);
-       }
+       if (sr_sw_limits_check(&devc->limits))
+               sdi->driver->dev_acquisition_stop(sdi);
 
        /* Only request the next packet if required. */
        if (!((sdi->status == SR_ST_ACTIVE) && (devc->acq_running)))
                return TRUE;
 
        if (devc->acq_req_pending) {
-               gint64 elapsed_us = g_get_monotonic_time() - devc->req_sent_at;
+               int64_t elapsed_us = g_get_monotonic_time() - devc->req_sent_at;
                if (elapsed_us > (REQ_TIMEOUT_MS * 1000)) {
-                       sr_spew("Request timeout: req=%d t=%lldus", (int)devc->acq_req, elapsed_us);
+                       sr_spew("Request timeout: req=%d t=%" PRIi64 "us",
+                               (int)devc->acq_req, elapsed_us);
                        devc->acq_req_pending = 0;
                }
        }