Example #1
0
/*-------------------------------------------------------------------------*/
int frontpanel_rs232::fp_read_msg(unsigned char *msg, unsigned long long *ts)
{
	int l;

	CHECK_FD();

	struct pollfd pfd[]=  {{fd, POLLIN|POLLERR|POLLHUP,0}
	};

	while(1) {
		poll(pfd,1,20);
//		u_sleep(10*1000);

		l=fp_read(buf+state,1);
		if (l!=1)		
			return 0;
			
//                printf("%02x ",*(buf+state)); fflush(stdout);
		if (state==0) {
			if (buf[0]==0x5a || buf[0]==0x55) { // 0x55 RAW IR
				state=1;
#if !FPCTL
				timestamp=get_timestamp();
#endif
			}
			if (buf[0]==0xff) { // flash-mode active?
				return 1;
			}
		}
		else if (state==1) {
			if (buf[0]==0x55)
				cmd_length=2;
			else
				cmd_length=get_answer_length(buf[1]);
			if (cmd_length==0) {
				state=0;
				memcpy(msg,buf,2);
				buf[0]=0;
				if (ts)
					*ts=timestamp;
				return 2;
			}
			state++;
		}
		else {
			if (state==1+cmd_length) {
				state=0;
				memcpy(msg,buf,2+cmd_length);
				buf[0]=0;
				if (ts)
					*ts=timestamp;			
				return 2+cmd_length;
			}
			state++;
		}
	}

	return 0;
}
Example #2
0
static __inline
int
read_check(struct file *fp, void *buf, size_t nbyte)
{
	size_t nread;
	int error;

	PRINTF(("reading %zd bytes\n", nbyte));
	error = fp_read(fp, buf, nbyte, &nread, 1, UIO_SYSSPACE);
	if (error) {
                PRINTF(("read failed - %d", error));
	} else if (nread != nbyte) {
                PRINTF(("wanted to read %zd - read %zd\n", nbyte, nread));
		error = EINVAL;
	}
	return error;
}