]> sigrok.org Git - sigrok-cli.git/blobdiff - sigrok-cli.c
Small variable naming fix to avoid confusion.
[sigrok-cli.git] / sigrok-cli.c
index e93fc63198d2064f7b11ed4a5208f51e78bac7fe..a194a5cb9c3ec9c4a7a8c854b5c52331ef4dc8ac 100644 (file)
@@ -314,11 +314,10 @@ static void show_dev_detail(void)
 {
        struct sr_dev_inst *sdi;
        const struct sr_config_info *srci;
-       struct sr_rational *rationals;
        GSList *devices;
        GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar;
        gsize num_opts, num_elements;
-       const uint64_t *integers;
+       const uint64_t *uint64, p, q;
        const int32_t *opts;
        unsigned int num_devices, tmp_bool, o, i;
        char *s;
@@ -387,15 +386,13 @@ static void show_dev_detail(void)
                        g_variant_unref(gvar);
 
                } else if (srci->key == SR_CONF_PATTERN_MODE) {
-                       /* TODO */
                        /* Pattern generator modes */
                        printf("    %s", srci->id);
                        if (sr_config_list(sdi->driver, srci->key, &gvar,
                                        sdi) == SR_OK) {
-//                             stropts = g_variant_get_fixed_array(gvar, &num_elements,
-//                                             sizeof
                                printf(" - supported patterns:\n");
-                               for (i = 0; stropts[i]; i++)
+                               stropts = g_variant_get_strv(gvar, &num_elements);
+                               for (i = 0; i < num_elements; i++)
                                        printf("      %s\n", stropts[i]);
                                g_variant_unref(gvar);
                        } else {
@@ -412,30 +409,31 @@ static void show_dev_detail(void)
                        }
                        if ((gvar_list = g_variant_lookup_value(gvar_dict,
                                        "samplerates", G_VARIANT_TYPE("at")))) {
-                               integers = g_variant_get_fixed_array(gvar_list,
+                               uint64 = g_variant_get_fixed_array(gvar_list,
                                                &num_elements, sizeof(uint64_t));
                                printf(" - supported samplerates:\n");
                                for (i = 0; i < num_elements; i++)
-                                       printf("      %s\n", sr_samplerate_string(integers[i]));
+                                       printf("      %s\n", sr_samplerate_string(uint64[i]));
                        } if ((gvar_list = g_variant_lookup_value(gvar_dict,
                                        "samplerate-steps", G_VARIANT_TYPE("at")))) {
-                               integers = g_variant_get_fixed_array(gvar_list,
+                               uint64 = g_variant_get_fixed_array(gvar_list,
                                                &num_elements, sizeof(uint64_t));
                                /* low */
-                               if (!(s = sr_samplerate_string(integers[0])))
+                               if (!(s = sr_samplerate_string(uint64[0])))
                                        continue;
                                printf(" (%s", s);
                                g_free(s);
                                /* high */
-                               if (!(s = sr_samplerate_string(integers[1])))
+                               if (!(s = sr_samplerate_string(uint64[1])))
                                        continue;
                                printf(" - %s", s);
                                g_free(s);
                                /* step */
-                               if (!(s = sr_samplerate_string(integers[2])))
+                               if (!(s = sr_samplerate_string(uint64[2])))
                                        continue;
                                printf(" in steps of %s)\n", s);
                                g_free(s);
+                               g_variant_unref(gvar_list);
                        }
                        g_variant_unref(gvar_dict);
 
@@ -443,82 +441,106 @@ static void show_dev_detail(void)
                        /* Supported buffer sizes */
                        printf("    %s", srci->id);
                        if (sr_config_list(sdi->driver, SR_CONF_BUFFERSIZE,
-                                       (const void **)&integers, sdi) != SR_OK) {
+                                       &gvar_list, sdi) != SR_OK) {
                                printf("\n");
                                continue;
                        }
+                       uint64 = g_variant_get_fixed_array(gvar_list,
+                                       &num_elements, sizeof(uint64_t));
                        printf(" - supported buffer sizes:\n");
-                       for (i = 0; integers[i]; i++)
-                               printf("      %"PRIu64"\n", integers[i]);
+                       for (i = 0; i < num_elements; i++)
+                               printf("      %"PRIu64"\n", uint64[i]);
+                       g_variant_unref(gvar_list);
 
                } else if (srci->key == SR_CONF_TIMEBASE) {
                        /* Supported time bases */
                        printf("    %s", srci->id);
                        if (sr_config_list(sdi->driver, SR_CONF_TIMEBASE,
-                                       (const void **)&rationals, sdi) != SR_OK) {
+                                       &gvar_list, sdi) != SR_OK) {
                                printf("\n");
                                continue;
                        }
                        printf(" - supported time bases:\n");
-                       for (i = 0; rationals[i].p && rationals[i].q; i++)
-                               printf("      %s\n", sr_period_string(
-                                               rationals[i].p * rationals[i].q));
+                       num_elements = g_variant_n_children(gvar_list);
+                       for (i = 0; i < num_elements; i++) {
+                               gvar = g_variant_get_child_value(gvar_list, i);
+                               g_variant_get(gvar, "(tt)", &p, &q);
+                               s = sr_period_string(p * q);
+                               printf("      %s\n", s);
+                               g_free(s);
+                       }
+                       g_variant_unref(gvar_list);
 
                } else if (srci->key == SR_CONF_TRIGGER_SOURCE) {
                        /* Supported trigger sources */
                        printf("    %s", srci->id);
                        if (sr_config_list(sdi->driver, SR_CONF_TRIGGER_SOURCE,
-                                       (const void **)&stropts, sdi) != SR_OK) {
+                                       &gvar, sdi) != SR_OK) {
                                printf("\n");
                                continue;
                        }
                        printf(" - supported trigger sources:\n");
-                       for (i = 0; stropts[i]; i++)
+                       stropts = g_variant_get_strv(gvar, &num_elements);
+                       for (i = 0; i < num_elements; i++)
                                printf("      %s\n", stropts[i]);
+                       g_variant_unref(gvar);
 
                } else if (srci->key == SR_CONF_FILTER) {
                        /* Supported filters */
                        printf("    %s", srci->id);
                        if (sr_config_list(sdi->driver, SR_CONF_FILTER,
-                                       (const void **)&stropts, sdi) != SR_OK) {
+                                       &gvar, sdi) != SR_OK) {
                                printf("\n");
                                continue;
                        }
                        printf(" - supported filter targets:\n");
-                       for (i = 0; stropts[i]; i++)
+                       stropts = g_variant_get_strv(gvar, &num_elements);
+                       for (i = 0; i < num_elements; i++)
                                printf("      %s\n", stropts[i]);
+                       g_variant_unref(gvar);
 
                } else if (srci->key == SR_CONF_VDIV) {
                        /* Supported volts/div values */
                        printf("    %s", srci->id);
                        if (sr_config_list(sdi->driver, SR_CONF_VDIV,
-                                       (const void **)&rationals, sdi) != SR_OK) {
+                                       &gvar_list, sdi) != SR_OK) {
                                printf("\n");
                                continue;
                        }
                        printf(" - supported volts/div:\n");
-                       for (i = 0; rationals[i].p && rationals[i].q; i++)
-                               printf("      %s\n", sr_voltage_string( &rationals[i]));
+                       num_elements = g_variant_n_children(gvar_list);
+                       for (i = 0; i < num_elements; i++) {
+                               gvar = g_variant_get_child_value(gvar_list, i);
+                               g_variant_get(gvar, "(tt)", &p, &q);
+                               s = sr_voltage_string(p, q);
+                               printf("      %s\n", s);
+                               g_free(s);
+                       }
+                       g_variant_unref(gvar_list);
 
                } else if (srci->key == SR_CONF_COUPLING) {
                        /* Supported coupling settings */
                        printf("    %s", srci->id);
                        if (sr_config_list(sdi->driver, SR_CONF_COUPLING,
-                                       (const void **)&stropts, sdi) != SR_OK) {
+                                       &gvar, sdi) != SR_OK) {
                                printf("\n");
                                continue;
                        }
                        printf(" - supported coupling options:\n");
-                       for (i = 0; stropts[i]; i++)
+                       stropts = g_variant_get_strv(gvar, &num_elements);
+                       for (i = 0; i < num_elements; i++)
                                printf("      %s\n", stropts[i]);
+                       g_variant_unref(gvar);
 
                } else if (srci->key == SR_CONF_DATALOG) {
+                       /* TODO test */
                        /* Turning on/off internal data logging. */
                        printf("    %s\t(on/off", srci->id);
                        if (sr_config_get(sdi->driver, SR_CONF_DATALOG,
                                        &gvar, sdi) == SR_OK) {
                                tmp_bool = g_variant_get_boolean(gvar);
                                printf(", currently %s", tmp_bool ? "on" : "off");
+                               g_variant_unref(gvar);
                        }
                        printf(")\n");
                } else {
@@ -1407,11 +1429,10 @@ static int set_dev_options(struct sr_dev_inst *sdi, GHashTable *args)
        GHashTableIter iter;
        gpointer key, value;
        int ret;
-       float tmp_float;
-       uint64_t tmp_u64;
-       struct sr_rational tmp_rat;
+       double tmp_double;
+       uint64_t tmp_u64, p, q;
        gboolean tmp_bool;
-       void *val;
+       GVariant *val, *rational[2];
 
        g_hash_table_iter_init(&iter, args);
        while (g_hash_table_iter_next(&iter, &key, &value)) {
@@ -1431,31 +1452,35 @@ static int set_dev_options(struct sr_dev_inst *sdi, GHashTable *args)
                        ret = sr_parse_sizestring(value, &tmp_u64);
                        if (ret != SR_OK)
                                break;
-                       val = &tmp_u64;
+                       val = g_variant_new_uint64(tmp_u64);
                        break;
                case SR_T_CHAR:
-                       val = value;
+                       val = g_variant_new_string(value);
                        break;
                case SR_T_BOOL:
                        if (!value)
                                tmp_bool = TRUE;
                        else
                                tmp_bool = sr_parse_boolstring(value);
-                       val = &tmp_bool;
+                       val = g_variant_new_boolean(tmp_bool);
                        break;
                case SR_T_FLOAT:
-                       tmp_float = strtof(value, NULL);
-                       val = &tmp_float;
+                       tmp_double = strtof(value, NULL);
+                       val = g_variant_new_double(tmp_double);
                        break;
                case SR_T_RATIONAL_PERIOD:
-                       if ((ret = sr_parse_period(value, &tmp_rat)) != SR_OK)
+                       if ((ret = sr_parse_period(value, &p, &q)) != SR_OK)
                                break;
-                       val = &tmp_rat;
+                       rational[0] = g_variant_new_uint64(p);
+                       rational[1] = g_variant_new_uint64(q);
+                       val = g_variant_new_tuple(rational, 2);
                        break;
                case SR_T_RATIONAL_VOLT:
-                       if ((ret = sr_parse_voltage(value, &tmp_rat)) != SR_OK)
+                       if ((ret = sr_parse_voltage(value, &p, &q)) != SR_OK)
                                break;
-                       val = &tmp_rat;
+                       rational[0] = g_variant_new_uint64(p);
+                       rational[1] = g_variant_new_uint64(q);
+                       val = g_variant_new_tuple(rational, 2);
                        break;
                default:
                        ret = SR_ERR;
@@ -1638,6 +1663,7 @@ static void run_session(void)
                        sr_session_destroy();
                        return;
                }
+               gvar = g_variant_new_uint64(limit_frames);
                if (sr_config_set(sdi, SR_CONF_LIMIT_FRAMES, gvar) != SR_OK) {
                        g_critical("Failed to configure frame limit.");
                        sr_session_destroy();