]> sigrok.org Git - sigrok-cli.git/blobdiff - sigrok-cli.c
cli: Print required/optional probes info.
[sigrok-cli.git] / sigrok-cli.c
index ab131965d93ab0f7c50204d7f0a121838645bfd1..560cbc5d08e7d18caef4208f802bdb64cf26aa03 100644 (file)
@@ -94,6 +94,11 @@ 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");
        drivers = sr_driver_list();
        for (i = 0; drivers[i]; i++) {
@@ -119,11 +124,13 @@ static void show_version(void)
                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)
@@ -262,6 +269,7 @@ static void show_pd_detail(void)
        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++) {
@@ -272,27 +280,50 @@ static void show_pd_detail(void)
                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_get(dec))) {
-                       printf("Documentation:\n%s\n", doc[0] == '\n' ? doc+1 : doc);
+                       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;
@@ -302,7 +333,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)
@@ -454,7 +485,6 @@ static void datafeed_in(struct sr_dev *dev, struct sr_datafeed_packet *packet)
 cleanup:
        g_free(filter_out);
        received_samples += logic->length / sample_size;
-
 }
 
 /* Register the given PDs for this session.
@@ -539,7 +569,6 @@ void show_pd_annotation(struct srd_proto_data *pdata, void *cb_data)
        for (i = 0; annotations[i]; i++)
                printf("\"%s\" ", annotations[i]);
        printf("\n");
-
 }
 
 static int select_probes(struct sr_dev *dev)
@@ -683,7 +712,6 @@ static void load_input_file_format(void)
                        printf("Failed to save session.\n");
        }
        sr_session_destroy();
-
 }
 
 static void load_input_file(void)
@@ -700,7 +728,6 @@ static void load_input_file(void)
                /* fall back on input modules */
                load_input_file_format();
        }
-
 }
 
 int num_real_devs(void)
@@ -939,7 +966,6 @@ static void run_session(void)
                        printf("Failed to save session.\n");
        }
        sr_session_destroy();
-
 }
 
 static void logger(const gchar *log_domain, GLogLevelFlags log_level,
@@ -1039,7 +1065,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