extern struct sr_hwcap_option sr_hwcap_options[];
-static gboolean debug = 0;
static uint64_t limit_samples = 0;
static struct sr_output_format *output_format = NULL;
static int default_output_format = FALSE;
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},
- {"output-format", 'O', 0, G_OPTION_ARG_STRING, &opt_output_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},
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");
drivers = sr_driver_list();
for (i = 0; drivers[i]; i++) {
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);
+ /* Print protocol description upon "-l 3" or higher. */
+ if (opt_loglevel >= SR_LOG_INFO)
+ printf(" %-20s %s\n", "", dec->desc);
}
srd_exit();
}
printf("\n");
-
}
static void print_dev_line(const struct sr_dev *dev)
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 {
GSList *l;
struct srd_decoder *dec;
char **pdtokens, **pdtok, **ann, *doc;
+ struct srd_probe *p;
pdtokens = g_strsplit(opt_pds, ",", -1);
for (pdtok = pdtokens; *pdtok; pdtok++) {
printf("ID: %s\nName: %s\nLong name: %s\nDescription: %s\n",
dec->id, dec->name, dec->longname, dec->desc);
printf("License: %s\n", dec->license);
+ printf("Annotations:\n");
if (dec->annotations) {
- printf("Annotations:\n");
for (l = dec->annotations; l; l = l->next) {
ann = l->data;
printf("- %s\n %s\n", ann[0], ann[1]);
}
+ } else {
+ printf("None.\n");
+ }
+ /* TODO: Print supported decoder options. */
+ printf("Required probes:\n");
+ if (dec->probes) {
+ for (l = dec->probes; l; l = l->next) {
+ p = l->data;
+ printf("- %s (%s): %s\n",
+ p->name, p->id, p->desc);
+ }
+ } else {
+ printf("None.\n");
+ }
+ printf("Optional probes:\n");
+ if (dec->opt_probes) {
+ for (l = dec->opt_probes; l; l = l->next) {
+ p = l->data;
+ printf("- %s (%s): %s\n",
+ p->name, p->id, p->desc);
+ }
+ } else {
+ printf("None.\n");
}
- if ((doc = srd_decoder_doc(dec))) {
- printf("Documentation:\n%s\n", doc[0] == '\n' ? doc+1 : doc);
+ if ((doc = srd_decoder_doc_get(dec))) {
+ printf("Documentation:\n%s\n",
+ doc[0] == '\n' ? doc + 1 : doc);
g_free(doc);
}
}
g_strfreev(pdtokens);
-
}
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;
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)
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 {
cleanup:
g_free(filter_out);
received_samples += logic->length / sample_size;
-
}
/* Register the given PDs for this session.
* 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;
for (i = 0; annotations[i]; i++)
printf("\"%s\" ", annotations[i]);
printf("\n");
-
}
static int select_probes(struct sr_dev *dev)
printf("Failed to save session.\n");
}
sr_session_destroy();
-
}
static void load_input_file(void)
/* fall back on input modules */
load_input_file_format();
}
-
}
int num_real_devs(void)
printf("Failed to save session.\n");
}
sr_session_destroy();
-
}
static void logger(const gchar *log_domain, GLogLevelFlags log_level,
* All messages, warnings, errors etc. go to stderr (not stdout) in
* order to not mess up the CLI tool data output, e.g. VCD output.
*/
- if (log_level & (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING)) {
+ if (log_level & (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_WARNING)
+ || opt_loglevel > SR_LOG_WARN) {
fprintf(stderr, "%s\n", message);
fflush(stderr);
- } else {
- if ((log_level & G_LOG_LEVEL_MESSAGE && debug == 1)
- || debug == 2) {
- printf("%s\n", message);
- fflush(stderr);
- }
}
}
char *fmtspec, **pds;
g_log_set_default_handler(logger, NULL);
- if (getenv("SIGROK_DEBUG"))
- debug = strtol(getenv("SIGROK_DEBUG"), NULL, 10);
error = NULL;
context = g_option_context_new(NULL);
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;
}
- }
- if (opt_pd_stack) {
- pds = g_strsplit(opt_pd_stack, ",", 0);
- if (g_strv_length(pds) < 2) {
- printf("Specify at least two protocol decoders to stack.\n");
- return 1;
- }
+ pds = g_strsplit(opt_pds, ",", 0);
+ if (g_strv_length(pds) > 1) {
+ if (opt_pd_stack) {
+ /* A stack setup was specified, use that. */
+ g_strfreev(pds);
+ pds = g_strsplit(opt_pd_stack, ",", 0);
+ if (g_strv_length(pds) < 2) {
+ g_strfreev(pds);
+ printf("Specify at least two protocol decoders to stack.\n");
+ return 1;
+ }
+ }
- if (!(di_from = srd_inst_find_by_id(pds[0]))) {
- printf("Cannot stack protocol decoder '%s': instance not found.\n", pds[0]);
- return 1;
- }
- for (i = 1; pds[i]; i++) {
- if (!(di_to = srd_inst_find_by_id(pds[i]))) {
- printf("Cannot stack protocol decoder '%s': instance not found.\n", pds[i]);
+ if (!(di_from = srd_inst_find_by_id(pds[0]))) {
+ printf("Cannot stack protocol decoder '%s': instance not found.\n", pds[0]);
return 1;
}
- if ((ret = srd_inst_stack(di_from, di_to) != SRD_OK))
- return ret;
+ for (i = 1; pds[i]; i++) {
+ if (!(di_to = srd_inst_find_by_id(pds[i]))) {
+ 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)
+ return ret;
- /* Don't show annotation from this PD. Only the last PD in
- * the stack will be left on the annotation list.
- */
- g_datalist_remove_data(&pd_ann_visible, di_from->inst_id);
+ /* Don't show annotation from this PD. Only the last PD in
+ * the stack will be left on the annotation list.
+ */
+ g_datalist_remove_data(&pd_ann_visible, di_from->inst_id);
- di_from = di_to;
+ di_from = di_to;
+ }
}
g_strfreev(pds);
}