static void set_options(void) { struct sr_dev_inst *sdi; GSList *devices; GHashTable *devargs; if (!opt_config) { g_critical("No setting specified."); return; } if (!(devargs = parse_generic_arg(opt_config, FALSE))) return; if (!(devices = device_scan())) { g_critical("No devices found."); return; } sdi = devices->data; g_slist_free(devices); if (sr_dev_open(sdi) != SR_OK) { g_critical("Failed to open device."); return; } set_dev_options(sdi, devargs); sr_dev_close(sdi); g_hash_table_destroy(devargs); }
void Device::use(SigSession *owner) throw(QString) { DevInst::use(owner); sr_session_new(); assert(_sdi); sr_dev_open(_sdi); if (sr_session_dev_add(_sdi) != SR_OK) throw QString(tr("Failed to use device.")); }
int DeviceManager::use_device(sr_dev_inst *sdi, SigSession *owner) { assert(sdi); assert(owner); if (sr_dev_open(sdi) != SR_OK) return SR_ERR; _used_devices[sdi] = owner; return SR_OK; }
static void get_option(void) { struct sr_dev_inst *sdi; struct sr_channel_group *cg; const struct sr_config_info *ci; GSList *devices; GVariant *gvar; GHashTable *devargs; int ret; char *s; struct sr_dev_driver *driver; if (!(devices = device_scan())) { g_critical("No devices found."); return; } sdi = devices->data; g_slist_free(devices); driver = sr_dev_inst_driver_get(sdi); if (sr_dev_open(sdi) != SR_OK) { g_critical("Failed to open device."); return; } cg = select_channel_group(sdi); if (!(ci = sr_config_info_name_get(opt_get))) g_critical("Unknown option '%s'", opt_get); if ((devargs = parse_generic_arg(opt_config, FALSE))) set_dev_options(sdi, devargs); else devargs = NULL; if ((ret = maybe_config_get(driver, sdi, cg, ci->key, &gvar)) != SR_OK) g_critical("Failed to get '%s': %s", opt_get, sr_strerror(ret)); s = g_variant_print(gvar, FALSE); printf("%s\n", s); g_free(s); g_variant_unref(gvar); sr_dev_close(sdi); if (devargs) g_hash_table_destroy(devargs); }
/** @private */ SR_PRIV struct sr_dev_inst *sr_session_prepare_sdi(const char *filename, struct sr_session **session) { struct sr_dev_inst *sdi = NULL; sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->driver = &session_driver; sdi->status = SR_ST_INACTIVE; if (!session_driver_initialized) { /* first device, init the driver */ session_driver_initialized = 1; sdi->driver->init(sdi->driver, NULL); } sr_dev_open(sdi); sr_session_dev_add(*session, sdi); (*session)->owned_devs = g_slist_append((*session)->owned_devs, sdi); sr_config_set(sdi, NULL, SR_CONF_SESSIONFILE, g_variant_new_string(filename)); return sdi; }
void run_session(void) { GSList *devices; GHashTable *devargs; GVariant *gvar; struct sr_dev_inst *sdi; uint64_t min_samples, max_samples; devices = device_scan(); if (!devices) { g_critical("No devices found."); return; } if (g_slist_length(devices) > 1) { g_critical("sigrok-cli only supports one device for capturing."); return; } sdi = devices->data; sr_session_new(); sr_session_datafeed_callback_add(datafeed_in, NULL); if (sr_dev_open(sdi) != SR_OK) { g_critical("Failed to open device."); return; } if (sr_session_dev_add(sdi) != SR_OK) { g_critical("Failed to add device to session."); sr_session_destroy(); return; } if (opt_config) { if ((devargs = parse_generic_arg(opt_config, FALSE))) { if (set_dev_options(sdi, devargs) != SR_OK) return; g_hash_table_destroy(devargs); } } if (select_channels(sdi) != SR_OK) { g_critical("Failed to set channels."); sr_session_destroy(); return; } if (opt_triggers) { if (!parse_triggerstring(sdi, opt_triggers)) { sr_session_destroy(); return; } } if (opt_continuous) { if (!sr_dev_has_option(sdi, SR_CONF_CONTINUOUS)) { g_critical("This device does not support continuous sampling."); sr_session_destroy(); return; } } if (opt_time) { if (set_limit_time(sdi) != SR_OK) { sr_session_destroy(); return; } } if (opt_samples) { if ((sr_parse_sizestring(opt_samples, &limit_samples) != SR_OK)) { g_critical("Invalid sample limit '%s'.", opt_samples); sr_session_destroy(); return; } if (sr_config_list(sdi->driver, sdi, NULL, SR_CONF_LIMIT_SAMPLES, &gvar) == SR_OK) { /* The device has no compression, or compression is turned * off, and publishes its sample memory size. */ g_variant_get(gvar, "(tt)", &min_samples, &max_samples); g_variant_unref(gvar); if (limit_samples < min_samples) { g_critical("The device stores at least %"PRIu64 " samples with the current settings.", min_samples); } if (limit_samples > max_samples) { g_critical("The device can store only %"PRIu64 " samples with the current settings.", max_samples); } } gvar = g_variant_new_uint64(limit_samples); if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_SAMPLES, gvar) != SR_OK) { g_critical("Failed to configure sample limit."); sr_session_destroy(); return; } } if (opt_frames) { if ((sr_parse_sizestring(opt_frames, &limit_frames) != SR_OK)) { g_critical("Invalid sample limit '%s'.", opt_samples); sr_session_destroy(); return; } gvar = g_variant_new_uint64(limit_frames); if (sr_config_set(sdi, NULL, SR_CONF_LIMIT_FRAMES, gvar) != SR_OK) { g_critical("Failed to configure frame limit."); sr_session_destroy(); return; } } if (sr_session_start() != SR_OK) { g_critical("Failed to start session."); sr_session_destroy(); return; } if (opt_continuous) add_anykey(); sr_session_run(); if (opt_continuous) clear_anykey(); sr_session_datafeed_callback_remove_all(); sr_session_destroy(); g_slist_free(devices); }
/** * Load the session from the specified filename. * * @param filename The name of the session file to load. Must not be NULL. * * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, * SR_ERR_MALLOC upon memory allocation errors, or SR_ERR upon * other errors. */ SR_API int sr_session_load(const char *filename) { GKeyFile *kf; GPtrArray *capturefiles; struct zip *archive; struct zip_file *zf; struct zip_stat zs; struct sr_dev_inst *sdi; struct sr_channel *probe; int ret, devcnt, i, j, k; uint16_t probenum; uint64_t tmp_u64, total_probes, enabled_probes; uint16_t p; char **sections, **keys, *metafile, *val, s[11]; char probename[SR_MAX_PROBENAME_LEN + 1]; int mode = LOGIC; int channel_type = SR_CHANNEL_LOGIC; double tmp_double; if (!filename) { sr_err("%s: filename was NULL", __func__); return SR_ERR_ARG; } if (!(archive = zip_open(filename, 0, &ret))) { sr_dbg("Failed to open session file: zip error %d", ret); return SR_ERR; } /* read "metadata" */ if (zip_stat(archive, "header", 0, &zs) == -1) { sr_dbg("Not a valid DSView data file."); return SR_ERR; } if (!(metafile = g_try_malloc(zs.size))) { sr_err("%s: metafile malloc failed", __func__); return SR_ERR_MALLOC; } zf = zip_fopen_index(archive, zs.index, 0); zip_fread(zf, metafile, zs.size); zip_fclose(zf); kf = g_key_file_new(); if (!g_key_file_load_from_data(kf, metafile, zs.size, 0, NULL)) { sr_dbg("Failed to parse metadata."); return SR_ERR; } sr_session_new(); devcnt = 0; capturefiles = g_ptr_array_new_with_free_func(g_free); sections = g_key_file_get_groups(kf, NULL); for (i = 0; sections[i]; i++) { if (!strcmp(sections[i], "version")) /* nothing really interesting in here yet */ continue; if (!strncmp(sections[i], "header", 6)) { /* device section */ sdi = NULL; enabled_probes = total_probes = 0; keys = g_key_file_get_keys(kf, sections[i], NULL, NULL); for (j = 0; keys[j]; j++) { val = g_key_file_get_string(kf, sections[i], keys[j], NULL); if (!strcmp(keys[j], "device mode")) { mode = strtoull(val, NULL, 10); } else if (!strcmp(keys[j], "capturefile")) { sdi = sr_dev_inst_new(mode, devcnt, SR_ST_ACTIVE, NULL, NULL, NULL); sdi->driver = &session_driver; if (devcnt == 0) /* first device, init the driver */ sdi->driver->init(NULL); sr_dev_open(sdi); sr_session_dev_add(sdi); sdi->driver->config_set(SR_CONF_SESSIONFILE, g_variant_new_bytestring(filename), sdi, NULL, NULL); sdi->driver->config_set(SR_CONF_CAPTUREFILE, g_variant_new_bytestring(val), sdi, NULL, NULL); g_ptr_array_add(capturefiles, val); } else if (!strcmp(keys[j], "samplerate")) { sr_parse_sizestring(val, &tmp_u64); sdi->driver->config_set(SR_CONF_SAMPLERATE, g_variant_new_uint64(tmp_u64), sdi, NULL, NULL); } else if (!strcmp(keys[j], "unitsize")) { tmp_u64 = strtoull(val, NULL, 10); sdi->driver->config_set(SR_CONF_CAPTURE_UNITSIZE, g_variant_new_uint64(tmp_u64), sdi, NULL, NULL); } else if (!strcmp(keys[j], "total samples")) { tmp_u64 = strtoull(val, NULL, 10); sdi->driver->config_set(SR_CONF_LIMIT_SAMPLES, g_variant_new_uint64(tmp_u64), sdi, NULL, NULL); } else if (!strcmp(keys[j], "hDiv")) { tmp_u64 = strtoull(val, NULL, 10); sdi->driver->config_set(SR_CONF_TIMEBASE, g_variant_new_uint64(tmp_u64), sdi, NULL, NULL); } else if (!strcmp(keys[j], "total probes")) { total_probes = strtoull(val, NULL, 10); sdi->driver->config_set(SR_CONF_CAPTURE_NUM_PROBES, g_variant_new_uint64(total_probes), sdi, NULL, NULL); channel_type = (mode == DSO) ? SR_CHANNEL_DSO : (mode == ANALOG) ? SR_CHANNEL_ANALOG : SR_CHANNEL_LOGIC; for (p = 0; p < total_probes; p++) { snprintf(probename, SR_MAX_PROBENAME_LEN, "%" PRIu64, p); if (!(probe = sr_channel_new(p, channel_type, FALSE, probename))) return SR_ERR; sdi->channels = g_slist_append(sdi->channels, probe); } } else if (!strncmp(keys[j], "probe", 5)) { if (!sdi) continue; enabled_probes++; tmp_u64 = strtoul(keys[j]+5, NULL, 10); /* sr_session_save() */ sr_dev_probe_name_set(sdi, tmp_u64, val); sr_dev_probe_enable(sdi, tmp_u64, TRUE); } else if (!strncmp(keys[j], "trigger", 7)) { probenum = strtoul(keys[j]+7, NULL, 10); sr_dev_trigger_set(sdi, probenum, val); } else if (!strncmp(keys[j], "enable", 6)) { probenum = strtoul(keys[j]+6, NULL, 10); tmp_u64 = strtoull(val, NULL, 10); if (probenum < g_slist_length(sdi->channels)) { probe = g_slist_nth(sdi->channels, probenum)->data; sdi->driver->config_set(SR_CONF_EN_CH, g_variant_new_boolean(tmp_u64), sdi, probe, NULL); } } else if (!strncmp(keys[j], "coupling", 8)) { probenum = strtoul(keys[j]+8, NULL, 10); tmp_u64 = strtoull(val, NULL, 10); if (probenum < g_slist_length(sdi->channels)) { probe = g_slist_nth(sdi->channels, probenum)->data; sdi->driver->config_set(SR_CONF_COUPLING, g_variant_new_byte(tmp_u64), sdi, probe, NULL); } } else if (!strncmp(keys[j], "vDiv", 4)) { probenum = strtoul(keys[j]+4, NULL, 10); tmp_u64 = strtoull(val, NULL, 10); if (probenum < g_slist_length(sdi->channels)) { probe = g_slist_nth(sdi->channels, probenum)->data; sdi->driver->config_set(SR_CONF_VDIV, g_variant_new_uint64(tmp_u64), sdi, probe, NULL); } } else if (!strncmp(keys[j], "vFactor", 7)) { probenum = strtoul(keys[j]+7, NULL, 10); tmp_u64 = strtoull(val, NULL, 10); if (probenum < g_slist_length(sdi->channels)) { probe = g_slist_nth(sdi->channels, probenum)->data; sdi->driver->config_set(SR_CONF_FACTOR, g_variant_new_uint64(tmp_u64), sdi, probe, NULL); } } else if (!strncmp(keys[j], "vPos", 4)) { probenum = strtoul(keys[j]+4, NULL, 10); tmp_double = strtod(val, NULL); if (probenum < g_slist_length(sdi->channels)) { probe = g_slist_nth(sdi->channels, probenum)->data; sdi->driver->config_set(SR_CONF_VPOS, g_variant_new_double(tmp_double), sdi, probe, NULL); } } else if (!strncmp(keys[j], "period", 6)) { probenum = strtoul(keys[j]+6, NULL, 10); tmp_u64 = strtoull(val, NULL, 10); if (probenum < g_slist_length(sdi->channels)) { probe = g_slist_nth(sdi->channels, probenum)->data; sdi->driver->config_set(SR_CONF_STATUS_PERIOD, g_variant_new_uint64(tmp_u64), sdi, probe, NULL); } } else if (!strncmp(keys[j], "pcnt", 4)) { probenum = strtoul(keys[j]+4, NULL, 10); tmp_u64 = strtoull(val, NULL, 10); if (probenum < g_slist_length(sdi->channels)) { probe = g_slist_nth(sdi->channels, probenum)->data; sdi->driver->config_set(SR_CONF_STATUS_PCNT, g_variant_new_uint64(tmp_u64), sdi, probe, NULL); } } else if (!strncmp(keys[j], "max", 3)) { probenum = strtoul(keys[j]+3, NULL, 10); tmp_u64 = strtoull(val, NULL, 10); if (probenum < g_slist_length(sdi->channels)) { probe = g_slist_nth(sdi->channels, probenum)->data; sdi->driver->config_set(SR_CONF_STATUS_MAX, g_variant_new_uint64(tmp_u64), sdi, probe, NULL); } } else if (!strncmp(keys[j], "min", 3)) { probenum = strtoul(keys[j]+3, NULL, 10); tmp_u64 = strtoull(val, NULL, 10); if (probenum < g_slist_length(sdi->channels)) { probe = g_slist_nth(sdi->channels, probenum)->data; sdi->driver->config_set(SR_CONF_STATUS_MIN, g_variant_new_uint64(tmp_u64), sdi, probe, NULL); } } } g_strfreev(keys); } devcnt++; } g_strfreev(sections); g_key_file_free(kf); return SR_OK; }
/** * Load the session from the specified filename. * * @param ctx The context in which to load the session. * @param filename The name of the session file to load. * @param session The session to load the file into. * * @retval SR_OK Success * @retval SR_ERR_MALLOC Memory allocation error * @retval SR_ERR_DATA Malformed session file * @retval SR_ERR This is not a session file */ SR_API int sr_session_load(struct sr_context *ctx, const char *filename, struct sr_session **session) { GKeyFile *kf; GPtrArray *capturefiles; struct zip *archive; struct zip_file *zf; struct zip_stat zs; struct sr_dev_inst *sdi; struct sr_channel *ch; int ret, i, j; uint64_t tmp_u64, total_channels, p; char **sections, **keys, *metafile, *val; char channelname[SR_MAX_CHANNELNAME_LEN + 1]; if ((ret = sr_sessionfile_check(filename)) != SR_OK) return ret; if (!(archive = zip_open(filename, 0, &ret))) return SR_ERR; if (zip_stat(archive, "metadata", 0, &zs) == -1) return SR_ERR; if (!(metafile = g_try_malloc(zs.size))) { sr_err("%s: metafile malloc failed", __func__); return SR_ERR_MALLOC; } zf = zip_fopen_index(archive, zs.index, 0); zip_fread(zf, metafile, zs.size); zip_fclose(zf); kf = g_key_file_new(); if (!g_key_file_load_from_data(kf, metafile, zs.size, 0, NULL)) { sr_dbg("Failed to parse metadata."); return SR_ERR; } if ((ret = sr_session_new(ctx, session)) != SR_OK) return ret; ret = SR_OK; capturefiles = g_ptr_array_new_with_free_func(g_free); sections = g_key_file_get_groups(kf, NULL); for (i = 0; sections[i] && ret == SR_OK; i++) { if (!strcmp(sections[i], "global")) /* nothing really interesting in here yet */ continue; if (!strncmp(sections[i], "device ", 7)) { /* device section */ sdi = NULL; keys = g_key_file_get_keys(kf, sections[i], NULL, NULL); for (j = 0; keys[j]; j++) { val = g_key_file_get_string(kf, sections[i], keys[j], NULL); if (!strcmp(keys[j], "capturefile")) { sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->driver = &session_driver; sdi->status = SR_ST_ACTIVE; if (!session_driver_initialized) { /* first device, init the driver */ session_driver_initialized = 1; sdi->driver->init(sdi->driver, NULL); } sr_dev_open(sdi); sr_session_dev_add(*session, sdi); (*session)->owned_devs = g_slist_append( (*session)->owned_devs, sdi); sdi->driver->config_set(SR_CONF_SESSIONFILE, g_variant_new_string(filename), sdi, NULL); sdi->driver->config_set(SR_CONF_CAPTUREFILE, g_variant_new_string(val), sdi, NULL); g_ptr_array_add(capturefiles, val); } else if (!strcmp(keys[j], "samplerate")) { if (!sdi) { ret = SR_ERR_DATA; break; } sr_parse_sizestring(val, &tmp_u64); sdi->driver->config_set(SR_CONF_SAMPLERATE, g_variant_new_uint64(tmp_u64), sdi, NULL); } else if (!strcmp(keys[j], "unitsize")) { if (!sdi) { ret = SR_ERR_DATA; break; } tmp_u64 = strtoull(val, NULL, 10); sdi->driver->config_set(SR_CONF_CAPTURE_UNITSIZE, g_variant_new_uint64(tmp_u64), sdi, NULL); } else if (!strcmp(keys[j], "total probes")) { if (!sdi) { ret = SR_ERR_DATA; break; } total_channels = strtoull(val, NULL, 10); sdi->driver->config_set(SR_CONF_NUM_LOGIC_CHANNELS, g_variant_new_uint64(total_channels), sdi, NULL); for (p = 0; p < total_channels; p++) { snprintf(channelname, SR_MAX_CHANNELNAME_LEN, "%" PRIu64, p); sr_channel_new(sdi, p, SR_CHANNEL_LOGIC, FALSE, channelname); } } else if (!strncmp(keys[j], "probe", 5)) { if (!sdi) { ret = SR_ERR_DATA; break; } tmp_u64 = strtoul(keys[j]+5, NULL, 10) - 1; ch = g_slist_nth_data(sdi->channels, tmp_u64); /* sr_session_save() */ sr_dev_channel_name_set(ch, val); sr_dev_channel_enable(ch, TRUE); } } g_strfreev(keys); } } g_strfreev(sections); g_key_file_free(kf); return ret; }
/** * Load the session from the specified filename. * * @param ctx The context in which to load the session. * @param filename The name of the session file to load. * @param session The session to load the file into. * * @retval SR_OK Success * @retval SR_ERR_MALLOC Memory allocation error * @retval SR_ERR_DATA Malformed session file * @retval SR_ERR This is not a session file */ SR_API int sr_session_load(struct sr_context *ctx, const char *filename, struct sr_session **session) { GKeyFile *kf; GError *error; struct zip *archive; struct zip_stat zs; struct sr_dev_inst *sdi; struct sr_channel *ch; int ret, i, j; uint64_t tmp_u64; int total_channels, k; int unitsize; char **sections, **keys, *val; char channelname[SR_MAX_CHANNELNAME_LEN + 1]; if ((ret = sr_sessionfile_check(filename)) != SR_OK) return ret; if (!(archive = zip_open(filename, 0, NULL))) return SR_ERR; if (zip_stat(archive, "metadata", 0, &zs) < 0) { zip_discard(archive); return SR_ERR; } kf = sr_sessionfile_read_metadata(archive, &zs); zip_discard(archive); if (!kf) return SR_ERR_DATA; if ((ret = sr_session_new(ctx, session)) != SR_OK) { g_key_file_free(kf); return ret; } error = NULL; ret = SR_OK; sections = g_key_file_get_groups(kf, NULL); for (i = 0; sections[i] && ret == SR_OK; i++) { if (!strcmp(sections[i], "global")) /* nothing really interesting in here yet */ continue; if (!strncmp(sections[i], "device ", 7)) { /* device section */ sdi = NULL; keys = g_key_file_get_keys(kf, sections[i], NULL, NULL); for (j = 0; keys[j]; j++) { if (!strcmp(keys[j], "capturefile")) { val = g_key_file_get_string(kf, sections[i], keys[j], &error); if (!val) { ret = SR_ERR_DATA; break; } sdi = g_malloc0(sizeof(struct sr_dev_inst)); sdi->driver = &session_driver; sdi->status = SR_ST_ACTIVE; if (!session_driver_initialized) { /* first device, init the driver */ session_driver_initialized = 1; sdi->driver->init(sdi->driver, NULL); } sr_dev_open(sdi); sr_session_dev_add(*session, sdi); (*session)->owned_devs = g_slist_append( (*session)->owned_devs, sdi); sr_config_set(sdi, NULL, SR_CONF_SESSIONFILE, g_variant_new_string(filename)); sr_config_set(sdi, NULL, SR_CONF_CAPTUREFILE, g_variant_new_string(val)); g_free(val); } else if (!strcmp(keys[j], "samplerate")) { val = g_key_file_get_string(kf, sections[i], keys[j], &error); if (!sdi || !val || sr_parse_sizestring(val, &tmp_u64) != SR_OK) { g_free(val); ret = SR_ERR_DATA; break; } g_free(val); sr_config_set(sdi, NULL, SR_CONF_SAMPLERATE, g_variant_new_uint64(tmp_u64)); } else if (!strcmp(keys[j], "unitsize")) { unitsize = g_key_file_get_integer(kf, sections[i], keys[j], &error); if (!sdi || unitsize <= 0 || error) { ret = SR_ERR_DATA; break; } sr_config_set(sdi, NULL, SR_CONF_CAPTURE_UNITSIZE, g_variant_new_uint64(unitsize)); } else if (!strcmp(keys[j], "total probes")) { total_channels = g_key_file_get_integer(kf, sections[i], keys[j], &error); if (!sdi || total_channels < 0 || error) { ret = SR_ERR_DATA; break; } sr_config_set(sdi, NULL, SR_CONF_NUM_LOGIC_CHANNELS, g_variant_new_int32(total_channels)); for (k = 0; k < total_channels; k++) { g_snprintf(channelname, sizeof channelname, "%d", k); sr_channel_new(sdi, k, SR_CHANNEL_LOGIC, 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) { ret = SR_ERR_DATA; break; } ch = g_slist_nth_data(sdi->channels, tmp_u64 - 1); 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); } } g_strfreev(sections); g_key_file_free(kf); if (error) { sr_err("Failed to parse metadata: %s", error->message); g_error_free(error); } return ret; }
void show_dev_detail(void) { struct sr_dev_inst *sdi; const struct sr_config_info *srci; struct sr_channel *ch; struct sr_channel_group *channel_group, *cg; GSList *devices, *cgl, *chl; GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar; gsize num_opts, num_elements; double dlow, dhigh, dcur_low, dcur_high; const uint64_t *uint64, p, q, low, high; uint64_t cur_low, cur_high; const int32_t *int32, *opts; unsigned int num_devices, o, i; char *tmp_str; char *s, c; const char **stropts; if (!(devices = device_scan())) { g_critical("No devices found."); return; } num_devices = g_slist_length(devices); if (num_devices > 1) { g_critical("%d devices found. Use --scan to show them, " "and select one to show.", num_devices); return; } sdi = devices->data; print_dev_line(sdi); if (sr_dev_open(sdi) != SR_OK) { g_critical("Failed to open device."); return; } if ((sr_config_list(sdi->driver, NULL, NULL, SR_CONF_SCAN_OPTIONS, &gvar_opts) == SR_OK)) { opts = g_variant_get_fixed_array(gvar_opts, &num_elements, sizeof(int32_t)); printf("Supported driver options:\n"); for (i = 0; i < num_elements; i++) { if (!(srci = sr_config_info_get(opts[i]))) continue; printf(" %s\n", srci->id); } g_variant_unref(gvar_opts); } /* Selected channels and channel group may affect which options are * returned, or which values for them. */ select_channels(sdi); channel_group = select_channel_group(sdi); if ((sr_config_list(sdi->driver, sdi, channel_group, SR_CONF_DEVICE_OPTIONS, &gvar_opts)) != SR_OK) /* Driver supports no device instance options. */ return; if (sdi->channel_groups) { printf("Channel groups:\n"); for (cgl = sdi->channel_groups; cgl; cgl = cgl->next) { cg = cgl->data; printf(" %s: channel%s", cg->name, g_slist_length(cg->channels) > 1 ? "s" : ""); for (chl = cg->channels; chl; chl = chl->next) { ch = chl->data; printf(" %s", ch->name); } printf("\n"); } } printf("Supported configuration options"); if (sdi->channel_groups) { if (!channel_group) printf(" across all channel groups"); else printf(" on channel group %s", channel_group->name); } printf(":\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]))) continue; if (srci->key == SR_CONF_TRIGGER_MATCH) { if (sr_config_list(sdi->driver, sdi, channel_group, srci->key, &gvar_list) != SR_OK) { printf("\n"); continue; } int32 = g_variant_get_fixed_array(gvar_list, &num_elements, sizeof(int32_t)); printf(" Supported triggers: "); for (i = 0; i < num_elements; i++) { switch(int32[i]) { case SR_TRIGGER_ZERO: c = '0'; break; case SR_TRIGGER_ONE: c = '1'; break; case SR_TRIGGER_RISING: c = 'r'; break; case SR_TRIGGER_FALLING: c = 'f'; break; case SR_TRIGGER_EDGE: c = 'e'; break; case SR_TRIGGER_OVER: c = 'o'; break; case SR_TRIGGER_UNDER: c = 'u'; break; default: c = 0; break; } if (c) printf("%c ", c); } printf("\n"); g_variant_unref(gvar_list); } else if (srci->key == SR_CONF_LIMIT_SAMPLES) { /* If implemented in config_list(), this denotes the * maximum number of samples a device can send. This * really applies only to logic analyzers, and then * only to those that don't support compression, or * have it turned off by default. The values returned * are the low/high limits. */ if (sr_config_list(sdi->driver, sdi, channel_group, srci->key, &gvar) != SR_OK) { continue; } g_variant_get(gvar, "(tt)", &low, &high); g_variant_unref(gvar); printf(" Maximum number of samples: %"PRIu64"\n", high); } else if (srci->key == SR_CONF_SAMPLERATE) { /* Supported samplerates */ printf(" %s", srci->id); if (sr_config_list(sdi->driver, sdi, channel_group, SR_CONF_SAMPLERATE, &gvar_dict) != SR_OK) { printf("\n"); continue; } if ((gvar_list = g_variant_lookup_value(gvar_dict, "samplerates", G_VARIANT_TYPE("at")))) { uint64 = g_variant_get_fixed_array(gvar_list, &num_elements, sizeof(uint64_t)); printf(" - supported samplerates:\n"); 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)); /* low */ if (!(s = sr_samplerate_string(uint64[0]))) continue; printf(" (%s", s); g_free(s); /* high */ if (!(s = sr_samplerate_string(uint64[1]))) continue; printf(" - %s", s); g_free(s); /* step */ 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); } else if (srci->key == SR_CONF_BUFFERSIZE) { /* Supported buffer sizes */ printf(" %s", srci->id); if (sr_config_list(sdi->driver, sdi, channel_group, SR_CONF_BUFFERSIZE, &gvar_list) != 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; 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, sdi, channel_group, SR_CONF_TIMEBASE, &gvar_list) != SR_OK) { printf("\n"); continue; } printf(" - supported time bases:\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)", &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_VDIV) { /* Supported volts/div values */ printf(" %s", srci->id); if (sr_config_list(sdi->driver, sdi, channel_group, SR_CONF_VDIV, &gvar_list) != SR_OK) { printf("\n"); continue; } printf(" - supported volts/div:\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)", &p, &q); s = sr_voltage_string(p, q); printf(" %s\n", s); g_free(s); } g_variant_unref(gvar_list); } else if (srci->datatype == SR_T_STRING) { printf(" %s: ", srci->id); if (sr_config_get(sdi->driver, sdi, channel_group, srci->key, &gvar) == 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, sdi, channel_group, srci->key, &gvar) != SR_OK) { printf("\n"); continue; } stropts = g_variant_get_strv(gvar, &num_elements); 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->datatype == SR_T_UINT64_RANGE) { printf(" %s: ", srci->id); if (sr_config_list(sdi->driver, sdi, channel_group, srci->key, &gvar_list) != SR_OK) { printf("\n"); continue; } if (sr_config_get(sdi->driver, sdi, NULL, srci->key, &gvar) == SR_OK) { g_variant_get(gvar, "(tt)", &cur_low, &cur_high); g_variant_unref(gvar); } else { cur_low = 0; cur_high = 0; } 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, sdi, NULL, srci->key, &gvar) == 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 if (srci->datatype == SR_T_DOUBLE_RANGE) { printf(" %s: ", srci->id); if (sr_config_list(sdi->driver, sdi, channel_group, srci->key, &gvar_list) != SR_OK) { printf("\n"); continue; } if (sr_config_get(sdi->driver, sdi, NULL, srci->key, &gvar) == SR_OK) { g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high); g_variant_unref(gvar); } else { dcur_low = 0; dcur_high = 0; } 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, "(dd)", &dlow, &dhigh); g_variant_unref(gvar); if (i) printf(", "); printf("%.1f-%.1f", dlow, dhigh); if (dlow == dcur_low && dhigh == dcur_high) printf(" (current)"); } printf("\n"); g_variant_unref(gvar_list); } else { /* Everything else */ printf(" %s\n", srci->id); } } g_variant_unref(gvar_opts); sr_dev_close(sdi); g_slist_free(devices); }