]> sigrok.org Git - sigrok-cli.git/blobdiff - sigrok-cli.c
device detail now lists probes
[sigrok-cli.git] / sigrok-cli.c
index ccfc5e0cfcd548b872fe58cf025a28dd571a2b89..aeffeaa8d42f659aac62fde3d31d642e175cc138 100644 (file)
@@ -132,7 +132,6 @@ static GSList *hash_to_hwopt(GHashTable *hash)
                value = g_hash_table_lookup(hash, key);
                hwopt->value = g_strdup(value);
                opts = g_slist_append(opts, hwopt);
-               break;
        }
        g_list_free(keys);
 
@@ -245,6 +244,8 @@ static void show_version(void)
 
 static void print_dev_line(const struct sr_dev_inst *sdi)
 {
+       struct sr_probe *probe;
+       GSList *l;
 
        if (sdi->vendor && sdi->vendor[0])
                printf("%s ", sdi->vendor);
@@ -252,9 +253,19 @@ static void print_dev_line(const struct sr_dev_inst *sdi)
                printf("%s ", sdi->model);
        if (sdi->version && sdi->version[0])
                printf("%s ", sdi->version);
-       if (sdi->probes)
-               printf("with %d probes", g_slist_length(sdi->probes));
-       printf("\n");
+       if (sdi->probes) {
+               if (g_slist_length(sdi->probes) == 1) {
+                       probe = sdi->probes->data;
+                       printf("with 1 probe: %s\n", probe->name);
+               } else {
+                       printf("with %d probes:\n", g_slist_length(sdi->probes));
+                       for (l = sdi->probes; l; l = l->next) {
+                               probe = l->data;
+                               printf("      %s\n", probe->name);
+                       }
+               }
+       } else
+               printf("\n");
 }
 
 static void show_dev_list(void)
@@ -546,6 +557,7 @@ static void datafeed_in(const struct sr_dev_inst *sdi,
        int num_enabled_probes, sample_size, ret, i;
        uint64_t output_len, filter_out_len;
        uint8_t *output_buf, *filter_out;
+       GString *out;
 
        /* If the first packet to come in isn't a header, don't even try. */
        if (packet->type != SR_DF_HEADER && o == NULL)
@@ -594,6 +606,9 @@ static void datafeed_in(const struct sr_dev_inst *sdi,
                               received_samples);
                if (outfile && outfile != stdout)
                        fclose(outfile);
+
+               if (o->format->cleanup)
+                       o->format->cleanup(o);
                g_free(o);
                o = NULL;
                break;
@@ -784,6 +799,14 @@ static void datafeed_in(const struct sr_dev_inst *sdi,
                g_message("received unknown packet type %d", packet->type);
        }
 
+       if (o && o->format->recv) {
+               out = o->format->recv(o, sdi, packet);
+               if (out && out->len) {
+                       fwrite(out->str, 1, out->len, outfile);
+                       fflush(outfile);
+               }
+       }
+
 }
 
 /* Register the given PDs for this session.
@@ -1267,7 +1290,7 @@ static int set_dev_options(struct sr_dev_inst *sdi, GHashTable *args)
                        ret = SR_ERR;
                }
                if (val)
-                       ret = sdi->driver->dev_config_set(sdi, hwo->hwcap, val);
+                       ret = sr_dev_config_set(sdi, hwo->hwcap, val);
                if (ret != SR_OK) {
                        g_critical("Failed to set device option '%s'.", (char *)key);
                        return ret;
@@ -1292,8 +1315,7 @@ static int set_limit_time(const struct sr_dev_inst *sdi)
        }
 
        if (sr_driver_hwcap_exists(sdi->driver, SR_HWCAP_LIMIT_MSEC)) {
-               if (sdi->driver->dev_config_set(sdi,
-                       SR_HWCAP_LIMIT_MSEC, &time_msec) != SR_OK) {
+               if (sr_dev_config_set(sdi, SR_HWCAP_LIMIT_MSEC, &time_msec) != SR_OK) {
                        g_critical("Failed to configure time limit.");
                        sr_session_destroy();
                        return SR_ERR;
@@ -1315,8 +1337,8 @@ static int set_limit_time(const struct sr_dev_inst *sdi)
                        return SR_ERR;
                }
 
-               if (sdi->driver->dev_config_set(sdi,
-                       SR_HWCAP_LIMIT_SAMPLES, &limit_samples) != SR_OK) {
+               if (sr_dev_config_set(sdi, SR_HWCAP_LIMIT_SAMPLES,
+                                       &limit_samples) != SR_OK) {
                        g_critical("Failed to configure time-based sample limit.");
                        sr_session_destroy();
                        return SR_ERR;
@@ -1383,13 +1405,6 @@ static void run_session(void)
                g_free(triggerlist);
        }
 
-       if (sdi->driver->dev_config_set(sdi, SR_HWCAP_PROBECONFIG,
-                       (char *)sdi->probes) != SR_OK) {
-               g_critical("Failed to configure probes.");
-               sr_session_destroy();
-               return;
-       }
-
        if (opt_continuous) {
                if (!sr_driver_hwcap_exists(sdi->driver, SR_HWCAP_CONTINUOUS)) {
                        g_critical("This device does not support continuous sampling.");
@@ -1407,7 +1422,7 @@ static void run_session(void)
 
        if (opt_samples) {
                if ((sr_parse_sizestring(opt_samples, &limit_samples) != SR_OK)
-                               || (sdi->driver->dev_config_set(sdi, SR_HWCAP_LIMIT_SAMPLES,
+                               || (sr_dev_config_set(sdi, SR_HWCAP_LIMIT_SAMPLES,
                                                &limit_samples) != SR_OK)) {
                        g_critical("Failed to configure sample limit.");
                        sr_session_destroy();
@@ -1417,8 +1432,8 @@ static void run_session(void)
 
        if (opt_frames) {
                if ((sr_parse_sizestring(opt_frames, &limit_frames) != SR_OK)
-                               || (sdi->driver->dev_config_set(sdi,
-                           SR_HWCAP_LIMIT_FRAMES, &limit_frames) != SR_OK)) {
+                               || (sr_dev_config_set(sdi, SR_HWCAP_LIMIT_FRAMES,
+                                               &limit_frames) != SR_OK)) {
                        g_critical("Failed to configure frame limit.");
                        sr_session_destroy();
                        return;
@@ -1514,10 +1529,10 @@ int main(int argc, char **argv)
                show_version();
        else if (opt_list_devs)
                show_dev_list();
+       else if (opt_pds && opt_show)
+               show_pd_detail();
        else if (opt_show)
                show_dev_detail();
-       else if (opt_pds)
-               show_pd_detail();
        else if (opt_input_file)
                load_input_file();
        else if (opt_samples || opt_time || opt_frames || opt_continuous)