From: Bert Vermeulen Date: Fri, 30 Apr 2010 22:54:39 +0000 (-0700) Subject: inout module infrastructure + binary input module X-Git-Tag: libsigrok-0.1.0~537 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=34e4813f2e8b75981ed92d625c5fd55146a35e66;p=libsigrok.git inout module infrastructure + binary input module --- diff --git a/Makefile.am b/Makefile.am index 193cccf2..935c20a3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 00000000..bace6f96 --- /dev/null +++ b/input/input.c @@ -0,0 +1,35 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2010 Bert Vermeulen + * + * 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 . + */ + +#include + +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 index 00000000..a6c6005a --- /dev/null +++ b/input/input_binary.c @@ -0,0 +1,83 @@ +/* + * This file is part of the sigrok project. + * + * Copyright (C) 2010 Bert Vermeulen + * + * 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 . + */ + +#include +#include +#include +#include +#include + +#include + +#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 +}; + diff --git a/sigrok.h b/sigrok.h index 17096628..a8703a38 100644 --- 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);