]> sigrok.org Git - libsigrok.git/blob - output/output_binary.c
80b1447f75d9eabfa06488e5b3d4bf2f0ae26bd4
[libsigrok.git] / output / output_binary.c
1 /*
2  * This file is part of the sigrok project.
3  *
4  * Copyright (C) 2010 Uwe Hermann <uwe@hermann-uwe.de>
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdlib.h>
22 #include <string.h>
23 #include <glib.h>
24 #include <sigrok.h>
25 #include "config.h"
26
27
28 static int event(struct output *o, int event_type, char **data_out,
29                  uint64_t *length_out)
30 {
31
32         /* Prevent compiler warnings. */
33         o = o;
34         event_type = event_type;
35         data_out = data_out;
36
37         switch (event_type) {
38         case DF_TRIGGER:
39                 break;
40         case DF_END:
41                 *length_out = 0;
42                 break;
43         }
44
45         return SIGROK_OK;
46 }
47
48 static int data(struct output *o, char *data_in, uint64_t length_in,
49                 char **data_out, uint64_t *length_out)
50 {
51         uint64_t outsize;
52         char *outbuf;
53
54         /* Prevent compiler warnings. */
55         o = o;
56
57         outsize = length_in;
58         outbuf = calloc(1, outsize);
59         if (outbuf == NULL)
60                 return SIGROK_ERR_MALLOC;
61
62         memcpy(outbuf, data_in, length_in);
63         *data_out = outbuf;
64         *length_out = outsize;
65
66         return SIGROK_OK;
67 }
68
69 struct output_format output_binary = {
70         "binary",
71         "Raw binary",
72         NULL,
73         data,
74         event,
75 };