]> sigrok.org Git - libsigrok.git/blobdiff - hardware/victor-dmm/api.c
Add and use std_session_send_df_header().
[libsigrok.git] / hardware / victor-dmm / api.c
index 3f76a128e231b21fd4862824177a386cdaf94c97..871c5de0e7257c2b977c47e092d22a7f0d926fc8 100644 (file)
@@ -74,16 +74,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)
@@ -99,10 +90,7 @@ static GSList *hw_scan(GSList *options)
 
        (void)options;
 
-       if (!(drvc = di->priv)) {
-               sr_err("Driver was not initialized.");
-               return NULL;
-       }
+       drvc = di->priv;
 
        /* USB scan is always authoritative. */
        clear_instances();
@@ -147,14 +135,7 @@ static GSList *hw_scan(GSList *options)
 
 static GSList *hw_dev_list(void)
 {
-       struct drv_context *drvc;
-
-       if (!(drvc = di->priv)) {
-               sr_err("Driver was not initialized.");
-               return NULL;
-       }
-
-       return drvc->instances;
+       return ((struct drv_context *)(di->priv))->instances;
 }
 
 static int hw_dev_open(struct sr_dev_inst *sdi)
@@ -244,21 +225,6 @@ static int hw_cleanup(void)
        return SR_OK;
 }
 
-static int config_get(int id, const void **data, const struct sr_dev_inst *sdi)
-{
-       (void)sdi;
-
-       switch (id) {
-       case SR_DI_HWCAPS:
-               *data = hwcaps;
-               break;
-       default:
-               return SR_ERR_ARG;
-       }
-
-       return SR_OK;
-}
-
 static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
@@ -298,6 +264,22 @@ static int config_set(int id, const void *value, const struct sr_dev_inst *sdi)
        return ret;
 }
 
+static int config_list(int key, const void **data, const struct sr_dev_inst *sdi)
+{
+
+       (void)sdi;
+
+       switch (key) {
+       case SR_CONF_DEVICE_OPTIONS:
+               *data = hwcaps;
+               break;
+       default:
+               return SR_ERR_ARG;
+       }
+
+       return SR_OK;
+}
+
 static void receive_transfer(struct libusb_transfer *transfer)
 {
        struct dev_context *devc;
@@ -381,8 +363,6 @@ static int handle_events(int fd, int revents, void *cb_data)
 static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                                    void *cb_data)
 {
-       struct sr_datafeed_packet packet;
-       struct sr_datafeed_header header;
        struct dev_context *devc;
        struct drv_context *drvc = di->priv;
        const struct libusb_pollfd **pfd;
@@ -395,17 +375,11 @@ static int hw_dev_acquisition_start(const struct sr_dev_inst *sdi,
                return SR_ERR;
        }
 
-       sr_dbg("Starting acquisition.");
-
        devc = sdi->priv;
        devc->cb_data = cb_data;
 
        /* Send header packet to the session bus. */
-       sr_dbg("Sending SR_DF_HEADER.");
-       packet.type = SR_DF_HEADER;
-       packet.payload = (uint8_t *)&header;
-       header.feed_version = 1;
-       sr_session_send(devc->cb_data, &packet);
+       std_session_send_df_header(cb_data, DRIVER_LOG_DOMAIN);
 
        pfd = libusb_get_pollfds(drvc->sr_ctx->libusb_ctx);
        for (i = 0; pfd[i]; i++) {
@@ -464,8 +438,8 @@ SR_PRIV struct sr_dev_driver victor_dmm_driver_info = {
        .scan = hw_scan,
        .dev_list = hw_dev_list,
        .dev_clear = clear_instances,
-       .config_get = config_get,
        .config_set = config_set,
+       .config_list = config_list,
        .dev_open = hw_dev_open,
        .dev_close = hw_dev_close,
        .dev_acquisition_start = hw_dev_acquisition_start,