2010-04-02 18:18:27 +00:00
|
|
|
/*
|
2013-04-23 20:24:30 +00:00
|
|
|
* This file is part of the libsigrok project.
|
2010-04-02 18:18:27 +00:00
|
|
|
*
|
2012-02-13 13:31:51 +00:00
|
|
|
* Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
|
2010-04-02 18:18:27 +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 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-07-04 22:55:07 +00:00
|
|
|
#include "libsigrok.h"
|
|
|
|
#include "libsigrok-internal.h"
|
2010-04-02 18:18:27 +00:00
|
|
|
|
2012-10-21 22:30:12 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* Output file/data format handling.
|
|
|
|
*/
|
|
|
|
|
2012-10-21 14:13:36 +00:00
|
|
|
/**
|
|
|
|
* @defgroup grp_output Output formats
|
|
|
|
*
|
|
|
|
* Output file/data format handling.
|
|
|
|
*
|
2013-02-22 14:12:32 +00:00
|
|
|
* libsigrok supports several output (file) formats, e.g. binary, VCD,
|
|
|
|
* gnuplot, and so on. It provides an output API that frontends can use.
|
|
|
|
* New output formats can be added/implemented in libsigrok without having
|
|
|
|
* to change the frontends at all.
|
|
|
|
*
|
|
|
|
* All output modules are fed data in a stream. Devices that can stream data
|
2014-04-20 20:51:09 +00:00
|
|
|
* into libsigrok, instead of storing and then transferring the whole buffer,
|
|
|
|
* can thus generate output live.
|
2013-02-22 14:12:32 +00:00
|
|
|
*
|
2014-04-20 20:51:09 +00:00
|
|
|
* Output modules generate a newly allocated GString. The caller is then
|
|
|
|
* expected to free this with g_string_free() when finished with it.
|
2013-02-22 14:12:32 +00:00
|
|
|
*
|
2012-10-21 14:13:36 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2012-10-19 08:07:22 +00:00
|
|
|
/** @cond PRIVATE */
|
2014-04-19 10:25:02 +00:00
|
|
|
extern SR_PRIV struct sr_output_format output_bits;
|
2014-04-19 10:31:50 +00:00
|
|
|
extern SR_PRIV struct sr_output_format output_hex;
|
2014-04-19 10:34:30 +00:00
|
|
|
extern SR_PRIV struct sr_output_format output_ascii;
|
2012-02-04 09:56:51 +00:00
|
|
|
extern SR_PRIV struct sr_output_format output_binary;
|
|
|
|
extern SR_PRIV struct sr_output_format output_vcd;
|
|
|
|
extern SR_PRIV struct sr_output_format output_ols;
|
|
|
|
extern SR_PRIV struct sr_output_format output_gnuplot;
|
|
|
|
extern SR_PRIV struct sr_output_format output_chronovu_la8;
|
|
|
|
extern SR_PRIV struct sr_output_format output_csv;
|
2012-09-08 11:24:48 +00:00
|
|
|
extern SR_PRIV struct sr_output_format output_analog;
|
2012-10-19 08:07:22 +00:00
|
|
|
/* @endcond */
|
2010-04-02 18:18:27 +00:00
|
|
|
|
2011-01-29 15:36:57 +00:00
|
|
|
static struct sr_output_format *output_module_list[] = {
|
2014-04-19 10:34:30 +00:00
|
|
|
&output_ascii,
|
2010-04-12 19:22:58 +00:00
|
|
|
&output_binary,
|
2014-04-20 20:51:09 +00:00
|
|
|
&output_bits,
|
|
|
|
&output_csv,
|
2010-04-06 12:38:47 +00:00
|
|
|
&output_gnuplot,
|
2014-04-20 20:51:09 +00:00
|
|
|
&output_hex,
|
|
|
|
&output_ols,
|
|
|
|
&output_vcd,
|
2011-04-10 21:33:43 +00:00
|
|
|
&output_chronovu_la8,
|
2012-09-08 11:24:48 +00:00
|
|
|
&output_analog,
|
2010-04-04 11:19:20 +00:00
|
|
|
NULL,
|
2010-04-02 18:18:27 +00:00
|
|
|
};
|
|
|
|
|
2014-05-04 18:51:05 +00:00
|
|
|
/** @since 0.1.0 */
|
2012-02-01 22:40:35 +00:00
|
|
|
SR_API struct sr_output_format **sr_output_list(void)
|
2010-04-02 18:18:27 +00:00
|
|
|
{
|
|
|
|
return output_module_list;
|
|
|
|
}
|
2012-10-21 14:13:36 +00:00
|
|
|
|
2014-05-04 18:51:05 +00:00
|
|
|
/** @since 0.3.0 */
|
2014-04-20 20:51:09 +00:00
|
|
|
SR_API struct sr_output *sr_output_new(struct sr_output_format *of,
|
|
|
|
GHashTable *params, const struct sr_dev_inst *sdi)
|
|
|
|
{
|
|
|
|
struct sr_output *o;
|
|
|
|
|
|
|
|
o = g_malloc(sizeof(struct sr_output));
|
|
|
|
o->format = of;
|
|
|
|
o->sdi = sdi;
|
|
|
|
o->params = params;
|
|
|
|
if (o->format->init && o->format->init(o) != SR_OK) {
|
|
|
|
g_free(o);
|
|
|
|
o = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
2014-05-04 18:51:05 +00:00
|
|
|
/** @since 0.3.0 */
|
2014-04-20 20:51:09 +00:00
|
|
|
SR_API int sr_output_send(struct sr_output *o,
|
|
|
|
const struct sr_datafeed_packet *packet, GString **out)
|
|
|
|
{
|
|
|
|
return o->format->receive(o, packet, out);
|
|
|
|
}
|
|
|
|
|
2014-05-04 18:51:05 +00:00
|
|
|
/** @since 0.3.0 */
|
2014-04-20 20:51:09 +00:00
|
|
|
SR_API int sr_output_free(struct sr_output *o)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = SR_OK;
|
|
|
|
if (o->format->cleanup)
|
|
|
|
ret = o->format->cleanup(o);
|
|
|
|
g_free(o);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-10-21 14:13:36 +00:00
|
|
|
/** @} */
|