2011-01-15 17:18:09 +00:00
|
|
|
/*
|
2013-04-23 20:24:30 +00:00
|
|
|
* This file is part of the libsigrok project.
|
2011-01-15 17:18:09 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Uwe Hermann <uwe@hermann-uwe.de>
|
2013-03-24 10:21:00 +00:00
|
|
|
* Copyright (C) 2013 Bert Vermeulen <bert@biot.com>
|
2011-01-15 17:18:09 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2011-02-12 05:18:16 +00:00
|
|
|
* This implements version 1.3 of the output format for the OpenBench Logic
|
|
|
|
* Sniffer "Alternative" Java client. Details:
|
|
|
|
* https://github.com/jawi/ols/wiki/OLS-data-file-format
|
2011-01-15 17:18:09 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
2012-07-04 22:55:07 +00:00
|
|
|
#include "libsigrok.h"
|
|
|
|
#include "libsigrok-internal.h"
|
2011-01-15 17:18:09 +00:00
|
|
|
|
2012-11-11 08:36:21 +00:00
|
|
|
/* Message logging helpers with driver-specific prefix string. */
|
|
|
|
#define DRIVER_LOG_DOMAIN "output/ols: "
|
|
|
|
#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
|
|
|
|
#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
|
|
|
|
#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
|
|
|
|
#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
|
|
|
|
#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
|
|
|
|
#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
|
|
|
|
|
2011-01-15 17:18:09 +00:00
|
|
|
struct context {
|
2011-02-01 05:13:32 +00:00
|
|
|
GString *header;
|
|
|
|
uint64_t num_samples;
|
2011-01-15 17:18:09 +00:00
|
|
|
unsigned int unitsize;
|
|
|
|
};
|
|
|
|
|
2011-02-01 05:13:32 +00:00
|
|
|
static int init(struct sr_output *o)
|
|
|
|
{
|
|
|
|
struct context *ctx;
|
2011-02-08 16:47:38 +00:00
|
|
|
struct sr_probe *probe;
|
2011-02-01 05:13:32 +00:00
|
|
|
GSList *l;
|
2013-03-25 19:27:26 +00:00
|
|
|
GVariant *gvar;
|
|
|
|
uint64_t samplerate;
|
2011-02-14 04:55:01 +00:00
|
|
|
int num_enabled_probes;
|
2011-01-15 17:18:09 +00:00
|
|
|
|
2011-04-16 12:17:51 +00:00
|
|
|
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
|
2012-11-11 08:36:21 +00:00
|
|
|
sr_err("%s: ctx malloc failed", __func__);
|
2011-02-01 05:13:32 +00:00
|
|
|
return SR_ERR_MALLOC;
|
2011-04-16 12:17:51 +00:00
|
|
|
}
|
2011-02-01 05:13:32 +00:00
|
|
|
o->internal = ctx;
|
2011-02-12 05:18:16 +00:00
|
|
|
|
2011-02-01 05:13:32 +00:00
|
|
|
ctx->num_samples = 0;
|
|
|
|
num_enabled_probes = 0;
|
2012-07-20 19:37:36 +00:00
|
|
|
for (l = o->sdi->probes; l; l = l->next) {
|
2011-02-01 05:13:32 +00:00
|
|
|
probe = l->data;
|
|
|
|
if (probe->enabled)
|
|
|
|
num_enabled_probes++;
|
2011-01-15 17:18:09 +00:00
|
|
|
}
|
2011-02-01 05:13:32 +00:00
|
|
|
ctx->unitsize = (num_enabled_probes + 7) / 8;
|
2011-01-15 17:18:09 +00:00
|
|
|
|
2013-03-25 19:27:26 +00:00
|
|
|
if (o->sdi->driver && sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) {
|
|
|
|
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi);
|
|
|
|
samplerate = g_variant_get_uint64(gvar);
|
|
|
|
g_variant_unref(gvar);
|
|
|
|
} else {
|
|
|
|
samplerate = 0;
|
2012-07-20 19:37:36 +00:00
|
|
|
}
|
2011-02-12 05:18:16 +00:00
|
|
|
|
|
|
|
ctx->header = g_string_sized_new(512);
|
2013-03-25 19:27:26 +00:00
|
|
|
g_string_append_printf(ctx->header, ";Rate: %"PRIu64"\n", samplerate);
|
2011-02-12 05:18:16 +00:00
|
|
|
g_string_append_printf(ctx->header, ";Channels: %d\n", num_enabled_probes);
|
|
|
|
g_string_append_printf(ctx->header, ";EnabledChannels: -1\n");
|
|
|
|
g_string_append_printf(ctx->header, ";Compressed: true\n");
|
|
|
|
g_string_append_printf(ctx->header, ";CursorEnabled: false\n");
|
|
|
|
|
2011-02-01 05:13:32 +00:00
|
|
|
return SR_OK;
|
2011-01-15 17:18:09 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 18:00:13 +00:00
|
|
|
static int event(struct sr_output *o, int event_type, uint8_t **data_out,
|
2011-01-15 17:18:09 +00:00
|
|
|
uint64_t *length_out)
|
|
|
|
{
|
|
|
|
struct context *ctx;
|
|
|
|
|
|
|
|
ctx = o->internal;
|
2011-02-01 05:13:32 +00:00
|
|
|
|
2011-02-12 05:18:16 +00:00
|
|
|
if (ctx && event_type == SR_DF_END) {
|
2012-01-18 23:32:02 +00:00
|
|
|
g_string_free(ctx->header, TRUE);
|
2012-02-11 19:06:46 +00:00
|
|
|
g_free(o->internal);
|
2011-01-15 17:18:09 +00:00
|
|
|
o->internal = NULL;
|
|
|
|
}
|
|
|
|
|
2011-02-12 05:18:16 +00:00
|
|
|
*data_out = NULL;
|
|
|
|
*length_out = 0;
|
|
|
|
|
2011-01-29 15:23:12 +00:00
|
|
|
return SR_OK;
|
2011-01-15 17:18:09 +00:00
|
|
|
}
|
|
|
|
|
2012-03-28 18:00:13 +00:00
|
|
|
static int data(struct sr_output *o, const uint8_t *data_in,
|
|
|
|
uint64_t length_in, uint8_t **data_out, uint64_t *length_out)
|
2011-01-15 17:18:09 +00:00
|
|
|
{
|
2011-02-12 05:18:16 +00:00
|
|
|
GString *out;
|
2011-01-15 17:18:09 +00:00
|
|
|
struct context *ctx;
|
|
|
|
uint64_t sample;
|
2011-02-01 05:13:32 +00:00
|
|
|
unsigned int i;
|
2011-01-15 17:18:09 +00:00
|
|
|
|
|
|
|
ctx = o->internal;
|
2011-02-12 05:18:16 +00:00
|
|
|
if (ctx->header) {
|
|
|
|
/* first data packet */
|
|
|
|
out = ctx->header;
|
|
|
|
ctx->header = NULL;
|
|
|
|
} else
|
|
|
|
out = g_string_sized_new(512);
|
|
|
|
|
2011-01-15 17:18:09 +00:00
|
|
|
for (i = 0; i <= length_in - ctx->unitsize; i += ctx->unitsize) {
|
2011-02-01 05:13:32 +00:00
|
|
|
sample = 0;
|
2011-01-15 17:18:09 +00:00
|
|
|
memcpy(&sample, data_in + i, ctx->unitsize);
|
2011-02-12 05:18:16 +00:00
|
|
|
g_string_append_printf(out, "%08x@%"PRIu64"\n",
|
2011-02-01 05:13:32 +00:00
|
|
|
(uint32_t) sample, ctx->num_samples++);
|
2011-01-15 17:18:09 +00:00
|
|
|
}
|
2012-03-28 18:00:13 +00:00
|
|
|
*data_out = (uint8_t *)out->str;
|
2011-02-12 05:18:16 +00:00
|
|
|
*length_out = out->len;
|
|
|
|
g_string_free(out, FALSE);
|
2011-01-15 17:18:09 +00:00
|
|
|
|
2011-01-29 15:23:12 +00:00
|
|
|
return SR_OK;
|
2011-01-15 17:18:09 +00:00
|
|
|
}
|
|
|
|
|
2012-02-04 09:56:51 +00:00
|
|
|
SR_PRIV struct sr_output_format output_ols = {
|
2011-04-06 19:51:36 +00:00
|
|
|
.id = "ols",
|
2011-04-06 17:42:49 +00:00
|
|
|
.description = "OpenBench Logic Sniffer",
|
|
|
|
.df_type = SR_DF_LOGIC,
|
|
|
|
.init = init,
|
|
|
|
.data = data,
|
|
|
|
.event = event,
|
2011-01-15 17:18:09 +00:00
|
|
|
};
|