]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/scpi-pps/api.c
scpi-pps: Populate sdi->serial_num and fix hw_info mem leak
[libsigrok.git] / src / hardware / scpi-pps / api.c
index e02515296b5afc529a60a2acc6f5cf73f4239100..412d94eef271f442624ec1a25ee90d5b84321de0 100644 (file)
@@ -88,6 +88,11 @@ static struct sr_dev_inst *probe_device(struct sr_scpi_dev_inst *scpi)
        sdi->conn = scpi;
        sdi->driver = di;
        sdi->inst_type = SR_INST_SCPI;
+       sdi->serial_num = g_strdup(hw_info->serial_number);
+
+       sr_scpi_hw_info_free(hw_info);
+       hw_info = NULL;
+
        devc = g_malloc0(sizeof(struct dev_context));
        devc->device = device;
        sdi->priv = devc;
@@ -153,7 +158,9 @@ static int dev_clear(void)
 
 static int dev_open(struct sr_dev_inst *sdi)
 {
+       struct dev_context *devc;
        struct sr_scpi_dev_inst *scpi;
+       GVariant *beeper;
 
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR;
@@ -165,6 +172,15 @@ static int dev_open(struct sr_dev_inst *sdi)
        sdi->status = SR_ST_ACTIVE;
 
        scpi_cmd(sdi, SCPI_CMD_REMOTE);
+       devc = sdi->priv;
+       devc->beeper_was_set = FALSE;
+       if (scpi_cmd_resp(sdi, &beeper, G_VARIANT_TYPE_BOOLEAN, SCPI_CMD_BEEPER) == SR_OK) {
+               if (g_variant_get_boolean(beeper)) {
+                       devc->beeper_was_set = TRUE;
+                       scpi_cmd(sdi, SCPI_CMD_BEEPER_DISABLE);
+               }
+               g_variant_unref(beeper);
+       }
 
        return SR_OK;
 }
@@ -172,12 +188,16 @@ static int dev_open(struct sr_dev_inst *sdi)
 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, SCPI_CMD_BEEPER_ENABLE);
                scpi_cmd(sdi, SCPI_CMD_LOCAL);
                sr_scpi_close(scpi);
                sdi->status = SR_ST_INACTIVE;
@@ -188,7 +208,7 @@ static int dev_close(struct sr_dev_inst *sdi)
 
 static int cleanup(void)
 {
-       return SR_OK;
+       return std_dev_clear(di, NULL);
 }
 
 static int config_get(uint32_t key, GVariant **data, const struct sr_dev_inst *sdi,
@@ -492,9 +512,10 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
        std_session_send_df_header(sdi, LOG_PREFIX);
 
        /* Prime the pipe with the first channel's fetch. */
-       ch = sdi->channels->data;
+       ch = next_enabled_channel(sdi, NULL);
        pch = ch->priv;
-       select_channel(sdi, ch);
+       if ((ret = select_channel(sdi, ch)) != SR_OK)
+               return ret;
        if (pch->mq == SR_MQ_VOLTAGE)
                cmd = SCPI_CMD_GET_MEAS_VOLTAGE;
        else if (pch->mq == SR_MQ_CURRENT)
@@ -510,6 +531,7 @@ static int dev_acquisition_start(const struct sr_dev_inst *sdi,
 
 static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
+       struct sr_datafeed_packet packet;
        struct sr_scpi_dev_inst *scpi;
        float f;
 
@@ -528,6 +550,9 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
        sr_scpi_get_float(scpi, NULL, &f);
        sr_scpi_source_remove(sdi->session, scpi);
 
+       packet.type = SR_DF_END;
+       sr_session_send(sdi, &packet);
+
        return SR_OK;
 }