X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=input%2Finput_binary.c;h=2f1462d07dc5f9424e34bd308d35224c9466ef31;hb=a61b0e6a35fdf06c98a2304e186a3a17c9fbf8d8;hp=a6c6005aae78c87828a96596b411a7dfba897552;hpb=34e4813f2e8b75981ed92d625c5fd55146a35e66;p=libsigrok.git diff --git a/input/input_binary.c b/input/input_binary.c index a6c6005a..2f1462d0 100644 --- a/input/input_binary.c +++ b/input/input_binary.c @@ -22,62 +22,61 @@ #include #include #include - #include #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, }; -