]>
Commit | Line | Data |
---|---|---|
34e4813f BV |
1 | /* |
2 | * This file is part of the sigrok project. | |
3 | * | |
4 | * Copyright (C) 2010 Bert Vermeulen <bert@biot.com> | |
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 3 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, see <http://www.gnu.org/licenses/>. | |
18 | */ | |
19 | ||
20 | #include <sys/types.h> | |
21 | #include <sys/stat.h> | |
22 | #include <fcntl.h> | |
23 | #include <unistd.h> | |
24 | #include <sys/time.h> | |
34e4813f BV |
25 | #include <sigrok.h> |
26 | ||
27 | #define CHUNKSIZE 4096 | |
28 | ||
757b8c62 | 29 | static int format_match(const char *filename) |
34e4813f | 30 | { |
34e4813f | 31 | filename = NULL; |
34e4813f BV |
32 | return TRUE; |
33 | } | |
34 | ||
757b8c62 | 35 | static int in_loadfile(const char *filename) |
34e4813f BV |
36 | { |
37 | struct datafeed_header header; | |
38 | struct datafeed_packet packet; | |
db91a1c3 | 39 | struct device *device; |
34e4813f | 40 | char buffer[CHUNKSIZE]; |
db91a1c3 | 41 | int fd, size, num_probes; |
34e4813f | 42 | |
757b8c62 | 43 | if ((fd = open(filename, O_RDONLY)) == -1) |
34e4813f BV |
44 | return SIGROK_ERR; |
45 | ||
757b8c62 | 46 | /* TODO: Number of probes is hardcoded to 8. */ |
db91a1c3 BV |
47 | num_probes = 8; |
48 | device = device_new(NULL, 0, num_probes); | |
49 | ||
34e4813f | 50 | header.feed_version = 1; |
c2616fb9 DR |
51 | header.num_logic_probes = num_probes; |
52 | header.num_analog_probes = 0; /* FIXME */ | |
34e4813f BV |
53 | header.protocol_id = PROTO_RAW; |
54 | header.samplerate = 0; | |
55 | gettimeofday(&header.starttime, NULL); | |
56 | packet.type = DF_HEADER; | |
57 | packet.length = sizeof(struct datafeed_header); | |
58 | packet.payload = &header; | |
db91a1c3 | 59 | session_bus(device, &packet); |
34e4813f | 60 | |
4c046c6b BV |
61 | packet.type = DF_LOGIC; |
62 | packet.unitsize = 1; | |
34e4813f | 63 | packet.payload = buffer; |
757b8c62 | 64 | while ((size = read(fd, buffer, CHUNKSIZE)) > 0) { |
34e4813f | 65 | packet.length = size; |
db91a1c3 | 66 | session_bus(device, &packet); |
34e4813f BV |
67 | } |
68 | close(fd); | |
69 | ||
70 | packet.type = DF_END; | |
db91a1c3 BV |
71 | packet.length = 0; |
72 | session_bus(device, &packet); | |
34e4813f | 73 | |
34e4813f BV |
74 | return SIGROK_OK; |
75 | } | |
76 | ||
34e4813f | 77 | struct input_format input_binary = { |
757b8c62 UH |
78 | "binary", |
79 | "Raw binary", | |
80 | format_match, | |
81 | in_loadfile, | |
34e4813f | 82 | }; |