]> sigrok.org Git - libsigrok.git/blobdiff - input/input_binary.c
configure: Add --enable-demo option.
[libsigrok.git] / input / input_binary.c
index a6c6005aae78c87828a96596b411a7dfba897552..2f1462d07dc5f9424e34bd308d35224c9466ef31 100644 (file)
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/time.h>
-
 #include <sigrok.h>
 
 #define CHUNKSIZE 4096
 
-
-static int format_match(char *filename)
+static int format_match(const char *filename)
 {
-
        filename = NULL;
-
        return TRUE;
 }
 
-
-/* TODO: number of probes hardcoded to 8 */
-static int in_loadfile(char *filename)
+static int in_loadfile(const char *filename)
 {
        struct datafeed_header header;
        struct datafeed_packet packet;
+       struct device *device;
        char buffer[CHUNKSIZE];
-       int fd, size;
+       int fd, size, num_probes;
 
-       if(fd = open(filename, O_RDONLY)) == -1)
+       if ((fd = open(filename, O_RDONLY)) == -1)
                return SIGROK_ERR;
 
+       /* TODO: Number of probes is hardcoded to 8. */
+       num_probes = 8;
+       device = device_new(NULL, 0, num_probes);
+
        header.feed_version = 1;
-       header.num_probes = 8;
+       header.num_logic_probes = num_probes;
+       header.num_analog_probes = 0; /* FIXME */
        header.protocol_id = PROTO_RAW;
        header.samplerate = 0;
        gettimeofday(&header.starttime, NULL);
        packet.type = DF_HEADER;
        packet.length = sizeof(struct datafeed_header);
        packet.payload = &header;
-       session_bus(NULL, &packet);
+       session_bus(device, &packet);
 
-       packet.type = DF_LOGIC8;
+       packet.type = DF_LOGIC;
+       packet.unitsize = 1;
        packet.payload = buffer;
-       while(size = read(fd, buffer, CHUNKSIZE)) > 0) {
+       while ((size = read(fd, buffer, CHUNKSIZE)) > 0) {
                packet.length = size;
-               session_bus(NULL, &packet);
+               session_bus(device, &packet);
        }
        close(fd);
 
        packet.type = DF_END;
-       session_bus(NULL, &packet);
-
+       packet.length = 0;
+       session_bus(device, &packet);
 
        return SIGROK_OK;
 }
 
-
 struct input_format input_binary = {
-               "binary",
-               "Raw binary",
-               format_match,
-               in_loadfile
+       "binary",
+       "Raw binary",
+       format_match,
+       in_loadfile,
 };
-