]> sigrok.org Git - libsigrok.git/blobdiff - hardware/teleinfo/protocol.c
Rename 'struct sr_probe' to 'struct sr_channel' everywhere.
[libsigrok.git] / hardware / teleinfo / protocol.c
index 28dfcfa1fbd3b950ebb22a6ce9945dbfce3ea9b8..5e0fa5e5a526773ec2b64a1ddb1bc8ed53fcdae5 100644 (file)
@@ -41,12 +41,12 @@ static gboolean teleinfo_control_check(char *label, char *data, char control)
 
 static gint teleinfo_probe_compare(gconstpointer a, gconstpointer b)
 {
-       const struct sr_probe *probe = a;
+       const struct sr_channel *probe = a;
        const char *name = b;
        return strcmp(probe->name, name);
 }
 
-static struct sr_probe *teleinfo_find_probe(struct sr_dev_inst *sdi,
+static struct sr_channel *teleinfo_find_probe(struct sr_dev_inst *sdi,
                                             const char *name)
 {
        GSList *elem = g_slist_find_custom(sdi->probes, name,
@@ -57,14 +57,18 @@ static struct sr_probe *teleinfo_find_probe(struct sr_dev_inst *sdi,
 static void teleinfo_send_value(struct sr_dev_inst *sdi, const char *probe_name,
                                 float value, int mq, int unit)
 {
-       struct dev_context *devc = sdi->priv;
+       struct dev_context *devc;
        struct sr_datafeed_packet packet;
-       struct sr_datafeed_analog analog = { 0 };
-       struct sr_probe *probe = teleinfo_find_probe(sdi, probe_name);
+       struct sr_datafeed_analog analog;
+       struct sr_channel *probe;
+
+       devc = sdi->priv;
+       probe = teleinfo_find_probe(sdi, probe_name);
 
        if (!probe || !probe->enabled)
                return;
 
+       memset(&analog, 0, sizeof(struct sr_datafeed_analog));
        analog.probes = g_slist_append(analog.probes, probe);
        analog.num_samples = 1;
        analog.mq = mq;
@@ -125,7 +129,7 @@ static gboolean teleinfo_parse_group(struct sr_dev_inst *sdi,
                                      const uint8_t *group, char *optarif)
 {
        char label[9], data[13], control, cr;
-       const char *str = (const char *) group;
+       const char *str = (const char *)group;
        if (sscanf(str, "\x0A%8s %13s %c%c", label, data, &control, &cr) != 4
            || cr != CR)
                return FALSE;
@@ -139,12 +143,13 @@ static const uint8_t *teleinfo_parse_data(struct sr_dev_inst *sdi,
                                           const uint8_t *buf, int len,
                                           char *optarif)
 {
-       const uint8_t *group_start = memchr(buf, LF, len);
+       const uint8_t *group_start, *group_end;
+
+       group_start = memchr(buf, LF, len);
        if (!group_start)
                return NULL;
 
-       const uint8_t *group_end = memchr(group_start, CR,
-                                         len - (group_start - buf));
+       group_end = memchr(group_start, CR, len - (group_start - buf));
        if (!group_end)
                return NULL;
 
@@ -181,6 +186,7 @@ SR_PRIV int teleinfo_receive_data(int fd, int revents, void *cb_data)
        struct sr_serial_dev_inst *serial;
        const uint8_t *ptr, *next_ptr, *end_ptr;
        int len;
+       int64_t time;
 
        (void)fd;
 
@@ -220,7 +226,7 @@ SR_PRIV int teleinfo_receive_data(int fd, int revents, void *cb_data)
        }
 
        if (devc->limit_msec) {
-               int64_t time = (g_get_monotonic_time() - devc->start_time) / 1000;
+               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);