analog save: Avoid index duplication between analog & logic channels.

This commit is contained in:
Soeren Apel 2016-03-24 08:55:42 +01:00
parent 1393bccfcb
commit e5b280e4c7
3 changed files with 12 additions and 10 deletions

View File

@ -33,7 +33,7 @@ struct out_context {
gboolean zip_created; gboolean zip_created;
uint64_t samplerate; uint64_t samplerate;
char *filename; char *filename;
gint min_analog_index; gint analog_offset;
}; };
static int init(struct sr_output *o, GHashTable *options) static int init(struct sr_output *o, GHashTable *options)
@ -67,6 +67,7 @@ static int zip_create(const struct sr_output *o)
char *s, *metabuf; char *s, *metabuf;
gsize metalen; gsize metalen;
guint logic_channels = 0, analog_channels = 0; guint logic_channels = 0, analog_channels = 0;
gint min_analog_index;
outc = o->priv; outc = o->priv;
@ -105,7 +106,7 @@ static int zip_create(const struct sr_output *o)
g_key_file_set_string(meta, devgroup, "samplerate", s); g_key_file_set_string(meta, devgroup, "samplerate", s);
g_free(s); g_free(s);
outc->min_analog_index = -1; min_analog_index = -1;
for (l = o->sdi->channels; l; l = l->next) { for (l = o->sdi->channels; l; l = l->next) {
ch = l->data; ch = l->data;
@ -114,14 +115,16 @@ static int zip_create(const struct sr_output *o)
logic_channels++; logic_channels++;
break; break;
case SR_CHANNEL_ANALOG: case SR_CHANNEL_ANALOG:
if (outc->min_analog_index == -1 || if (min_analog_index == -1 ||
ch->index < outc->min_analog_index) ch->index < min_analog_index)
outc->min_analog_index = ch->index; min_analog_index = ch->index;
analog_channels++; analog_channels++;
break; break;
} }
} }
outc->analog_offset = logic_channels - min_analog_index + 1;
g_key_file_set_integer(meta, devgroup, "total probes", logic_channels); g_key_file_set_integer(meta, devgroup, "total probes", logic_channels);
g_key_file_set_integer(meta, devgroup, "total analog", analog_channels); g_key_file_set_integer(meta, devgroup, "total analog", analog_channels);
@ -132,8 +135,7 @@ static int zip_create(const struct sr_output *o)
s = g_strdup_printf("probe%d", ch->index + 1); s = g_strdup_printf("probe%d", ch->index + 1);
break; break;
case SR_CHANNEL_ANALOG: case SR_CHANNEL_ANALOG:
s = g_strdup_printf("analog%d", s = g_strdup_printf("analog%d", ch->index + outc->analog_offset);
ch->index - outc->min_analog_index + 1);
break; break;
} }
if (ch->enabled) if (ch->enabled)
@ -318,7 +320,7 @@ static int zip_append_analog(const struct sr_output *o,
channel = analog->meaning->channels->data; channel = analog->meaning->channels->data;
basename = g_strdup_printf("analog-1-%u", basename = g_strdup_printf("analog-1-%u",
channel->index - outc->min_analog_index + 1); channel->index + outc->analog_offset);
baselen = strlen(basename); baselen = strlen(basename);
next_chunk_num = 1; next_chunk_num = 1;
num_files = zip_get_num_entries(archive, 0); num_files = zip_get_num_entries(archive, 0);

View File

@ -113,7 +113,7 @@ static gboolean stream_session_data(struct sr_dev_inst *sdi)
sr_dbg("Opened %s.", capturefile); sr_dbg("Opened %s.", capturefile);
} else if (vdev->cur_analog_channel < vdev->num_analog_channels) { } else if (vdev->cur_analog_channel < vdev->num_analog_channels) {
vdev->capturefile = g_strdup_printf("analog-1-%d", vdev->capturefile = g_strdup_printf("analog-1-%d",
vdev->cur_analog_channel + 1); vdev->num_channels + vdev->cur_analog_channel + 1);
vdev->cur_analog_channel++; vdev->cur_analog_channel++;
vdev->cur_chunk = 0; vdev->cur_chunk = 0;
return TRUE; return TRUE;

View File

@ -293,7 +293,7 @@ SR_API int sr_session_load(struct sr_context *ctx, const char *filename,
} }
sr_config_set(sdi, NULL, SR_CONF_NUM_ANALOG_CHANNELS, sr_config_set(sdi, NULL, SR_CONF_NUM_ANALOG_CHANNELS,
g_variant_new_int32(total_analog)); g_variant_new_int32(total_analog));
for (k = 0; k < total_analog; k++) { for (k = total_channels; k < (total_channels + total_analog); k++) {
g_snprintf(channelname, sizeof(channelname), g_snprintf(channelname, sizeof(channelname),
"%d", k); "%d", k);
sr_channel_new(sdi, k, SR_CHANNEL_ANALOG, sr_channel_new(sdi, k, SR_CHANNEL_ANALOG,