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

📄 tmbsl10086scanauto.c

📁 卫星接收机器卫星 自动搜索, 包括优化处理
💻 C
📖 第 1 页 / 共 4 页
字号:
//-----------------------------------------------------------------------------
// $Header: 
// (C) Copyright 2001 Philips Semiconductors, All rights reserved
//
// This source code and any compilation or derivative thereof is the sole
// property of Philips Corporation and is provided pursuant to a Software
// License Agreement.  This code is the proprietary information of Philips
// Corporation and is confidential in nature.  Its use and dissemination by
// any party other than Philips Corporation is strictly limited by the
// confidential information provisions of the Agreement referenced above.
//-----------------------------------------------------------------------------
// FILE NAME:    %M%
//
// DESCRIPTION:  Function for the silicon demodulator TDA10086
//
// DOCUMENT REF: <References to specification or other documents related to
//               this module>
//
// NOTES:        %I% %G% %U%
//-----------------------------------------------------------------------------
//

//-----------------------------------------------------------------------------
// Standard include files:
//-----------------------------------------------------------------------------
//
#include "tmbslDemodSat.h"
#include <stdlib.h>        // for malloc in Tda10086StartPreScan()

//-----------------------------------------------------------------------------
// Project include files:
//-----------------------------------------------------------------------------
//

#include "debug.h"
#include "tmbsl10086local.h"

#ifndef _WIN32
#include "tmhpiCommonTypes_Int.h"
#include "tmhpiCommon_Memory.h"
#endif

extern tm10086object_t g10086Instance[];



//-----------------------------------------------------------------------------
// Types and defines:
//-----------------------------------------------------------------------------
//
#define MAX_MIN_THRESHOLD   10
#define NB_MAX_REGION       1000
#define MIN_CHANNEL_WIDTH   1200000
#define MAX_AMP_REBOUND     15
#define RF_MIN_MARGIN       3 		// 30 Is also an acceptable value found during test field Shenzhen 17-10-2004
									// With 30, Autoscan is slower but finds more carriers 	
#define RF_MAX_MARGIN       9 		// 25 Is also an acceptable value found during test field Shenzhen 17-10-2004
									// With 25, Autoscan is slower but finds more carriers 	
#define MEDIAN_FILTER       0
#define SMOOTH_FILTER_1     0
#define SMOOTH_FILTER_2     0
#define SMOOTH_FILTER_3     1
//#define NTHR                225
//#define NEST_THR            220
#define RF_OFFSET           500000

#define TRACE_BLUE          0
#define TRACE_RED           1
#define TRACE_GREEN         2

#define FREQ_STEP           250000
#define DISPLAY_STEP        250000
#define MAX_SR_SCAN         45000000
#define MIN_SR_SCAN         1500000
#define SKIP_REGION         MAX_SR_SCAN
#define MIN_TRIANGLE        320
#define SPECTRUM_AVERAGING  5

#define EXTEND_RF_REGION    2000000
#define MINMAX_SEARCH_RANGE 16
#define MIN_SEARCH_RANGE    30000000

#define FREQ2INDEX(x)       ((x+(DISPLAY_STEP/2))/DISPLAY_STEP)

#define NO_ACI               0
#define L_ACI                1
#define U_ACI                2
#define LU_ACI               3


#define RF_MIN_MARGIN_FINE       30
#define RF_MAX_MARGIN_FINE       25
//-----------------------------------------------------------------------------
// Global data:
//-----------------------------------------------------------------------------
//
//UInt32 StartTime = 0;
//UInt32 StopTime = 0;
//Int32 RFMinMargin;
//Int32 RFMaxMargin;
//Int32 SRMinMargin;
//Int32 SRMaxMargin;
UInt32 NoiseFloor    =    255;
//Int32 SmallerRFMinMargin = 255;
//Int32 SmallerRFMaxMargin = 255;
//Int32 SmallerSRMinMargin = 255;
//Int32 SmallerSRMaxMargin = 255;
//Int32 CarlockOnes;
//Int32 CarlockZeros;
UInt32 AverageGFARA=0;
UInt32 AverageGNYQA=0;
UInt32 NbSamples=0;
UInt32    uGFARA;
UInt32    uGNYQA;

//-----------------------------------------------------------------------------
// Internal Prototypes:
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// Exported functions:
//-----------------------------------------------------------------------------
//

//-----------------------------------------------------------------------------
// FUNCTION:    Tda10086StartPreScan
//
// DESCRIPTION: Start a pre-scanning
//
// RETURN:      always True 
//
// NOTES:       
//-----------------------------------------------------------------------------
//
Bool
Tda10086StartPreScan(
    tm10086object_t *psObject
)
{
    UInt32 i;
    
    psObject->bStateSpectrum = 0;
    psObject->uNbRegion = 0;
    psObject->sApiStatus.iPreSpectrum = True;
    psObject->sApiStatus.iPreScan = True;

    psObject->uStopFrequency += 3000000;
    psObject->uStartFrequency = psObject->sCurrentChannel.uRF - 3000000;

    psObject->uGraphPos = psObject->uStartFrequency;

    psObject->uNbSamples = (psObject->uStopFrequency - psObject->uStartFrequency)/FREQ_STEP + 1;

#ifdef _WIN32
    psObject->pbSpectrum = (UInt8*) malloc( psObject->uNbSamples * sizeof( UInt8 ));
#else
    psObject->pbSpectrum = (UInt8*) tmhpiCommonMemAlloc( psObject->uNbSamples * sizeof( UInt8 ));
#endif
    psObject->pbSpectrum[0] = 255;
    if (0 == psObject->pbSpectrum)
        return TM_FALSE;

#ifdef _WIN32
    psObject->pbDeriv = (UInt8*) calloc( psObject->uNbSamples, sizeof( UInt8 ));
#else
    psObject->pbDeriv = (UInt8*) tmhpiCommonMemAlloc( psObject->uNbSamples * sizeof( UInt8 ));
#endif
    if (0 == psObject->pbDeriv)
        return TM_FALSE;
    for ( i=0; i<psObject->uNbSamples; i++)
        psObject->pbDeriv[i] = 0;

#ifdef _WIN32        
    psObject->puRegion = (tm10086region_t*)malloc( NB_MAX_REGION * sizeof(tm10086region_t) );
#else
    psObject->puRegion = (tm10086region_t*)tmhpiCommonMemAlloc( NB_MAX_REGION * sizeof(tm10086region_t) );
#endif
    if (0 == psObject->puRegion)
        return False;

    SEND_TRACESPECTRUM(0, DEBUG_XRANGE, (psObject->uStartFrequency-(DISPLAY_STEP/2))/DISPLAY_STEP, (psObject->uStopFrequency+(DISPLAY_STEP/2))/DISPLAY_STEP);
    SEND_TRACESPECTRUM(0, DEBUG_YRANGE, 0, 255);

    return True;
}

//-----------------------------------------------------------------------------
// FUNCTION:    Tda10086FindRegion
//
// DESCRIPTION: extract regions from the prescanning
//
// RETURN:      always True 
//
// NOTES:       A region is RfMin, RfMax, SrMin and SrMax
//-----------------------------------------------------------------------------
//
Bool
Tda10086FindRegion(
    tm10086object_t *psObject
)
{
    UInt32 uCounter, uValue;
    UInt32 uCnt = 0;
    UInt32 uLastValidRegion;
    int tab[7];
    int comp(const int *, const int *);
    UInt32 lv_RF_Min_Margin, lv_RF_Max_Margin;
    
    // set proper autoscan parameters according to the autoscan mode chosen by user.
    if ( psObject->eAutoScanMode == tmhalFEAutoScanAverage )
    {
    	lv_RF_Min_Margin = RF_MIN_MARGIN;
    	lv_RF_Max_Margin = RF_MAX_MARGIN;
    }
    else
    {
    	lv_RF_Min_Margin = RF_MIN_MARGIN_FINE;
    	lv_RF_Max_Margin = RF_MAX_MARGIN_FINE;
    }
    // Find region
    SEND_TRACE_CALLS(0x0020,0);

    if (MEDIAN_FILTER)
    {
        // median filter algorithm
        for (uCounter = 0; uCounter < psObject->uNbSamples-6; uCounter++)
        {
            tab[0]=(int)psObject->pbSpectrum[uCounter+0];
            tab[1]=(int)psObject->pbSpectrum[uCounter+1];
            tab[2]=(int)psObject->pbSpectrum[uCounter+2];
            tab[3]=(int)psObject->pbSpectrum[uCounter+3];
            tab[4]=(int)psObject->pbSpectrum[uCounter+4];
            tab[5]=(int)psObject->pbSpectrum[uCounter+5];
            tab[6]=(int)psObject->pbSpectrum[uCounter+6];

            qsort(tab, 7,sizeof(int),comp);

            psObject->pbSpectrum[uCounter] = (UInt8)(tab[3]);

        }

        // re-center due to filtering shift for 3 MHz
        for (uCounter = psObject->uNbSamples-4; uCounter >= 3; uCounter--)
        {
            UInt32 uCurrentRf = psObject->uStartFrequency + (uCounter * FREQ_STEP);

            psObject->pbSpectrum[uCounter] = psObject->pbSpectrum[uCounter-3];

//            SEND_TRACESPECTRUM(TRACE_BLUE, DEBUG_XY, FREQ2INDEX(uCurrentRf), psObject->pbSpectrum[uCounter]);
        }
    }


    else if (SMOOTH_FILTER_1)
    {
        // smooth filter algorithm
        for (uCounter = 0; uCounter < psObject->uNbSamples-6; uCounter++)
        {
            uValue =  (UInt32)(
                  1*psObject->pbSpectrum[uCounter+0]
                + 1*psObject->pbSpectrum[uCounter+1]
                + 1*psObject->pbSpectrum[uCounter+2]
                + 1*psObject->pbSpectrum[uCounter+3]
                + 1*psObject->pbSpectrum[uCounter+4]
                + 1*psObject->pbSpectrum[uCounter+5]
                + 1*psObject->pbSpectrum[uCounter+6]);

            psObject->pbSpectrum[uCounter] = (UInt8)(uValue/7);
        }

        // re-center due to filtering shift for 3 MHz
        for (uCounter = psObject->uNbSamples-4; uCounter >= 3; uCounter--)
        {
            UInt32 uCurrentRf = psObject->uStartFrequency + (uCounter * FREQ_STEP);

            psObject->pbSpectrum[uCounter] = psObject->pbSpectrum[uCounter-3];

//            SEND_TRACESPECTRUM(TRACE_BLUE, DEBUG_XY, FREQ2INDEX(uCurrentRf), psObject->pbSpectrum[uCounter]);
        }
    }

    else if (SMOOTH_FILTER_2)
    {
        // smooth filter algorithm
        for (uCounter = 0; uCounter < psObject->uNbSamples-10; uCounter++)
        {
            uValue =  (UInt32)(
                  1*psObject->pbSpectrum[uCounter+0]
                + 1*psObject->pbSpectrum[uCounter+1]
                + 1*psObject->pbSpectrum[uCounter+2]
                + 1*psObject->pbSpectrum[uCounter+3]
                + 1*psObject->pbSpectrum[uCounter+4]
                + 1*psObject->pbSpectrum[uCounter+5]
                + 1*psObject->pbSpectrum[uCounter+6]
                + 1*psObject->pbSpectrum[uCounter+7]
                + 1*psObject->pbSpectrum[uCounter+8]
                + 1*psObject->pbSpectrum[uCounter+9]
                + 1*psObject->pbSpectrum[uCounter+10]);

            psObject->pbSpectrum[uCounter] = (UInt8)(uValue/11);
        }

        // re-center due to filtering shift for 5 MHz
        for (uCounter = psObject->uNbSamples-6; uCounter >= 5; uCounter--)
        {
            UInt32 uCurrentRf = psObject->uStartFrequency + (uCounter * FREQ_STEP);

            psObject->pbSpectrum[uCounter] = psObject->pbSpectrum[uCounter-5];

//            SEND_TRACESPECTRUM(TRACE_BLUE, DEBUG_XY, FREQ2INDEX(uCurrentRf), psObject->pbSpectrum[uCounter]);
        }
    }

    else if (SMOOTH_FILTER_3)
    {
        // smooth filter algorithm
        for (uCounter = 0; uCounter < psObject->uNbSamples-2; uCounter++)
        {
            uValue =  (UInt32)(
                  1*psObject->pbSpectrum[uCounter+0]
                + 1*psObject->pbSpectrum[uCounter+1]
                + 1*psObject->pbSpectrum[uCounter+2]);

            psObject->pbSpectrum[uCounter] = (UInt8)(uValue/3);
        }

        // re-center due to filtering shift for 1 MHz
        for (uCounter = psObject->uNbSamples-2; uCounter >= 1; uCounter--)
        {
            UInt32 uCurrentRf = psObject->uStartFrequency + (uCounter * FREQ_STEP);

            psObject->pbSpectrum[uCounter] = psObject->pbSpectrum[uCounter-1];

//            SEND_TRACESPECTRUM(TRACE_BLUE, DEBUG_XY, FREQ2INDEX(uCurrentRf), psObject->pbSpectrum[uCounter]);
        }
    }


    // Calculate derivation
    for (uCounter = 1; uCounter < psObject->uNbSamples - 2; uCounter++)
    {
        UInt32 uCurrentRf = psObject->uStartFrequency + (uCounter * FREQ_STEP);
        Int32  iDeriv;

        iDeriv  = (UInt32)psObject->pbSpectrum[uCounter + 1];
        iDeriv -= (UInt32)psObject->pbSpectrum[uCounter];
        iDeriv *= 20;
        iDeriv += 128;

        if(iDeriv>255)
            iDeriv = 255;
        else if(iDeriv<0)
            iDeriv = 0;

        psObject->pbDeriv[uCounter] = (UInt8)iDeriv;

//        SEND_TRACESPECTRUM(TRACE_GREEN, DEBUG_XY, FREQ2INDEX(uCurrentRf), psObject->pbDeriv[uCounter]);
    }

    // smooth filtered algorithm
    for (uCounter = 0; uCounter < psObject->uNbSamples-4; uCounter++)
    {
        uValue =  (UInt32)(
              1*psObject->pbDeriv[uCounter+0]
            + 1*psObject->pbDeriv[uCounter+1]
            + 1*psObject->pbDeriv[uCounter+2]
            + 1*psObject->pbDeriv[uCounter+3]
            + 1*psObject->pbDeriv[uCounter+4]);

        psObject->pbDeriv[uCounter] = (UInt8)(uValue/5);
    }

    // re-center due to filtering shift for 2 MHz
    for (uCounter = psObject->uNbSamples-3; uCounter >= 2; uCounter--)
    {
        UInt32 uCurrentRf = psObject->uStartFrequency + (uCounter * FREQ_STEP);

        psObject->pbDeriv[uCounter] = psObject->pbDeriv[uCounter-2];
    }

    psObject->uNbRegion = 0;


    // find local maxima of derivation
    for (uCounter = 3; uCounter < psObject->uNbSamples - 4 - MINMAX_SEARCH_RANGE; uCounter++)
    {
        UInt32 uCounterMax, uMaxVal = 0;

        // find max
        for (uCounterMax = uCounter; uCounterMax < MINMAX_SEARCH_RANGE + uCounter; uCounterMax++)
        {

⌨️ 快捷键说明

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