2 * This file is part of the sigrok project.
4 * Copyright (C) 2011 Uwe Hermann <uwe@hermann-uwe.de>
5 * Copyright (C) 2011 Bert Vermeulen <bert@biot.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 * This implements version 1.3 of the output format for the OpenBench Logic
24 * Sniffer "Alternative" Java client. Details:
25 * https://github.com/jawi/ols/wiki/OLS-data-file-format
37 unsigned int unitsize;
41 static int init(struct sr_output *o)
44 struct sr_probe *probe;
47 int num_enabled_probes, i;
49 if (!(ctx = g_malloc(sizeof(struct context))))
54 num_enabled_probes = 0;
55 for (l = o->device->probes; l; l = l->next) {
60 ctx->unitsize = (num_enabled_probes + 7) / 8;
62 if (o->device->plugin && sr_device_has_hwcap(o->device, SR_HWCAP_SAMPLERATE))
63 samplerate = *((uint64_t *) o->device->plugin->get_device_info(
64 o->device->plugin_index, SR_DI_CUR_SAMPLERATE));
68 ctx->header = g_string_sized_new(512);
69 g_string_append_printf(ctx->header, ";Rate: %"PRIu64"\n", samplerate);
70 g_string_append_printf(ctx->header, ";Channels: %d\n", num_enabled_probes);
71 g_string_append_printf(ctx->header, ";EnabledChannels: -1\n");
72 g_string_append_printf(ctx->header, ";Compressed: true\n");
73 g_string_append_printf(ctx->header, ";CursorEnabled: false\n");
74 for (i = 0; i < 10; i++)
75 g_string_append_printf(ctx->header, ";Cursor%d: 0\n", i);
80 static int event(struct sr_output *o, int event_type, char **data_out,
87 if (ctx && event_type == SR_DF_END) {
89 g_string_free(ctx->header, TRUE);
100 static int data(struct sr_output *o, char *data_in, uint64_t length_in,
101 char **data_out, uint64_t *length_out)
110 /* first data packet */
114 out = g_string_sized_new(512);
116 for (i = 0; i <= length_in - ctx->unitsize; i += ctx->unitsize) {
118 memcpy(&sample, data_in + i, ctx->unitsize);
119 g_string_append_printf(out, "%08x@%"PRIu64"\n",
120 (uint32_t) sample, ctx->num_samples++);
122 *data_out = out->str;
123 *length_out = out->len;
124 g_string_free(out, FALSE);
129 struct sr_output_format output_ols = {
131 "OpenBench Logic Sniffer",