]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/teleinfo/protocol.c
Introduce standard cleanup helper
[libsigrok.git] / src / hardware / teleinfo / protocol.c
index a610173d1aaaa20421d2716bf44b3e7eaf8f42cd..fbbc044d4b96f75b6daf57e8e760556d39efecdb 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
@@ -57,33 +58,30 @@ static struct sr_channel *teleinfo_find_channel(struct sr_dev_inst *sdi,
 static void teleinfo_send_value(struct sr_dev_inst *sdi, const char *channel_name,
                                 float value, int mq, int unit)
 {
-       struct dev_context *devc;
        struct sr_datafeed_packet packet;
-       struct sr_datafeed_analog analog;
+       struct sr_datafeed_analog_old analog;
        struct sr_channel *ch;
 
-       devc = sdi->priv;
        ch = teleinfo_find_channel(sdi, channel_name);
 
        if (!ch || !ch->enabled)
                return;
 
-       memset(&analog, 0, sizeof(struct sr_datafeed_analog));
+       memset(&analog, 0, sizeof(struct sr_datafeed_analog_old));
        analog.channels = g_slist_append(analog.channels, ch);
        analog.num_samples = 1;
        analog.mq = mq;
        analog.unit = unit;
        analog.data = &value;
 
-       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);
 }
 
-static void teleinfo_handle_mesurement(struct sr_dev_inst *sdi,
-                                       const char *label, const char *data,
-                                       char *optarif)
+static void teleinfo_handle_measurement(struct sr_dev_inst *sdi,
+               const char *label, const char *data, char *optarif)
 {
        struct dev_context *devc;
        int v = atoi(data);
@@ -135,7 +133,7 @@ static gboolean teleinfo_parse_group(struct sr_dev_inst *sdi,
                return FALSE;
        if (!teleinfo_control_check(label, data, control))
                return FALSE;
-       teleinfo_handle_mesurement(sdi, label, data, optarif);
+       teleinfo_handle_measurement(sdi, label, data, optarif);
        return TRUE;
 }
 
@@ -196,7 +194,7 @@ SR_PRIV int teleinfo_receive_data(int fd, int revents, void *cb_data)
 
        /* Try to get as much data as the buffer can hold. */
        len = TELEINFO_BUF_SIZE - 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;
@@ -221,7 +219,7 @@ SR_PRIV int teleinfo_receive_data(int fd, int revents, void *cb_data)
 
        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);
+               sdi->driver->dev_acquisition_stop(sdi);
                return TRUE;
        }
 
@@ -229,7 +227,7 @@ SR_PRIV int teleinfo_receive_data(int fd, int revents, void *cb_data)
                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);
+                       sdi->driver->dev_acquisition_stop(sdi);
                        return TRUE;
                }
        }