From: Martin Ling Date: Tue, 11 Sep 2018 12:08:12 +0000 (+0100) Subject: scpi-pps: Fix broken channel selection code. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3d11872282d2186310a3f8bf8f0c6b887e04be25;p=libsigrok.git scpi-pps: Fix broken channel selection code. Fixes bug #1279. --- diff --git a/src/hardware/scpi-pps/protocol.c b/src/hardware/scpi-pps/protocol.c index 37c327c4..47717587 100644 --- a/src/hardware/scpi-pps/protocol.c +++ b/src/hardware/scpi-pps/protocol.c @@ -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); diff --git a/src/scpi.h b/src/scpi.h index f4fe651b..e55d36f1 100644 --- a/src/scpi.h +++ b/src/scpi.h @@ -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, diff --git a/src/scpi/scpi.c b/src/scpi/scpi.c index 82c95bfc..37004786 100644 --- a/src/scpi/scpi.c +++ b/src/scpi/scpi.c @@ -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;