2 * This file is part of the sigrok project.
4 * Copyright (C) 2010 Bert Vermeulen <bert@biot.com>
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 3 of the License, or
9 * (at your option) any later version.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <sys/types.h>
28 #define CHUNKSIZE 4096
29 #define DEFAULT_NUM_PROBES 8
32 static int format_match(const char *filename)
35 /* suppress compiler warning */
38 /* this module will handle anything you throw at it */
42 static int init(struct sr_input *in)
46 if (in->param && in->param[0]) {
47 num_probes = strtoul(in->param, NULL, 10);
51 num_probes = DEFAULT_NUM_PROBES;
53 /* create a virtual device */
54 in->vdevice = device_new(NULL, 0, num_probes);
59 static int loadfile(struct sr_input *in, const char *filename)
61 struct datafeed_header header;
62 struct datafeed_packet packet;
63 char buffer[CHUNKSIZE];
64 int fd, size, num_probes;
66 if ((fd = open(filename, O_RDONLY)) == -1)
69 num_probes = g_slist_length(in->vdevice->probes);
72 header.feed_version = 1;
73 header.num_logic_probes = num_probes;
74 header.num_analog_probes = 0;
75 header.protocol_id = PROTO_RAW;
76 header.samplerate = 0;
77 gettimeofday(&header.starttime, NULL);
78 packet.type = DF_HEADER;
79 packet.length = sizeof(struct datafeed_header);
80 packet.payload = &header;
81 session_bus(in->vdevice, &packet);
83 /* chop up the input file into chunks and feed it into the session bus */
84 packet.type = DF_LOGIC;
85 packet.unitsize = (num_probes + 7) / 8;
86 packet.payload = buffer;
87 while ((size = read(fd, buffer, CHUNKSIZE)) > 0) {
89 session_bus(in->vdevice, &packet);
96 session_bus(in->vdevice, &packet);
101 struct sr_input_format input_binary = {