nidas v1.2.3
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
nidas::core::MessageStreamScanner Class Reference

A SampleScanner which supports the set/get of message separation parameters and extracts samples from the internal buffer by recognizing separators in the message stream. More...

#include <SampleScanner.h>

Inheritance diagram for nidas::core::MessageStreamScanner:
Inheritance graph
[legend]

Public Member Functions

 MessageStreamScanner (int bufsize=4096)
 
void setMessageParameters (unsigned int len, const std::string &val, bool eom)
 
const std::string & getMessageSeparator () const
 Get message separator string.
 
const std::string getBackslashedMessageSeparator () const
 Get message separator with backslash sequences added back.
 
bool getMessageSeparatorAtEOM () const
 
unsigned int getMessageLength () const
 Returns 0.
 
void setNullTerminate (bool val)
 
bool getNullTerminate () const
 Should the SampleScanner append a null character, '\0', to the messages.
 
SamplenextSample (DSMSensor *sensor)
 Extract the next sample from the buffer.
 
size_t readBuffer (DSMSensor *sensor, bool &exhausted)
 
size_t readBuffer (DSMSensor *sensor, bool &exhausted, int msecTimeout)
 
void warnNonIncrTimeTag (const DSMSensor *sensor, dsm_time_t badtt, dsm_time_t cortt, unsigned int nbad)
 Issue warning log message about a non-forward time tag.
 
void warnBackwardsStepTimeTag (const DSMSensor *sensor, dsm_time_t badtt, unsigned int nbad)
 
virtual void init ()
 Initialize the scanner.
 
void setUsecsPerByte (int val)
 
int getUsecsPerByte () const
 
virtual void clearBuffer ()
 
unsigned int getBytesInBuffer () const
 
virtual void resetStatistics ()
 
virtual void calcStatistics (unsigned int periodUsec)
 Update the sensor sampling statistics: samples/sec, bytes/sec, min/max sample size, that can be accessed via getObservedSamplingRate(), getObservedDataRate() etc.
 
unsigned int getMaxSampleLength () const
 
unsigned int getMinSampleLength () const
 
unsigned int getBadTimeTagCount () const
 
float getObservedSamplingRate () const
 
float getObservedDataRate () const
 
void addNumBytesToStats (size_t val)
 
void addSampleToStats (unsigned int val)
 
void incrementBadTimeTags ()
 

Protected Member Functions

virtual SamplenextSampleSepBOM (DSMSensor *sensor)
 Method to read input and break it into samples where the message separator occurs at the beginning of the message.
 
virtual SamplenextSampleSepEOM (DSMSensor *sensor)
 Method to read input and break it into samples where the message separator occurs at the end of the message.
 
SamplenextSampleByLength (DSMSensor *sensor)
 Method to read input and break it into samples strictly by record length.
 
SamplerequestBiggerSample (unsigned int nc)
 If a new sample can be allocated without exceeding MAX_MESSAGE_STREAM_SAMPLE_SIZE then get a new, larger sample, copying the timetag, id and existing data from the current sample, and return null.
 

Protected Attributes

Sample *(MessageStreamScanner::* _nextSampleFunc )(DSMSensor *)
 
dsm_time_t _tfirstchar
 
dsm_time_t _lastBufferTime
 
dsm_time_t _lastSampleTime
 
const unsigned int MAX_MESSAGE_STREAM_SAMPLE_SIZE
 
int _separatorCnt
 
dsm_time_t _bomtt
 
int _sampleOverflows
 
unsigned int _sampleLengthAlloc
 Size of samples to allocate.
 
bool _nullTerminate
 
int _nsmallSamples
 Count of number of consecutive samples smaller than _sampleLengthAlloc.
 
unsigned int _outSampLengthAlloc
 Number of bytes allocated in data portion of current output sample.
 
bool _stepBackwards
 If the system time of a buffer read is earlier than the previous read.
 
unsigned int _stepBackTimeTag
 Number of time tags that were not monotonically increasing, due to backward step changes.
 
unsigned int _nonIncrTimeTag
 Number of time tags that were not monotonically increasing, not because of backward step changes, but instead due to system buffering, where the receipt times of two buffers are closer together than should be possible at the given baud rate.
 
const unsigned int BUFSIZE
 Buffer size for reading from sensor.
 
char_buffer
 
unsigned int _bufhead
 
unsigned int _buftail
 
Sample_osamp
 
struct dsm_sample _header
 
unsigned int _outSampRead
 
unsigned int _outSampToRead
 
char_outSampDataPtr
 
std::string _messageSeparator
 
int _messageLength
 
bool _separatorAtEOM
 
char_separator
 messageSeparator in a C string.
 
int _separatorLen
 Length of messageSeparator.
 

Private Attributes

std::string _emptyString
 
time_t _initialTimeSecs
 
unsigned int _minSampleLength [2]
 
unsigned int _maxSampleLength [2]
 
int _currentIndex
 
int _reportIndex
 
size_t _nsamples
 
size_t _nbytes
 
unsigned int _badTimeTags
 
float _sampleRateObs
 Observed number of samples per second.
 
float _dataRateObs
 
int _usecsPerByte
 

Detailed Description

A SampleScanner which supports the set/get of message separation parameters and extracts samples from the internal buffer by recognizing separators in the message stream.

Timetags are applied to the samples based on the time of receipt of each chunk of data, corrected backwards by the computed tranmission time of each byte in the chunk.

See also
setUsecsPerByte().

Constructor & Destructor Documentation

◆ MessageStreamScanner()

MessageStreamScanner::MessageStreamScanner ( int bufsize = 4096)

Member Function Documentation

◆ addNumBytesToStats()

void nidas::core::SampleScanner::addNumBytesToStats ( size_t val)
inlineinherited

◆ addSampleToStats()

void nidas::core::SampleScanner::addSampleToStats ( unsigned int val)
inlineinherited

◆ calcStatistics()

void SampleScanner::calcStatistics ( unsigned int periodUsec)
virtualinherited

◆ clearBuffer()

void SampleScanner::clearBuffer ( )
virtualinherited

◆ getBackslashedMessageSeparator()

const string MessageStreamScanner::getBackslashedMessageSeparator ( ) const
virtual

Get message separator with backslash sequences added back.

Reimplemented from nidas::core::SampleScanner.

References nidas::core::SampleScanner::_messageSeparator, and nidas::util::addBackslashSequences().

◆ getBadTimeTagCount()

unsigned int nidas::core::SampleScanner::getBadTimeTagCount ( ) const
inlineinherited

◆ getBytesInBuffer()

unsigned int nidas::core::SampleScanner::getBytesInBuffer ( ) const
inlineinherited

◆ getMaxSampleLength()

unsigned int nidas::core::SampleScanner::getMaxSampleLength ( ) const
inlineinherited

◆ getMessageLength()

unsigned int nidas::core::MessageStreamScanner::getMessageLength ( ) const
inlinevirtual

◆ getMessageSeparator()

const std::string & nidas::core::MessageStreamScanner::getMessageSeparator ( ) const
inlinevirtual

Get message separator string.

Any backslash sequences will have been replaced by their intended value.

Reimplemented from nidas::core::SampleScanner.

References nidas::core::SampleScanner::_messageSeparator.

◆ getMessageSeparatorAtEOM()

bool nidas::core::MessageStreamScanner::getMessageSeparatorAtEOM ( ) const
inlinevirtual

◆ getMinSampleLength()

unsigned int nidas::core::SampleScanner::getMinSampleLength ( ) const
inlineinherited

◆ getNullTerminate()

bool nidas::core::MessageStreamScanner::getNullTerminate ( ) const
inlinevirtual

Should the SampleScanner append a null character, '\0', to the messages.

Reimplemented from nidas::core::SampleScanner.

References _nullTerminate.

Referenced by nextSampleSepBOM(), nextSampleSepEOM(), requestBiggerSample(), and setMessageParameters().

◆ getObservedDataRate()

float SampleScanner::getObservedDataRate ( ) const
inherited

◆ getObservedSamplingRate()

float SampleScanner::getObservedSamplingRate ( ) const
inherited

◆ getUsecsPerByte()

int nidas::core::SampleScanner::getUsecsPerByte ( ) const
inlineinherited

◆ incrementBadTimeTags()

void nidas::core::SampleScanner::incrementBadTimeTags ( )
inlineinherited

◆ init()

void SampleScanner::init ( )
virtualinherited

Initialize the scanner.

Must be called by a user of SampleScanner prior to calling readSamples().

References nidas::core::SampleScanner::resetStatistics().

Referenced by nidas::core::DSMSensor::open().

◆ nextSample()

Sample * nidas::core::MessageStreamScanner::nextSample ( DSMSensor * sensor)
inlinevirtual

Extract the next sample from the buffer.

Returns NULL if there are no more samples in the buffer.

Implements nidas::core::SampleScanner.

References _nextSampleFunc.

◆ nextSampleByLength()

Sample * MessageStreamScanner::nextSampleByLength ( DSMSensor * sensor)
protected

◆ nextSampleSepBOM()

Sample * MessageStreamScanner::nextSampleSepBOM ( DSMSensor * sensor)
protectedvirtual

◆ nextSampleSepEOM()

Sample * MessageStreamScanner::nextSampleSepEOM ( DSMSensor * sensor)
protectedvirtual

◆ readBuffer() [1/2]

size_t MessageStreamScanner::readBuffer ( DSMSensor * sensor,
bool & exhausted )
virtual

◆ readBuffer() [2/2]

size_t MessageStreamScanner::readBuffer ( DSMSensor * sensor,
bool & exhausted,
int msecTimeout )
virtual

◆ requestBiggerSample()

Sample * MessageStreamScanner::requestBiggerSample ( unsigned int nc)
protected

If a new sample can be allocated without exceeding MAX_MESSAGE_STREAM_SAMPLE_SIZE then get a new, larger sample, copying the timetag, id and existing data from the current sample, and return null.

The data members _osamp, and _outSampDataPtr are updated to point to the new sample. Otherwise, since we've reached the MAX limit, more data will not be added to the sample, so return a pointer to the existing max'd out sample, which should then be returned as the value of the nextSample() method.

References nidas::core::SampleScanner::_osamp, nidas::core::SampleScanner::_outSampDataPtr, _outSampLengthAlloc, nidas::core::SampleScanner::_outSampRead, _sampleOverflows, nidas::core::SampleScanner::addSampleToStats(), nidas::core::Sample::freeReference(), nidas::core::Sample::getAllocByteLength(), nidas::core::Sample::getId(), getNullTerminate(), nidas::core::getSample(), nidas::core::Sample::getTimeTag(), nidas::core::Sample::getVoidDataPtr(), MAX_MESSAGE_STREAM_SAMPLE_SIZE, and nidas::core::Sample::setDataLength().

Referenced by nextSampleByLength(), nextSampleSepBOM(), and nextSampleSepEOM().

◆ resetStatistics()

void SampleScanner::resetStatistics ( )
virtualinherited

◆ setMessageParameters()

void MessageStreamScanner::setMessageParameters ( unsigned int len,
const std::string & val,
bool eom )
virtual

◆ setNullTerminate()

void nidas::core::MessageStreamScanner::setNullTerminate ( bool val)
inline

◆ setUsecsPerByte()

void nidas::core::SampleScanner::setUsecsPerByte ( int val)
inlineinherited

◆ warnBackwardsStepTimeTag()

void MessageStreamScanner::warnBackwardsStepTimeTag ( const DSMSensor * sensor,
dsm_time_t badtt,
unsigned int nbad )

◆ warnNonIncrTimeTag()

void MessageStreamScanner::warnNonIncrTimeTag ( const DSMSensor * sensor,
dsm_time_t badtt,
dsm_time_t cortt,
unsigned int nbad )

Member Data Documentation

◆ _badTimeTags

unsigned int nidas::core::SampleScanner::_badTimeTags
privateinherited

◆ _bomtt

dsm_time_t nidas::core::MessageStreamScanner::_bomtt
protected

Referenced by nextSampleSepBOM().

◆ _buffer

char* nidas::core::SampleScanner::_buffer
protectedinherited

◆ _bufhead

unsigned int nidas::core::SampleScanner::_bufhead
protectedinherited

◆ _buftail

unsigned int nidas::core::SampleScanner::_buftail
protectedinherited

◆ _currentIndex

int nidas::core::SampleScanner::_currentIndex
privateinherited

◆ _dataRateObs

float nidas::core::SampleScanner::_dataRateObs
privateinherited

◆ _emptyString

std::string nidas::core::SampleScanner::_emptyString
privateinherited

◆ _header

struct dsm_sample nidas::core::SampleScanner::_header
protectedinherited

◆ _initialTimeSecs

time_t nidas::core::SampleScanner::_initialTimeSecs
privateinherited

◆ _lastBufferTime

dsm_time_t nidas::core::MessageStreamScanner::_lastBufferTime
protected

Referenced by readBuffer(), and readBuffer().

◆ _lastSampleTime

dsm_time_t nidas::core::MessageStreamScanner::_lastSampleTime
protected

◆ _maxSampleLength

unsigned int nidas::core::SampleScanner::_maxSampleLength[2]
privateinherited

◆ _messageLength

int nidas::core::SampleScanner::_messageLength
protectedinherited

◆ _messageSeparator

std::string nidas::core::SampleScanner::_messageSeparator
protectedinherited

◆ _minSampleLength

unsigned int nidas::core::SampleScanner::_minSampleLength[2]
privateinherited

◆ _nbytes

size_t nidas::core::SampleScanner::_nbytes
privateinherited

◆ _nextSampleFunc

Sample *(MessageStreamScanner::* nidas::core::MessageStreamScanner::_nextSampleFunc) (DSMSensor *)
protected

Referenced by nextSample(), and setMessageParameters().

◆ _nonIncrTimeTag

unsigned int nidas::core::MessageStreamScanner::_nonIncrTimeTag
protected

Number of time tags that were not monotonically increasing, not because of backward step changes, but instead due to system buffering, where the receipt times of two buffers are closer together than should be possible at the given baud rate.

Referenced by nextSampleByLength(), nextSampleSepBOM(), and nextSampleSepEOM().

◆ _nsamples

size_t nidas::core::SampleScanner::_nsamples
privateinherited

◆ _nsmallSamples

int nidas::core::MessageStreamScanner::_nsmallSamples
protected

Count of number of consecutive samples smaller than _sampleLengthAlloc.

Referenced by nextSampleSepBOM(), and nextSampleSepEOM().

◆ _nullTerminate

bool nidas::core::MessageStreamScanner::_nullTerminate
protected

◆ _osamp

Sample* nidas::core::SampleScanner::_osamp
protectedinherited

◆ _outSampDataPtr

char* nidas::core::SampleScanner::_outSampDataPtr
protectedinherited

◆ _outSampLengthAlloc

unsigned int nidas::core::MessageStreamScanner::_outSampLengthAlloc
protected

Number of bytes allocated in data portion of current output sample.

Referenced by nextSampleByLength(), nextSampleSepBOM(), nextSampleSepEOM(), and requestBiggerSample().

◆ _outSampRead

unsigned int nidas::core::SampleScanner::_outSampRead
protectedinherited

◆ _outSampToRead

unsigned int nidas::core::SampleScanner::_outSampToRead
protectedinherited

◆ _reportIndex

int nidas::core::SampleScanner::_reportIndex
privateinherited

◆ _sampleLengthAlloc

unsigned int nidas::core::MessageStreamScanner::_sampleLengthAlloc
protected

Size of samples to allocate.

Referenced by nextSampleByLength(), nextSampleSepBOM(), nextSampleSepEOM(), and setMessageParameters().

◆ _sampleOverflows

int nidas::core::MessageStreamScanner::_sampleOverflows
protected

Referenced by requestBiggerSample().

◆ _sampleRateObs

float nidas::core::SampleScanner::_sampleRateObs
privateinherited

◆ _separator

char* nidas::core::SampleScanner::_separator
protectedinherited

◆ _separatorAtEOM

bool nidas::core::SampleScanner::_separatorAtEOM
protectedinherited

◆ _separatorCnt

int nidas::core::MessageStreamScanner::_separatorCnt
protected

◆ _separatorLen

int nidas::core::SampleScanner::_separatorLen
protectedinherited

◆ _stepBackTimeTag

unsigned int nidas::core::MessageStreamScanner::_stepBackTimeTag
protected

Number of time tags that were not monotonically increasing, due to backward step changes.

Referenced by nextSampleByLength(), nextSampleSepBOM(), and nextSampleSepEOM().

◆ _stepBackwards

bool nidas::core::MessageStreamScanner::_stepBackwards
protected

If the system time of a buffer read is earlier than the previous read.

This should only happen due to a step change of the system clock.

Referenced by nextSampleByLength(), nextSampleSepBOM(), nextSampleSepEOM(), readBuffer(), and readBuffer().

◆ _tfirstchar

dsm_time_t nidas::core::MessageStreamScanner::_tfirstchar
protected

◆ _usecsPerByte

int nidas::core::SampleScanner::_usecsPerByte
privateinherited

◆ BUFSIZE

const unsigned int nidas::core::SampleScanner::BUFSIZE
protectedinherited

Buffer size for reading from sensor.

Referenced by nidas::core::SampleScanner::readBuffer(), and nidas::core::DatagramSampleScanner::readBuffer().

◆ MAX_MESSAGE_STREAM_SAMPLE_SIZE

const unsigned int nidas::core::MessageStreamScanner::MAX_MESSAGE_STREAM_SAMPLE_SIZE
protected

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