]> sigrok.org Git - libsigrok.git/commitdiff
analog save: Avoid index duplication between analog & logic channels.
authorSoeren Apel <redacted>
Thu, 24 Mar 2016 07:55:42 +0000 (08:55 +0100)
committerSoeren Apel <redacted>
Thu, 24 Mar 2016 07:55:42 +0000 (08:55 +0100)
src/output/srzip.c
src/session_driver.c
src/session_file.c

index aa3c37577d33fbe17dbf576f79f8da9986017993..2d269aebd27bbed078c563859b760c729646d060 100644 (file)
@@ -33,7 +33,7 @@ struct out_context {
        gboolean zip_created;
        uint64_t samplerate;
        char *filename;
-       gint min_analog_index;
+       gint analog_offset;
 };
 
 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;
        gsize metalen;
        guint logic_channels = 0, analog_channels = 0;
+       gint min_analog_index;
 
        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_free(s);
 
-       outc->min_analog_index = -1;
+       min_analog_index = -1;
 
        for (l = o->sdi->channels; l; l = l->next) {
                ch = l->data;
@@ -114,14 +115,16 @@ static int zip_create(const struct sr_output *o)
                        logic_channels++;
                        break;
                case SR_CHANNEL_ANALOG:
-                       if (outc->min_analog_index == -1 ||
-                                       ch->index < outc->min_analog_index)
-                               outc->min_analog_index = ch->index;
+                       if (min_analog_index == -1 ||
+                                       ch->index < min_analog_index)
+                               min_analog_index = ch->index;
                        analog_channels++;
                        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 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);
                        break;
                case SR_CHANNEL_ANALOG:
-                       s = g_strdup_printf("analog%d",
-                                       ch->index - outc->min_analog_index + 1);
+                       s = g_strdup_printf("analog%d", ch->index + outc->analog_offset);
                        break;
                }
                if (ch->enabled)
@@ -318,7 +320,7 @@ static int zip_append_analog(const struct sr_output *o,
        channel = analog->meaning->channels->data;
 
        basename = g_strdup_printf("analog-1-%u",
-                       channel->index - outc->min_analog_index + 1);
+                       channel->index + outc->analog_offset);
        baselen = strlen(basename);
        next_chunk_num = 1;
        num_files = zip_get_num_entries(archive, 0);
index dc2fb1ebc44c70d3cd00284bedad589895658f64..07ee10b04aee08d974daa55b62444df373e219ab 100644 (file)
@@ -113,7 +113,7 @@ static gboolean stream_session_data(struct sr_dev_inst *sdi)
                                sr_dbg("Opened %s.", capturefile);
                        } else if (vdev->cur_analog_channel < vdev->num_analog_channels) {
                                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_chunk = 0;
                                return TRUE;
index 9aa56601c8ab67a31818c5ef26e149d2067a50bc..f8746f60fa0ae9ae75ab5c1a8cab7c541399b743 100644 (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,
                                                        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),
                                                                "%d", k);
                                                sr_channel_new(sdi, k, SR_CHANNEL_ANALOG,