]> sigrok.org Git - libsigrok.git/blobdiff - src/output/analog.c
output/null: Add a null module that discards all data.
[libsigrok.git] / src / output / analog.c
index 9ff77da4b765cf7ae7d8ea4af9b42dd66b3fdf71..94175369e1a15c43e4d0a48f7a3a6df9b4fb6b4e 100644 (file)
@@ -75,11 +75,14 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
 {
        struct context *ctx;
        const struct sr_datafeed_analog *analog;
+       const struct sr_datafeed_meta *meta;
+       const struct sr_config *src;
+       const struct sr_key_info *srci;
        struct sr_channel *ch;
        GSList *l;
        float *fdata;
        unsigned int i;
-       int num_channels, c, ret, digits;
+       int num_channels, c, ret, digits, actual_digits;
        char *number, *suffix;
 
        *out = NULL;
@@ -94,6 +97,29 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
        case SR_DF_FRAME_END:
                *out = g_string_new("FRAME-END\n");
                break;
+       case SR_DF_META:
+               meta = packet->payload;
+               for (l = meta->config; l; l = l->next) {
+                       src = l->data;
+                       if (!(srci = sr_key_info_get(SR_KEY_CONFIG, src->key)))
+                               return SR_ERR;
+                       *out = g_string_sized_new(512);
+                       g_string_append(*out, "META ");
+                       g_string_append_printf(*out, "%s: ", srci->id);
+                       if (srci->datatype == SR_T_BOOL) {
+                               g_string_append_printf(*out, "%u",
+                                       g_variant_get_boolean(src->data));
+                       } else if (srci->datatype == SR_T_FLOAT) {
+                               g_string_append_printf(*out, "%f",
+                                       g_variant_get_double(src->data));
+                       } else if (srci->datatype == SR_T_UINT64) {
+                               g_string_append_printf(*out, "%"
+                                       G_GUINT64_FORMAT,
+                                       g_variant_get_uint64(src->data));
+                       }
+                       g_string_append(*out, "\n");
+               }
+               break;
        case SR_DF_ANALOG:
                analog = packet->payload;
                num_channels = g_slist_length(analog->meaning->channels);
@@ -119,11 +145,12 @@ static int receive(const struct sr_output *o, const struct sr_datafeed_packet *p
                        for (l = analog->meaning->channels, c = 0; l; l = l->next, c++) {
                                float value = fdata[i * num_channels + c];
                                const char *prefix = "";
+                               actual_digits = digits;
                                if (si_friendly)
-                                       prefix = sr_analog_si_prefix(&value, &digits);
+                                       prefix = sr_analog_si_prefix(&value, &actual_digits);
                                ch = l->data;
                                g_string_append_printf(*out, "%s: ", ch->name);
-                               number = g_strdup_printf("%.*f", MAX(digits, 0), value);
+                               number = g_strdup_printf("%.*f", MAX(actual_digits, 0), value);
                                g_string_append(*out, number);
                                g_free(number);
                                g_string_append(*out, " ");
@@ -178,7 +205,7 @@ static int cleanup(struct sr_output *o)
 SR_PRIV struct sr_output_module output_analog = {
        .id = "analog",
        .name = "Analog",
-       .desc = "Analog data and types",
+       .desc = "ASCII analog data values and units",
        .exts = NULL,
        .flags = 0,
        .options = get_options,