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

📄 driv0299.c

📁 stv0299资料
💻 C
📖 第 1 页 / 共 4 页
字号:
--PARAMS OUT::	NONE (Results are returned by the RegisterCarrier() function)
--RETURN	::	NONE
--***************************************************/
void AutoFrequencyScan(long StartScanFrequency, long EndScanFrequency,long *ScanLnb, long *pSymbolRate, int DerotStep,POLARIZATION PolarizationMode)
{
	long 	CurrentFrequency,						/*	Frequency currently scanned	*/
			CurrentLnb=0,							/*	Current lnb used	*/
			*pWidth,								/*	Pointer to size array	*/ 
			MinWidth;								/*	Width of the used low pass filter	*/
			
	int		index;						/*	Number of consecutive carrier detected	*/		
	
	SCANDIR			Direction = SCANUP;				/*	Direction of the scan	*/
	POLARIZATION	Polarization;					/*	Polarization	*/
	
	InitParams();									/*	structure initialisation	*/
	
	pWidth=FillWidthArray(pSymbolRate,Params.RollOff,&MinWidth);	/*	Create an array 	*/
	
	if(StartScanFrequency >= EndScanFrequency)  	/*	Init direction	*/
		Direction = SCANDOWN;
	
	Polarization = FirstPolarization(PolarizationMode);				/*	Select the first polarization	*/  
	
	#if (HOST > 1000)
		ScanInsertMessage(SCANDIRECTION,Direction,0);     
	#endif
	
	while(Polarization)				/*	While not all the polarization are tested	*/
	{
		CurrentFrequency = StartScanFrequency;
		Result.Polarization = Polarization;    
		#if (HOST > 1000)
			ScanInsertMessage(SCANPOLARIZATION,Polarization,0);      
		#endif
		
		while(!EndOfScan(Direction,CurrentFrequency,EndScanFrequency))				/*	While not all the bandwidth is scanned	*/
		{
			index = 0;
			Result.SignalType = NOAGC1; 
			
			SelectLnb(&CurrentLnb,ScanLnb,CurrentFrequency);
		
			#if (HOST > 1000)
				ScanInsertMessage(SCANFREQUENCY,CurrentFrequency,0);     
			#endif
			
			while(pSymbolRate[index] && Result.SignalType!=RANGEOK)					/*	While no channel is found and all symbol rates are not tested	*/  
			{
				#if (HOST > 1000)
					ScanInsertMessage(SCANSYMBOLRATE,pSymbolRate[index],0);    
				#endif
				
				InitSearch(CurrentFrequency-CurrentLnb,pSymbolRate[index],MinWidth,DerotStep,DRV_SCAN);  
				
				AutoSearchAlgo();	/*	Search carrier	*/ 
				
				if(Result.SignalType!=RANGEOK) 
					index++;
					
				#if (HOST > 1000)
					ScanDeleteLastMessage();       
				#endif
			}
			
			#if (HOST > 1000)
				ScanDeleteLastMessage();  
			#endif
			
			if(!pSymbolRate[index])
				index--;
			
			Result.Frequency += CurrentLnb;
			
			switch(Result.SignalType)
			{
				case RANGEOK:																		/*	A carrier has been founded	*/
					#if (HOST > 1000)
						ScanInsertMessage(SCANFOUND,Result.Frequency,Result.SymbolRate);  
						ScanInsertMessage(SCAN_SR_PR,Result.SymbolRate,Result.PunctureRate); 
						ScanInsertMessage(BLANKLINE,0,0);     
					#endif
					CurrentFrequency = Result.Frequency + Direction * (pWidth[index] + MinWidth)/2000;	/*	Jump after the founded carrier	*/
				break;
				
				default:																			/*	There is signal but no carrier	*/
					CurrentFrequency = CurrentFrequency + Direction * MinWidth/2000;				/*	Jump of (Fs min size)/ 2	*/
				break;
			}
		}
		
		Polarization = NextPolarization(Polarization,PolarizationMode);				/*	Select the next polarization 	*/
	}
	
	DeleteWidthArray(pWidth);		/*	Delete the size array	*/
}


/*****************************************************
--FUNCTION	::	AutoBenchmark
--ACTION	::	Search all the carriers with the selected symbol rates and polarization 
--				in the bandwidth [StartScanFrequency,EndScanFrequency]
--				(symbol rates must be in increase order)
--PARAMS IN	::	StartScanFrequency	->	start frequency
--				EndScanFrequency	->	end frequency
--				pSymbolRate			->	List of symbol rates (Kbauds)
--				PolarizationMode	->	polarization test order
--PARAMS OUT::	NONE (Results are returned by the RegisterCarrier() function)
--RETURN	::	NONE
--***************************************************/
void AutoBenchMark    (long   Frequency,
						long   SymbolRate,
						long   SearchRange,
						int    DerotatorStep ,
						long   _Offset    ,
						long   _Jump      ,
						int    _NbSteps   ,
						int    NbTrials  )
{
	long  CurrentFrequency   ,
		  FrequencyStep      ,
		  Offset             ,
		  Jump               ,
		  long_tmp           ;
	int   i                  ,
          int_tmp            ,
		  iTrials            ,
		  iSteps             ,
		  NbSteps            ,
		  NbSuccess          ;
	double dbl_tmp           ,
		   JumpDuration      ;      
	#if( HOST > 1000 )
		double param[4];
  	#endif
  	SEARCHRESULT	Result;							/*	Structure used to store search results	*/       
	
	if((Frequency <= 0)||(SymbolRate <= 0)||(_Offset < 0)
	 ||(_NbSteps <= 0)||(NbTrials <= 0))
		return;	/* bad parameters */   
	
	#if( HOST > 1000 )
		SystemStartTimer(2);
	#endif
	
	Offset         = _Offset/1000L;	/* in KHz  */
	Jump           = _Jump/1000L;	/* in KHz  */
	
	NbSteps  = _NbSteps ;
	if(NbSteps <= 1)
	 	FrequencyStep = 0 ;
	else
	 	FrequencyStep = Offset/(NbSteps - 1) ;
	
	/*	Calculation of the tuner jump duration	*/
	CurrentFrequency = Frequency - Jump ; /* in KHz */
	int_tmp = 0 ;
	JumpDuration = 0 ;
	dbl_tmp = 0;
	for (i = 0; i < 10 ; i++)
	{
		/* frequency jump of JUMP */
		#if( HOST > 1000 )
			SystemStartTimer(1);
		#endif
		TunerSetFrequency(CurrentFrequency - Jump);	/*	Move the tuner	*/ 
		#if( HOST > 1000 )
			SystemStopTimer(1);
			JumpDuration += SystemGetTimerValue(1);
			SystemStartTimer(1);
		#endif
		TunerSetFrequency(CurrentFrequency);	/*	Move the tuner	*/         
		#if( HOST > 1000 )
			SystemStopTimer(1);
			dbl_tmp += SystemGetTimerValue(1);
		#endif
	}
	int_tmp /= 10 ;
	JumpDuration /= 10 ; /* This duration will be lost each time a frequency change
							  from UserFrequency until UserFrequency + Jump will
							  be performed. */
  	#if( HOST > 1000 )
		param[0]=Frequency;
		param[1]=SymbolRate;   
		param[2]=Jump;   
		param[3]=dbl_tmp;   
	 	BenchMarkInsertMessage(10,param);  
	#endif
	
	CurrentFrequency = Frequency ;
	long_tmp = 0 ;
	
	InitParams();
	Result.Polarization = GetPolarization();
	
	for (iSteps = 0 ; iSteps < (2*NbSteps - 1) ; iSteps++)
	{
		NbSuccess = 0 ;
		CurrentFrequency += long_tmp ;
		#if( HOST > 1000 )
			param[0]=CurrentFrequency;
			BenchMarkInsertMessage(20,param);
		#endif
		long_tmp = (long_tmp <= 0 ) ?
		           -long_tmp + FrequencyStep  : -long_tmp - FrequencyStep ;
		
		#if( HOST > 1000 )
			SystemStartTimer(1); /* clear of the acquisition time value */
		#endif
		
		for (iTrials = 0; iTrials < NbTrials ; iTrials++)
		{
			Result.SignalType = NOAGC1;
			Result.Frequency = 0;
			Result.SymbolRate = 0;
			
			InitSearch(CurrentFrequency,SymbolRate,SearchRange,DerotatorStep,DRV_SCAN);
			
			if(AutoSearchAlgo() == RANGEOK) 
				NbSuccess += 1;
			else
				NbSuccess += 0;   
		}
		
		#if( HOST > 1000 )
			SystemStopTimer(1) ;
			dbl_tmp = SystemGetTimerValue(1)/NbTrials ;  /* mean value of the acquisition time */
			param[0]=CurrentFrequency - Frequency;
			param[1]=dbl_tmp;
			param[2]=(100*NbSuccess)/NbTrials;
			BenchMarkInsertMessage(30,param);
		#endif
	}
	#if( HOST > 1000 )
		SystemStopTimer(2);
		BenchMarkInsertMessage(40,NULL);      
 	#endif
}

/*****************************************************
--FUNCTION	::	CarrierTracking
--ACTION	::	Track the carrier
--PARAMS IN	::	NONE	
--PARAMS OUT::	NONE
--RETURN	::	New frequency of the carrier 
--***************************************************/
int CarrierTracking(void)    
{
	if(Result.SignalType == RANGEOK)
	{
		/*RegGetRegisters(R_CFRM,2); */								/*	Get the derotator frequency	*/ 
		/*Params.DerotFreq = (short int) MAKEWORD(FieldGetVal(DEROTATORFREQUENCYMSB),FieldGetVal(DEROTATORFREQUENCYLSB));
		Params.Frequency = Result.Frequency;*/
		
		TunerCentering(&Params,&Result,2000000);
	}	
	return Params.Frequency;
}

/*****************************************************
--FUNCTION	::	CarrierGetQuality
--ACTION	::	Return the carrier to noise of the current carrier
--PARAMS IN	::	NONE	
--PARAMS OUT::	NONE
--RETURN	::	C/N of the carrier, 0 if no carrier 
--***************************************************/
int CarrierGetQuality(LOOKUP *lookup)
{
	int c_n = 0,
		regval,
		Imin,
		Imax,
		i;
	
	if(RegGetField(CF))
	{
		if((lookup != NULL) && lookup->size)
		{
			RegGetRegisters(R_NIRH,2);
			regval = MAKEWORD(FieldGetVal(NOISEINDICATORMSB),FieldGetVal(NOISEINDICATORLSB));
		
			Imin = 0;
			Imax = lookup->size-1;
			
			if(INRANGE(lookup->table[Imin].regval,regval,lookup->table[Imax].regval))
			{
				while((Imax-Imin)>1)
				{
					i=(Imax+Imin)/2; 
					if(INRANGE(lookup->table[Imin].regval,regval,lookup->table[i].regval))
						Imax = i;
					else
						Imin = i;
				}
				
				c_n =	((regval - lookup->table[Imin].regval)
						* (lookup->table[Imax].realval - lookup->table[Imin].realval)
						/ (lookup->table[Imax].regval - lookup->table[Imin].regval))
						+ lookup->table[Imin].realval;
			}
			else
				c_n = 100;
		}
	}
	
	return c_n;
}

/*****************************************************
--FUNCTION	::	DiseqcSend
--ACTION	::	Send bytes accross the diseqc interface
--PARAMS IN	::	Data	=> Data to send
--				NbData	=> Number of data to send 
--PARAMS OUT::	NONE
--RETURN	::	NONE
--***************************************************/
void DiseqcSend(unsigned char *Data ,int NbData)
{
	int i=0;
	
	while(i<NbData)
	{
		while(RegGetField(FIFOFULL));		/* wait for FIFO empty	*/
		RegSetField(DISEQCFIFO,Data[i]);	/* send byte to FIFO	*/
		i++;
	}
}

/*****************************************************
--FUNCTION	::	CarrierGetError
--ACTION	::	Compute errors accordings to registers settings
--PARAMS IN	::	NONE
--PARAMS OUT::	NONE
--RETURN	::	Nb of errors if mode = ERRORCOUNT, Bit error rate x 10^7 otherwise 
--***************************************************/
int CarrierGetError(void)
{
	int result = 0;
	
	result = RegGetErrorCount();  
	
	if(RegGetField(CF))	/*	Check for carrier	*/
	{
		if(!FieldGetVal(ERRORMODE))   
		{
			/*	Error Rate	*/
			result *= 9766;
			result /= PowOf2(2 + 2*FieldGetVal(NOE));	/*  theses two lines => result = result * 10^7	*/
			
			switch(FieldGetVal(ERRORSOURCE))
			{
				case 0 :				/*	QPSK bit errors	*/
					result /= 8;
					switch(FieldGetVal(CPR))
					{
						case	0:		/*	PR 2/3	*/
							result *= 2;
							result /= 3;
						break;
				
						case	1:		/*	PR 3/4	*/
							result *= 3;
							result /= 4;
						break;
				
						case	2:		/*	PR 5/6	*/
							result *= 5;
							result /= 6;
						break	;
				
						case	3:		/*	PR 7/8	*/
							result *= 7;
							result /= 8;
						break;
				
						case	4:		/*	PR 1/2	*/
							result *= 1;
							result /= 2;
						break;
				
						default	:
							result = 0;
						break;
				  	}
					break;
			
				case 1:		/*	Viterbi bit errors	*/
					result /= 8;
				break;
		
				case 2:		/*	Viterbi	byte errors	*/
				break;
		  
				case 3:		/*	Packet errors	*/
					result *= 204;
				break;	
			}
		}
	}
	
	return result;
}

/*****************************************************
--FUNCTION	::	SignalGetPower
--ACTION	::	Return power of the signal
--PARAMS IN	::	NONE	
--PARAMS OUT::	NONE
--RETURN	::	Power of the signal (dBm), -100 if no signal 
--***************************************************/
int SignalGetPower(LOOKUP *lookup)
{
	int power = -100,
		regval,
		Imin,
		Imax,
		i;
	
	if((lookup != NULL) && lookup->size)
	{
		regval = RegGetField(AGCINTEGRATORVALUE);    
	
		Imin = 0;
		Imax = lookup->size-1;
		
		if(INRANGE(lookup->table[Imin].regval,regval,lookup->table[Imax].regval))
		{
			while((Imax-Imin)>1)
			{
				i=(Imax+Imin)/2; 
				if(INRANGE(lookup->table[Imin].regval,regval,lookup->table[i].regval))
					Imax = i;
				else
					Imin = i;
			}
			
			power =	((regval - lookup->table[Imin].regval)
					* (lookup->table[Imax].realval - lookup->table[Imin].realval)
					/ (lookup->table[Imax].regval - lookup->table[Imin].regval))
					+ lookup->table[Imin].realval;
		}
		else
			power =  - 100;
	}
	
	
	return power;
}


/*
--
--==============================================================================
--
-- END of the source code .
--
--==============================================================================
--
--   TTT  H H  EEE
--    T   HHH  EE
--    T   H H  EEE
--
--
--             EEEEEEEEEEEE        NNNNNNNN      NNNN       DDDDDDDDDDDDDD
--             EEEEEEEEEEEE        NNNNNNNN      NNNN       DDDDDDDDDDDDDDDD
--             EEEE                NNNN NNNN     NNNN       DDDD         DDDD
--             EEEE                NNNN  NNNN    NNNN       DDDD          DDDD
--             EEEEEEEE            NNNN   NNNN   NNNN       DDDD          DDDD
--             EEEEEEEE            NNNN    NNNN  NNNN       DDDD          DDDD
--             EEEE                NNNN     NNNN NNNN       DDDD         DDDD
--             EEEE                NNNN      NNNNNNNN       DDDD        DDDD
--             EEEEEEEEEEEE        NNNN       NNNNNNN       DDDDDDDDDDDDDDD
--             EEEEEEEEEEEE        NNNN        NNNNNN       DDDDDDDDDDDDDD
--
--
*/

⌨️ 快捷键说明

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