⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 irrecord.c

📁 很少见的linux下的红外口的工具
💻 C
📖 第 1 页 / 共 4 页
字号:
		remote->flags|=SPACE_ENC;		return;	}	else	{		struct lengths *maxp,*max2p,*maxs,*max2s;		maxp=get_max_length(first_pulse,NULL);		unlink_length(&first_pulse,maxp);		if(first_pulse==NULL)		{			first_pulse=maxp;		}		else		{			max2p=get_max_length(first_pulse,NULL);			maxp->next=first_pulse;			first_pulse=maxp;						maxs=get_max_length(first_space,NULL);			unlink_length(&first_space,maxs);			if(first_space==NULL)			{				first_space=maxs;			}			else			{				max2s=get_max_length(first_space,NULL);				maxs->next=first_space;				first_space=maxs;								maxs=get_max_length(first_space,NULL);								if((calc_signal(maxp)<500 ||				    calc_signal(max2p)<500) &&				   (calc_signal(maxs)<500 ||				    calc_signal(max2s)<500))				{					printf("RC-6 remote control found.\n");					remote->flags|=RC6;				}				else				{					printf("RC-5 remote control found.\n");					remote->flags|=RC5;				}				return;			}		}	}	length++;	printf("Suspicious data length: %u.\n",length);	/* this is not yet the number of bits */	remote->bits=length;	remote->flags|=SPACE_ENC;}struct lengths *get_max_length(struct lengths *first,unsigned int *sump){	unsigned int sum;	struct lengths *scan,*max_length;		if(first==NULL) return(NULL);	max_length=first;	sum=first->count;		scan=first->next;	while(scan)	{		if(scan->count>max_length->count)		{			max_length=scan;		}		sum+=scan->count;#               ifdef DEBUG		if(scan->count>0) printf("%u x %lu\n",scan->count,					 (unsigned long) calc_signal(scan));#               endif		scan=scan->next;	}	if(sump!=NULL) *sump=sum;	return(max_length);}int get_trail_length(struct ir_remote *remote){	unsigned int sum,max_count;	struct lengths *max_length;	if(is_biphase(remote)) return(1);		max_length=get_max_length(first_trail,&sum);	max_count=max_length->count;#       ifdef DEBUG	printf("get_trail_length(): sum: %u, max_count %u\n",sum,max_count);#       endif	if(max_count>=sum*TH_TRAIL/100)	{		printf("Found trail pulse: %lu\n",		       (unsigned long) calc_signal(max_length));		remote->ptrail=calc_signal(max_length);		return(1);	}	printf("No trail pulse found.\n");	return(1);}int get_lead_length(struct ir_remote *remote){	unsigned int sum,max_count;	struct lengths *first_lead,*max_length,*max2_length;	lirc_t a,b;		if(!is_biphase(remote)) return(1);	if(is_rc6(remote)) return(1);		first_lead=has_header(remote) ? first_3lead:first_1lead;	max_length=get_max_length(first_lead,&sum);	max_count=max_length->count;#       ifdef DEBUG	printf("get_lead_length(): sum: %u, max_count %u\n",sum,max_count);#       endif	if(max_count>=sum*TH_LEAD/100)	{		printf("Found lead pulse: %lu\n",		       (unsigned long) calc_signal(max_length));		remote->plead=calc_signal(max_length);		return(1);	}	unlink_length(&first_lead,max_length);	max2_length=get_max_length(first_lead,&sum);	max_length->next=first_lead;first_lead=max_length;	a=calc_signal(max_length);	b=calc_signal(max2_length);	if(a>b)	b^=a^=b^=a;	if(abs(2*a-b)<b*EPS/100 || abs(2*a-b)<AEPS)	{		printf("Found hidden lead pulse: %lu\n",		       (unsigned long) a);		remote->plead=a;		return(1);	}	printf("No lead pulse found.\n");	return(1);}int get_header_length(struct ir_remote *remote){	unsigned int sum,max_count;	lirc_t headerp,headers;	struct lengths *max_plength,*max_slength;	if(first_headerp!=NULL)	{		max_plength=get_max_length(first_headerp,&sum);		max_count=max_plength->count;	}	else	{		printf("No header data.\n");		return(1);	}#       ifdef DEBUG	printf("get_header_length(): sum: %u, max_count %u\n",sum,max_count);#       endif	if(max_count>=sum*TH_HEADER/100)	{		max_slength=get_max_length(first_headers,&sum);		max_count=max_slength->count;#               ifdef DEBUG		printf("get_header_length(): sum: %u, max_count %u\n",		       sum,max_count);#               endif		if(max_count>=sum*TH_HEADER/100)		{			headerp=calc_signal(max_plength);			headers=calc_signal(max_slength);			printf("Found possible header: %lu %lu\n",			       (unsigned long) headerp,			       (unsigned long) headers);			remote->phead=headerp;			remote->shead=headers;			if(first_lengths<second_lengths)			{				printf("Header is not being repeated.\n");				remote->flags|=NO_HEAD_REP;			}			return(1);		}	}	printf("No header found.\n");	return(1);}int get_repeat_length(struct ir_remote *remote){	unsigned int sum,max_count;	lirc_t repeatp,repeats,repeat_gap;	struct lengths *max_plength,*max_slength;	if(!((count_3repeats>SAMPLES/2 ? 1:0) ^	     (count_5repeats>SAMPLES/2 ? 1:0)))	{		if(count_3repeats>SAMPLES/2 || count_5repeats>SAMPLES/2)		{			printf("Repeat inconsitentcy.\n");			return(0);		}		printf("No repeat code found.\n");		return(1);	}	max_plength=get_max_length(first_repeatp,&sum);	max_count=max_plength->count;#       ifdef DEBUG	printf("get_repeat_length(): sum: %u, max_count %u\n",sum,max_count);#       endif		if(max_count>=sum*TH_REPEAT/100)	{		max_slength=get_max_length(first_repeats,&sum);		max_count=max_slength->count;#               ifdef DEBUG		printf("get_repeat_length(): sum: %u, max_count %u\n",		       sum,max_count);#               endif		if(max_count>=sum*TH_REPEAT/100)		{			if(count_5repeats>count_3repeats &&			   !has_header(remote))			{				printf("Repeat code has header,"				       " but no header found!\n");				return(0);			}			if(count_5repeats>count_3repeats &&			   has_header(remote))			{				remote->flags|=REPEAT_HEADER;			}			repeatp=calc_signal(max_plength);			repeats=calc_signal(max_slength);						printf("Found repeat code: %lu %lu\n",			       (unsigned long) repeatp,			       (unsigned long) repeats);			remote->prepeat=repeatp;			remote->srepeat=repeats;			if(!(remote->flags&CONST_LENGTH))			{				max_slength=get_max_length(first_repeat_gap,							   NULL);				repeat_gap=calc_signal(max_slength);				printf("Found repeat gap: %lu\n",				       (unsigned long) repeat_gap);				remote->repeat_gap=repeat_gap;							}			return(1);		}	}	printf("No repeat header found.\n");	return(1);}void unlink_length(struct lengths **first,struct lengths *remove){	struct lengths *last,*scan;	if(remove==*first)	{		*first=remove->next;		remove->next=NULL;		return;	}	else	{		scan=(*first)->next;		last=*first;		while(scan)		{			if(scan==remove)			{				last->next=remove->next;				remove->next=NULL;				return;			}			last=scan;			scan=scan->next;		}	}	printf("unlink_length(): report this bug!\n");}int get_data_length(struct ir_remote *remote){	unsigned int sum,max_count;	lirc_t p1,p2,s1,s2;	struct lengths *max_plength,*max_slength;	struct lengths *max2_plength,*max2_slength;	max_plength=get_max_length(first_pulse,&sum);	max_count=max_plength->count;#       ifdef DEBUG	printf("get_data_length(): sum: %u, max_count %u\n",sum,max_count);#       endif	if(max_count>=sum*TH_IS_BIT/100)	{		unlink_length(&first_pulse,max_plength);		max2_plength=get_max_length(first_pulse,NULL);		if(max2_plength!=NULL)		{			if(max2_plength->count<max_count*TH_IS_BIT/100)				max2_plength=NULL;		}#               ifdef DEBUG		printf("Pulse canditates: ");		printf("%u x %lu",max_plength->count,		       (unsigned long) calc_signal(max_plength));		if(max2_plength) printf(", %u x %lu",max2_plength->count,					(unsigned long)					calc_signal(max2_plength));		printf("\n");#               endif		max_slength=get_max_length(first_space,&sum);		max_count=max_slength->count;#               ifdef DEBUG		printf("get_data_length(): sum: %u, max_count %u\n",		       sum,max_count);#               endif		if(max_count>=sum*TH_IS_BIT/100)		{			unlink_length(&first_space,max_slength);						max2_slength=get_max_length(first_space,NULL);			if(max2_slength!=NULL)			{				if(max2_slength->count<max_count*TH_IS_BIT/100)					max2_slength=NULL;			}			#                       ifdef DEBUG			printf("Space canditates: ");			printf("%u x %lu",max_slength->count,			       (unsigned long) calc_signal(max_slength));			if(max2_slength) printf(", %u x %lu",						max2_slength->count,						(unsigned long) calc_signal(max2_slength));			printf("\n");#                       endif			remote->eps=EPS;			remote->aeps=AEPS;			if(is_biphase(remote))			{				if(max2_plength==NULL || max2_slength==NULL)				{					printf("Unknown encoding found.\n");					return(0);				}				printf("Signals are biphase encoded.\n");				p1=calc_signal(max_plength);				p2=calc_signal(max2_plength);				s1=calc_signal(max_slength);				s2=calc_signal(max2_slength);								remote->pone=(min(p1,p2)+max(p1,p2)/2)/2;				remote->sone=(min(s1,s2)+max(s1,s2)/2)/2;				remote->pzero=remote->pone;				remote->szero=remote->sone;			}			else			{				if(max2_plength==NULL &&				   max2_slength==NULL)				{					printf("No encoding found.\n");					return(0);				}				if(max2_plength && max2_slength)				{					printf("Unknown encoding found.\n");					return(0);				}				p1=calc_signal(max_plength);				s1=calc_signal(max_slength);				if(max2_plength)				{					p2=calc_signal(max2_plength);					printf("Signals are pulse encoded.\n");					remote->pone=max(p1,p2);					remote->sone=s1;					remote->pzero=min(p1,p2);					remote->szero=s1;				}				else				{					s2=calc_signal(max2_slength);					printf("Signals are space encoded.\n");					remote->pone=p1;					remote->sone=max(s1,s2);					remote->pzero=p1;					remote->szero=min(s1,s2);				}			}			if(has_header(remote) &&			   (!has_repeat(remote) || remote->flags&NO_HEAD_REP)			   )			{				if(!is_biphase(remote) &&				   ((expect(remote,remote->phead,remote->pone) &&				     expect(remote,remote->shead,remote->sone)) ||				    (expect(remote,remote->phead,remote->pzero) &&				     expect(remote,remote->shead,remote->szero))))				{					remote->phead=remote->shead=0;					remote->flags&=~NO_HEAD_REP;					printf("Removed header.\n");				}				if(is_biphase(remote) &&				   expect(remote,remote->shead,remote->sone))				{					remote->plead=remote->phead;					remote->phead=remote->shead=0;					remote->flags&=~NO_HEAD_REP;					printf("Removed header.\n");				}			}			if(is_biphase(remote))			{				struct lengths *signal_length;				lirc_t data_length;				signal_length=get_max_length(first_signal_length,							     NULL);				data_length=calc_signal(signal_length)-					remote->plead-					remote->phead-					remote->shead+					/* + 1/2 bit */					(remote->pone+remote->sone)/2;				remote->bits=data_length/					(remote->pone+remote->sone);				if(is_rc6(remote)) remote->bits--;			}			else			{				remote->bits=(remote->bits-					      (has_header(remote) ? 2:0)+					      1-(remote->ptrail>0 ? 2:0))/2;			}			printf("Signal length is %d\n",remote->bits);			free_lengths(max_plength);			free_lengths(max_slength);			return(1);		}		free_lengths(max_plength);	}	printf("Could not find data lengths.\n");	return(0);}int get_gap_length(struct ir_remote *remote){	struct lengths *gaps=NULL;	struct timeval start,end,last;	int count,flag;	struct lengths *scan;	int maxcount,lastmaxcount;	lirc_t gap;		remote->eps=EPS;	remote->aeps=AEPS;	count=0;flag=0;lastmaxcount=0;	printf("Hold down an arbitrary button.\n");	while(1)	{		while(availabledata())		{			hw.rec_func(NULL);		}		if(!waitfordata(10000000))		{			free_lengths(gaps);			return(0);		}		gettimeofday(&start,NULL);		while(availabledata())		{			hw.rec_func(NULL);		}		gettimeofday(&end,NULL);		if(flag)		{			gap=time_elapsed(&last,&start);			add_length(&gaps,gap);			merge_lengths(gaps);			maxcount=0;			scan=gaps;			while(scan)			{				maxcount=max(maxcount,					     scan->count);				if(scan->count>SAMPLES)				{					remote->gap=calc_signal(scan);					/* this does not work very reliably */					remote->gap+=100000;					printf("\nFound gap length: %lu\n",					       (unsigned long) remote->gap);					free_lengths(gaps);					return(1);				}				scan=scan->next;			}			if(maxcount>lastmaxcount)			{				lastmaxcount=maxcount;				printf(".");fflush(stdout);			}		}		else		{			flag=1;		}		last=end;	}	return(1);}void fprint_copyright(FILE *fout){	fprintf(fout,		"\n"		"# Please make this file available to others\n"		"# by sending it to <lirc@bartelmus.de>\n");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -