2 * This file is part of the sigrok project.
4 * Copyright (C) 2011 Uwe Hermann <uwe@hermann-uwe.de>
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 2 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, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * Output format for the OpenBench Logic Sniffer "Alternative" Java client.
23 * Details: https://github.com/jawi/ols/wiki/OLS-data-file-format
33 unsigned int num_enabled_probes;
34 unsigned int unitsize;
35 char *probelist[MAX_NUM_PROBES + 1];
40 #define MAX_HEADER_LEN 2048
42 /* TODO: Support cursors? */
44 "# Generated by: %s on %s%s\n" \
45 "# Probe list used for capturing:\n" \
46 "# Number:\tName:\n" \
48 ";Size: %" PRIu64 "\n" \
49 ";Rate: %" PRIu64 "\n" \
51 ";EnabledChannels: -1\n" \
52 ";Compressed: true\n" \
53 ";AbsoluteLength: %" PRIu64 "\n" \
54 ";CursorEnabled: false\n" \
55 ";Cursor0: -9223372036854775808\n" \
56 ";Cursor1: -9223372036854775808\n" \
57 ";Cursor2: -9223372036854775808\n" \
58 ";Cursor3: -9223372036854775808\n" \
59 ";Cursor4: -9223372036854775808\n" \
60 ";Cursor5: -9223372036854775808\n" \
61 ";Cursor6: -9223372036854775808\n" \
62 ";Cursor7: -9223372036854775808\n" \
63 ";Cursor8: -9223372036854775808\n" \
64 ";Cursor9: -9223372036854775808\n"
66 const char *ols_header_comment = "\
67 # Comment: Acquisition with %d/%d probes at %s";
69 static int init(struct output *o)
77 char *c, *frequency_s;
78 char wbuf[1000], comment[128];
81 if (!(ctx = calloc(1, sizeof(struct context))))
82 return SIGROK_ERR_MALLOC;
84 if (!(ctx->header = calloc(1, MAX_HEADER_LEN + 1))) {
86 return SIGROK_ERR_MALLOC;
90 ctx->num_enabled_probes = 0;
91 for (l = o->device->probes; l; l = l->next) {
95 ctx->probelist[ctx->num_enabled_probes++] = probe->name;
97 ctx->probelist[ctx->num_enabled_probes] = 0;
98 ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
100 num_probes = g_slist_length(o->device->probes);
103 /* TODO: Currently not available in the demo module. */
105 if (o->device->plugin) {
106 samplerate = *((uint64_t *) o->device->plugin->get_device_info(
107 o->device->plugin_index, DI_CUR_SAMPLERATE));
108 if (!(frequency_s = sigrok_samplerate_string(samplerate))) {
113 snprintf(comment, 127, ols_header_comment,
114 ctx->num_enabled_probes, num_probes, frequency_s);
118 /* Columns / channels */
120 for (i = 0; i < ctx->num_enabled_probes; i++) {
121 c = (char *)&wbuf + strlen((char *)&wbuf);
122 sprintf(c, "# %d\t\t%s\n", i + 1, ctx->probelist[i]);
125 if (!(frequency_s = sigrok_period_string(samplerate))) {
133 /* TODO: Special handling for the demo driver. */
134 /* TODO: Don't hardcode numsamples! */
135 /* TODO: Check if num_enabled_probes/channels setting is correct. */
136 b = snprintf(ctx->header, MAX_HEADER_LEN, OLS_HEADER,
137 PACKAGE_STRING, ctime(&t),
140 (uint64_t)10000 /* numsamples */,
142 ctx->num_enabled_probes,
143 (uint64_t)10000 /* numsamples */);
145 /* TODO: Yield errors on stuff the OLS format doesn't support. */
158 static int event(struct output *o, int event_type, char **data_out,
159 uint64_t *length_out)
164 switch (event_type) {
180 static int data(struct output *o, char *data_in, uint64_t length_in,
181 char **data_out, uint64_t *length_out)
184 unsigned int max_linelen, outsize, i;
186 static uint64_t samplecount = 0;
190 max_linelen = 100; /* FIXME */
191 outsize = length_in / ctx->unitsize * max_linelen;
193 outsize += strlen(ctx->header);
195 if (!(outbuf = calloc(1, outsize)))
196 return SIGROK_ERR_MALLOC;
200 /* The header is still here, this must be the first packet. */
201 strncpy(outbuf, ctx->header, outsize);
206 for (i = 0; i <= length_in - ctx->unitsize; i += ctx->unitsize) {
207 memcpy(&sample, data_in + i, ctx->unitsize);
209 c = outbuf + strlen(outbuf);
210 /* FIXME: OLS seems to only support 2^31 total samples? */
211 sprintf(c, "%08x@%" PRIu64 "\n", (uint32_t)sample,
216 *length_out = strlen(outbuf);
221 struct output_format output_ols = {
223 "OpenBench Logic Sniffer",