AURobotServers  4
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
UVarHist Class Reference

#include <uvarlog.h>

Inheritance diagram for UVarHist:
Inheritance graph

Public Member Functions

void changed (double *data, bool isDouble, UTime updTime)
 
const double * getData (int idx)
 
int getMeanMinMax (int element, UTime toTime, double *mean, double *min, double *max, int sampleInterval=1)
 
double getSampleRate (int element)
 
UMatrixgetTimeSeries (UMatrix *buffer, int maxRows)
 
int getTimeVector (double *buffer, int bufferCnt, int element, int interval=1)
 
UTime getUpdTime ()
 
UTime getUpdTime (int idx)
 
int getVectorToTime (double *buffer, int bufferCnt, int element, UTime tot, int interval, double *gotdt)
 
void logAll ()
 
void logDataDouble (int idx)
 
void makeLogName (const char *preName, const char *varName)
 
bool setHistSize (int histRowCnt, int histColCnt)
 
 UVarHist (UVarLog *parent)
 
 ~UVarHist ()
 
- Public Member Functions inherited from ULogFile
void closeLog ()
 
void doFlush ()
 
FILE * getF ()
 
const char * getLogFileName ()
 
const char * getLogName ()
 
bool isLogOpen ()
 
bool isOpen ()
 
void logLock ()
 
bool logRename (const char *name)
 
void logUnlock ()
 
bool openLog ()
 
bool openLog (bool doOpen)
 
bool openLog (const char *resName)
 
void setLogFlush (bool doFlush)
 
void setLogName (const char *resName, const char *ext="log")
 
void setLogNameNumber (int number)
 add a number to the logfile name, That is if the logName is 'svs' and number is 2 (and logPath is '/rhome/demo'), then logfilename is set to '/rhome/demo/svs_2.log'. The purpose is to have an alternative, if the file renaming fails (if the file system is locked or something). More...
 
void setLogTime (UTime timestamp)
 
void toLog (const char *logString)
 
void toLog (const char *s1, const char *s2)
 
void toLog (const int num, const char *s1, const char *s2)
 
void toLog (const char *s1, const int num, const char *s2)
 
void toLog (const char *s1, const int n1, const int n2, const char *s2)
 
void toLog (const char *s1, const int num, const char *s2, const char *s3)
 
void toLog (const char *s1, const int n1, const int n2, const char *s2, const char *s3)
 
 ULogFile ()
 
void useLogTime (bool value)
 
 ~ULogFile ()
 
- Public Member Functions inherited from UReplay
void addChild (UReplay *child)
 
char * getLogFileName (char *fn, const int fnCnt)
 
char * getReplayFileName (char *fn, const int fnCnt)
 
int getReplayLogLine ()
 
bool isReplay ()
 
bool isReplayFileOpen ()
 
void removeChild (UReplay *child)
 
virtual void replayAdvanceTime (UTime untilTime)
 
void replaySetBaseFileName (const char *name, const char *preName="")
 
void replaySetFileName (const char *name)
 
virtual bool replayStep ()
 
int replayStep (int steps)
 
virtual bool replayToTime (UTime untilTime)
 
void setParent (UReplay *parent)
 
bool setReplay (bool value)
 
virtual void updateReplayStatus ()
 
 UReplay ()
 
virtual ~UReplay ()
 

Public Attributes

int colCnt
 size of each history data row (each row may be a matrix in its own right) More...
 
double * histData
 
UTimehistTime
 time associated with each history element More...
 
double minUpdTime
 min update time More...
 
int rowCnt
 number of elements used. More...
 
int rowMaxCnt
 number of history elements in buffer More...
 
int rowNext
 next element to fill next More...
 
UTime tUpd1
 time of first update not yet in update history More...
 
char * varLogName
 name of fully qualified variable (also base name of logfile (less path and extension)) More...
 
int varLogNameMaxCnt
 max length of name More...
 
UVarLogvarParent
 pointer to parent variable - to allow replay. More...
 
- Public Attributes inherited from UReplay
bool replayTimeAdvancePending
 
UTime replayTimeNow
 

Protected Member Functions

virtual bool decodeReplayLine (char *line)
 

Additional Inherited Members

- Protected Attributes inherited from ULogFile
int failCnt
 
FILE * logFile
 
ULock logFileLock
 
char logFileName [MAX_FILENAME_SIZE]
 
bool logFlush
 
char logName [MAX_FILENAME_SIZE]
 
UTime logTime
 
bool logTimeUse
 
- Protected Attributes inherited from UReplay
bool replay
 
FILE * replayFile
 
char replayFileName [REPLAY_FILE_NAME_LENGTH]
 replay filename More...
 
char replayLine [MAX_LOG_LINE_LENGTH]
 
int replayLogLine
 
UReplayreplayParent
 
UTime replayTimeNext
 
- Static Protected Attributes inherited from UReplay
static const int MAX_LOG_LINE_LENGTH = 10000
 
static const int REPLAY_FILE_NAME_LENGTH = 264
 max length of replay filename More...
 

Detailed Description

Class to extend functionality of a UVariable with functions for available (fixed size) history and logfile functionality

Constructor & Destructor Documentation

UVarHist::UVarHist ( UVarLog parent)

Constructor

References colCnt, histData, histTime, minUpdTime, rowCnt, rowMaxCnt, rowNext, varLogName, and varParent.

Referenced by UVarLog::makeHist().

UVarHist::~UVarHist ( )

Destructor

References histData, histTime, logDataDouble(), rowCnt, rowMaxCnt, and rowNext.

Member Function Documentation

void UVarHist::changed ( double *  data,
bool  isDouble,
UTime  updTime 
)

Data has been updated - make history.

Parameters
datais a pointer to curreent data (after change).
updTimeis time associated with update.
isDoubleif true then data is a double buffer, else a char buffer.
Todo:
if time goes backwards, it is likely to be old data replayed, this is seen as start of a new time series, and NOT put sorted into the history. - this is to allow switch from live to replay (and back)

References colCnt, histData, histTime, ULogFile::isLogOpen(), logDataDouble(), minUpdTime, rowCnt, rowMaxCnt, rowNext, ULogFile::toLog(), and tUpd1.

bool UVarHist::decodeReplayLine ( char *  line)
protectedvirtual

Decode this replay line, that is assumed to be valid.

Parameters
lineis a pointer to the line.
Returns
true if the line is valid and used (step is successfull).
false if line is not a valid step.

Reimplemented from UReplay.

References UVarLog::decodeReplayLine(), and varParent.

Referenced by getData().

const double* UVarHist::getData ( int  idx)
inline

Get data pointer of indexed element

Parameters
idxis the index to a historic value. 0 is newest

References colCnt, decodeReplayLine(), getMeanMinMax(), getSampleRate(), getTimeSeries(), getTimeVector(), getVectorToTime(), histData, logAll(), makeLogName(), min, rowCnt, rowMaxCnt, and rowNext.

Referenced by getMeanMinMax(), getTimeSeries(), getTimeVector(), UVariable::getValuedAsString(), and getVectorToTime().

int UVarHist::getMeanMinMax ( int  element,
UTime  toTime,
double *  mean,
double *  min,
double *  max,
int  sampleInterval = 1 
)

Get some statistics from the time series

Parameters
elementis the element (history column) to use, 0=first element.
toTimeis the end time where the vector should end.
meanis set to the mean value in the specified time series (unchanged if no data) - may be NULL
minis set to the minimum value in the specified time series (unchanged if no data) - may be NULL
maxis set to the maximum value in the time series (unchanged if no data) - may be NULL.
sampleIntervalis the interval between samples to test (default is 1)
Returns
number of elements used - 0 if no data.

References colCnt, getData(), getUpdTime(), maxi(), and rowCnt.

Referenced by getData(), and UVarLog::getElementCnt2().

double UVarHist::getSampleRate ( int  element)

Get actual sample rate, when looking this number of samples back. Function just looks at the oldest and newest element an number of history elements.

Parameters
elementis the (max) number of time series elements to look back for average sample rate.
Returns
sample rate in Hz, or -1.0 if there is not at least 2 elements in the time series.

References getUpdTime(), mini(), and rowCnt.

Referenced by getData().

UMatrix * UVarHist::getTimeSeries ( UMatrix buffer,
int  maxRows 
)

Get time series as a matrix with all comumns a maximum of rows. The first row is the newest (history) data (not current data). the buffer matrix will be resized (if needed) to fit data size.

Parameters
bufferis the matrix that is to be filled with the data.
maxRowsis the maximum size of the data.

References colCnt, UMatrix::cols(), getData(), mini(), rowCnt, UMatrix::rows(), UMatrix::setRow(), and UMatrix::setSize().

Referenced by getData(), and UVarLog::getElementCnt2().

int UVarHist::getTimeVector ( double *  buffer,
int  bufferCnt,
int  element,
int  interval = 1 
)

Get a time series vector from current history

Parameters
bufferis a result buffer for the values
bufferCntis the size of the buffer (maximum this number of elements will be loaded into buffer.
elementis the element (history column) to use, 0=first element. if element is -1, then the update time in decimal seconds is returned. if -2 then time is relative to newest update time.
intervalis the interval of the samples taken, 2 means use every second measurement only
Returns
number of elements returned (may be less than or equal to bufferCnt dependent of available data and history buffer size.
0 if no history is available.

References colCnt, getData(), UTime::getDecSec(), getUpdTime(), maxi(), mini(), and rowCnt.

Referenced by getData(), and UVarLog::getElementCnt2().

UTime UVarHist::getUpdTime ( )
inline

Get update time of newest element

References histTime, and rowNext.

Referenced by UVariable::copy(), getMeanMinMax(), getSampleRate(), getTimeVector(), getVectorToTime(), and UFunctionVarPool::sendVar().

UTime UVarHist::getUpdTime ( int  idx)
inline

Get update time of indexed element

References histTime, rowCnt, rowMaxCnt, and rowNext.

int UVarHist::getVectorToTime ( double *  buffer,
int  bufferCnt,
int  element,
UTime  tot,
int  interval,
double *  gotdt 
)

Get a time series vector from current history with specifiet update rate and end time. if update rate is not possible, then average rate is returned. The method is to skip recorded updates until specified dt is passed, then use and increase to next expected time

Parameters
bufferis a result buffer for the values
bufferCntis the size of the buffer (maximum this number of elements will be loaded into buffer.
elementis the element (history column) to use, 0=first element. if -1 then the update time value (in decimal seconds) is returned. if -2 then time is relative to newest update time.
totis the end time where the vector should end.
intervalis interval of the samples taken, 1 is all, 2 is every second ....
gotdtis the (average) sample interval of saved data [sec].
Returns
number of elements returned (may be less than or equal to bufferCnt dependent of available data and history buffer size.
0 if no history is available.

References colCnt, getData(), UTime::getDecSec(), getUpdTime(), maxi(), mini(), and rowCnt.

Referenced by getData(), and UVarLog::getElementCnt2().

void UVarHist::logAll ( )

Log all elements in in-memory history.

References logDataDouble(), rowCnt, rowMaxCnt, and rowNext.

Referenced by getData().

void UVarHist::logDataDouble ( int  idx)

Save newest data to logfile as doubles (if open)

Parameters
idxis the history index to log.

References colCnt, data, ULogFile::getF(), UTime::getMicrosec(), UTime::getSec(), histData, histTime, ULogFile::isLogOpen(), and ULogFile::logFlush.

Referenced by changed(), logAll(), and ~UVarHist().

void UVarHist::makeLogName ( const char *  preName,
const char *  varName 
)

Make log filename buffer for this name.

Parameters
preNameis the name of the struct.
varNameis the name of the variable.

References ULogFile::setLogName(), varLogName, and varLogNameMaxCnt.

Referenced by getData().

bool UVarHist::setHistSize ( int  histRowCnt,
int  histColCnt 
)

Set history buffer size - if size is changed, then history is lost.

Parameters
histRowCntis the number of history rows to be allocated.
histColCntis the number of data elements (columns) in each hirtory element
Returns
true if allocated.

References UTime::clear(), colCnt, histData, histTime, rowCnt, rowMaxCnt, and rowNext.

Referenced by UVariable::openVarLog(), and UVariable::setSize().

Member Data Documentation

int UVarHist::colCnt

size of each history data row (each row may be a matrix in its own right)

Referenced by changed(), getData(), getMeanMinMax(), getTimeSeries(), getTimeVector(), getVectorToTime(), logDataDouble(), setHistSize(), UVariable::setSize(), and UVarHist().

double* UVarHist::histData
UTime* UVarHist::histTime

time associated with each history element

Referenced by changed(), getUpdTime(), logDataDouble(), setHistSize(), UVarHist(), and ~UVarHist().

double UVarHist::minUpdTime
int UVarHist::rowCnt
int UVarHist::rowMaxCnt
int UVarHist::rowNext

next element to fill next

Referenced by changed(), getData(), getUpdTime(), logAll(), setHistSize(), UVarHist(), and ~UVarHist().

UTime UVarHist::tUpd1

time of first update not yet in update history

Referenced by changed().

char* UVarHist::varLogName

name of fully qualified variable (also base name of logfile (less path and extension))

Referenced by makeLogName(), and UVarHist().

int UVarHist::varLogNameMaxCnt

max length of name

Referenced by makeLogName().

UVarLog* UVarHist::varParent

pointer to parent variable - to allow replay.

Referenced by decodeReplayLine(), and UVarHist().


The documentation for this class was generated from the following files: