]> sigrok.org Git - libsigrok.git/blobdiff - input/binary.c
sr: change all drivers to use SR_DF_META_LOGIC
[libsigrok.git] / input / binary.c
index 50f7f501820382031307ca4412eea28cfa49a1ad..4d6c42461e64051af849fddf86ecef1a4f513e98 100644 (file)
@@ -52,12 +52,12 @@ static int init(struct sr_input *in)
        }
 
        /* Create a virtual device. */
-       in->vdevice = sr_dev_new(NULL, 0);
+       in->vdev = sr_dev_new(NULL, 0);
 
        for (i = 0; i < num_probes; i++) {
                snprintf(name, SR_MAX_PROBENAME_LEN, "%d", i);
                /* TODO: Check return value. */
-               sr_dev_probe_add(in->vdevice, name);
+               sr_dev_probe_add(in->vdev, name);
        }
 
        return SR_OK;
@@ -67,6 +67,7 @@ static int loadfile(struct sr_input *in, const char *filename)
 {
        struct sr_datafeed_header header;
        struct sr_datafeed_packet packet;
+       struct sr_datafeed_meta_logic meta;
        struct sr_datafeed_logic logic;
        unsigned char buffer[CHUNKSIZE];
        int fd, size, num_probes;
@@ -74,16 +75,21 @@ static int loadfile(struct sr_input *in, const char *filename)
        if ((fd = open(filename, O_RDONLY)) == -1)
                return SR_ERR;
 
-       num_probes = g_slist_length(in->vdevice->probes);
+       num_probes = g_slist_length(in->vdev->probes);
 
        /* send header */
        header.feed_version = 1;
-       header.num_logic_probes = num_probes;
-       header.samplerate = 0;
        gettimeofday(&header.starttime, NULL);
        packet.type = SR_DF_HEADER;
        packet.payload = &header;
-       sr_session_bus(in->vdevice, &packet);
+       sr_session_send(in->vdev, &packet);
+
+       /* Send metadata about the SR_DF_LOGIC packets to come. */
+       packet.type = SR_DF_META_LOGIC;
+       packet.payload = &meta;
+       meta.samplerate = 0;
+       meta.num_probes = num_probes;
+       sr_session_send(in->vdev, &packet);
 
        /* chop up the input file into chunks and feed it into the session bus */
        packet.type = SR_DF_LOGIC;
@@ -92,13 +98,13 @@ static int loadfile(struct sr_input *in, const char *filename)
        logic.data = buffer;
        while ((size = read(fd, buffer, CHUNKSIZE)) > 0) {
                logic.length = size;
-               sr_session_bus(in->vdevice, &packet);
+               sr_session_send(in->vdev, &packet);
        }
        close(fd);
 
        /* end of stream */
        packet.type = SR_DF_END;
-       sr_session_bus(in->vdevice, &packet);
+       sr_session_send(in->vdev, &packet);
 
        return SR_OK;
 }