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

📄 clid.cpp

📁 This R2.9 revision of the CLID detector provides the TYPE 1 (on-hook, between first and second ring,
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*-------------------------------------------------------------------------*
 *                                                                         *
 *   THIS IS AN UNPUBLISHED WORK CONTAINING CONFIDENTIAL AND PROPRIETARY   *
 *   INFORMATION.  IF PUBLICATION OCCURS, THE FOLLOWING NOTICE APPLIES:    *
 *      "COPYRIGHT 2001 MICHAEL TSIROULNIKOV, ALL RIGHTS RESERVED"         *
 *                                                                         *
 *-------------------------------------------------------------------------*/


#if !defined _dsp
#include <memory.h>
#include <math.h>
#include <stdlib.h>
#else
#include <string.h> /* memcpy() */
#endif

#include "stddefs.h"
#include "clidi.h"


/*--------------------- local defs ----------------------------------------*/

/*--------------------- public vars ---------------------------------------*/

/*--------------------- local vars ----------------------------------------*/

#if defined (_dsp)

#pragma DATA_SECTION (CLID_asBpfI,  ".clida")
#pragma DATA_SECTION (CLID_asBpfQ,  ".clidb")
#pragma DATA_SECTION (CLID_asMfI,   ".clidc")
#pragma DATA_SECTION (CLID_asMfQ,   ".clidc")
#pragma DATA_SECTION (CLID_as1700,  ".clidc")
#pragma DATA_SECTION (CLID_asLpf24, ".clidc")
#pragma DATA_SECTION (CLID_asShape, ".clidc")

#endif

#include "clidtab.c"


/*--------------------- local functions -----------------------------------*/

/*---------------------------------------------------------------------*/
static void                 _reset
/*---------------------------------------------------------------------*/
(
CLID_tDb *pDb
)
{
    ICLID_tCfg Cfg = pDb->Cfg;
    CLID_MIKET_tStts Stts = pDb->Stts;

    memset(pDb, 0, sizeof(CLID_tDb));
    pDb->Cfg = Cfg;
    pDb->Stts = Stts;
}

/*-------------------------------------------------------------------------*/
static void                 _analize_bitstream
/*-------------------------------------------------------------------------*/
(
CLID_tDb *pDb,
CLID_tSc *pSc
)
{
    S16 k;

    /* Searches the buffer for reversal sequence */
    for (k = 0; k < CLID6_FR_SZ; k++)
    {
        S32 ac0 = pSc->asOut[k] * (S32) pSc->asOut[k+1];
            /* Zero crossing found */
        if (ac0 < 0)
        {
            /* Zero crossing within reasonable distance from last zero
               crossing. 5 good bits -> REVERSALS
               */
            if ((pSc->sCurrBitLen < 2) || (pSc->sCurrBitLen > 8))
            {
                /* bad bit */
                pSc->sBits -= 5;
            }
            else /* good bit */
            {
                pSc->sBits++;     /* Increment number of bits */
            }
            pSc->sCurrBitLen = 0;                /* Zero bit counter */
        }
        else
        {
            pSc->sCurrBitLen++;
        }
    }
}
/*-------------------------------------------------------------------------*/
static void                  _wait_marks
/*-------------------------------------------------------------------------*/
(
CLID_tDb *pDb, 
CLID_tSc *pSc
)
{
    S16 k;
    S16 sBitLen = pDb->sCurrBitLen;

    for (k = 0; k < CLID6_FR_SZ; k++)
    {
        if (pSc->asOut[k] > 0)
        {
            sBitLen++;
        }
        else
        {
            sBitLen = 0;
        }
    }
    pDb->sCurrBitLen = sBitLen;
}

#if !defined (_dsp)
    S16 asOffsets[10];
    S16 _sShift;
#endif

/*-------------------------------------------------------------------------*/
static U16                  _find_byte_position
/*-------------------------------------------------------------------------*/
(
CLID_tDb *pDb,
CLID_tSc *pSc,
S16 sInitial
)
{
    U16 uByte;
    S16 sMax;
    S16 sShift;
    S16 k;

//    sInitial++;

    // looking for max eye opening...
    for (sShift = 0; sShift < CLID_SHIFT; sShift++)
    {
        pSc->asSum[sShift] = clid_match_byte(
            &pSc->asOut[sInitial + sShift],
            &pSc->auByte[sShift]);
        if (pSc->asOut[sInitial + sShift] > 0) pSc->asSum[sShift] = -1;
        if (pSc->asOut[sInitial + sShift + 45] < 0) pSc->asSum[sShift] = -2;
    }

    sMax = pSc->asSum[0];
    sShift = 0;
    for (k = 1; k < CLID_SHIFT; k++)
    {
        S16 m = pSc->asSum[k];
        if (m > sMax)
        {
            sMax = m;
            sShift = k;
        }
    }

    /* now Shift is 'the best' */
//    pDb->ZC = Initial + Shift;
#if !defined (_dsp)
    for (k = 0; k < 10; k++)
    {
        S16 sOffset = sInitial + sShift + k*5;
        asOffsets[k] = sOffset;
    }
    _sShift = sShift;
#endif

    if (pSc->asSum[sShift] > 0)
    {
        uByte = (pSc->auByte[sShift] >> 1) & 0x00ff;
    }
    else
    {
        uByte = 0xffff;
    }
    return uByte;
}

/*-------------------------------------------------------------------------*/
static U16                  _find_byte
/*-------------------------------------------------------------------------*/
(
CLID_tDb *pDb, 
CLID_tSc *pSc
)
{
    S16 k;
    U16 uByte = 0xffff;

    /* Start from where the last byte left off */
    if (pDb->sStart > CLID6_FR_SZ+2)
    {
        pDb->sStart -= CLID6_FR_SZ;
    }
    else
    {
        pDb->sStart = 2;
    }

    /* Examine only the first packet in the buffer */
    for (k = pDb->sStart; k < CLID6_FR_SZ+2; k++)
    {
        /* Find first zero crossing */
        if (pSc->asOut[k] < 0)
        {
            uByte = _find_byte_position(pDb, pSc, k);
            /* check if byte is valid */            
            if (!(uByte & 0xff00)) 
            {
                pDb->sCurrBitLen = 0;
                pDb->sStart = k;
                break;
            }
            else  // go on...
            {
                k += 4; // next bit
            }
        } 
        else
        {
            pDb->sCurrBitLen++;
        }
    }
    return uByte;
}

/*-------------------------------------------------------------------------*/
static void                 _store_byte
/*-------------------------------------------------------------------------*/
(
CLID_tDb *pDb, 
CLID_tSc *pSc,
U16 uByte
)
{
    if (pDb->sBytes < ICLID_MSG_SZ*2)
    {
        S16 sOffset = pDb->sBytes >> 1;
        if (pDb->sBytes & 1)
        {
            pDb->auByteStorage[sOffset] |= uByte << 8;
        }
        else
        {
            pDb->auByteStorage[sOffset] = uByte;
        }
    }
    pDb->sBytes++;
    // advance start to the stop bit (positive one...)
    pDb->sStart += 48;
}

/*-------------------------------------------------------------------------*/
S16                         _state_machine_type1
/*-------------------------------------------------------------------------*/
(
CLID_tDb *pDb,
CLID_tSc *pSc
)
{
    U16 uByte;
    S16 sReport = ICLID_EV_NONE;

    switch(pDb->sState)
    {
    case CLID_ST_IDLE:
        _analize_bitstream(pDb, pSc);
        if (pSc->sBits < 0)
        {
            pSc->sBits = 0;
        }
        else if (pSc->sBits > 5)
        {
            pDb->sState = CLID_ST_REVERSAL;
            sReport = ICLID_EV_EARLY_ON;
        }
        else ; // 0...5 reversal trial zone
        break;

    case CLID_ST_REVERSAL:
        _analize_bitstream(pDb, pSc);
        if (pSc->sBits < 0)
        {
            pSc->sBits = 0;
            pSc->sAlignment = 0;
            sReport = ICLID_EV_EARLY_OFF;
            pDb->sState = CLID_ST_IDLE;
        }
        else
        {
            if (pSc->sCurrBitLen > 30)
            {
                if (pSc->sBits > 240)
                {
                    if (pSc->asOut[CLID6_FR_SZ] > 0)
                    {
                        pDb->sState = CLID_ST_MARKS;
                        pSc->sBits = 0;
                    }
                    else
                    {
                        pSc->sBits = 0;
                        pSc->sAlignment = 0;
                        pDb->sState = CLID_ST_IDLE;
                        sReport = ICLID_EV_EARLY_OFF;
                    }
                }
                else
                {
                    pSc->sBits = 0;
                    pSc->sAlignment = 0;
                    pDb->sState = CLID_ST_IDLE;
                    sReport = ICLID_EV_EARLY_OFF;
                }
            }
            // keep doing reversals...
            else
            {
                if ((pSc->sCurrBitLen < 15) && (pSc->sBits < 240))
                {
                    pSc->sAlignment -= pSc->sAverage;
                }
            }
        }
        break;

    case CLID_ST_MARKS:
        uByte = _find_byte(pDb, pSc);
        if ((uByte & 0xff) != 0xff) // ParameterType can not be 0xff
        {

⌨️ 快捷键说明

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