]> sigrok.org Git - libsigrok.git/commitdiff
inout module infrastructure + binary input module
authorBert Vermeulen <redacted>
Fri, 30 Apr 2010 22:54:39 +0000 (15:54 -0700)
committerBert Vermeulen <redacted>
Fri, 30 Apr 2010 23:09:47 +0000 (16:09 -0700)
Makefile.am
input/input.c [new file with mode: 0644]
input/input_binary.c [new file with mode: 0644]
sigrok.h

index 193cccf2d71497ef02dfba8bc219f0500d831044..935c20a3d687a88e002c211397291468cb4b3317 100644 (file)
@@ -40,6 +40,8 @@ libsigrok_la_SOURCES = \
        hardware/zeroplus-logic-cube/gl_usb.c \
        hardware/zeroplus-logic-cube/gl_usb.h \
        hardware/zeroplus-logic-cube/zeroplus.c \
+       input/input_binary.c \
+       input/input.c \
        output/output_binary.c \
        output/output_text.c \
        output/output_vcd.c \
diff --git a/input/input.c b/input/input.c
new file mode 100644 (file)
index 0000000..bace6f9
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2010 Bert Vermeulen <bert@biot.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sigrok.h>
+
+extern struct input_format input_binary;
+
+struct input_format *input_module_list[] = {
+
+       /* this one has to be last, because it will take any input */
+       &input_binary,
+       NULL,
+};
+
+struct input_format **input_list(void)
+{
+
+       return input_module_list;
+}
diff --git a/input/input_binary.c b/input/input_binary.c
new file mode 100644 (file)
index 0000000..a6c6005
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * This file is part of the sigrok project.
+ *
+ * Copyright (C) 2010 Bert Vermeulen <bert@biot.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/time.h>
+
+#include <sigrok.h>
+
+#define CHUNKSIZE 4096
+
+
+static int format_match(char *filename)
+{
+
+       filename = NULL;
+
+       return TRUE;
+}
+
+
+/* TODO: number of probes hardcoded to 8 */
+static int in_loadfile(char *filename)
+{
+       struct datafeed_header header;
+       struct datafeed_packet packet;
+       char buffer[CHUNKSIZE];
+       int fd, size;
+
+       if( (fd = open(filename, O_RDONLY)) == -1)
+               return SIGROK_ERR;
+
+       header.feed_version = 1;
+       header.num_probes = 8;
+       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);
+
+       packet.type = DF_LOGIC8;
+       packet.payload = buffer;
+       while( (size = read(fd, buffer, CHUNKSIZE)) > 0) {
+               packet.length = size;
+               session_bus(NULL, &packet);
+       }
+       close(fd);
+
+       packet.type = DF_END;
+       session_bus(NULL, &packet);
+
+
+       return SIGROK_OK;
+}
+
+
+struct input_format input_binary = {
+               "binary",
+               "Raw binary",
+               format_match,
+               in_loadfile
+};
+
index 170966282e8ea01238fce1fc6f318dec5c3756ff..a8703a38a2f23919cc789cb4f8dcacab2b98f3c1 100644 (file)
--- a/sigrok.h
+++ b/sigrok.h
@@ -106,6 +106,25 @@ struct datafeed_header {
        int num_probes;
 };
 
+/*
+ * Input
+ */
+struct input {
+       struct input_format *format;
+       void *param;
+       void *internal;
+};
+
+struct input_format {
+       char *extension;
+       char *description;
+       int (*format_match) (char *filename);
+       int (*in_loadfile) (char *filename);
+};
+
+struct input_format **input_list(void);
+
+
 /*
  * Output
  */
@@ -127,6 +146,8 @@ struct output_format {
 };
 
 struct output_format **output_list(void);
+
+
 int filter_probes(int in_unitsize, int out_unitsize, int *probelist,
                  char *data_in, uint64_t length_in, char **data_out,
                  uint64_t *length_out);