static void show_dev_list(void) { struct sr_dev *dev, *demo_dev; GSList *devs, *l; int devcnt; devcnt = 0; devs = sr_dev_list(); if (g_slist_length(devs) == 0) return; printf("The following devices were found:\nID Device\n"); demo_dev = NULL; for (l = devs; l; l = l->next) { dev = l->data; if (sr_dev_has_hwcap(dev, SR_HWCAP_DEMO_DEV)) { demo_dev = dev; continue; } printf("%-3d ", devcnt++); print_dev_line(dev); } if (demo_dev) { printf("demo "); print_dev_line(demo_dev); } }
int num_real_devs(void) { struct sr_dev *dev; GSList *devs, *l; int num_devs; num_devs = 0; devs = sr_dev_list(); for (l = devs; l; l = l->next) { dev = l->data; if (!sr_dev_has_hwcap(dev, SR_HWCAP_DEMO_DEV)) num_devs++; } return num_devs; }
static int init(struct sr_output *o) { struct context *ctx; struct sr_probe *probe; GSList *l; uint64_t *samplerate, tmp; int num_enabled_probes; if (!(ctx = g_try_malloc(sizeof(struct context)))) { sr_err("%s: ctx malloc failed", __func__); return SR_ERR_MALLOC; } o->internal = ctx; ctx->num_samples = 0; num_enabled_probes = 0; for (l = o->sdi->probes; l; l = l->next) { probe = l->data; if (probe->enabled) num_enabled_probes++; } ctx->unitsize = (num_enabled_probes + 7) / 8; if (o->sdi->driver && sr_dev_has_hwcap(o->sdi, SR_HWCAP_SAMPLERATE)) o->sdi->driver->info_get(SR_DI_CUR_SAMPLERATE, (const void **)&samplerate, o->sdi); else { tmp = 0; samplerate = &tmp; } ctx->header = g_string_sized_new(512); g_string_append_printf(ctx->header, ";Rate: %"PRIu64"\n", *samplerate); g_string_append_printf(ctx->header, ";Channels: %d\n", num_enabled_probes); g_string_append_printf(ctx->header, ";EnabledChannels: -1\n"); g_string_append_printf(ctx->header, ";Compressed: true\n"); g_string_append_printf(ctx->header, ";CursorEnabled: false\n"); return SR_OK; }
static void capture_run(GtkAction *action, GObject *parent) { (void)action; struct sr_dev *dev = g_object_get_data(G_OBJECT(parent), "dev"); GtkEntry *timesamples = g_object_get_data(parent, "timesamples"); GtkComboBox *timeunit = g_object_get_data(parent, "timeunit"); gint i = gtk_combo_box_get_active(timeunit); guint64 time_msec = 0; guint64 limit_samples = 0; switch (i) { case 0: /* Samples */ sr_parse_sizestring(gtk_entry_get_text(timesamples), &limit_samples); break; case 1: /* Milliseconds */ time_msec = strtoull(gtk_entry_get_text(timesamples), NULL, 10); break; case 2: /* Seconds */ time_msec = strtoull(gtk_entry_get_text(timesamples), NULL, 10) * 1000; break; } if (time_msec) { if (sr_driver_hwcap_exists(dev->driver, SR_HWCAP_LIMIT_MSEC)) { if (dev->driver->dev_config_set(dev->driver_index, SR_HWCAP_LIMIT_MSEC, &time_msec) != SR_OK) { g_critical("Failed to configure time limit."); sr_session_destroy(); return; } } else { /* time limit set, but device doesn't support this... * convert to samples based on the samplerate. */ limit_samples = 0; if (sr_dev_has_hwcap(dev, SR_HWCAP_SAMPLERATE)) { guint64 tmp_u64; tmp_u64 = *((uint64_t *)dev->driver->dev_info_get( dev->driver_index, SR_DI_CUR_SAMPLERATE)); limit_samples = tmp_u64 * time_msec / (uint64_t) 1000; } if (limit_samples == 0) { g_critical("Not enough time at this samplerate."); return; } if (dev->driver->dev_config_set(dev->driver_index, SR_HWCAP_LIMIT_SAMPLES, &limit_samples) != SR_OK) { g_critical("Failed to configure time-based sample limit."); return; } } } if (limit_samples) { if (dev->driver->dev_config_set(dev->driver_index, SR_HWCAP_LIMIT_SAMPLES, &limit_samples) != SR_OK) { g_critical("Failed to configure sample limit."); return; } } if (dev->driver->dev_config_set(dev->driver_index, SR_HWCAP_PROBECONFIG, (char *)dev->probes) != SR_OK) { printf("Failed to configure probes.\n"); sr_session_destroy(); return; } if (sr_session_start() != SR_OK) { g_critical("Failed to start session."); return; } sr_session_run(); }
SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode) { struct context *ctx; struct sr_probe *probe; GSList *l; uint64_t samplerate; int num_probes; char *samplerate_s; if (!(ctx = g_try_malloc0(sizeof(struct context)))) { sr_err("text out: %s: ctx malloc failed", __func__); return SR_ERR_MALLOC; } o->internal = ctx; ctx->num_enabled_probes = 0; for (l = o->dev->probes; l; l = l->next) { probe = l->data; if (!probe->enabled) continue; ctx->probelist[ctx->num_enabled_probes++] = probe->name; } ctx->probelist[ctx->num_enabled_probes] = 0; ctx->unitsize = (ctx->num_enabled_probes + 7) / 8; ctx->line_offset = 0; ctx->spl_cnt = 0; ctx->mark_trigger = -1; ctx->mode = mode; if (o->param && o->param[0]) { ctx->samples_per_line = strtoul(o->param, NULL, 10); if (ctx->samples_per_line < 1) return SR_ERR; } else ctx->samples_per_line = default_spl; if (!(ctx->header = g_try_malloc0(512))) { g_free(ctx); sr_err("text out: %s: ctx->header malloc failed", __func__); return SR_ERR_MALLOC; } snprintf(ctx->header, 511, "%s\n", PACKAGE_STRING); num_probes = g_slist_length(o->dev->probes); if (o->dev->driver || sr_dev_has_hwcap(o->dev, SR_HWCAP_SAMPLERATE)) { samplerate = *((uint64_t *) o->dev->driver->dev_info_get( o->dev->driver_index, SR_DI_CUR_SAMPLERATE)); if (!(samplerate_s = sr_samplerate_string(samplerate))) { g_free(ctx->header); g_free(ctx); return SR_ERR; } snprintf(ctx->header + strlen(ctx->header), 511 - strlen(ctx->header), "Acquisition with %d/%d probes at %s\n", ctx->num_enabled_probes, num_probes, samplerate_s); g_free(samplerate_s); } ctx->linebuf_len = ctx->samples_per_line * 2 + 4; if (!(ctx->linebuf = g_try_malloc0(num_probes * ctx->linebuf_len))) { g_free(ctx->header); g_free(ctx); sr_err("text out: %s: ctx->linebuf malloc failed", __func__); return SR_ERR_MALLOC; } if (!(ctx->linevalues = g_try_malloc0(num_probes))) { g_free(ctx->header); g_free(ctx); sr_err("text out: %s: ctx->linevalues malloc failed", __func__); return SR_ERR_MALLOC; } return SR_OK; }
static void run_session(void) { struct sr_dev *dev; GHashTable *devargs; int num_devs, max_probes, i; uint64_t time_msec; char **probelist, *devspec; devargs = NULL; if (opt_dev) { devargs = parse_generic_arg(opt_dev); devspec = g_hash_table_lookup(devargs, "sigrok_key"); dev = parse_devstring(devspec); if (!dev) { g_critical("Device not found."); return; } g_hash_table_remove(devargs, "sigrok_key"); } else { num_devs = num_real_devs(); if (num_devs == 1) { /* No device specified, but there is only one. */ devargs = NULL; dev = parse_devstring("0"); } else if (num_devs == 0) { g_critical("No devices found."); return; } else { g_critical("%d devices found, please select one.", num_devs); return; } } sr_session_new(); sr_session_datafeed_callback_add(datafeed_in); if (sr_session_dev_add(dev) != SR_OK) { g_critical("Failed to use device."); sr_session_destroy(); return; } if (devargs) { if (set_dev_options(dev, devargs) != SR_OK) { sr_session_destroy(); return; } g_hash_table_destroy(devargs); } if (select_probes(dev) != SR_OK) return; if (opt_continuous) { if (!sr_driver_hwcap_exists(dev->driver, SR_HWCAP_CONTINUOUS)) { g_critical("This device does not support continuous sampling."); sr_session_destroy(); return; } } if (opt_triggers) { probelist = sr_parse_triggerstring(dev, opt_triggers); if (!probelist) { sr_session_destroy(); return; } max_probes = g_slist_length(dev->probes); for (i = 0; i < max_probes; i++) { if (probelist[i]) { sr_dev_trigger_set(dev, i + 1, probelist[i]); g_free(probelist[i]); } } g_free(probelist); } if (opt_time) { time_msec = sr_parse_timestring(opt_time); if (time_msec == 0) { g_critical("Invalid time '%s'", opt_time); sr_session_destroy(); return; } if (sr_driver_hwcap_exists(dev->driver, SR_HWCAP_LIMIT_MSEC)) { if (dev->driver->dev_config_set(dev->driver_index, SR_HWCAP_LIMIT_MSEC, &time_msec) != SR_OK) { g_critical("Failed to configure time limit."); sr_session_destroy(); return; } } else { /* time limit set, but device doesn't support this... * convert to samples based on the samplerate. */ limit_samples = 0; if (sr_dev_has_hwcap(dev, SR_HWCAP_SAMPLERATE)) { const uint64_t *samplerate; sr_dev_info_get(dev, SR_DI_CUR_SAMPLERATE, (const void **)&samplerate); limit_samples = (*samplerate) * time_msec / (uint64_t)1000; } if (limit_samples == 0) { g_critical("Not enough time at this samplerate."); sr_session_destroy(); return; } if (dev->driver->dev_config_set(dev->driver_index, SR_HWCAP_LIMIT_SAMPLES, &limit_samples) != SR_OK) { g_critical("Failed to configure time-based sample limit."); sr_session_destroy(); return; } } } if (opt_samples) { if ((sr_parse_sizestring(opt_samples, &limit_samples) != SR_OK) || (dev->driver->dev_config_set(dev->driver_index, SR_HWCAP_LIMIT_SAMPLES, &limit_samples) != 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) || (dev->driver->dev_config_set(dev->driver_index, SR_HWCAP_LIMIT_FRAMES, &limit_frames) != SR_OK)) { printf("Failed to configure frame limit.\n"); sr_session_destroy(); return; } } if (dev->driver->dev_config_set(dev->driver_index, SR_HWCAP_PROBECONFIG, (char *)dev->probes) != SR_OK) { g_critical("Failed to configure probes."); 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(); if (opt_output_file && default_output_format) { if (sr_session_save(opt_output_file) != SR_OK) g_critical("Failed to save session."); } sr_session_destroy(); }