![]() |
libsigrok
0.3.0
sigrok hardware access and backend library
|
00001 /* 00002 * This file is part of the libsigrok project. 00003 * 00004 * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com> 00005 * 00006 * This program is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 #include "libsigrok.h" 00021 #include "libsigrok-internal.h" 00022 00023 /** 00024 * @file 00025 * 00026 * Output file/data format handling. 00027 */ 00028 00029 /** 00030 * @defgroup grp_output Output formats 00031 * 00032 * Output file/data format handling. 00033 * 00034 * libsigrok supports several output (file) formats, e.g. binary, VCD, 00035 * gnuplot, and so on. It provides an output API that frontends can use. 00036 * New output formats can be added/implemented in libsigrok without having 00037 * to change the frontends at all. 00038 * 00039 * All output modules are fed data in a stream. Devices that can stream data 00040 * into libsigrok, instead of storing and then transferring the whole buffer, 00041 * can thus generate output live. 00042 * 00043 * Output modules generate a newly allocated GString. The caller is then 00044 * expected to free this with g_string_free() when finished with it. 00045 * 00046 * @{ 00047 */ 00048 00049 /** @cond PRIVATE */ 00050 extern SR_PRIV struct sr_output_format output_bits; 00051 extern SR_PRIV struct sr_output_format output_hex; 00052 extern SR_PRIV struct sr_output_format output_ascii; 00053 extern SR_PRIV struct sr_output_format output_binary; 00054 extern SR_PRIV struct sr_output_format output_vcd; 00055 extern SR_PRIV struct sr_output_format output_ols; 00056 extern SR_PRIV struct sr_output_format output_gnuplot; 00057 extern SR_PRIV struct sr_output_format output_chronovu_la8; 00058 extern SR_PRIV struct sr_output_format output_csv; 00059 extern SR_PRIV struct sr_output_format output_analog; 00060 /* @endcond */ 00061 00062 static struct sr_output_format *output_module_list[] = { 00063 &output_ascii, 00064 &output_binary, 00065 &output_bits, 00066 &output_csv, 00067 &output_gnuplot, 00068 &output_hex, 00069 &output_ols, 00070 &output_vcd, 00071 &output_chronovu_la8, 00072 &output_analog, 00073 NULL, 00074 }; 00075 00076 /** @since 0.1.0 */ 00077 SR_API struct sr_output_format **sr_output_list(void) 00078 { 00079 return output_module_list; 00080 } 00081 00082 /** @since 0.3.0 */ 00083 SR_API struct sr_output *sr_output_new(struct sr_output_format *of, 00084 GHashTable *params, const struct sr_dev_inst *sdi) 00085 { 00086 struct sr_output *o; 00087 00088 o = g_malloc(sizeof(struct sr_output)); 00089 o->format = of; 00090 o->sdi = sdi; 00091 o->params = params; 00092 if (o->format->init && o->format->init(o) != SR_OK) { 00093 g_free(o); 00094 o = NULL; 00095 } 00096 00097 return o; 00098 } 00099 00100 /** @since 0.3.0 */ 00101 SR_API int sr_output_send(struct sr_output *o, 00102 const struct sr_datafeed_packet *packet, GString **out) 00103 { 00104 return o->format->receive(o, packet, out); 00105 } 00106 00107 /** @since 0.3.0 */ 00108 SR_API int sr_output_free(struct sr_output *o) 00109 { 00110 int ret; 00111 00112 ret = SR_OK; 00113 if (o->format->cleanup) 00114 ret = o->format->cleanup(o); 00115 g_free(o); 00116 00117 return ret; 00118 } 00119 00120 /** @} */
1.7.6.1