X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=hardware%2Fteleinfo%2Fprotocol.c;h=746d43c07210ba47af30485d82ae555ca8531bb1;hb=53b4680fceab9351fc87b8c5b34854733f5fdac0;hp=28dfcfa1fbd3b950ebb22a6ce9945dbfce3ea9b8;hpb=5542bee61b0e18e9ae3fa6edb361b8ed1bb77425;p=libsigrok.git diff --git a/hardware/teleinfo/protocol.c b/hardware/teleinfo/protocol.c index 28dfcfa1..746d43c0 100644 --- a/hardware/teleinfo/protocol.c +++ b/hardware/teleinfo/protocol.c @@ -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);