Esempio n. 1
0
inline int get_repeat(struct ir_remote *remote)
{
	if (!get_lead(remote))
		return (0);
	if (is_biphase(remote)) {
		if (!expectspace(remote, remote->srepeat))
			return (0);
		if (!expectpulse(remote, remote->prepeat))
			return (0);
	} else {
		if (!expectpulse(remote, remote->prepeat))
			return (0);
		set_pending_space(remote->srepeat);
	}
	if (!get_trail(remote))
		return (0);
	if (!get_gap
	    (remote,
	     is_const(remote) ? (min_gap(remote) >
				 rec_buffer.sum ? min_gap(remote) -
				 rec_buffer.sum : 0) : (has_repeat_gap(remote) ? remote->repeat_gap : min_gap(remote))
	    ))
		return (0);
	return (1);
}
Esempio n. 2
0
void rewind_rec_buffer(void)
{
	rec_buffer.rptr=0;
	rec_buffer.too_long=0;
	set_pending_pulse(0);
	set_pending_space(0);
	rec_buffer.sum=0;
}
Esempio n. 3
0
inline int expectzero(struct ir_remote *remote, int bit)
{
	if (is_biphase(remote)) {
		int all_bits = bit_count(remote);
		ir_code mask;

		mask = ((ir_code) 1) << (all_bits - 1 - bit);
		if (mask & remote->rc6_mask) {
			if (!expectpulse(remote, 2 * remote->pzero)) {
				unget_rec_buffer(1);
				return (0);
			}
			set_pending_space(2 * remote->szero);
		} else {
			if (!expectpulse(remote, remote->pzero)) {
				unget_rec_buffer(1);
				return (0);
			}
			set_pending_space(remote->szero);
		}
	} else if (is_space_first(remote)) {
		if (remote->szero > 0 && !expectspace(remote, remote->szero)) {
			unget_rec_buffer(1);
			return (0);
		}
		if (remote->pzero > 0 && !expectpulse(remote, remote->pzero)) {
			unget_rec_buffer(2);
			return (0);
		}
	} else {
		if (!expectpulse(remote, remote->pzero)) {
			unget_rec_buffer(1);
			return (0);
		}
		if (remote->ptrail > 0) {
			if (!expectspace(remote, remote->szero)) {
				unget_rec_buffer(2);
				return (0);
			}
		} else {
			set_pending_space(remote->szero);
		}
	}
	return (1);
}
Esempio n. 4
0
inline int get_header(struct ir_remote *remote)
{
	if (is_rcmm(remote)) {
		lirc_t deltap, deltas, sum;

		deltap = get_next_pulse(remote->phead);
		if (deltap == 0) {
			unget_rec_buffer(1);
			return (0);
		}
		deltas = get_next_space(remote->shead);
		if (deltas == 0) {
			unget_rec_buffer(2);
			return (0);
		}
		sum = deltap + deltas;
		if (expect(remote, sum, remote->phead + remote->shead)) {
			return (1);
		}
		unget_rec_buffer(2);
		return (0);
	} else if (is_bo(remote)) {
		if (expectpulse(remote, remote->pone) && expectspace(remote, remote->sone)
		    && expectpulse(remote, remote->pone) && expectspace(remote, remote->sone)
		    && expectpulse(remote, remote->phead) && expectspace(remote, remote->shead)) {
			return 1;
		}
		return 0;
	}
	if (remote->shead == 0) {
		if (!sync_pending_space(remote))
			return 0;
		set_pending_pulse(remote->phead);
		return 1;
	}
	if (!expectpulse(remote, remote->phead)) {
		unget_rec_buffer(1);
		return (0);
	}
	/* if this flag is set I need a decision now if this is really
	   a header */
	if (remote->flags & NO_HEAD_REP) {
		lirc_t deltas;

		deltas = get_next_space(remote->shead);
		if (deltas != 0) {
			if (expect(remote, remote->shead, deltas)) {
				return (1);
			}
			unget_rec_buffer(2);
			return (0);
		}
	}

	set_pending_space(remote->shead);
	return (1);
}
Esempio n. 5
0
inline int sync_pending_space(struct ir_remote *remote)
{
	if(rec_buffer.pendings>0)
	{
		lirc_t deltas;
		
		deltas=get_next_space(rec_buffer.pendings);
		if(deltas==0) return 0;
		if(!expect(remote,deltas,rec_buffer.pendings)) return 0;
		set_pending_space(0);
	}
	return 1;
}
Esempio n. 6
0
ir_code get_pre(struct ir_remote * remote)
{
	ir_code pre;

	pre = get_data(remote, remote->pre_data_bits, 0);

	if (pre == (ir_code) - 1) {
		logprintf(1, "failed on pre_data");
		return ((ir_code) - 1);
	}
	if (remote->pre_p > 0 && remote->pre_s > 0) {
		if (!expectpulse(remote, remote->pre_p))
			return ((ir_code) - 1);
		set_pending_space(remote->pre_s);
	}
	return (pre);
}
Esempio n. 7
0
ir_code get_post(struct ir_remote * remote)
{
	ir_code post;

	if (remote->post_p > 0 && remote->post_s > 0) {
		if (!expectpulse(remote, remote->post_p))
			return ((ir_code) - 1);
		set_pending_space(remote->post_s);
	}

	post = get_data(remote, remote->post_data_bits, remote->pre_data_bits + remote->bits);

	if (post == (ir_code) - 1) {
		logprintf(1, "failed on post_data");
		return ((ir_code) - 1);
	}
	return (post);
}
Esempio n. 8
0
int expectspace(struct ir_remote *remote,int exdelta)
{
	lirc_t deltas;
	int retval;

	//LOGPRINTF(5, "expecting space: %lu", exdelta);
	if(!sync_pending_pulse(remote)) return 0;
	
	deltas=get_next_space(rec_buffer.pendings+exdelta);
	if(deltas==0) return(0);
	if(rec_buffer.pendings>0)
	{
		if(rec_buffer.pendings>deltas) return 0;
		retval=expect(remote,deltas-rec_buffer.pendings,exdelta);
		if(!retval) return(0);
		set_pending_space(0);
	}
	else
	{
		retval=expect(remote,deltas,exdelta);
	}
	return(retval);
}
Esempio n. 9
0
ir_code get_data(struct ir_remote *remote,int bits,int done)
{
	ir_code code;
	int i;
	
	code=0;
	
	if(is_rcmm(remote))
	{
		lirc_t deltap,deltas,sum;
		
		if(bits%2 || done%2)
		{
			return((ir_code) -1);
		}
		if(!sync_pending_space(remote)) return 0;
		for(i=0;i<bits;i+=2)
		{
			code<<=2;
			deltap=get_next_pulse(remote->pzero+remote->pone+
					      remote->ptwo+remote->pthree);
			deltas=get_next_space(remote->szero+remote->sone+
					      remote->stwo+remote->sthree);
			if(deltap==0 || deltas==0) 
			{
				return((ir_code) -1);
			}
			sum=deltap+deltas;
			//LOGPRINTF(3,"rcmm: sum %ld",(unsigned long) sum);
			if(expect(remote,sum,remote->pzero+remote->szero))
			{
				code|=0;
				//LOGPRINTF(2,"00");
			}
			else if(expect(remote,sum,remote->pone+remote->sone))
			{
				code|=1;
				//LOGPRINTF(2,"01");
			}
			else if(expect(remote,sum,remote->ptwo+remote->stwo))
			{
				code|=2;
				//LOGPRINTF(2,"10");
			}
			else if(expect(remote,sum,remote->pthree+remote->sthree))
			{
				code|=3;
				//LOGPRINTF(2,"11");
			}
			else
			{
				//LOGPRINTF(2,"no match for %d+%d=%d",deltap,deltas,sum);
				return((ir_code) -1);
			}
		}
		return(code);
	}
	else if(is_grundig(remote))
	{
		lirc_t deltap,deltas,sum;
		int state,laststate;
		
		if(bits%2 || done%2)
		{
			return((ir_code) -1);
		}
		if(!sync_pending_pulse(remote)) return ((ir_code) -1);
		for(laststate=state=-1,i=0;i<bits;)
		{
			deltas=get_next_space(remote->szero+remote->sone+
					      remote->stwo+remote->sthree);
			deltap=get_next_pulse(remote->pzero+remote->pone+
					      remote->ptwo+remote->pthree);
			if(deltas==0 || deltap==0) 
			{
				return((ir_code) -1);
			}
			sum=deltas+deltap;
			//LOGPRINTF(3,"grundig: sum %ld",(unsigned long) sum);
			if(expect(remote,sum,remote->szero+remote->pzero))
			{
				state=0;
				//LOGPRINTF(2,"2T");
			}
			else if(expect(remote,sum,remote->sone+remote->pone))
			{
				state=1;
				//LOGPRINTF(2,"3T");
			}
			else if(expect(remote,sum,remote->stwo+remote->ptwo))
			{
				state=2;
				//LOGPRINTF(2,"4T");
			}
			else if(expect(remote,sum,remote->sthree+remote->pthree))
			{
				state=3;
				//LOGPRINTF(2,"6T");
			}
			else
			{
				//LOGPRINTF(2,"no match for %d+%d=%d",deltas,deltap,sum);
				return((ir_code) -1);
			}
			if(state==3) /* 6T */
			{
				i+=2;code<<=2;state=-1;
				code|=0;
			}
			else if(laststate==2 && state==0) /* 4T2T */
			{
				i+=2;code<<=2;state=-1;
				code|=1;
			}
			else if(laststate==1 && state==1) /* 3T3T */
			{
				i+=2;code<<=2;state=-1;
				code|=2;
			}
			else if(laststate==0 && state==2) /* 2T4T */
			{
				i+=2;code<<=2;state=-1;
				code|=3;
			}
			else if(laststate==-1)
			{
				/* 1st bit */
			}
			else
			{
				return((ir_code) -1);
			}
			laststate=state;
		}
		return(code);
	}
	else if(is_serial(remote))
	{
		int received;
		int space, start_bit, stop_bit, parity_bit;
		int parity;
		lirc_t delta,origdelta,pending,expecting, gap_delta;
		lirc_t base, stop;
		lirc_t max_space, max_pulse;
		
		base=1000000/remote->baud;
		
		/* start bit */
		set_pending_pulse(base);
		
		received=0;
		space=(rec_buffer.pendingp==0); /* expecting space ? */
		start_bit=0;
		stop_bit=0;
		parity_bit=0;
		delta=origdelta=0;
		stop=base*remote->stop_bits/2;
		parity=0;
		gap_delta=0;
		
		max_space = remote->sone*remote->bits_in_byte+stop;
		max_pulse = remote->pzero*(1+remote->bits_in_byte);
		if(remote->parity != IR_PARITY_NONE)
		{
			parity_bit = 1;
			max_space += remote->sone;
			max_pulse += remote->pzero;
			bits += bits/remote->bits_in_byte;
		}
		
		while(received<bits || stop_bit)
		{
			if(delta==0)
			{
				delta=space ?
					get_next_space(max_space):
					get_next_pulse(max_pulse);
				if(delta==0 && space &&
				   received+remote->bits_in_byte+parity_bit>=bits)
				{
					/* open end */
					delta=max_space;
				}
				origdelta=delta;
			}
			if(delta==0)
			{
				//LOGPRINTF(1,"failed before bit %d",received+1);
				return((ir_code) -1);
			}
			pending=(space ?
				 rec_buffer.pendings:rec_buffer.pendingp);
			if(expect(remote, delta, pending))
			{
				delta=0;
			}
			else if(delta>pending)
			{
				delta-=pending;
			}
			else
			{
				//LOGPRINTF(1,"failed before bit %d",received+1);
				return((ir_code) -1);
			}
			if(pending>0)
			{
				if(stop_bit)
				{
					//LOGPRINTF(5, "delta: %lu", delta);
					gap_delta = delta;
					delta=0;
					set_pending_pulse(base);
					set_pending_space(0);
					stop_bit=0;
					space=0;
					//LOGPRINTF(3,"stop bit found");
				}
				else
				{
					//LOGPRINTF(3,"pending bit found");
					set_pending_pulse(0);
					set_pending_space(0);
					if(delta==0)
					{
						space=(space ? 0:1);
					}
				}
				continue;
			}
			expecting=(space ? remote->sone:remote->pzero);
			if(delta>expecting || expect(remote,delta,expecting))
			{
				delta-=(expecting>delta ? delta:expecting);
				received++;
				code<<=1;
				code|=space;
				parity^=space;
				//LOGPRINTF(2,"adding %d",space);
				if(received%(remote->bits_in_byte+parity_bit)==0)
				{
					ir_code temp;
					
					if((remote->parity == IR_PARITY_EVEN && parity) ||
					   (remote->parity == IR_PARITY_ODD && !parity))
					{
						//LOGPRINTF(1, "parity error ""after %d bits",received+1);
						return((ir_code) -1);
					}
					parity = 0;
					
					/* parity bit is filtered out */
					temp=code>>(remote->bits_in_byte+parity_bit);
					code=temp<<remote->bits_in_byte|
						reverse(code>>parity_bit,
							remote->bits_in_byte);
					
					if(space && delta==0)
					{
						//LOGPRINTF(1,"failed at stop ""bit after %d bits",received+1);
						return((ir_code) -1);
					}
					//LOGPRINTF(3,"awaiting stop bit");
					set_pending_space(stop);
					stop_bit=1;
				}				
			}
			else
			{
				if(delta==origdelta)