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

A DriverSampleScanner which supports the set/get of message separation parameters. More...

#include <SampleScanner.h>

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

Public Member Functions

 MessageSampleScanner (int bufsize=8192)
 
void setMessageParameters (unsigned int len, const std::string &val, bool eom)
 Set the parameters which delineate a message for this scanner.
 
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
 Is the message separator at the end of the message (true), or at the beginning (false)?
 
unsigned int getMessageLength () const
 Returns 0.
 
SamplenextSample (DSMSensor *sensor)
 Extract the next sample from the buffer.
 
virtual void init ()
 Initialize the scanner.
 
virtual bool getNullTerminate () const
 Should the SampleScanner append a null character, '\0', to the messages.
 
void setUsecsPerByte (int val)
 
int getUsecsPerByte () const
 
virtual size_t readBuffer (DSMSensor *sensor, bool &exhausted)
 Read from the sensor into the internal buffer of this SampleScanner.
 
virtual size_t readBuffer (DSMSensor *sensor, bool &exhausted, int msecTimeout)
 Read from the sensor into the internal buffer of this SampleScanner, providing a timeout in milliseconds.
 
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 Attributes

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 DriverSampleScanner which supports the set/get of message separation parameters.

Typically these parameters are sent down to a driver module by an implementation of DSMSensor.

Constructor & Destructor Documentation

◆ MessageSampleScanner()

MessageSampleScanner::MessageSampleScanner ( int bufsize = 8192)

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 MessageSampleScanner::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::MessageSampleScanner::getMessageLength ( ) const
inlinevirtual

Returns 0.

Reimplemented from nidas::core::SampleScanner.

References nidas::core::SampleScanner::_messageLength.

◆ getMessageSeparator()

const std::string & nidas::core::MessageSampleScanner::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::MessageSampleScanner::getMessageSeparatorAtEOM ( ) const
inlinevirtual

Is the message separator at the end of the message (true), or at the beginning (false)?

Reimplemented from nidas::core::SampleScanner.

References nidas::core::SampleScanner::_separatorAtEOM.

◆ getMinSampleLength()

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

◆ getNullTerminate()

virtual bool nidas::core::SampleScanner::getNullTerminate ( ) const
inlinevirtualinherited

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

Reimplemented in nidas::core::MessageStreamScanner, and nidas::core::DatagramSampleScanner.

Referenced by nidas::core::CharacterSensor::getNullTerminated().

◆ 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 * DriverSampleScanner::nextSample ( DSMSensor * sensor)
virtualinherited

◆ readBuffer() [1/2]

size_t SampleScanner::readBuffer ( DSMSensor * sensor,
bool & exhausted )
virtualinherited

◆ readBuffer() [2/2]

size_t SampleScanner::readBuffer ( DSMSensor * sensor,
bool & exhausted,
int msecTimeout )
virtualinherited

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.

Exceptions
nidas::util::IOException

Reimplemented in nidas::core::MessageStreamScanner.

References nidas::core::DSMSensor::getName(), nidas::core::DSMSensor::getReadFd(), nidas::core::getSample(), MSECS_PER_SEC, NLOG, NSECS_PER_MSEC, and nidas::core::SampleScanner::readBuffer().

◆ resetStatistics()

void SampleScanner::resetStatistics ( )
virtualinherited

◆ setMessageParameters()

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

Set the parameters which delineate a message for this scanner.

The messageSeparator is the string of bytes that a sensor outputs between messages. The string may contain baskslash sequences.

Parameters
lenThe message length in bytes. A value of zero means the message length is completely variable, and that a scanner is should always be looking for a messageSeparator in the data. A positive value means read in messageLength number of bytes and then start looking for the messageSeparator. The messageLength does not include the length of the messageSeparator.

Setting a positive message length is only necessary if there is a chance that the message separator could be found in the data portion of the message. This may be the case if the sensor is generating binary data. A positive message length causes the parser to read messageLength number of bytes before again searching for the separator. This also makes the parsing a bit more efficient. If the messageLength is too small it will not necessarily cause messages to be truncated - all the data up to, and including the separator is still read and passed along for processing. If the value is larger than the actual message length it will cause two or more messages to be concatenated into one.

Parameters
eomTrue means the message scanner expects the separator at the end of the message, and the next byte read after the separator is the first byte of the next message. The timetag of a sample is the receipt time of the first byte after the separator of the previous message. False means the scanner expects the separator at the beginning of the message, in which case the timetag of a sample is the receipt time of the first byte of the messageSeparator.
See also
* nidas::util::replaceBackslashSequences()
Exceptions
nidas::util::InvalidParameterException

Reimplemented from nidas::core::DriverSampleScanner.

References nidas::core::SampleScanner::_messageSeparator, nidas::core::SampleScanner::_separatorAtEOM, nidas::core::SampleScanner::_separatorLen, nidas::core::getSample(), len, and nidas::util::replaceBackslashSequences().

◆ setUsecsPerByte()

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

Member Data Documentation

◆ _badTimeTags

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

◆ _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

◆ _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

◆ _nsamples

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

◆ _osamp

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

◆ _outSampDataPtr

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

◆ _outSampRead

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

◆ _outSampToRead

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

◆ _reportIndex

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

◆ _sampleRateObs

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

◆ _separator

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

◆ _separatorAtEOM

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

◆ _separatorLen

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

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


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