]> sigrok.org Git - libsigrok.git/commitdiff
sr_session_load(): Create analog channels from loaded file.
authorMartin Ling <redacted>
Mon, 28 Dec 2015 19:47:54 +0000 (19:47 +0000)
committerUwe Hermann <redacted>
Sun, 13 Mar 2016 23:34:09 +0000 (00:34 +0100)
src/session_driver.c
src/session_file.c

index 6befa780ece2b88492abc699a2ab8b266a3168c1..8efba3edb7729997828514ad34844e6e6044e2b2 100644 (file)
@@ -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;
        }
index 149e6d1a0237000c93e85b793310603ca85fd8e2..9aa56601c8ab67a31818c5ef26e149d2067a50bc 100644 (file)
@@ -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);