26 #include "sigrok-internal.h"
60 sr_err(
"csv out: %s: o was NULL", __func__);
65 sr_err(
"csv out: %s: o->dev was NULL", __func__);
70 sr_err(
"csv out: %s: o->dev->driver was NULL", __func__);
74 if (!(ctx = g_try_malloc0(
sizeof(
struct context)))) {
75 sr_err(
"csv out: %s: ctx malloc failed", __func__);
83 for (l = o->
dev->
probes; l; l = l->next) {
92 num_probes = g_slist_length(o->
dev->
probes);
105 ctx->
header = g_string_sized_new(512);
110 g_string_append_printf(ctx->
header,
"; CSV, generated by %s on %s",
112 g_string_append_printf(ctx->
header,
"; Samplerate: %"PRIu64
"\n",
116 g_string_append_printf(ctx->
header,
"; Channels (%d/%d): ",
120 g_string_append_printf(ctx->
header,
"\n");
125 static int event(
struct sr_output *o,
int event_type, uint8_t **data_out,
126 uint64_t *length_out)
131 sr_err(
"csv out: %s: o was NULL", __func__);
136 sr_err(
"csv out: %s: o->internal was NULL", __func__);
141 sr_err(
"csv out: %s: data_out was NULL", __func__);
145 switch (event_type) {
147 sr_dbg(
"csv out: %s: SR_DF_TRIGGER event", __func__);
153 sr_dbg(
"csv out: %s: SR_DF_END event", __func__);
161 sr_err(
"csv out: %s: unsupported event type: %d", __func__,
171 static int data(
struct sr_output *o,
const uint8_t *data_in,
172 uint64_t length_in, uint8_t **data_out, uint64_t *length_out)
180 sr_err(
"csv out: %s: o was NULL", __func__);
185 sr_err(
"csv out: %s: o->internal was NULL", __func__);
190 sr_err(
"csv out: %s: data_in was NULL", __func__);
199 outstr = g_string_sized_new(512);
203 memcpy(&sample, data_in + i, ctx->
unitsize);
205 g_string_append_printf(outstr,
"%d%c",
206 (
int)((sample & (1 << j)) >> j),
209 g_string_append_printf(outstr,
"\n");
212 *data_out = (uint8_t *)outstr->str;
213 *length_out = outstr->len;
214 g_string_free(outstr, FALSE);
221 .description =
"Comma-separated values (CSV)",