nidas  v1.2-1520
Public Member Functions | Protected 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) throw (nidas::util::InvalidParameterException)
 Set the parameters which delineate a message for this scanner. 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
 Is the message separator at the end of the message (true), or at the beginning (false)? More...
 
unsigned int getMessageLength () const
 Returns 0. More...
 
SamplenextSample (DSMSensor *sensor)
 Extract the next sample from the buffer. More...
 
virtual void init ()
 Initialize the scanner. More...
 
virtual bool getNullTerminate () const
 Should the SampleScanner append a null character, '\0', to the messages. More...
 
void setUsecsPerByte (int val)
 
int getUsecsPerByte () const
 
virtual size_t readBuffer (DSMSensor *sensor, bool &exhausted) throw (nidas::util::IOException)
 Read from the sensor into the internal buffer of this SampleScanner. More...
 
virtual 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...
 
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 Attributes

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

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

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

Returns 0.

Reimplemented from nidas::core::SampleScanner.

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

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.

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.

unsigned int nidas::core::SampleScanner::getMinSampleLength ( ) const
inlineinherited
virtual bool nidas::core::SampleScanner::getNullTerminate ( ) const
inlinevirtualinherited

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

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

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

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 * DriverSampleScanner::nextSample ( DSMSensor sensor)
virtualinherited
size_t SampleScanner::readBuffer ( DSMSensor sensor,
bool &  exhausted 
)
throw (nidas::util::IOException
)
virtualinherited
size_t SampleScanner::readBuffer ( DSMSensor sensor,
bool &  exhausted,
int  msecTimeout 
)
throw (nidas::util::IOException
)
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.

Reimplemented in nidas::core::MessageStreamScanner.

References MSECS_PER_SEC, NLOG, NSECS_PER_MSEC, and nidas::core::SampleScanner::readBuffer().

void SampleScanner::resetStatistics ( )
virtualinherited
void MessageSampleScanner::setMessageParameters ( unsigned int  len,
const std::string &  val,
bool  eom 
)
throw (nidas::util::InvalidParameterException
)
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()

Reimplemented from nidas::core::DriverSampleScanner.

References len, and nidas::util::replaceBackslashSequences().

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

Member Data Documentation

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
int nidas::core::SampleScanner::_messageLength
protectedinherited
std::string nidas::core::SampleScanner::_messageSeparator
protectedinherited
Sample* nidas::core::SampleScanner::_osamp
protectedinherited
char* nidas::core::SampleScanner::_outSampDataPtr
protectedinherited
unsigned int nidas::core::SampleScanner::_outSampRead
protectedinherited
unsigned int nidas::core::SampleScanner::_outSampToRead
protectedinherited
char* nidas::core::SampleScanner::_separator
protectedinherited
bool nidas::core::SampleScanner::_separatorAtEOM
protectedinherited
int nidas::core::SampleScanner::_separatorLen
protectedinherited
const unsigned int nidas::core::SampleScanner::BUFSIZE
protectedinherited

Buffer size for reading from sensor.


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