📄 rec_observ.cpp
字号:
/*
** 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: 12/01/00 12:45p $
** Last modified by: $Author: Bill $
**
** VCS archive path: $Archive: /Hank/DMM/FirmWare/Level3/ObDatMgr/rec_observ.cpp $
** VCS revision: $Revision: 30 $
*/
#include "PQDIF_classes.h"
// Local functions
// ===============
// Function to round second values to the nearest nanosecond.
inline double _FixSeconds(double dTime)
{
return floor( dTime * 1000000000.0 + 0.5 )/ 1000000000.0;
}
static void _AddSeconds( TIMESTAMPPQDIF &dt, double secondsToAdd )
{
// Record the current day for an overflow check.
DWORD dwDay = dt.day;
// Perform the requested operation.
dt.sec += secondsToAdd;
// If the result is greater than the number of seconds in
// a day then ...
if( dt.sec > (double) SECONDS_PER_DAY )
{
// Carry resulting number of days.
long lDays = (long)( dt.sec / (double) SECONDS_PER_DAY );
dt.day += lDays;
dt.sec -= ( lDays * (double) SECONDS_PER_DAY );
// Check for an overflow.
if( dt.day < dwDay )
{
dt.day = 0xffffffff;
dt.sec = 86399.999999;
}
}
// Else if the result is less than 0.0.
else if( dt.sec < 0.0 )
{
// Borrow the required number of days.
long lDays = 1 - (long)( dt.sec / (double) SECONDS_PER_DAY );
dt.day -= lDays;
dt.sec += ( lDays * (double) SECONDS_PER_DAY );
// Check for an underflow.
if( dt.day > dwDay )
{
dt.day = 0;
dt.sec = 0.0;
}
}
// Adjust the result.
dt.sec = _FixSeconds( dt.sec );
}
// 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 )
{
psc = FindScalarInCollection( m_record->m_pcollMain, tagTimeStart );
if( psc )
{
status = psc->GetValueTimeStamp( timeStart );
}
}
if( status )
{
psc = FindScalarInCollection( m_record->m_pcollMain, tagTimeCreate );
if( psc )
{
status = psc->GetValueTimeStamp( timeCreate );
}
}
// Get name
if( status )
{
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;
}
#ifdef zap
//
//
// Depricated function
//
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;
}
#endif
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 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -