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

📄 repid.c

📁 有线电视系统前端设备复用器原代码。 用语接受卫星信号
💻 C
📖 第 1 页 / 共 5 页
字号:
		for(i=0;i<Times;i++)
		{
			FIFO_Flag=*(unsigned char *)(PSI_FIFO_FLAG_REG_BASE_ADDR + 0x100*PortNo);
			if(FIFO_Flag&0x01)
			{
				GotPSI=1;
				break;
			}
			my_Delay(1);/*by xu*/
		}

		if(GotPSI==0) 
		{
			Display("Got the succeed SDT TS failed! no data in FIFO!\n");
			return 0;
		}
		else
		{
			for(i=0;i<188;i++)
				TS[i]=*(unsigned char *)(PSI_FIFO_BASE_ADDR + 0x100*PortNo);

			/*----------------------------------------------------------------------------*/
			/* 写包结束寄存器                                                             */
			/*----------------------------------------------------------------------------*/
			ReadVal=*(unsigned char *)(PSI_FIFO_PACKET_END_REG_BASE_ADDR + 0x100*PortNo);

			TS_Head=(TS_TAG *)TS;

			if(TS_Head->Sync_byte!=0x47) 
				return 0;
			if(TS_Head->PID!=PID)
				return 0;			
			if(TS_Head->Adaption_field_control==0)
				return 0;
			/*-----------------------------------------------------------------------------*/
			/* 如果和第一个TS包一样,就结束                                                */
			/*-----------------------------------------------------------------------------*/

			if(IsSame((unsigned long *)TS,(unsigned long *)Buf))
				Completed=1;
			else
			{
				MemCopy(Buf + TS_Count*188,TS,188);
				TS_Count++;
			}
		}
	}

	return TS_Count;
}

#if 0
unsigned long AnalysePSITS(unsigned char PortNo,unsigned short PID)
{
	unsigned char   TS_Count,Proc_TS_Count;
	TS_TAG          *TS_Head;
	SECTION_TAG     *Section_Head;

	unsigned char   Adaption_field_length;
	unsigned char   Point_field;
	unsigned short  SectionLength;
	unsigned short  PayLoadLength;
	
	unsigned short  SectionRest;
	short			TSRest;

	unsigned char   *Dest,*Source,*CopyStart;

	unsigned char   TSEND;

	unsigned char   CheckVal;

	unsigned short  Offset=0;

	int             loop;

	Get_PSI_Result[PortNo].SectionCount=0;


	if(TS_Buf[PortNo]!=NULL)
	{
		TS_Count=GetPSITS(PortNo,PID,TS_Buf[PortNo]);
			
		if(TS_Count==0)
			return 0;
		else
		{
			TS_Head=(TS_TAG *)TS_Buf[PortNo];

			if((TS_Head->Adaption_field_control==2)||(TS_Head->Adaption_field_control==3))
			{
				Adaption_field_length=*(unsigned char *)((unsigned char *)TS_Head + sizeof(TS_TAG));
				Point_field=*(unsigned char *)((unsigned char *)TS_Head + sizeof(TS_TAG) + Adaption_field_length + 1);					
				Section_Head=(SECTION_TAG *)((unsigned char *)TS_Head + sizeof(TS_TAG) + Adaption_field_length + 1 + 1+Point_field);				
				TSRest=188 - sizeof(TS_TAG) - (Adaption_field_length +1) - (Point_field + 1) ; 
			}
			if(TS_Head->Adaption_field_control==1)
			{
				Point_field=*(unsigned char *)((unsigned char *)TS_Head + sizeof(TS_TAG));					
				Section_Head=(SECTION_TAG *)((unsigned char *)TS_Head + sizeof(TS_TAG) + 1 + Point_field);	
				TSRest=188 - sizeof(TS_TAG) - (Point_field + 1) ;
			}

			SectionRest=SectionLength=Section_Head->SectionLength + 3;
			/*-------------------------------------------------------------------------------*/
			/* 新建一个section                                                               */
			/*-------------------------------------------------------------------------------*/
			Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].PID=PID;
			Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].SectionLength=SectionLength;
			Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength=0;
		
			Proc_TS_Count=0;

			while(1)
			{
				if(Proc_TS_Count==TS_Count)
					return Get_PSI_Result[PortNo].SectionCount;
				/*---------------------------------------------------*/
				/* 包的净荷是 section 头                             */
				/*---------------------------------------------------*/
				if(TSRest>=SectionRest)
				{
					PayLoadLength=SectionRest;
					/*-----------------------------------------------*/
					/* 拷贝这个SECTION                               */
					/*-----------------------------------------------*/
					Dest=(unsigned char *)((unsigned char *)Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].Section + Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength);															
					Source  =(unsigned char *)Section_Head;

					MemCopy(Dest,Source,PayLoadLength);

					Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength+=PayLoadLength;	
					Get_PSI_Result[PortNo].SectionCount++;
					
					/*-----------------------------------------------*/
					/* 这个包的后面还有另外一个SECTION的数据吗       */
					/*-----------------------------------------------*/
					TSEND=0;

					CheckVal=*(unsigned char *)((unsigned char *)Section_Head + PayLoadLength);
					/*------------------------------------------------------------------------*/
					/*  SDT的TABLE ID =0x42/0x46                                              */
					/*------------------------------------------------------------------------*/
					if(PID==0x11)
					{
						if((CheckVal!=0x42)&&(CheckVal!=0x46))
							TSEND=1;
					}
					else
					{
						if((CheckVal!=0x2))
							TSEND=1;
					}

					/*-----------------------------------------------*/
					/* 分析下面一个TS包                              */
					/*-----------------------------------------------*/
					if(TSEND==1)
					{
						TS_Head=(TS_TAG *)((unsigned char *)TS_Head + 188);

						Proc_TS_Count++;
						
						if((TS_Head->Adaption_field_control==2)||(TS_Head->Adaption_field_control==3))
						{
							Adaption_field_length=*(unsigned char *)((unsigned char *)TS_Head + sizeof(TS_TAG));
							Point_field=*(unsigned char *)((unsigned char *)TS_Head + sizeof(TS_TAG) + Adaption_field_length + 1);					
							Section_Head=(SECTION_TAG *)((unsigned char *)TS_Head + sizeof(TS_TAG) + Adaption_field_length + 1 + 1+Point_field);				
							TSRest=188 - sizeof(TS_TAG) - (Adaption_field_length +1) - (Point_field + 1) ; 
						}
						if(TS_Head->Adaption_field_control==1)
						{
							Point_field=*(unsigned char *)((unsigned char *)TS_Head + sizeof(TS_TAG));					
							Section_Head=(SECTION_TAG *)((unsigned char *)TS_Head + sizeof(TS_TAG) + 1 + Point_field);	
							TSRest=188 - sizeof(TS_TAG) - (Point_field + 1) ;
						}


						/*--------------------------------------------------------------*/
						/* 错误处理                                                     */
						/* added by johnnyling 2003-09-16                               */
						/*--------------------------------------------------------------*/
						if(TSRest<=0)
							return Get_PSI_Result[PortNo].SectionCount;
						/*--------------------------------------------------------------*/

						SectionRest=SectionLength=Section_Head->SectionLength + 3;
						/*-------------------------------------------*/
						/* 一个新的section                           */
						/*-------------------------------------------*/
						Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].PID=PID;
						Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].SectionLength=SectionLength;
						Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength=0;

					}
					else
					{
						TSRest-=PayLoadLength;
						Section_Head=(SECTION_TAG *)((unsigned char *)Section_Head + PayLoadLength);						
						SectionRest=SectionLength=Section_Head->SectionLength + 3;
						/*-------------------------------------------*/
						/* 一个新的section                           */
						/*-------------------------------------------*/
						Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].PID=PID;
						Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].SectionLength=SectionLength;
						Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength=0;
					}

				}
				/*---------------------------------------------------*/
				/*  包的内容是Section的中间部分                      */
				/*  直接拷贝                                         */
				/*---------------------------------------------------*/
				else
				{
					PayLoadLength=TSRest;
					/*-----------------------------------------------*/
					Dest=(unsigned char *)((unsigned char *)Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].Section + Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength);															
											
					Source  =(unsigned char *)((unsigned char *)TS_Head + 188 - TSRest);

					MemCopy(Dest,Source,PayLoadLength);

					SectionRest-=PayLoadLength;

					Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength+=PayLoadLength;

					/*-----------------------------------------------*/
					/* 这个包已经处理完,换下个包                    */
					/*-----------------------------------------------*/
					TS_Head=(TS_TAG *)((unsigned char *)TS_Head + 188);
					Proc_TS_Count++;

					/*-----------------------------------------------*/
					/* 如果这个包的PayLoadIndicator=1,就有PointField */
					/*-----------------------------------------------*/
					if(TS_Head->Payload_unit_start_indicator==1)
					{							
						Point_field=*(unsigned char *)((unsigned char *)TS_Head + sizeof(TS_TAG));					
						PayLoadLength=Point_field;
						/*-----------------------------------------------*/
						/* 拷贝这个SECTION                               */
						/*-----------------------------------------------*/
						Dest=(unsigned char *)((unsigned char *)Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].Section + Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength);															
						Source  =(unsigned char *)((unsigned char *)TS_Head + sizeof(TS_TAG) + 1);

						MemCopy(Dest,Source,PayLoadLength);

						Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength+=PayLoadLength;	
						Get_PSI_Result[PortNo].SectionCount++;

						Section_Head=(SECTION_TAG *)((unsigned char *)TS_Head + sizeof(TS_TAG) + 1 + Point_field);	
						TSRest=188 - sizeof(TS_TAG) - (Point_field + 1) ;

						SectionRest=Section_Head->SectionLength + 3;

						Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].PID=PID;
						Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].SectionLength=Section_Head->SectionLength + 3;
						Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength=0;							
					}
					else
					{
						TSRest=188 - sizeof(TS_TAG);
						Section_Head=(SECTION_TAG *)((unsigned char *)TS_Head + sizeof(TS_TAG));
					}				
				}
			}
			
			my_Delay(2);
		}
	}
	else
	
		return 0;
}
#else

/*分析相应端口的PSI信息*/
unsigned long AnalysePSITS(unsigned char PortNo,unsigned short PID)
{
	unsigned char   	TS_Count,Proc_TS_Count;
	TS_TAG          	*TS_Head;
	SECTION_TAG     	*Section_Head;

	unsigned char   Adaption_field_length;
	unsigned char   Point_field;
	unsigned short  SectionLength;
	unsigned short  PayLoadLength;
	
	unsigned short  SectionRest;
	short			TSRest;

	unsigned char   *Dest,*Source,*CopyStart;

	unsigned char   TSEND;

	unsigned char   CheckVal;

	unsigned short  Offset=0;

	int             sectionoffset;
	int             i;


	Get_PSI_Result[PortNo].SectionCount=0;

	if(TS_Buf[PortNo]!=NULL)
	{
		/*从相应端口读取PSITS包*/
		TS_Count=GetPSITS(PortNo,PID,TS_Buf[PortNo]);

		if(TS_Count==0)
			return 0;
		else
		{
			TS_Head=(TS_TAG *)TS_Buf[PortNo];

			Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].PID=PID;
			Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].SectionLength=0;
			Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength=0;

			for(i=0;i<TS_Count;i++)
			{
				if(TS_Head->Payload_unit_start_indicator==1)
				{
					if((TS_Head->Adaption_field_control==2)||(TS_Head->Adaption_field_control==3))
					{
						Adaption_field_length=*(unsigned char *)((unsigned char *)TS_Head + sizeof(TS_TAG));
						Point_field=*(unsigned char *)((unsigned char *)TS_Head + sizeof(TS_TAG) + Adaption_field_length + 1);					
						Section_Head=(SECTION_TAG *)((unsigned char *)TS_Head + sizeof(TS_TAG) + Adaption_field_length + 1 + 1+Point_field);				
						TSRest=188 - sizeof(TS_TAG) - (Adaption_field_length +1) - (Point_field + 1) ; 
					}
					if(TS_Head->Adaption_field_control==1)
					{
						Point_field=*(unsigned char *)((unsigned char *)TS_Head + sizeof(TS_TAG));					
						Section_Head=(SECTION_TAG *)((unsigned char *)TS_Head + sizeof(TS_TAG) + 1 + Point_field);	
						TSRest=188 - sizeof(TS_TAG) - (Point_field + 1) ;
					}

					if(TSRest<=0)
					{
						Display("[AnalysePSITS]:got point field, but TSRest<0 in this TS, quit.\n");
						return Get_PSI_Result[PortNo].SectionCount;
					}
					/*-------------------------------------------------------------------------------------*/
					/* 上一个section没有处理完,point filed前面的是上一个section的数据                     */
					/*-------------------------------------------------------------------------------------*/
					if(Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength)
					{
						sectionoffset=Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength;
						MemCopy(Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].Section + sectionoffset,(char *)TS_Head + sizeof(TS_TAG) + 1,Point_field);
						
						Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength+=Point_field;

						if(Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].AssembleLength!=Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].SectionLength)
						{
							Display("[AnalysePSITS]:section not finished, but point filed found!\n");
							return Get_PSI_Result[PortNo].SectionCount;
						}

						Get_PSI_Result[PortNo].SectionCount++;
						Get_PSI_Result[PortNo].Sections[Get_PSI_Result[PortNo].SectionCount].PID=PID;

⌨️ 快捷键说明

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