]>
Commit | Line | Data |
---|---|---|
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> | |
25 | ||
26 | #include <sigrok.h> | |
27 | ||
28 | #define CHUNKSIZE 4096 | |
29 | ||
30 | ||
31 | static int format_match(char *filename) | |
32 | { | |
33 | ||
34 | filename = NULL; | |
35 | ||
36 | return TRUE; | |
37 | } | |
38 | ||
39 | ||
40 | static int in_loadfile(char *filename) | |
41 | { | |
42 | struct datafeed_header header; | |
43 | struct datafeed_packet packet; | |
44 | struct device *device; | |
45 | char buffer[CHUNKSIZE]; | |
46 | int fd, size, num_probes; | |
47 | ||
48 | if( (fd = open(filename, O_RDONLY)) == -1) | |
49 | return SIGROK_ERR; | |
50 | ||
51 | /* TODO: number of probes hardcoded to 8 */ | |
52 | num_probes = 8; | |
53 | device = device_new(NULL, 0, num_probes); | |
54 | ||
55 | header.feed_version = 1; | |
56 | header.num_probes = num_probes; | |
57 | header.protocol_id = PROTO_RAW; | |
58 | header.samplerate = 0; | |
59 | gettimeofday(&header.starttime, NULL); | |
60 | packet.type = DF_HEADER; | |
61 | packet.length = sizeof(struct datafeed_header); | |
62 | packet.payload = &header; | |
63 | session_bus(device, &packet); | |
64 | ||
65 | packet.type = DF_LOGIC8; | |
66 | packet.payload = buffer; | |
67 | while( (size = read(fd, buffer, CHUNKSIZE)) > 0) { | |
68 | packet.length = size; | |
69 | session_bus(device, &packet); | |
70 | } | |
71 | close(fd); | |
72 | ||
73 | packet.type = DF_END; | |
74 | packet.length = 0; | |
75 | session_bus(device, &packet); | |
76 | ||
77 | ||
78 | return SIGROK_OK; | |
79 | } | |
80 | ||
81 | ||
82 | struct input_format input_binary = { | |
83 | "binary", | |
84 | "Raw binary", | |
85 | format_match, | |
86 | in_loadfile | |
87 | }; | |
88 |