]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/center-3xx/protocol.c
SR_DF_ANALOG_OLD and sr_datafeed_analog_old renames.
[libsigrok.git] / src / hardware / center-3xx / protocol.c
index ef8b9dcd600c7f45858e399b6fbfb93aa678fc55..34478faeca681c1fcfa7020e179fd8d3b585ebf5 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <config.h>
 #include "protocol.h"
 
+#define NUM_CHANNELS 4
+
 struct center_info {
-       float temp[4];
+       float temp[NUM_CHANNELS];
        gboolean rec, std, max, min, maxmin, t1t2, rel, hold, lowbat, celsius;
        gboolean memfull, autooff;
        gboolean mode_std, mode_rel, mode_max, mode_min, mode_maxmin;
@@ -31,7 +34,8 @@ static int center_send(struct sr_serial_dev_inst *serial, const char *cmd)
 {
        int ret;
 
-       if ((ret = serial_write(serial, cmd, strlen(cmd))) < 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;
        }
@@ -84,21 +88,21 @@ static int packet_parse(const uint8_t *buf, int idx, struct center_info *info)
        info->autooff     = (buf[2] & (1 << 7)) != 0;
 
        /* Byte 7+8/9+10/11+12/13+14: channel T1/T2/T3/T4 temperature. */
-       for (i = 0; i < 4; i++) {
+       for (i = 0; i < NUM_CHANNELS; i++) {
                temp_u16 = buf[8 + (i * 2)];
                temp_u16 |= ((uint16_t)buf[7 + (i * 2)] << 8);
                info->temp[i] = (float)temp_u16;
        }
 
        /* Byte 43: Specifies whether we need to divide the value(s) by 10. */
-       for (i = 0; i < 4; i++) {
+       for (i = 0; i < NUM_CHANNELS; i++) {
                /* Bit = 0: Divide by 10. Bit = 1: Don't divide by 10. */
                if ((buf[43] & (1 << i)) == 0)
                        info->temp[i] /= 10;
        }
 
        /* Bytes 39-42: Overflow/overlimit bits, depending on mode. */
-       for (i = 0; i < 4; i++) {
+       for (i = 0; i < NUM_CHANNELS; i++) {
                if (info->mode_std && ((buf[39] & (1 << i)) != 0))
                        info->temp[i] = INFINITY;
                /* TODO: Rel. Not available on all models. */
@@ -119,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;
@@ -127,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);
@@ -137,14 +141,14 @@ 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;
        analog.num_samples = 1;
 
        /* Send the values for T1 - T4. */
-       for (i = 0; i < 4; i++) {
+       for (i = 0; i < NUM_CHANNELS; i++) {
                l = NULL;
                l = g_slist_append(l, g_slist_nth_data(sdi->channels, i));
                analog.channels = l;
@@ -170,7 +174,7 @@ static gboolean handle_new_data(struct sr_dev_inst *sdi, int idx)
 
        /* Try to get as much data as the buffer can hold. */
        len = SERIAL_BUFSIZE - devc->buflen;
-       len = serial_read(serial, devc->buf + devc->buflen, len);
+       len = serial_read_nonblocking(serial, devc->buf + devc->buflen, len);
        if (len < 1) {
                sr_err("Serial port read error: %d.", len);
                return FALSE;