26 #include "sigrok-internal.h"
35 #define MAX_HEADER_LEN \
36 (1024 + (SR_MAX_NUM_PROBES * (SR_MAX_PROBENAME_LEN + 10)))
38 static const char *gnuplot_header =
"\
39 # Sample data in space-separated columns format usable by gnuplot\n\
41 # Generated by: %s on %s%s\
45 # -------------------------------------\
46 ----------------------------------------\n\
47 # 0\t\tSample counter (for internal gnuplot purposes)\n%s\n";
49 static const char *gnuplot_header_comment =
"\
50 # Comment: Acquisition with %d/%d probes at %s\n";
60 char *c, *frequency_s;
61 char wbuf[1000], comment[128];
65 sr_err(
"gnuplot out: %s: o was NULL", __func__);
70 sr_err(
"gnuplot out: %s: o->dev was NULL", __func__);
75 sr_err(
"gnuplot out: %s: o->dev->driver was NULL", __func__);
79 if (!(ctx = g_try_malloc0(
sizeof(
struct context)))) {
80 sr_err(
"gnuplot out: %s: ctx malloc failed", __func__);
85 sr_err(
"gnuplot out: %s: ctx->header malloc failed", __func__);
92 for (l = o->
dev->
probes; l; l = l->next) {
101 num_probes = g_slist_length(o->
dev->
probes);
107 sr_err(
"gnuplot out: %s: sr_samplerate_string failed",
113 snprintf(comment, 127, gnuplot_header_comment,
121 c = (
char *)&wbuf + strlen((
const char *)&wbuf);
122 sprintf(c,
"# %d\t\t%s\n", i + 1, ctx->
probelist[i]);
126 sr_err(
"gnuplot out: %s: sr_period_string failed", __func__);
139 sr_err(
"gnuplot out: %s: sprintf failed", __func__);
148 static int event(
struct sr_output *o,
int event_type, uint8_t **data_out,
149 uint64_t *length_out)
152 sr_err(
"gnuplot out: %s: o was NULL", __func__);
157 sr_err(
"gnuplot out: %s: data_out was NULL", __func__);
162 sr_err(
"gnuplot out: %s: length_out was NULL", __func__);
166 switch (event_type) {
175 sr_err(
"gnuplot out: %s: unsupported event type: %d",
176 __func__, event_type);
186 static int data(
struct sr_output *o,
const uint8_t *data_in,
187 uint64_t length_in, uint8_t **data_out, uint64_t *length_out)
190 unsigned int max_linelen, outsize, p, curbit, i;
192 static uint64_t samplecount = 0, old_sample = 0;
196 sr_err(
"gnuplot out: %s: o was NULL", __func__);
201 sr_err(
"gnuplot out: %s: o->internal was NULL", __func__);
206 sr_err(
"gnuplot out: %s: data_in was NULL", __func__);
211 sr_err(
"gnuplot out: %s: data_out was NULL", __func__);
216 sr_err(
"gnuplot out: %s: length_out was NULL", __func__);
222 outsize = length_in / ctx->
unitsize * max_linelen;
224 outsize += strlen(ctx->
header);
226 if (!(outbuf = g_try_malloc0(outsize))) {
227 sr_err(
"gnuplot out: %s: outbuf malloc failed", __func__);
234 strncpy((
char *)outbuf, ctx->
header, outsize);
241 memcpy(&sample, data_in + i, ctx->
unitsize);
247 if (samplecount++ != 0 && sample == old_sample) {
248 if (i != (length_in - ctx->
unitsize))
254 c = outbuf + strlen((
const char *)outbuf);
255 sprintf((
char *)c,
"%" PRIu64
"\t", samplecount++);
259 curbit = (sample & ((uint64_t) (1 << p))) >> p;
260 c = outbuf + strlen((
const char *)outbuf);
261 sprintf((
char *)c,
"%d ", curbit);
264 c = outbuf + strlen((
const char *)outbuf);
265 sprintf((
char *)c,
"\n");
269 *length_out = strlen((
const char *)outbuf);
276 .description =
"Gnuplot",
285 static int analog_init(
struct sr_output *o)
293 char *c, *frequency_s;
294 char wbuf[1000], comment[128];
297 if (!(ctx = g_try_malloc0(
sizeof(
struct context)))) {
298 sr_err(
"gnuplot out: %s: ctx malloc failed", __func__);
304 sr_err(
"gnuplot out: %s: ctx->header malloc failed", __func__);
310 for (l = o->
dev->
probes; l; l = l->next) {
321 num_probes = g_slist_length(o->
dev->
probes);
331 snprintf(comment, 127, gnuplot_header_comment,
339 c = (
char *)&wbuf + strlen((
char *)&wbuf);
340 sprintf(c,
"# %d\t\t%s\n", i + 1, ctx->
probelist[i]);
363 static int analog_data(
struct sr_output *o, uint8_t *data_in,
364 uint64_t length_in, uint8_t **data_out,
365 uint64_t *length_out)
368 unsigned int max_linelen, outsize, p, i;
370 static uint64_t samplecount = 0;
377 outsize = length_in / ctx->
unitsize * max_linelen;
379 outsize += strlen(ctx->
header);
381 if (!(outbuf = g_try_malloc0(outsize))) {
382 sr_err(
"gnuplot out: %s: outbuf malloc failed", __func__);
389 strncpy(outbuf, ctx->
header, outsize);
399 c = outbuf + strlen(outbuf);
400 sprintf(c,
"%" PRIu64
"\t", samplecount++);
405 c = outbuf + strlen(outbuf);
412 sprintf(c,
"%f ", (
double) ((int16_t) (sample->
probes[p].
val &
416 c = outbuf + strlen(outbuf);
421 *length_out = strlen(outbuf);
427 .
id =
"analog_gnuplot",
428 .description =
"Gnuplot analog",
429 .df_type = SR_DF_ANALOG,