8 void dowrite(char *s, int len)
13 int cs = ((len-i) > 1) ? 1 : (len-i);
20 int waitchar(int timeout)
26 return poll(&pfd, 1, timeout) == 1;
29 int expect(char *s, int len)
33 for (i=0; i < len; i++)
35 if (waitchar(1000) == 0)
37 fprintf(stderr, "Timeout reached in expect (expected %c)\n", s[i]);
40 while (read(0, &c, 1) == 0)
41 fprintf(stderr, "Short read...\n");
44 fprintf(stderr, "Expect failed: expected %d, got %d (pos %d)\n", s[i], c, i);
51 void expect_no_chars()
55 while (waitchar(100) == 1)
58 if (read(0, &c, 1) == 0)
59 fprintf(stderr, "enc Short read...\n");
61 fprintf(stderr, "Warning: expected no chars, got %d\n", c);
64 fprintf(stderr, "Expect no chars failed: got %d chars\n", cs);
67 void main(int argc, char **argv)
69 unsigned char buf[259];
76 fprintf(stderr, "Usage: %s [filename]\n", argv[0]);
79 rfd = open(argv[1], O_RDONLY);
86 dowrite("\x1B" "A\x00\x00\x00", 5);
87 fprintf(stderr, "Address sent\n");
90 while ((sz = read(rfd, buf+3, 255)) > 0)
99 abuf[2] = (tc >> 16) & 0xFF;
100 abuf[3] = (tc >> 8) & 0xFF;
106 dowrite(buf, sz + 3);
107 fprintf(stderr, "Data sent (%d)\n", tc);
108 rv |= expect("D", 1);
112 printf("Failure to ack... retrying\n");
114 rv = expect("...", 3);