X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=sigrok-cli.c;h=2aec20593269085241b28ccfb5ab9c205030e597;hp=1627522d27748efc18e3adb3a7d9891e0412a897;hb=e2dd5a767b7ac36614ecb626216fcce6ebe22585;hpb=b921027525e5dbde831dfde9b0793b2afff3854d diff --git a/sigrok-cli.c b/sigrok-cli.c index 1627522..2aec205 100644 --- a/sigrok-cli.c +++ b/sigrok-cli.c @@ -58,25 +58,25 @@ static gchar *opt_triggers = NULL; static gchar *opt_pds = NULL; static gchar *opt_pd_stack = NULL; static gchar *opt_input_format = NULL; -static gchar *opt_format = NULL; +static gchar *opt_output_format = NULL; static gchar *opt_time = NULL; static gchar *opt_samples = NULL; static gchar *opt_continuous = NULL; static GOptionEntry optargs[] = { {"version", 'V', 0, G_OPTION_ARG_NONE, &opt_version, "Show version and support list", NULL}, - {"loglevel", 'l', 0, G_OPTION_ARG_INT, &opt_loglevel, "Select libsigrok loglevel", NULL}, - {"list-devices", 'D', 0, G_OPTION_ARG_NONE, &opt_list_devs, "List devices", NULL}, + {"loglevel", 'l', 0, G_OPTION_ARG_INT, &opt_loglevel, "Select libsigrok/libsigrokdecode loglevel", NULL}, + {"list-devices", 'D', 0, G_OPTION_ARG_NONE, &opt_list_devs, "Scan for devices", NULL}, + {"device", 'd', 0, G_OPTION_ARG_STRING, &opt_dev, "Use specified device", NULL}, {"input-file", 'i', 0, G_OPTION_ARG_FILENAME, &opt_input_file, "Load input from file", NULL}, + {"input-format", 'I', 0, G_OPTION_ARG_STRING, &opt_input_format, "Input format", NULL}, {"output-file", 'o', 0, G_OPTION_ARG_FILENAME, &opt_output_file, "Save output to file", NULL}, - {"device", 'd', 0, G_OPTION_ARG_STRING, &opt_dev, "Use device ID", NULL}, + {"output-format", 'O', 0, G_OPTION_ARG_STRING, &opt_output_format, "Output format", NULL}, {"probes", 'p', 0, G_OPTION_ARG_STRING, &opt_probes, "Probes to use", NULL}, {"triggers", 't', 0, G_OPTION_ARG_STRING, &opt_triggers, "Trigger configuration", NULL}, {"wait-trigger", 'w', 0, G_OPTION_ARG_NONE, &opt_wait_trigger, "Wait for trigger", NULL}, - {"protocol-decoders", 'a', 0, G_OPTION_ARG_STRING, &opt_pds, "Protocol decoder sequence", NULL}, + {"protocol-decoders", 'a', 0, G_OPTION_ARG_STRING, &opt_pds, "Protocol decoders to run", NULL}, {"protocol-decoder-stack", 's', 0, G_OPTION_ARG_STRING, &opt_pd_stack, "Protocol decoder stack", NULL}, - {"input-format", 'I', 0, G_OPTION_ARG_STRING, &opt_input_format, "Input format", NULL}, - {"format", 'f', 0, G_OPTION_ARG_STRING, &opt_format, "Output format", NULL}, {"time", 0, 0, G_OPTION_ARG_STRING, &opt_time, "How long to sample (ms)", NULL}, {"samples", 0, 0, G_OPTION_ARG_STRING, &opt_samples, "Number of samples to acquire", NULL}, {"continuous", 0, 0, G_OPTION_ARG_NONE, &opt_continuous, "Sample continuously", NULL}, @@ -85,8 +85,8 @@ static GOptionEntry optargs[] = { static void show_version(void) { - GSList *plugins, *p, *l; - struct sr_dev_plugin *plugin; + GSList *l; + struct sr_dev_driver **drivers; struct sr_input_format **inputs; struct sr_output_format **outputs; struct srd_decoder *dec; @@ -94,11 +94,15 @@ static void show_version(void) printf("sigrok-cli %s\n\n", VERSION); + printf("Using libsigrok %s (lib version %s).\n", + sr_package_version_string_get(), sr_lib_version_string_get()); + printf("Using libsigrokdecode %s (lib version %s).\n\n", + srd_package_version_string_get(), srd_lib_version_string_get()); + printf("Supported hardware drivers:\n"); - plugins = sr_hw_list(); - for (p = plugins; p; p = p->next) { - plugin = p->data; - printf(" %-20s %s\n", plugin->name, plugin->longname); + drivers = sr_driver_list(); + for (i = 0; drivers[i]; i++) { + printf(" %-20s %s\n", drivers[i]->name, drivers[i]->longname); } printf("\n"); @@ -116,8 +120,8 @@ static void show_version(void) if (srd_init(NULL) == SRD_OK) { printf("Supported protocol decoders:\n"); - srd_decoders_load_all(); - for (l = srd_decoders_list(); l; l = l->next) { + srd_decoder_load_all(); + for (l = srd_decoder_list(); l; l = l->next) { dec = l->data; printf(" %-20s %s\n", dec->id, dec->longname); } @@ -178,7 +182,7 @@ static void show_dev_detail(void) struct sr_dev *dev; struct sr_hwcap_option *hwo; const struct sr_samplerates *samplerates; - int cap, *capabilities, i; + int cap, *hwcaps, i; char *s, *title; const char *charopts, **stropts; @@ -201,9 +205,9 @@ static void show_dev_detail(void) } title = "Supported options:\n"; - capabilities = dev->plugin->get_capabilities(); - for (cap = 0; capabilities[cap]; cap++) { - if (!(hwo = sr_hw_hwcap_get(capabilities[cap]))) + hwcaps = dev->driver->hwcap_get_all(); + for (cap = 0; hwcaps[cap]; cap++) { + if (!(hwo = sr_hw_hwcap_get(hwcaps[cap]))) continue; if (title) { @@ -211,17 +215,17 @@ static void show_dev_detail(void) title = NULL; } - if (hwo->capability == SR_HWCAP_PATTERN_MODE) { + if (hwo->hwcap == SR_HWCAP_PATTERN_MODE) { printf(" %s", hwo->shortname); - if (sr_dev_info_get(dev, SR_DI_PATTERNMODES, + if (sr_dev_info_get(dev, SR_DI_PATTERNS, (const void **)&stropts) == SR_OK) { - printf(" - supported modes:\n"); + printf(" - supported patterns:\n"); for (i = 0; stropts[i]; i++) printf(" %s\n", stropts[i]); } else { printf("\n"); } - } else if (hwo->capability == SR_HWCAP_SAMPLERATE) { + } else if (hwo->hwcap == SR_HWCAP_SAMPLERATE) { printf(" %s", hwo->shortname); /* Supported samplerates */ if (sr_dev_info_get(dev, SR_DI_SAMPLERATES, @@ -249,7 +253,7 @@ static void show_dev_detail(void) } else { printf(" - supported samplerates:\n"); for (i = 0; samplerates->list[i]; i++) { - printf(" %7s\n", sr_samplerate_string(samplerates->list[i])); + printf(" %s\n", sr_samplerate_string(samplerates->list[i])); } } } else { @@ -280,7 +284,7 @@ static void show_pd_detail(void) printf("- %s\n %s\n", ann[0], ann[1]); } } - if ((doc = srd_decoder_doc(dec))) { + if ((doc = srd_decoder_doc_get(dec))) { printf("Documentation:\n%s\n", doc[0] == '\n' ? doc+1 : doc); g_free(doc); } @@ -293,7 +297,7 @@ static void show_pd_detail(void) static void datafeed_in(struct sr_dev *dev, struct sr_datafeed_packet *packet) { static struct sr_output *o = NULL; - static int probelist[SR_MAX_NUM_PROBES] = { 0 }; + static int probelist[SR_MAX_NUM_PROBES + 1] = { 0 }; static uint64_t received_samples = 0; static int unitsize = 0; static int triggered = 0; @@ -303,7 +307,7 @@ static void datafeed_in(struct sr_dev *dev, struct sr_datafeed_packet *packet) struct sr_datafeed_logic *logic; int num_enabled_probes, sample_size, ret, i; uint64_t output_len, filter_out_len; - char *output_buf, *filter_out; + uint8_t *output_buf, *filter_out; /* If the first packet to come in isn't a header, don't even try. */ if (packet->type != SR_DF_HEADER && o == NULL) @@ -352,7 +356,7 @@ static void datafeed_in(struct sr_dev *dev, struct sr_datafeed_packet *packet) } } else { /* saving to a file in whatever format was set - * with --format, so all we need is a filehandle */ + * with -O, so all we need is a filehandle */ outfile = g_fopen(opt_output_file, "wb"); } } @@ -439,7 +443,7 @@ static void datafeed_in(struct sr_dev *dev, struct sr_datafeed_packet *packet) goto cleanup; if (opt_pds) { - if (srd_session_feed(received_samples, (uint8_t*)filter_out, + if (srd_session_send(received_samples, (uint8_t*)filter_out, filter_out_len) != SRD_OK) sr_session_halt(); } else { @@ -499,7 +503,7 @@ static int register_pds(struct sr_dev *dev, const char *pdstring) * is the probe name as specified in the decoder class, and the * value is the probe number i.e. the order in which the PD's * incoming samples are arranged. */ - if (srd_inst_probes_set(di, pd_opthash) != SRD_OK) + if (srd_inst_probe_set_all(di, pd_opthash) != SRD_OK) goto err_out; g_hash_table_destroy(pd_opthash); pd_opthash = NULL; @@ -515,13 +519,13 @@ err_out: return 0; } -void show_pd_annotation(struct srd_proto_data *pdata, void *user_data) +void show_pd_annotation(struct srd_proto_data *pdata, void *cb_data) { int i; char **annotations; - /* 'user_data' is not used in this specific callback. */ - (void)user_data; + /* 'cb_data' is not used in this specific callback. */ + (void)cb_data; if (pdata->ann_format != 0) { /* CLI only shows the default annotation format. */ @@ -564,7 +568,7 @@ static int select_probes(struct sr_dev *dev) for (i = 0; i < max_probes; i++) { if (probelist[i]) { - sr_dev_probe_name(dev, i + 1, probelist[i]); + sr_dev_probe_name_set(dev, i + 1, probelist[i]); g_free(probelist[i]); } else { probe = sr_dev_probe_find(dev, i + 1); @@ -733,7 +737,7 @@ static int set_dev_options(struct sr_dev *dev, GHashTable *args) g_hash_table_iter_init(&iter, args); while (g_hash_table_iter_next(&iter, &key, &value)) { found = FALSE; - for (i = 0; sr_hwcap_options[i].capability; i++) { + for (i = 0; sr_hwcap_options[i].hwcap; i++) { if (strcmp(sr_hwcap_options[i].shortname, key)) continue; if ((value == NULL) && @@ -747,20 +751,20 @@ static int set_dev_options(struct sr_dev *dev, GHashTable *args) ret = sr_parse_sizestring(value, &tmp_u64); if (ret != SR_OK) break; - ret = dev->plugin->set_configuration(dev->plugin_index, - sr_hwcap_options[i].capability, &tmp_u64); + ret = dev->driver->dev_config_set(dev->driver_index, + sr_hwcap_options[i].hwcap, &tmp_u64); break; case SR_T_CHAR: - ret = dev->plugin->set_configuration(dev->plugin_index, - sr_hwcap_options[i].capability, value); + ret = dev->driver->dev_config_set(dev->driver_index, + sr_hwcap_options[i].hwcap, value); break; case SR_T_BOOL: if (!value) tmp_bool = TRUE; else tmp_bool = sr_parse_boolstring(value); - ret = dev->plugin->set_configuration(dev->plugin_index, - sr_hwcap_options[i].capability, + ret = dev->driver->dev_config_set(dev->driver_index, + sr_hwcap_options[i].hwcap, GINT_TO_POINTER(tmp_bool)); break; default: @@ -837,7 +841,7 @@ static void run_session(void) return; if (opt_continuous) { - if (!sr_hw_has_hwcap(dev->plugin, SR_HWCAP_CONTINUOUS)) { + if (!sr_driver_hwcap_exists(dev->driver, SR_HWCAP_CONTINUOUS)) { printf("This device does not support continuous sampling."); sr_session_destroy(); return; @@ -869,9 +873,9 @@ static void run_session(void) return; } - if (sr_hw_has_hwcap(dev->plugin, SR_HWCAP_LIMIT_MSEC)) { - if (dev->plugin->set_configuration(dev->plugin_index, - SR_HWCAP_LIMIT_MSEC, &time_msec) != SR_OK) { + 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) { printf("Failed to configure time limit.\n"); sr_session_destroy(); return; @@ -895,8 +899,8 @@ static void run_session(void) return; } - if (dev->plugin->set_configuration(dev->plugin_index, - SR_HWCAP_LIMIT_SAMPLES, &limit_samples) != SR_OK) { + if (dev->driver->dev_config_set(dev->driver_index, + SR_HWCAP_LIMIT_SAMPLES, &limit_samples) != SR_OK) { printf("Failed to configure time-based sample limit.\n"); sr_session_destroy(); return; @@ -906,15 +910,15 @@ static void run_session(void) if (opt_samples) { if ((sr_parse_sizestring(opt_samples, &limit_samples) != SR_OK) - || (dev->plugin->set_configuration(dev->plugin_index, - SR_HWCAP_LIMIT_SAMPLES, &limit_samples) != SR_OK)) { + || (dev->driver->dev_config_set(dev->driver_index, + SR_HWCAP_LIMIT_SAMPLES, &limit_samples) != SR_OK)) { printf("Failed to configure sample limit.\n"); sr_session_destroy(); return; } } - if (dev->plugin->set_configuration(dev->plugin_index, + 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(); @@ -944,11 +948,11 @@ static void run_session(void) } static void logger(const gchar *log_domain, GLogLevelFlags log_level, - const gchar *message, gpointer user_data) + const gchar *message, gpointer cb_data) { /* Avoid compiler warnings. */ (void)log_domain; - (void)user_data; + (void)cb_data; /* * All messages, warnings, errors etc. go to stderr (not stdout) in @@ -1017,7 +1021,7 @@ int main(int argc, char **argv) printf("Failed to register protocol decoders\n"); return 1; } - if (srd_register_callback(SRD_OUTPUT_ANN, + if (srd_pd_output_callback_add(SRD_OUTPUT_ANN, show_pd_annotation, NULL) != SRD_OK) { printf("Failed to register protocol decoder callback\n"); return 1; @@ -1040,7 +1044,7 @@ int main(int argc, char **argv) printf("Cannot stack protocol decoder '%s': instance not found.\n", pds[i]); return 1; } - if ((ret = srd_inst_stack(di_from, di_to) != SRD_OK)) + if ((ret = srd_inst_stack(di_from, di_to)) != SRD_OK) return ret; /* Don't show annotation from this PD. Only the last PD in @@ -1053,14 +1057,14 @@ int main(int argc, char **argv) g_strfreev(pds); } - if (!opt_format) { - opt_format = DEFAULT_OUTPUT_FORMAT; + if (!opt_output_format) { + opt_output_format = DEFAULT_OUTPUT_FORMAT; /* we'll need to remember this so when saving to a file * later, sigrok session format will be used. */ default_output_format = TRUE; } - fmtargs = parse_generic_arg(opt_format); + fmtargs = parse_generic_arg(opt_output_format); fmtspec = g_hash_table_lookup(fmtargs, "sigrok_key"); if (!fmtspec) { printf("Invalid output format.\n"); @@ -1082,7 +1086,7 @@ int main(int argc, char **argv) break; } if (!output_format) { - printf("invalid output format %s\n", opt_format); + printf("invalid output format %s\n", opt_output_format); return 1; }