From: Martin Ling Date: Mon, 28 Dec 2015 19:47:54 +0000 (+0000) Subject: sr_session_load(): Create analog channels from loaded file. X-Git-Tag: libsigrok-0.5.0~547 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=b317d1bbfb83f152f94959588336f4a07328d154;p=libsigrok.git sr_session_load(): Create analog channels from loaded file. --- diff --git a/src/session_driver.c b/src/session_driver.c index 6befa780..8efba3ed 100644 --- a/src/session_driver.c +++ b/src/session_driver.c @@ -45,6 +45,7 @@ struct session_vdev { uint64_t samplerate; int unitsize; int num_channels; + int num_analog_channels; int cur_chunk; gboolean finished; }; @@ -53,6 +54,7 @@ static const uint32_t devopts[] = { SR_CONF_CAPTUREFILE | SR_CONF_SET, SR_CONF_CAPTURE_UNITSIZE | SR_CONF_GET | SR_CONF_SET, SR_CONF_NUM_LOGIC_CHANNELS | SR_CONF_SET, + SR_CONF_NUM_ANALOG_CHANNELS | SR_CONF_SET, SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET, SR_CONF_SESSIONFILE | SR_CONF_SET, }; @@ -280,6 +282,9 @@ static int config_set(uint32_t key, GVariant *data, const struct sr_dev_inst *sd case SR_CONF_NUM_LOGIC_CHANNELS: vdev->num_channels = g_variant_get_int32(data); break; + case SR_CONF_NUM_ANALOG_CHANNELS: + vdev->num_analog_channels = g_variant_get_int32(data); + break; default: return SR_ERR_NA; } diff --git a/src/session_file.c b/src/session_file.c index 149e6d1a..9aa56601 100644 --- a/src/session_file.c +++ b/src/session_file.c @@ -186,7 +186,8 @@ SR_API int sr_session_load(struct sr_context *ctx, const char *filename, struct sr_channel *ch; int ret, i, j; uint64_t tmp_u64; - int total_channels, k; + int total_channels, total_analog, k; + GSList *l; int unitsize; char **sections, **keys, *val; char channelname[SR_MAX_CHANNELNAME_LEN + 1]; @@ -283,6 +284,21 @@ SR_API int sr_session_load(struct sr_context *ctx, const char *filename, sr_channel_new(sdi, k, SR_CHANNEL_LOGIC, FALSE, channelname); } + } else if (!strcmp(keys[j], "total analog")) { + total_analog = g_key_file_get_integer(kf, + sections[i], keys[j], &error); + if (!sdi || total_analog < 0 || error) { + ret = SR_ERR_DATA; + break; + } + sr_config_set(sdi, NULL, SR_CONF_NUM_ANALOG_CHANNELS, + g_variant_new_int32(total_analog)); + for (k = 0; k < total_analog; k++) { + g_snprintf(channelname, sizeof(channelname), + "%d", k); + sr_channel_new(sdi, k, SR_CHANNEL_ANALOG, + FALSE, channelname); + } } else if (!strncmp(keys[j], "probe", 5)) { tmp_u64 = g_ascii_strtoull(keys[j] + 5, NULL, 10); if (!sdi || tmp_u64 == 0 || tmp_u64 > G_MAXINT) { @@ -304,6 +320,34 @@ SR_API int sr_session_load(struct sr_context *ctx, const char *filename, sr_dev_channel_name_set(ch, val); g_free(val); sr_dev_channel_enable(ch, TRUE); + } else if (!strncmp(keys[j], "analog", 6)) { + tmp_u64 = g_ascii_strtoull(keys[j]+6, NULL, 10); + if (!sdi || tmp_u64 == 0 || tmp_u64 > G_MAXINT) { + ret = SR_ERR_DATA; + break; + } + ch = NULL; + for (l = sdi->channels; l; l = l->next) { + ch = l->data; + if ((guint64)ch->index == tmp_u64 - 1) + break; + else + ch = NULL; + } + if (!ch) { + ret = SR_ERR_DATA; + break; + } + val = g_key_file_get_string(kf, sections[i], + keys[j], &error); + if (!val) { + ret = SR_ERR_DATA; + break; + } + /* sr_session_save() */ + sr_dev_channel_name_set(ch, val); + g_free(val); + sr_dev_channel_enable(ch, TRUE); } } g_strfreev(keys);