]> sigrok.org Git - libsigrok.git/blobdiff - hardware/chronovu-la8/api.c
Add and use std_session_send_df_header().
[libsigrok.git] / hardware / chronovu-la8 / api.c
index 478f0a1c95b1763de0893a25b1adb6b4065b3f62..66cbdb6ecdfa83393d409b55dc222f945ccdd5e3 100644 (file)
@@ -70,17 +70,7 @@ static int clear_instances(void)
 
 static int hw_init(struct sr_context *sr_ctx)
 {
-       struct drv_context *drvc;
-
-       if (!(drvc = g_try_malloc0(sizeof(struct drv_context)))) {
-               sr_err("Driver context malloc failed.");
-               return SR_ERR_MALLOC;
-       }
-
-       drvc->sr_ctx = sr_ctx;
-       di->priv = drvc;
-
-       return SR_OK;
+       return std_hw_init(sr_ctx, di, DRIVER_LOG_DOMAIN);
 }
 
 static GSList *hw_scan(GSList *options)
@@ -96,6 +86,7 @@ static GSList *hw_scan(GSList *options)
        (void)options;
 
        drvc = di->priv;
+
        devices = NULL;
 
        /* Allocate memory for our private device context. */
@@ -169,8 +160,6 @@ static GSList *hw_scan(GSList *options)
        devices = g_slist_append(devices, sdi);
        drvc->instances = g_slist_append(drvc->instances, sdi);
 
-       sr_spew("Device init successful.");
-
        /* Close device. We'll reopen it again when we need it. */
        (void) la8_close(devc); /* Log, but ignore errors. */
 
@@ -191,11 +180,7 @@ err_free_nothing:
 
 static GSList *hw_dev_list(void)
 {
-       struct drv_context *drvc;
-
-       drvc = di->priv;
-
-       return drvc->instances;
+       return ((struct drv_context *)(di->priv))->instances;
 }
 
 static int hw_dev_open(struct sr_dev_inst *sdi)
@@ -255,12 +240,7 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
 
-       if (!(devc = sdi->priv)) {
-               sr_err("%s: sdi->priv was NULL.", __func__);
-               return SR_ERR_BUG;
-       }
-
-       sr_dbg("Closing device.");
+       devc = sdi->priv;
 
        if (sdi->status == SR_ST_ACTIVE) {
                sr_dbg("Status ACTIVE, closing device.");
@@ -271,7 +251,6 @@ static int hw_dev_close(struct sr_dev_inst *sdi)
 
        sdi->status = SR_ST_INACTIVE;
 
-       sr_dbg("Freeing sample buffer.");
        g_free(devc->final_buf);
 
        return SR_OK;
@@ -427,8 +406,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                                    void *cb_data)
 {
        struct dev_context *devc;
-       struct sr_datafeed_packet packet;
-       struct sr_datafeed_header header;
        uint8_t buf[4];
        int bytes_written;
 
@@ -453,8 +430,6 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                return SR_ERR;
        }
 
-       sr_dbg("Starting acquisition.");
-
        /* Fill acquisition parameters into buf[]. */
        buf[0] = devc->divcount;
        buf[1] = 0xff; /* This byte must always be 0xff. */
@@ -472,17 +447,12 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                return SR_ERR;
        }
 
-       sr_dbg("Acquisition started successfully.");
+       sr_dbg("Hardware acquisition started successfully.");
 
        devc->session_dev_id = cb_data;
 
        /* Send header packet to the session bus. */
-       sr_dbg("Sending SR_DF_HEADER.");
-       packet.type = SR_DF_HEADER;
-       packet.payload = &header;
-       header.feed_version = 1;
-       gettimeofday(&header.starttime, NULL);
-       sr_session_send(devc->session_dev_id, &packet);
+       std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
 
        /* Time when we should be done (for detecting trigger timeouts). */
        devc->done = (devc->divcount + 1) * 0.08388608 + time(NULL)