loop1.c
1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include <netinet/in.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <signal.h>
#include <bbcard.h>
#define BB_FL_BLOCK_SIZE 0x4000 /* 16KB */
char *pname;
char *dname = "/dev/usb/bbrdb0";
int
main(int argc, char **argv)
{
BBCHandle h;
int rv;
char *idbuf;
int idlen;
#if 0
int bbid;
#endif
pname = argv[0];
if (argc > 1)
dname = argv[argc - 1];
idlen = BB_FL_BLOCK_SIZE;
if ((idbuf = malloc(idlen)) == NULL) {
perror("malloc");
exit(1);
}
setbuf(stdout, NULL);
setbuf(stderr, NULL);
while (1) {
printf("%s: BBCInit(%s) ", pname, dname);
fflush(stdout);
h = BBCInit(dname, BBC_SYNC);
printf("returns %d\n", h);
if (h < 0) continue;
#if 0
//sleep(2);
printf("%s: BBCGetIdentity ", pname);
if ((rv = BBCGetIdentity(h, &bbid, idbuf, idlen)) < 0)
printf("returns %d\n", rv);
else
printf("returns %d bbid 0x%x\n", rv, bbid);
bbid = 0x1234abcd;
printf("%s: BBCStoreIdentity ", pname);
rv = BBCStoreIdentity(h, bbid, NULL, 0);
printf("returns %d\n", rv);
//sleep(2);
#endif
rv = BBCClose(h);
printf("%s: BBCClose returns %d\n", pname, rv);
}
exit(0);
}