loop1.c 1.25 KB
#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);
}