]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/scpi-pps/api.c
saleae-logic-pro: Implement FX3 firmware upload
[libsigrok.git] / src / hardware / scpi-pps / api.c
index c6bd3e591925d87d0dc117e944b5829e7091751e..5d2488252aa0a5e154ea9a096f7cc1cdce5fd075 100644 (file)
@@ -251,15 +251,10 @@ static int dev_open(struct sr_dev_inst *sdi)
        struct sr_scpi_dev_inst *scpi;
        GVariant *beeper;
 
-       if (sdi->status != SR_ST_INACTIVE)
-               return SR_ERR;
-
        scpi = sdi->conn;
        if (sr_scpi_open(scpi) < 0)
                return SR_ERR;
 
-       sdi->status = SR_ST_ACTIVE;
-
        devc = sdi->priv;
        scpi_cmd(sdi, devc->device->commands, SCPI_CMD_REMOTE);
        devc->beeper_was_set = FALSE;
@@ -280,35 +275,28 @@ static int dev_close(struct sr_dev_inst *sdi)
        struct sr_scpi_dev_inst *scpi;
        struct dev_context *devc;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
        scpi = sdi->conn;
-       if (scpi) {
-               if (devc->beeper_was_set)
-                       scpi_cmd(sdi, devc->device->commands, SCPI_CMD_BEEPER_ENABLE);
-               scpi_cmd(sdi, devc->device->commands, SCPI_CMD_LOCAL);
-               sr_scpi_close(scpi);
-               sdi->status = SR_ST_INACTIVE;
-       }
 
-       return SR_OK;
+       if (!scpi)
+               return SR_ERR_BUG;
+
+       if (devc->beeper_was_set)
+               scpi_cmd(sdi, devc->device->commands, SCPI_CMD_BEEPER_ENABLE);
+       scpi_cmd(sdi, devc->device->commands, SCPI_CMD_LOCAL);
+
+       return sr_scpi_close(scpi);
 }
 
-static void clear_helper(void *priv)
+static void clear_helper(struct dev_context *devc)
 {
-       struct dev_context *devc;
-
-       devc = priv;
        g_free(devc->channels);
        g_free(devc->channel_groups);
-       g_free(devc);
 }
 
 static int dev_clear(const struct sr_dev_driver *di)
 {
-       return std_dev_clear(di, clear_helper);
+       return std_dev_clear_with_callback(di, (std_dev_clear_callback)clear_helper);
 }
 
 static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
@@ -450,9 +438,6 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd
        if (!sdi)
                return SR_ERR_ARG;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        if (cg)
                /* Channel group specified. */
                select_channel(sdi, cg->channels->data);
@@ -532,7 +517,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
        const struct channel_spec *ch_spec;
        GVariant *gvar;
        GVariantBuilder gvb;
-       int ret, i;
+       int i;
        const char *s[16];
 
        /* Always available, even without sdi. */
@@ -550,7 +535,6 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                return SR_ERR_ARG;
        devc = sdi->priv;
 
-       ret = SR_OK;
        if (!cg) {
                /* No channel group: global options. */
                switch (key) {
@@ -631,7 +615,7 @@ static int config_list(uint32_t key, GVariant **data, const struct sr_dev_inst *
                }
        }
 
-       return ret;
+       return SR_OK;
 }
 
 static int dev_acquisition_start(const struct sr_dev_inst *sdi)
@@ -642,9 +626,6 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi)
        struct pps_channel *pch;
        int cmd, ret;
 
-       if (sdi->status != SR_ST_ACTIVE)
-               return SR_ERR_DEV_CLOSED;
-
        devc = sdi->priv;
        scpi = sdi->conn;