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

📄 rec_observ.cpp

📁 PQDIF软件包(SDK,Software Development Kit),它能转换、生成并且显示PQDIF文件.对于开发电力系统的数据输出非常有用。
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
**  CPQDIF_R_Observation class. Implements a PQDIF record "wrapper" for the
**  data source record. You can NOT cast a standard record object to this
**  class, because it has its own member data.
**  --------------------------------------------------------------------------
**
**  File name:          $Workfile: rec_observ.cpp $
**  Last modified:      $Modtime: 9/11/98 2:55p $
**  Last modified by:   $Author: Rob $
**
**  VCS archive path:   $Archive: /Hank/DMM/FirmWare/Level3/ObDatMgr/rec_observ.cpp $
**  VCS revision:       $Revision: 13 $ 
*/
#include "PQDIF_classes.h"


//  Construction
//  ============

CPQDIF_R_Observation::CPQDIF_R_Observation()
{
    m_pds = NULL;
    m_psett = NULL;
    m_record = NULL;
}

CPQDIF_R_Observation::CPQDIF_R_Observation( CPQDIFRecord& record )
{
    m_pds = NULL;
    m_psett = NULL;
    m_record = (CPQDIF_R_General *) &record;
}


CPQDIF_R_Observation::~CPQDIF_R_Observation()
{
    //  Don't destroy m_pds or m_record; these are only by reference, not by value.
}


bool CPQDIF_R_Observation::GetInfo
            (
            TIMESTAMPPQDIF&     timeStart,
            TIMESTAMPPQDIF&     timeCreate,
            string&             name
            )
{
    bool    status;
    long    countEntries = 0;

    CPQDIF_E_Scalar *   psc;
    CPQDIF_E_Vector *   pvect;

    //  Init
    status = TRUE;
    memset( &timeStart, 0, sizeof( timeStart ) );
    memset( &timeCreate, 0, sizeof( timeCreate ) );
    name = "";

    //  First, find the times
    if( status )
    {
        status = false;
        psc = FindScalarInCollection( m_record->m_pcollMain, tagTimeStart );
        if( psc )
        {
            status = psc->GetValueTimeStamp( timeStart );
        }
    }

    if( status )
    {
        status = false;
        psc = FindScalarInCollection( m_record->m_pcollMain, tagTimeCreate );
        if( psc )
        {
            status = psc->GetValueTimeStamp( timeCreate );
        }
    }

    //  Get name
    if( status )
    {
        status = false;
        pvect = FindVectorInCollection( m_record->m_pcollMain, tagObservationName );
        if( pvect )
        {
            status = pvect->GetValues( name );
        }
    }

    return status;
}

            
long CPQDIF_R_Observation::GetCountChannels( void )
{
    long                    count = 0;
    CPQDIF_E_Collection *   pcolCI;

    pcolCI = GetChannelInstances();
    if( pcolCI )
    {
        count = pcolCI->GetCount(); 
    }

    return count;
}


bool CPQDIF_R_Observation::GetTriggerInfo
            (
            UINT4&              idTriggerMethod,
            CPQDIF_E_Vector **  pvectTriggerChanIdx,
            TIMESTAMPPQDIF&     timeTriggered
            )
{
    bool    status = false;
    long    countEntries = 0;

    CPQDIF_E_Scalar *   psc;
    CPQDIF_E_Vector *   pvect;

    //  Init
    idTriggerMethod = ID_TRIGGER_METH_NONE;
//    ASSERT( pvectTriggerChanIdx );
    *pvectTriggerChanIdx = NULL;
    memset( &timeTriggered, 0, sizeof( timeTriggered ) );

    //  First, find the trigger method
    psc = FindScalarInCollection( m_record->m_pcollMain, tagTriggerMethodID );
    if( psc )
    {
        status = psc->GetValueUINT4( idTriggerMethod );
    }
    else
    {
        //  Default to channel? NAHHH
        //status = TRUE;
        //idTriggerMethod = ID_TRIGGER_METH_CHANNEL;
    }

    //  Get triggered channels? (NOT required; leave status alone)
    if( status && idTriggerMethod == ID_TRIGGER_METH_CHANNEL )
    {
        pvect = FindVectorInCollection( m_record->m_pcollMain, tagChannelTriggerIdx );
        if( pvect )
        {
            //  Validate physical type
            if( pvect->GetPhysicalType() == ID_PHYS_TYPE_UNS_INTEGER4 )
            {
                //  Return a pointer to the vector
                *pvectTriggerChanIdx = pvect;
            }
        }
    }

    //  Get the time it was triggered
    if( status )
    {
        status = false;
        psc = FindScalarInCollection( m_record->m_pcollMain, tagTimeTriggered );
        if( psc )
        {
            status = psc->GetValueTimeStamp( timeTriggered );
        }
    }

    return status;
}


long CPQDIF_R_Observation::GetCountSeries( int idxChannel )
{
    long                    count = 0;
    CPQDIF_E_Collection *   pcolOneChannel;
    CPQDIF_E_Collection *   pcolSI;

    pcolOneChannel = GetOneChannel( idxChannel );
    if( pcolOneChannel )
    {
        pcolSI = GetSeriesInstances( pcolOneChannel );
        if( pcolSI )
        {
            count = pcolSI->GetCount(); 
        }
    }

    return count;
}


bool CPQDIF_R_Observation::GetChannelInfo
            (
            long        idxChannel,
            string&     name,
            UINT4&      idPhase,
            GUID&       idQuantityType,
            UINT4&      idQuantityMeasured
            )
{
    bool        status = true;
    long        idxChannelDefn;

    //  Find the channel defn index
    if( status )
    {
        status = GetChannelDefnIdx( idxChannel, idxChannelDefn );
    }

    //  Gather information from the channel definitions
    if( status && m_pds )
    {
        status = m_pds->GetChannelDefnInfo( idxChannelDefn, name, idPhase, 
            idQuantityType, idQuantityMeasured );
    }
    else
    {
        status = false;
    }

    return status;
}

bool CPQDIF_R_Observation::GetChannelPrimarySeries
            (
            long        idxChannel,
            long&       idxPrimarySeries
            )
{
    bool        status = true;
    long        idxChannelDefn;

    //  Find the channel defn index
    if( status )
    {
        status = GetChannelDefnIdx( idxChannel, idxChannelDefn );
    }

    //  Gather information from the channel definitions
    if( status && m_pds )
    {
        status = m_pds->GetChannelPrimarySeries( idxChannelDefn, idxPrimarySeries );
    }
    else
    {
        status = false;
    }

    return status;
}


bool CPQDIF_R_Observation::GetChannelThresholds
            (
            long                idxChannel,
            UINT4&              triggerTypeID,
            REAL8&              fullScale,  
            REAL8&              noiseFloor, 
            REAL8&              triggerLow, 
            REAL8&              triggerHigh,
            REAL8&              triggerRate,
            CPQDIF_E_Vector&    triggerShapeParam   //  Array of [3]
            )
{
    bool        status = false;
    long        idxChannelDefn;

    bool        found;
    long        idxChannSett;
    long        countChannSett;
    UINT4       idxChannelDefnSett;

    //  DO we have settings?
    if( m_psett )
    {
        //  Determine which channel def'n is used for this channel
        //  Find the channel defn index
        status = GetChannelDefnIdx( idxChannel, idxChannelDefn );

        //  Check all settings channels to see which matches the def'n
        if( status )
        {
            //  Init
            status = false;

            countChannSett = m_psett->GetCountChannels();
            for( idxChannSett = 0; idxChannSett < countChannSett; idxChannSett++ )
            {
                found = m_psett->GetChannelInfo( idxChannSett, idxChannelDefnSett,
                            triggerTypeID, fullScale,  noiseFloor, 
                            triggerLow, triggerHigh, triggerRate,
                            triggerShapeParam );

                //  Is this the one that corresponds to the same def'n?
                if( found && idxChannelDefn == (long) idxChannelDefnSett )
                {
                    status = TRUE;
                    break;
                }
            }   //  For( channel setting )

        }   //  Found channel def'n        
    }   //  Have settings

    return status;
}


bool CPQDIF_R_Observation::GetSeriesInfo
            (
            long        idxChannel,
            long        idxSeries,
            UINT4&      idQuantityUnits,
            GUID&       idQuantityCharacteristic,
            GUID&       idValueType
            )
{
    bool        status = true;
    long        idxChannelDefn;
    UINT4       idStorageMethod;

    //  Find the channel defn index
    if( status )
    {
        status = GetChannelDefnIdx( idxChannel, idxChannelDefn );
    }

    //  Gather information from the series definition
    if( status && m_pds )
    {
        status = m_pds->GetSeriesDefnInfo( idxChannelDefn, idxSeries,
                    idQuantityUnits, idValueType, idQuantityCharacteristic,
                    idStorageMethod );
    }
    else
    {
        status = false;
    }

    return status;
}


long CPQDIF_R_Observation::AddChannel
            (
            long        idxChannelDefn
            )
{
    long        idxNew = -1;

    CPQDIF_E_Collection *   pcolInstances = GetChannelInstances();
    CPQDIF_E_Collection *   pcollOne;
    CPQDIF_E_Collection *   pcollSeriesInstances;

    if( pcolInstances )
    {
        //  Get the new index
        idxNew = GetCountChannels();

        //  Create the new channel instance
        pcollOne = (CPQDIF_E_Collection *) theFactory.NewElement( ID_ELEMENT_TYPE_COLLECTION );
        pcollOne->SetTag( tagOneChannelInst );

        //  Stuff in the information...
        pcollOne->SetScalarUINT4( tagChannelDefnIdx, idxChannelDefn );

        //  Also need a series instances collection
        pcollSeriesInstances = (CPQDIF_E_Collection *) theFactory.NewElement( ID_ELEMENT_TYPE_COLLECTION );
        if( pcollSeriesInstances )
        {
            pcollSeriesInstances->SetTag( tagSeriesInstances );
            pcollOne->Add( pcollSeriesInstances );
        }

        //  Add it!
        pcolInstances->Add( pcollOne );
    }

    return idxNew;
}


long CPQDIF_R_Observation::AddSeriesDouble
            (
            long        idxChannel,
            long        countValues,
            double *    arValues
            )
{
    long        idxNew = -1;

    CPQDIF_E_Vector *       pvectData;
    
    long        idx;
    double *    pValue;

    //  Create vector for the series data
    pvectData = (CPQDIF_E_Vector *) theFactory.NewElement( ID_ELEMENT_TYPE_VECTOR );
    if( pvectData )
    {
        pvectData->SetTag( tagSeriesValues );
        pvectData->SetPhysicalType( ID_PHYS_TYPE_REAL8 );

        //  Copy over series data
        pValue = arValues;
        pvectData->SetCount( countValues );
        for( idx = 0; idx < countValues; idx++, pValue++ )
        {
            pvectData->SetValue( idx, *pValue );
        }

        //  Add it ...
        idxNew = AddSeriesVector( idxChannel, pvectData );

        //  If it was not successful, delete the vector
        if( idxNew < 0 )
        {
            delete pvectData;
        }
    }

    return idxNew;
}


long CPQDIF_R_Observation::AddSeriesVector
            (
            long                idxChannel,
            CPQDIF_E_Vector *   pvectData
            )
{
    long        idxNew = -1;

    CPQDIF_E_Collection *   pcolOneChannel;
    CPQDIF_E_Collection *   pcolSI;
    CPQDIF_E_Collection *   pcollOne;
    
    pcolOneChannel = GetOneChannel( idxChannel );
    if( pcolOneChannel && pvectData )
    {
        pcolSI = GetSeriesInstances( pcolOneChannel );
        if( pcolSI )
        {
            //  New channel index
            idxNew = pcolSI->GetCount(); 

            //  Create the new channel def'n
            pcollOne = (CPQDIF_E_Collection *) theFactory.NewElement( ID_ELEMENT_TYPE_COLLECTION );
            if( pcollOne )
            {
                //  Set the tag for this collection ...
                pcollOne->SetTag( tagOneSeriesInstance );

                //  Make sure the vector has the right tag ...

⌨️ 快捷键说明

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