nidas  v1.2-1520
Public Member Functions | Protected Member Functions | Protected 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) throw (nidas::util::InvalidParameterException)
 Set the parameters associated with scanning of character messages. More...
 
const std::string & getMessageSeparator () const
 Get message separator string. More...
 
const std::string getBackslashedMessageSeparator () const
 Get message separator with backslash sequences added back. More...
 
bool getMessageSeparatorAtEOM () const
 
unsigned int getMessageLength () const
 Returns 0. More...
 
void setNullTerminate (bool val)
 
bool getNullTerminate () const
 Should the SampleScanner append a null character, '\0', to the messages. More...
 
SamplenextSample (DSMSensor *sensor)
 Extract the next sample from the buffer. More...
 
size_t readBuffer (DSMSensor *sensor, bool &exhausted) throw (nidas::util::IOException)
 Read from the sensor into the internal buffer of this SampleScanner. More...
 
size_t readBuffer (DSMSensor *sensor, bool &exhausted, int msecTimeout) throw (nidas::util::IOException)
 Read from the sensor into the internal buffer of this SampleScanner, providing a timeout in milliseconds. More...
 
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. More...
 
void warnBackwardsStepTimeTag (const DSMSensor *sensor, dsm_time_t badtt, unsigned int nbad)
 
virtual void init ()
 Initialize the scanner. More...
 
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. More...
 
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. More...
 
virtual SamplenextSampleSepEOM (DSMSensor *sensor)
 Method to read input and break it into samples where the message separator occurs at the end of the message. More...
 
SamplenextSampleByLength (DSMSensor *sensor)
 Method to read input and break it into samples strictly by record length. More...
 
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. More...
 

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. More...
 
bool _nullTerminate
 
int _nsmallSamples
 Count of number of consecutive samples smaller than _sampleLengthAlloc. More...
 
unsigned int _outSampLengthAlloc
 Number of bytes allocated in data portion of current output sample. More...
 
bool _stepBackwards
 If the system time of a buffer read is earlier than the previous read. More...
 
unsigned int _stepBackTimeTag
 Number of time tags that were not monotonically increasing, due to backward step changes. More...
 
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. More...
 
const unsigned int BUFSIZE
 Buffer size for reading from sensor. More...
 
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. More...
 
int _separatorLen
 Length of messageSeparator. More...
 

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 ( int  bufsize = 4096)

Member Function Documentation

void nidas::core::SampleScanner::addNumBytesToStats ( size_t  val)
inlineinherited
void nidas::core::SampleScanner::addSampleToStats ( unsigned int  val)
inlineinherited
void SampleScanner::calcStatistics ( unsigned int  periodUsec)
virtualinherited
void SampleScanner::clearBuffer ( )
virtualinherited
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().

unsigned int nidas::core::SampleScanner::getBadTimeTagCount ( ) const
inlineinherited
unsigned int nidas::core::SampleScanner::getBytesInBuffer ( ) const
inlineinherited
unsigned int nidas::core::SampleScanner::getMaxSampleLength ( ) const
inlineinherited
unsigned int nidas::core::MessageStreamScanner::getMessageLength ( ) const
inlinevirtual
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.

bool nidas::core::MessageStreamScanner::getMessageSeparatorAtEOM ( ) const
inlinevirtual
unsigned int nidas::core::SampleScanner::getMinSampleLength ( ) const
inlineinherited
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(), and requestBiggerSample().

float SampleScanner::getObservedDataRate ( ) const
inherited
float SampleScanner::getObservedSamplingRate ( ) const
inherited
int nidas::core::SampleScanner::getUsecsPerByte ( ) const
inlineinherited
void nidas::core::SampleScanner::incrementBadTimeTags ( )
inlineinherited
void SampleScanner::init ( )
virtualinherited

Initialize the scanner.

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

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

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.

Sample * MessageStreamScanner::nextSampleByLength ( DSMSensor sensor)
protected
Sample * MessageStreamScanner::nextSampleSepBOM ( DSMSensor sensor)
protectedvirtual
Sample * MessageStreamScanner::nextSampleSepEOM ( DSMSensor sensor)
protectedvirtual
size_t MessageStreamScanner::readBuffer ( DSMSensor sensor,
bool &  exhausted 
)
throw (nidas::util::IOException
)
virtual

Read from the sensor into the internal buffer of this SampleScanner.

Reimplemented from nidas::core::SampleScanner.

References nidas::util::getSystemTime(), and nidas::core::SampleScanner::readBuffer().

size_t MessageStreamScanner::readBuffer ( DSMSensor sensor,
bool &  exhausted,
int  msecTimeout 
)
throw (nidas::util::IOException
)
virtual

Read from the sensor into the internal buffer of this SampleScanner, providing a timeout in milliseconds.

This will throw nidas::util::IOTimeoutException if the read fails due to a timeout.

Reimplemented from nidas::core::SampleScanner.

References nidas::util::getSystemTime(), and nidas::core::SampleScanner::readBuffer().

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::Sample::getTimeTag(), nidas::core::Sample::getVoidDataPtr(), nidas::core::SampleT< DataT >::getVoidDataPtr(), MAX_MESSAGE_STREAM_SAMPLE_SIZE, nidas::core::Sample::setDataLength(), nidas::core::Sample::setId(), and nidas::core::Sample::setTimeTag().

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

void SampleScanner::resetStatistics ( )
virtualinherited
void MessageStreamScanner::setMessageParameters ( unsigned int  len,
const std::string &  val,
bool  eom 
)
throw (nidas::util::InvalidParameterException
)
virtual

Set the parameters associated with scanning of character messages.

Implements nidas::core::SampleScanner.

References len, nextSampleByLength(), nextSampleSepBOM(), nextSampleSepEOM(), and nidas::util::replaceBackslashSequences().

Referenced by nidas::dynld::GPS_NMEA_Serial::buildSampleScanner().

void nidas::core::MessageStreamScanner::setNullTerminate ( bool  val)
inline
void nidas::core::SampleScanner::setUsecsPerByte ( int  val)
inlineinherited
void MessageStreamScanner::warnBackwardsStepTimeTag ( const DSMSensor sensor,
dsm_time_t  badtt,
unsigned int  nbad 
)
void MessageStreamScanner::warnNonIncrTimeTag ( const DSMSensor sensor,
dsm_time_t  badtt,
dsm_time_t  cortt,
unsigned int  nbad 
)

Member Data Documentation

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

Referenced by nextSampleSepBOM().

char* nidas::core::SampleScanner::_buffer
protectedinherited
unsigned int nidas::core::SampleScanner::_bufhead
protectedinherited
unsigned int nidas::core::SampleScanner::_buftail
protectedinherited
struct dsm_sample nidas::core::SampleScanner::_header
protectedinherited
dsm_time_t nidas::core::MessageStreamScanner::_lastBufferTime
protected
dsm_time_t nidas::core::MessageStreamScanner::_lastSampleTime
protected
int nidas::core::SampleScanner::_messageLength
protectedinherited
std::string nidas::core::SampleScanner::_messageSeparator
protectedinherited
Sample*(MessageStreamScanner::* nidas::core::MessageStreamScanner::_nextSampleFunc)(DSMSensor *)
protected

Referenced by nextSample().

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().

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

Count of number of consecutive samples smaller than _sampleLengthAlloc.

Referenced by nextSampleSepBOM(), and nextSampleSepEOM().

bool nidas::core::MessageStreamScanner::_nullTerminate
protected
Sample* nidas::core::SampleScanner::_osamp
protectedinherited
char* nidas::core::SampleScanner::_outSampDataPtr
protectedinherited
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().

unsigned int nidas::core::SampleScanner::_outSampRead
protectedinherited
unsigned int nidas::core::SampleScanner::_outSampToRead
protectedinherited
unsigned int nidas::core::MessageStreamScanner::_sampleLengthAlloc
protected

Size of samples to allocate.

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

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

Referenced by requestBiggerSample().

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

messageSeparator in a C string.

Referenced by nextSampleSepBOM(), nextSampleSepEOM(), and nidas::core::SampleScanner::~SampleScanner().

bool nidas::core::SampleScanner::_separatorAtEOM
protectedinherited
int nidas::core::MessageStreamScanner::_separatorCnt
protected
int nidas::core::SampleScanner::_separatorLen
protectedinherited

Length of messageSeparator.

Referenced by nextSampleSepBOM(), and nextSampleSepEOM().

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().

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(), and nextSampleSepEOM().

dsm_time_t nidas::core::MessageStreamScanner::_tfirstchar
protected
const unsigned int nidas::core::SampleScanner::BUFSIZE
protectedinherited

Buffer size for reading from sensor.

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

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