X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=sigrok-cli.c;h=07dacfee0f67f75ae8a0a3228d20308df6e60600;hp=1ca2c090eea331bba58938c489cbdbf121c4d3f8;hb=6de7ec06e266e8c075708b560584e7fcab1e0b91;hpb=43e5747a59ed92243c217f7e36da2ac35bbcd80d diff --git a/sigrok-cli.c b/sigrok-cli.c index 1ca2c09..07dacfe 100644 --- a/sigrok-cli.c +++ b/sigrok-cli.c @@ -38,12 +38,12 @@ extern struct sr_hwcap_option sr_hwcap_options[]; -gboolean debug = 0; -uint64_t limit_samples = 0; -struct sr_output_format *output_format = NULL; -int default_output_format = FALSE; -char *output_format_param = NULL; -char *input_format_param = NULL; +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 char *output_format_param = NULL; +static char *input_format_param = NULL; static gboolean opt_version = FALSE; static gint opt_loglevel = SR_LOG_WARN; /* Show errors+warnings per default. */ @@ -258,7 +258,7 @@ static void show_device_detail(void) static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *packet) { static struct sr_output *o = NULL; - static int probelist[65] = { 0 }; + static int probelist[SR_MAX_NUM_PROBES] = { 0 }; static uint64_t received_samples = 0; static int unitsize = 0; static int triggered = 0; @@ -322,8 +322,8 @@ static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *pac } } if (opt_pds) - srd_session_start(device->plugin->name, unitsize, - time(NULL), header->samplerate); + srd_session_start(num_enabled_probes, unitsize, + header->samplerate); break; case SR_DF_END: g_message("cli: Received SR_DF_END"); @@ -461,9 +461,15 @@ static int register_pds(struct sr_device *device, const char *pdstring) for (optok = optokens+1; *optok; optok++) { char probe[strlen(*optok)]; int num; - if(sscanf(*optok, "%[^=]=%d", probe, &num) == 2) + if (sscanf(*optok, "%[^=]=%d", probe, &num) == 2) { + printf("Setting probe '%s' to %d\n", probe, num); srd_instance_set_probe(di, probe, num); - /* TODO: else fail somehow */ + } else { + fprintf(stderr, "Error: Couldn't parse decoder " + "options correctly! Aborting.\n"); + /* FIXME: Better error handling. */ + exit(EXIT_FAILURE); + } } g_strfreev(optokens); @@ -475,6 +481,24 @@ static int register_pds(struct sr_device *device, const char *pdstring) return 0; } +void show_pd_annotation(struct srd_protocol_data *pdata) +{ + int i; + char **annotation; + + annotation = pdata->data; + if (pdata->annotation_format != 0) { + /* CLI only shows the default annotation format */ + return; + } + + printf("%s: ", pdata->pdo->protocol_id); + for (i = 0; annotation[i]; i++) + printf("\"%s\" ", annotation[i]); + printf("\n"); + +} + static int select_probes(struct sr_device *device) { struct sr_probe *probe; @@ -653,7 +677,7 @@ int num_real_devices(void) return num_devices; } -int set_device_options(struct sr_device *device, GHashTable *args) +static int set_device_options(struct sr_device *device, GHashTable *args) { GHashTableIter iter; gpointer key, value; @@ -929,13 +953,30 @@ int main(int argc, char **argv) return 1; } + /* Set the loglevel (amount of messages to output) for libsigrokdecode. */ + if (srd_set_loglevel(opt_loglevel) != SRD_OK) { + fprintf(stderr, "cli: %s: srd_set_loglevel(%d) failed\n", + __func__, opt_loglevel); + return 1; + } + if (sr_init() != SR_OK) return 1; if (opt_pds) { - /* TODO: Error handling. */ - srd_init(); - register_pds(NULL, opt_pds); + if (srd_init() != SRD_OK) { + printf("Failed to initialize sigrokdecode\n"); + return 1; + } + if (register_pds(NULL, opt_pds) != 0) { + printf("Failed to register protocol decoders\n"); + return 1; + } + if (srd_register_callback(SRD_OUTPUT_ANNOTATION, + show_pd_annotation) != SRD_OK) { + printf("Failed to register protocol decoder callback\n"); + return 1; + } } if (!opt_format) {