X-Git-Url: https://sigrok.org/gitweb/?p=sigrok-cli.git;a=blobdiff_plain;f=sigrok-cli.c;h=1d5d61c12e684d50e08d119a11c68e68cca13a9b;hp=337d878bdc1cc4c438ce23d617ee3f12f8b8e863;hb=213c6cead388576c01b53bf8d28d59581b7e4c59;hpb=1999ae06a4d06ea323218707f8e8a3c59ed404e7 diff --git a/sigrok-cli.c b/sigrok-cli.c index 337d878..1d5d61c 100644 --- a/sigrok-cli.c +++ b/sigrok-cli.c @@ -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; @@ -933,9 +957,19 @@ int main(int argc, char **argv) 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) {