]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/appa-55ii/protocol.c
std_init(): Drop check if pass in driver is non-NULL
[libsigrok.git] / src / hardware / appa-55ii / protocol.c
index 708262bd779403fd1cfd65f7c20afd7a3a89a8fa..4720fd4f24d11b5c0e3b660e58229713919cdb21 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include <string.h>
 #include <math.h>
 #include "protocol.h"
@@ -91,7 +92,7 @@ static void appa_55ii_live_data(struct sr_dev_inst *sdi, const uint8_t *buf)
 {
        struct dev_context *devc;
        struct sr_datafeed_packet packet;
-       struct sr_datafeed_analog analog;
+       struct sr_datafeed_analog_old analog;
        struct sr_channel *ch;
        float values[APPA_55II_NUM_CHANNELS], *val_ptr;
        int i;
@@ -102,7 +103,7 @@ static void appa_55ii_live_data(struct sr_dev_inst *sdi, const uint8_t *buf)
                return;
 
        val_ptr = values;
-       memset(&analog, 0, sizeof(analog));
+       memset(&analog, 0, sizeof(struct sr_datafeed_analog_old));
        analog.num_samples = 1;
        analog.mq = SR_MQ_TEMPERATURE;
        analog.unit = SR_UNIT_CELSIUS;
@@ -117,12 +118,12 @@ static void appa_55ii_live_data(struct sr_dev_inst *sdi, const uint8_t *buf)
                *val_ptr++ = appa_55ii_temp(buf, i);
        }
 
-       packet.type = SR_DF_ANALOG;
+       packet.type = SR_DF_ANALOG_OLD;
        packet.payload = &analog;
-       sr_session_send(devc->session_cb_data, &packet);
+       sr_session_send(sdi, &packet);
        g_slist_free(analog.channels);
 
-       devc->num_samples++;
+       sr_sw_limits_update_samples_read(&devc->limits, 1);
 }
 
 static void appa_55ii_log_metadata(struct sr_dev_inst *sdi, const uint8_t *buf)
@@ -137,7 +138,7 @@ static void appa_55ii_log_data_parse(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;
        struct sr_channel *ch;
        float values[APPA_55II_NUM_CHANNELS], *val_ptr;
        const uint8_t *buf;
@@ -154,7 +155,7 @@ static void appa_55ii_log_data_parse(struct sr_dev_inst *sdi)
                /* FIXME: Timestamp should be sent in the packet. */
                sr_dbg("Timestamp: %02d:%02d:%02d", buf[2], buf[3], buf[4]);
 
-               memset(&analog, 0, sizeof(analog));
+               memset(&analog, 0, sizeof(struct sr_datafeed_analog_old));
                analog.num_samples = 1;
                analog.mq = SR_MQ_TEMPERATURE;
                analog.unit = SR_UNIT_CELSIUS;
@@ -169,12 +170,12 @@ static void appa_55ii_log_data_parse(struct sr_dev_inst *sdi)
                        *val_ptr++ = temp == 0x7FFF ? INFINITY : (float)temp / 10;
                }
 
-               packet.type = SR_DF_ANALOG;
+               packet.type = SR_DF_ANALOG_OLD;
                packet.payload = &analog;
-               sr_session_send(devc->session_cb_data, &packet);
+               sr_session_send(sdi, &packet);
                g_slist_free(analog.channels);
 
-               devc->num_samples++;
+               sr_sw_limits_update_samples_read(&devc->limits, 1);
                devc->log_buf_len -= 20;
                offset += 20;
                devc->num_log_records--;
@@ -215,7 +216,7 @@ static void appa_55ii_log_end(struct sr_dev_inst *sdi)
        if (devc->data_source != DATA_SOURCE_MEMORY)
                return;
 
-       sdi->driver->dev_acquisition_stop(sdi, devc->session_cb_data);
+       sdi->driver->dev_acquisition_stop(sdi);
 }
 
 static const uint8_t *appa_55ii_parse_data(struct sr_dev_inst *sdi,
@@ -265,7 +266,6 @@ SR_PRIV int appa_55ii_receive_data(int fd, int revents, void *cb_data)
        struct sr_dev_inst *sdi;
        struct dev_context *devc;
        struct sr_serial_dev_inst *serial;
-       int64_t time;
        const uint8_t *ptr, *next_ptr, *end_ptr;
        int len;
 
@@ -277,7 +277,7 @@ SR_PRIV int appa_55ii_receive_data(int fd, int revents, void *cb_data)
 
        /* Try to get as much data as the buffer can hold. */
        len = sizeof(devc->buf) - devc->buf_len;
-       len = serial_read(serial, devc->buf + devc->buf_len, len);
+       len = serial_read_nonblocking(serial, devc->buf + devc->buf_len, len);
        if (len < 1) {
                sr_err("Serial port read error: %d.", len);
                return FALSE;
@@ -300,21 +300,10 @@ SR_PRIV int appa_55ii_receive_data(int fd, int revents, void *cb_data)
                return FALSE;
        }
 
-       if (devc->limit_samples && devc->num_samples >= devc->limit_samples) {
-               sr_info("Requested number of samples reached.");
-               sdi->driver->dev_acquisition_stop(sdi, devc->session_cb_data);
+       if (sr_sw_limits_check(&devc->limits)) {
+               sdi->driver->dev_acquisition_stop(sdi);
                return TRUE;
        }
 
-       if (devc->limit_msec) {
-               time = (g_get_monotonic_time() - devc->start_time) / 1000;
-               if (time > (int64_t)devc->limit_msec) {
-                       sr_info("Requested time limit reached.");
-                       sdi->driver->dev_acquisition_stop(sdi,
-                                       devc->session_cb_data);
-                       return TRUE;
-               }
-       }
-
        return TRUE;
 }