AURobotServers
4
|
#include <uvarlog.h>
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) |
UMatrix * | getTimeSeries (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 |
UTime * | histTime |
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... | |
UVarLog * | varParent |
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 |
UReplay * | replayParent |
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... | |
Class to extend functionality of a UVariable with functions for available (fixed size) history and logfile functionality
UVarHist::UVarHist | ( | UVarLog * | parent | ) |
Constructor
References colCnt, histData, histTime, minUpdTime, rowCnt, rowMaxCnt, rowNext, varLogName, and varParent.
Referenced by UVarLog::makeHist().
UVarHist::~UVarHist | ( | ) |
void UVarHist::changed | ( | double * | data, |
bool | isDouble, | ||
UTime | updTime | ||
) |
Data has been updated - make history.
data | is a pointer to curreent data (after change). |
updTime | is time associated with update. |
isDouble | if true then data is a double buffer, else a char buffer. |
References colCnt, histData, histTime, ULogFile::isLogOpen(), logDataDouble(), minUpdTime, rowCnt, rowMaxCnt, rowNext, ULogFile::toLog(), and tUpd1.
|
protectedvirtual |
Decode this replay line, that is assumed to be valid.
line | is a pointer to the line. |
Reimplemented from UReplay.
References UVarLog::decodeReplayLine(), and varParent.
Referenced by getData().
|
inline |
Get data pointer of indexed element
idx | is 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
element | is the element (history column) to use, 0=first element. |
toTime | is the end time where the vector should end. |
mean | is set to the mean value in the specified time series (unchanged if no data) - may be NULL |
min | is set to the minimum value in the specified time series (unchanged if no data) - may be NULL |
max | is set to the maximum value in the time series (unchanged if no data) - may be NULL. |
sampleInterval | is the interval between samples to test (default is 1) |
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.
element | is the (max) number of time series elements to look back for average sample rate. |
References getUpdTime(), mini(), and rowCnt.
Referenced by getData().
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.
buffer | is the matrix that is to be filled with the data. |
maxRows | is 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
buffer | is a result buffer for the values |
bufferCnt | is the size of the buffer (maximum this number of elements will be loaded into buffer. |
element | is 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. |
interval | is the interval of the samples taken, 2 means use every second measurement only |
References colCnt, getData(), UTime::getDecSec(), getUpdTime(), maxi(), mini(), and rowCnt.
Referenced by getData(), and UVarLog::getElementCnt2().
|
inline |
Get update time of newest element
References histTime, and rowNext.
Referenced by UVariable::copy(), getMeanMinMax(), getSampleRate(), getTimeVector(), getVectorToTime(), and UFunctionVarPool::sendVar().
|
inline |
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
buffer | is a result buffer for the values |
bufferCnt | is the size of the buffer (maximum this number of elements will be loaded into buffer. |
element | is 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. |
tot | is the end time where the vector should end. |
interval | is interval of the samples taken, 1 is all, 2 is every second .... |
gotdt | is the (average) sample interval of saved data [sec]. |
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)
idx | is 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.
preName | is the name of the struct. |
varName | is 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.
histRowCnt | is the number of history rows to be allocated. |
histColCnt | is the number of data elements (columns) in each hirtory element |
References UTime::clear(), colCnt, histData, histTime, rowCnt, rowMaxCnt, and rowNext.
Referenced by UVariable::openVarLog(), and UVariable::setSize().
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 |
Referenced by changed(), getData(), logDataDouble(), setHistSize(), UVarHist(), and ~UVarHist().
UTime* UVarHist::histTime |
time associated with each history element
Referenced by changed(), getUpdTime(), logDataDouble(), setHistSize(), UVarHist(), and ~UVarHist().
double UVarHist::minUpdTime |
min update time
Referenced by changed(), UFunctionVarPool::handleVarValues(), UFunctionVarPool::sendVar(), and UVarHist().
int UVarHist::rowCnt |
number of elements used.
Referenced by changed(), getData(), getMeanMinMax(), getSampleRate(), getTimeSeries(), getTimeVector(), getUpdTime(), getVectorToTime(), logAll(), UFunctionVarPool::sendVar(), setHistSize(), UVariable::setSize(), UVarHist(), and ~UVarHist().
int UVarHist::rowMaxCnt |
number of history elements in buffer
Referenced by changed(), getData(), getUpdTime(), UFunctionVarPool::handleVarValues(), logAll(), UVariable::openVarLog(), UFunctionVarPool::sendVar(), UFunctionVarPool::sendVarList(), setHistSize(), UVarHist(), and ~UVarHist().
int UVarHist::rowNext |
next element to fill next
Referenced by changed(), getData(), getUpdTime(), logAll(), setHistSize(), UVarHist(), and ~UVarHist().
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().