return NULL;
}
drvopts = NULL;
- if (g_hash_table_size(drvargs) > 0)
- if (!(drvopts = hash_to_hwopt(drvargs)))
+ if (g_hash_table_size(drvargs) > 0) {
+ if (!(drvopts = hash_to_hwopt(drvargs))) {
/* Unknown options, already logged. */
+ g_hash_table_destroy(drvargs);
return NULL;
+ }
+ }
+ g_hash_table_destroy(drvargs);
devices = sr_driver_scan(driver, drvopts);
g_slist_free_full(drvopts, (GDestroyNotify)free_drvopts);
} else {
outputs = sr_output_list();
for (i = 0; outputs[i]; i++)
printf(" %-20s %s\n", outputs[i]->id, outputs[i]->description);
+ printf(" %-20s %s\n", "sigrok", "Default file output format");
printf("\n");
#ifdef HAVE_SRD
GSList *devices;
GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar;
gsize num_opts, num_elements;
- const uint64_t *uint64, p, q;
+ const uint64_t *uint64, p, q, low, high;
+ uint64_t cur_low, cur_high;
const int32_t *opts;
- unsigned int num_devices, tmp_bool, o, i;
+ unsigned int num_devices, o, i;
+ char *tmp_str;
char *s;
const char *charopts, **stropts;
num_devices = g_slist_length(devices);
if (num_devices > 1) {
- g_critical("%d devices found. Use --list-devices to show them, "
+ g_critical("%d devices found. Use --scan to show them, "
"and select one to show.", num_devices);
return;
}
/* Driver supports no device instance options. */
return;
- printf("Supported device options:\n");
+ printf("Supported configuration options:\n");
opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(int32_t));
for (o = 0; o < num_opts; o++) {
if (!(srci = sr_config_info_get(opts[o])))
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(uint64[i]));
- } if ((gvar_list = g_variant_lookup_value(gvar_dict,
+ for (i = 0; i < num_elements; i++) {
+ if (!(s = sr_samplerate_string(uint64[i])))
+ continue;
+ printf(" %s\n", s);
+ g_free(s);
+ }
+ g_variant_unref(gvar_list);
+ } else if ((gvar_list = g_variant_lookup_value(gvar_dict,
"samplerate-steps", G_VARIANT_TYPE("at")))) {
uint64 = g_variant_get_fixed_array(gvar_list,
&num_elements, sizeof(uint64_t));
}
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,
- &gvar, sdi) != SR_OK) {
- printf("\n");
- continue;
- }
- printf(" - supported trigger sources:\n");
- 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,
- &gvar, sdi) != SR_OK) {
- printf("\n");
- continue;
- }
- printf(" - supported filter targets:\n");
- 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);
}
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,
+ } else if (srci->datatype == SR_T_CHAR) {
+ printf(" %s: ", srci->id);
+ if (sr_config_get(sdi->driver, srci->key,
+ &gvar, sdi) == SR_OK) {
+ tmp_str = g_strdup(g_variant_get_string(gvar, NULL));
+ g_variant_unref(gvar);
+ } else
+ tmp_str = NULL;
+
+ if (sr_config_list(sdi->driver, srci->key,
&gvar, sdi) != SR_OK) {
printf("\n");
continue;
}
- printf(" - supported coupling options:\n");
+
stropts = g_variant_get_strv(gvar, &num_elements);
- for (i = 0; i < num_elements; i++)
- printf(" %s\n", stropts[i]);
+ for (i = 0; i < num_elements; i++) {
+ if (i)
+ printf(", ");
+ printf("%s", stropts[i]);
+ if (tmp_str && !strcmp(tmp_str, stropts[i]))
+ printf(" (current)");
+ }
+ printf("\n");
+ g_free(stropts);
+ g_free(tmp_str);
g_variant_unref(gvar);
- } else if (srci->key == SR_CONF_DATALOG) {
- /* 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");
+ } else if (srci->datatype == SR_T_UINT64_RANGE) {
+ printf(" %s: ", srci->id);
+ if (sr_config_list(sdi->driver, srci->key,
+ &gvar_list, sdi) != SR_OK) {
+ printf("\n");
+ continue;
+ }
+
+ if (sr_config_get(sdi->driver, srci->key, &gvar, sdi) == SR_OK) {
+ g_variant_get(gvar, "(tt)", &cur_low, &cur_high);
g_variant_unref(gvar);
+ } else {
+ cur_low = 0;
+ cur_high = 0;
}
- printf(")\n");
+
+ 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)", &low, &high);
+ g_variant_unref(gvar);
+ if (i)
+ printf(", ");
+ printf("%"PRIu64"-%"PRIu64, low, high);
+ if (low == cur_low && high == cur_high)
+ printf(" (current)");
+ }
+ printf("\n");
+ g_variant_unref(gvar_list);
+
+ } else if (srci->datatype == SR_T_BOOL) {
+ printf(" %s: ", srci->id);
+ if (sr_config_get(sdi->driver, srci->key,
+ &gvar, sdi) == SR_OK) {
+ if (g_variant_get_boolean(gvar))
+ printf("on (current), off\n");
+ else
+ printf("on, off (current)\n");
+ g_variant_unref(gvar);
+ } else
+ printf("on, off\n");
+
} else {
+
/* Everything else */
printf(" %s\n", srci->id);
}
g_variant_unref(gvar_opts);
sr_dev_close(sdi);
+ g_slist_free(devices);
}
static FILE *outfile = NULL;
GSList *l;
GString *out;
- GVariant *gvar;
int sample_size, ret;
uint64_t samplerate, output_len, filter_out_len;
uint8_t *output_buf, *filter_out;
unitsize = (logic_probelist->len + 7) / 8;
#ifdef HAVE_SRD
+ GVariant *gvar;
if (opt_pds && logic_probelist->len) {
if (sr_config_get(sdi->driver, SR_CONF_SAMPLERATE,
&gvar, sdi) != SR_OK) {
if (outfile && outfile != stdout)
fclose(outfile);
- if (opt_output_file && default_output_format) {
+ if (opt_output_file && default_output_format && savebuf->len) {
if (sr_session_save(opt_output_file, sdi, savebuf->data,
unitsize, savebuf->len / unitsize) != SR_OK)
g_critical("Failed to save session.");
int i;
char *fmtspec;
+ if (opt_output_format && !strcmp(opt_output_format, "sigrok")) {
+ /* Doesn't really exist as an output module - this is
+ * the session save mode. */
+ g_free(opt_output_format);
+ opt_output_format = NULL;
+ }
+
if (!opt_output_format) {
opt_output_format = DEFAULT_OUTPUT_FORMAT;
/* we'll need to remember this so when saving to a file
gpointer key, value;
int ret;
double tmp_double;
- uint64_t tmp_u64, p, q;
+ uint64_t tmp_u64, p, q, low, high;
gboolean tmp_bool;
- GVariant *val, *rational[2];
+ GVariant *val, *rational[2], *range[2];
g_hash_table_iter_init(&iter, args);
while (g_hash_table_iter_next(&iter, &key, &value)) {
rational[1] = g_variant_new_uint64(q);
val = g_variant_new_tuple(rational, 2);
break;
+ case SR_T_UINT64_RANGE:
+ if (sscanf(value, "%"PRIu64"-%"PRIu64, &low, &high) != 2) {
+ ret = SR_ERR;
+ break;
+ } else {
+ range[0] = g_variant_new_uint64(low);
+ range[1] = g_variant_new_uint64(high);
+ val = g_variant_new_tuple(range, 2);
+ }
+ break;
default:
ret = SR_ERR;
}
if (opt_continuous)
clear_anykey();
+ sr_session_datafeed_callback_remove_all();
sr_session_destroy();
g_slist_free(devices);
int main(int argc, char **argv)
{
- int ret = 1;
GOptionContext *context;
GError *error;
+ int ret;
+ char *help;
g_log_set_default_handler(logger, NULL);
- error = NULL;
context = g_option_context_new(NULL);
g_option_context_add_main_entries(context, optargs, NULL);
+ ret = 1;
+ error = NULL;
if (!g_option_context_parse(context, &argc, &argv, &error)) {
g_critical("%s", error->message);
goto done;
set_options();
else if (opt_samples || opt_time || opt_frames || opt_continuous)
run_session();
- else
- printf("%s", g_option_context_get_help(context, TRUE, NULL));
+ else {
+ help = g_option_context_get_help(context, TRUE, NULL);
+ printf("%s", help);
+ g_free(help);
+ }
#ifdef HAVE_SRD
if (opt_pds)