]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/center-3xx/protocol.c
Match std_init() parameter order to the driver init() callback
[libsigrok.git] / src / hardware / center-3xx / protocol.c
index bd00e77aea65c1833a0730bfa09ab386d5b523be..a67a884f97a7a31c7ffeb4a7b95af7234f93b1e6 100644 (file)
@@ -34,7 +34,8 @@ static int center_send(struct sr_serial_dev_inst *serial, const char *cmd)
 {
        int ret;
 
-       if ((ret = serial_write_blocking(serial, cmd, strlen(cmd), 0)) < 0) {
+       if ((ret = serial_write_blocking(serial, cmd, strlen(cmd),
+                       serial_timeout(serial, strlen(cmd)))) < 0) {
                sr_err("Error sending '%s' command: %d.", cmd, ret);
                return SR_ERR;
        }
@@ -122,7 +123,7 @@ static int packet_parse(const uint8_t *buf, int idx, struct center_info *info)
 static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
 {
        struct sr_datafeed_packet packet;
-       struct sr_datafeed_analog analog;
+       struct sr_datafeed_analog_old analog;
        struct dev_context *devc;
        struct center_info info;
        GSList *l;
@@ -130,7 +131,7 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
 
        devc = sdi->priv;
 
-       memset(&analog, 0, sizeof(struct sr_datafeed_analog));
+       memset(&analog, 0, sizeof(struct sr_datafeed_analog_old));
        memset(&info, 0, sizeof(struct center_info));
 
        ret = packet_parse(buf, idx, &info);
@@ -140,7 +141,7 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
        }
 
        /* Common values for all 4 channels. */
-       packet.type = SR_DF_ANALOG;
+       packet.type = SR_DF_ANALOG_OLD;
        packet.payload = &analog;
        analog.mq = SR_MQ_TEMPERATURE;
        analog.unit = (info.celsius) ? SR_UNIT_CELSIUS : SR_UNIT_FAHRENHEIT;
@@ -152,11 +153,11 @@ static int handle_packet(const uint8_t *buf, struct sr_dev_inst *sdi, int idx)
                l = g_slist_append(l, g_slist_nth_data(sdi->channels, i));
                analog.channels = l;
                analog.data = &(info.temp[i]);
-               sr_session_send(devc->cb_data, &packet);
+               sr_session_send(sdi, &packet);
                g_slist_free(l);
        }
 
-       devc->num_samples++;
+       sr_sw_limits_update_samples_read(&devc->sw_limits, 1);
 
        return SR_OK;
 }
@@ -204,7 +205,6 @@ static int receive_data(int fd, int revents, int idx, void *cb_data)
 {
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
-       int64_t t;
        static gboolean request_new_packet = TRUE;
        struct sr_serial_dev_inst *serial;
 
@@ -232,20 +232,8 @@ static int receive_data(int fd, int revents, int idx, void *cb_data)
                }
        }
 
-       if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
-               sr_info("Requested number of samples reached.");
-               sdi->driver->dev_acquisition_stop(sdi, cb_data);
-               return TRUE;
-       }
-
-       if (devc->limit_msec) {
-               t = (g_get_monotonic_time() - devc->starttime) / 1000;
-               if (t > (int64_t)devc->limit_msec) {
-                       sr_info("Requested time limit reached.");
-                       sdi->driver->dev_acquisition_stop(sdi, cb_data);
-                       return TRUE;
-               }
-       }
+       if (sr_sw_limits_check(&devc->sw_limits))
+               sdi->driver->dev_acquisition_stop(sdi);
 
        return TRUE;
 }