]> sigrok.org Git - libsigrok.git/commitdiff
scpi-pps: Fix broken channel selection code.
authorMartin Ling <redacted>
Tue, 11 Sep 2018 12:08:12 +0000 (13:08 +0100)
committerMartin Ling <redacted>
Tue, 11 Sep 2018 12:08:12 +0000 (13:08 +0100)
Fixes bug #1279.

src/hardware/scpi-pps/protocol.c
src/scpi.h
src/scpi/scpi.c

index 37c327c41bab10e12c806da01b546909b4182a23..477175872430d7da9db7b608ff26eb72c80106f2 100644 (file)
@@ -34,7 +34,7 @@ SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data)
        struct sr_analog_spec spec;
        struct sr_dev_inst *sdi;
        int channel_group_cmd;
-       char *channel_group_name;
+       const char *channel_group_name;
        struct pps_channel *pch;
        const struct channel_spec *ch_spec;
        int ret;
@@ -52,14 +52,15 @@ SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data)
        if (!(devc = sdi->priv))
                return TRUE;
 
+       pch = devc->cur_acquisition_channel->priv;
+
        channel_group_cmd = 0;
        channel_group_name = NULL;
        if (g_slist_length(sdi->channel_groups) > 1) {
                channel_group_cmd = SCPI_CMD_SELECT_CHANNEL;
-               channel_group_name = g_strdup(devc->cur_acquisition_channel->name);
+               channel_group_name = pch->hwname;
        }
 
-       pch = devc->cur_acquisition_channel->priv;
        if (pch->mq == SR_MQ_VOLTAGE) {
                gvtype = G_VARIANT_TYPE_DOUBLE;
                cmd = SCPI_CMD_GET_MEAS_VOLTAGE;
@@ -78,7 +79,6 @@ SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data)
 
        ret = sr_scpi_cmd_resp(sdi, devc->device->commands,
                channel_group_cmd, channel_group_name, &gvdata, gvtype, cmd);
-       g_free(channel_group_name);
 
        if (ret != SR_OK)
                return ret;
@@ -106,6 +106,7 @@ SR_PRIV int scpi_pps_receive_data(int fd, int revents, void *cb_data)
        }
        analog.meaning->mqflags = SR_MQFLAG_DC;
        f = (float)g_variant_get_double(gvdata);
+       g_variant_unref(gvdata);
        analog.data = &f;
        sr_session_send(sdi, &packet);
        g_slist_free(analog.meaning->channels);
index f4fe651b94dee45a34dea4784f5ab48e71e63ae3..e55d36f1513880d84a8d6119a92c59abc507a0d1 100644 (file)
@@ -100,7 +100,7 @@ struct sr_scpi_dev_inst {
        /* Only used for quirk workarounds, notably the Rigol DS1000 series. */
        uint64_t firmware_version;
        GMutex scpi_mutex;
-       const char *actual_channel_name;
+       char *actual_channel_name;
 };
 
 SR_PRIV GSList *sr_scpi_scan(struct drv_context *drvc, GSList *options,
index 82c95bfc7586850c0f8cd232b78c659707e6779f..3700478692229e7a78813c4058fe608beac93ab7 100644 (file)
@@ -587,6 +587,7 @@ SR_PRIV void sr_scpi_free(struct sr_scpi_dev_inst *scpi)
 
        scpi->free(scpi->priv);
        g_free(scpi->priv);
+       g_free(scpi->actual_channel_name);
        g_free(scpi);
 }
 
@@ -1195,7 +1196,8 @@ SR_PRIV int sr_scpi_cmd(const struct sr_dev_inst *sdi,
        if (channel_cmd && channel_name &&
                        g_strcmp0(channel_name, scpi->actual_channel_name)) {
                sr_spew("sr_scpi_cmd(): new channel = %s", channel_name);
-               scpi->actual_channel_name = channel_name;
+               g_free(scpi->actual_channel_name);
+               scpi->actual_channel_name = g_strdup(channel_name);
                ret = scpi_send(scpi, channel_cmd, channel_name);
                if (ret != SR_OK)
                        return ret;
@@ -1239,7 +1241,8 @@ SR_PRIV int sr_scpi_cmd_resp(const struct sr_dev_inst *sdi,
        if (channel_cmd && channel_name &&
                        g_strcmp0(channel_name, scpi->actual_channel_name)) {
                sr_spew("sr_scpi_cmd_get(): new channel = %s", channel_name);
-               scpi->actual_channel_name = channel_name;
+               g_free(scpi->actual_channel_name);
+               scpi->actual_channel_name = g_strdup(channel_name);
                ret = scpi_send(scpi, channel_cmd, channel_name);
                if (ret != SR_OK)
                        return ret;