diff testugen.c @ 27:d5a265299a4b

Test programs to talk to the hardware from a PC
author darius
date Mon, 10 Apr 2006 17:22:17 +0930
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testugen.c	Mon Apr 10 17:22:17 2006 +0930
@@ -0,0 +1,44 @@
+#include <sys/types.h>
+#include <sys/ioctl.h>
+#include <dev/usb/usb.h>
+#include <sys/errno.h>
+#include <sys/uio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+
+int
+main(int argc, char **argv) {
+    int		endpt2fd, i, len;
+    char	*endpt2name = "/dev/ugen0.2";
+    uint8_t	data[256];
+    
+    if ((endpt2fd = open(endpt2name, O_RDWR)) == -1) {
+	fprintf(stderr, "Unable to open %s: %s\n", endpt2name, strerror(errno));
+	exit(1);
+    }
+
+    i = 1;
+    if (ioctl(endpt2fd, USB_SET_SHORT_XFER, &i) == -1) {
+	fprintf(stderr, "Unable to set short xfer on end point 2: %s\n", strerror(errno));
+	exit(1);
+    }
+    
+    while(1) {
+	len = read(endpt2fd, data, 256);
+	printf("len = %d\n", len);
+	if (len == 0) {
+	    printf("EOF\n");
+	    continue;
+	}
+	if (len == -1) {
+	    printf("read error: %s\n", strerror(errno));
+	    exit(1);
+	}
+	
+	for (i = 0; i < len; i++)
+	    printf("0x%02x ", data[i]);
+	printf("\n");
+    }
+}
+