]> sigrok.org Git - libsigrok.git/blobdiff - hardware/teleinfo/protocol.c
Consistently use 'cg' for channel group variables.
[libsigrok.git] / hardware / teleinfo / protocol.c
index 28dfcfa1fbd3b950ebb22a6ce9945dbfce3ea9b8..746d43c07210ba47af30485d82ae555ca8531bb1 100644 (file)
@@ -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_probe *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);