2 * This file is part of the sigrok project.
4 * Copyright (C) 2012 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "libsigrok.h"
24 #include "libsigrok-internal.h"
27 unsigned int num_enabled_probes;
31 static int init(struct sr_output *o)
34 struct sr_probe *probe;
46 if (!(ctx = g_try_malloc0(sizeof(struct context))))
51 /* Get the number of probes and their names. */
52 ctx->probelist = g_ptr_array_new();
53 for (l = o->sdi->probes; l; l = l->next) {
55 if (!probe || !probe->enabled)
57 g_ptr_array_add(ctx->probelist, probe->name);
58 ctx->num_enabled_probes++;
64 static int event(struct sr_output *o, int event_type, uint8_t **data_out,
72 if (!(ctx = o->internal))
79 case SR_DF_FRAME_BEGIN:
80 *data_out = (uint8_t *)g_strdup("FRAME-BEGIN\n");
84 *data_out = (uint8_t *)g_strdup("FRAME-END\n");
90 g_ptr_array_free(ctx->probelist, TRUE);
95 /* Ignore everything else. */
104 static int data(struct sr_output *o, const uint8_t *data_in,
105 uint64_t length_in, uint8_t **data_out, uint64_t *length_out)
116 if (!(ctx = o->internal))
119 if (!data_in || !data_out)
122 outstr = g_string_sized_new(512);
124 fdata = (float *)data_in;
125 max = length_in / sizeof(float);
126 for (i = 0; i < max;) {
127 for (j = 0; j < ctx->num_enabled_probes; j++) {
128 g_string_append_printf(outstr, "%s: %.12f\n",
129 (char *)g_ptr_array_index(ctx->probelist, j),
134 *data_out = (uint8_t *)outstr->str;
135 *length_out = outstr->len;
136 g_string_free(outstr, FALSE);
141 SR_PRIV struct sr_output_format output_float = {
143 .description = "Floating point",
144 .df_type = SR_DF_ANALOG,