nidas v1.2.3
|
A DriverSampleScanner which supports the set/get of message separation parameters. More...
#include <SampleScanner.h>
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. | |
Sample * | nextSample (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 |
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.
MessageSampleScanner::MessageSampleScanner | ( | int | bufsize = 8192 | ) |
References nidas::core::SampleScanner::_nbytes, and nidas::core::getSample().
Referenced by nidas::core::SampleScanner::readBuffer(), and nidas::core::DatagramSampleScanner::readBuffer().
References nidas::core::SampleScanner::_currentIndex, nidas::core::SampleScanner::_maxSampleLength, nidas::core::SampleScanner::_minSampleLength, and nidas::core::SampleScanner::_nsamples.
Referenced by nidas::core::DriverSampleScanner::nextSample(), nidas::core::DatagramSampleScanner::nextSample(), nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), and nidas::core::MessageStreamScanner::requestBiggerSample().
Update the sensor sampling statistics: samples/sec, bytes/sec, min/max sample size, that can be accessed via getObservedSamplingRate(), getObservedDataRate() etc.
Should be called every periodUsec by a user of this sensor.
periodUsec | Statistics period. |
References nidas::core::SampleScanner::_currentIndex, nidas::core::SampleScanner::_dataRateObs, nidas::core::SampleScanner::_maxSampleLength, nidas::core::SampleScanner::_minSampleLength, nidas::core::SampleScanner::_nbytes, nidas::core::SampleScanner::_nsamples, nidas::core::SampleScanner::_reportIndex, nidas::core::SampleScanner::_sampleRateObs, nidas::core::getSample(), and USECS_PER_SEC.
Referenced by nidas::core::DSMSensor::calcStatistics().
|
virtualinherited |
References nidas::core::SampleScanner::_bufhead, and nidas::core::SampleScanner::_buftail.
Referenced by nidas::core::DSMSensor::clearBuffer().
|
virtual |
Get message separator with backslash sequences added back.
Reimplemented from nidas::core::SampleScanner.
References nidas::core::SampleScanner::_messageSeparator, and nidas::util::addBackslashSequences().
References nidas::core::SampleScanner::_badTimeTags.
Referenced by nidas::core::DSMSensor::getBadTimeTagCount().
References nidas::core::SampleScanner::_bufhead, and nidas::core::SampleScanner::_buftail.
References nidas::core::SampleScanner::_maxSampleLength, and nidas::core::SampleScanner::_reportIndex.
Referenced by nidas::core::DSMSensor::getMaxSampleLength().
Returns 0.
Reimplemented from nidas::core::SampleScanner.
References nidas::core::SampleScanner::_messageLength.
|
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.
|
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.
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().
|
inherited |
|
inherited |
|
inlineinherited |
References nidas::core::SampleScanner::_usecsPerByte.
Referenced by nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), nidas::core::MessageStreamScanner::readBuffer(), and nidas::core::MessageStreamScanner::readBuffer().
|
inlineinherited |
References nidas::core::SampleScanner::_badTimeTags.
Referenced by nidas::core::DriverSampleScanner::nextSample().
|
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().
Extract the next sample from the buffer.
Returns NULL if there are no more samples in the buffer.
Implements nidas::core::SampleScanner.
References nidas::core::SampleScanner::_buffer, nidas::core::SampleScanner::_bufhead, nidas::core::SampleScanner::_buftail, nidas::core::SampleScanner::_header, nidas::core::SampleScanner::_osamp, nidas::core::SampleScanner::_outSampDataPtr, nidas::core::SampleScanner::_outSampRead, nidas::core::SampleScanner::_outSampToRead, nidas::core::SampleScanner::addSampleToStats(), nidas::core::Sample::freeReference(), nidas::core::Sample::getDataByteLength(), nidas::core::DSMSensor::getDriverTimeTagUsecs(), nidas::core::DSMSensor::getId(), nidas::core::SampleClock::getInstance(), nidas::core::getSample(), nidas::core::Sample::getVoidDataPtr(), nidas::core::SampleScanner::incrementBadTimeTags(), len, nidas::core::SampleClock::OK, nidas::core::Sample::setDataLength(), nidas::core::Sample::setId(), nidas::core::Sample::setTimeTag(), and SIZEOF_DSM_SAMPLE_HEADER.
Read from the sensor into the internal buffer of this SampleScanner.
nidas::util::IOException |
Reimplemented in nidas::core::MessageStreamScanner, and nidas::core::DatagramSampleScanner.
References nidas::core::SampleScanner::_buffer, nidas::core::SampleScanner::_bufhead, nidas::core::SampleScanner::_buftail, nidas::core::SampleScanner::addNumBytesToStats(), nidas::core::SampleScanner::BUFSIZE, DLOG, nidas::core::DSMSensor::getDSMId(), nidas::core::Project::getInstance(), nidas::core::DSMSensor::getName(), nidas::core::getSample(), nidas::core::DSMSensor::getSensorId(), len, and nidas::core::DSMSensor::read().
Referenced by nidas::core::DSMSensor::readBuffer(), nidas::core::MessageStreamScanner::readBuffer(), nidas::core::SampleScanner::readBuffer(), nidas::core::MessageStreamScanner::readBuffer(), and nidas::core::DSMSensor::readBuffer().
|
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.
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().
|
virtualinherited |
References nidas::core::SampleScanner::_badTimeTags, nidas::core::SampleScanner::_currentIndex, nidas::core::SampleScanner::_dataRateObs, nidas::core::SampleScanner::_initialTimeSecs, nidas::core::SampleScanner::_maxSampleLength, nidas::core::SampleScanner::_minSampleLength, nidas::core::SampleScanner::_nbytes, nidas::core::SampleScanner::_nsamples, nidas::core::SampleScanner::_reportIndex, nidas::core::SampleScanner::_sampleRateObs, and nidas::core::getSample().
Referenced by nidas::core::SampleScanner::init(), and nidas::core::SampleScanner::SampleScanner().
|
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.
len | The 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.
eom | True 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. |
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().
References nidas::core::SampleScanner::_usecsPerByte, and nidas::core::getSample().
Referenced by nidas::dynld::ModbusRTU::open().
|
protectedinherited |
Referenced by nidas::core::DriverSampleScanner::nextSample(), nidas::core::DatagramSampleScanner::nextSample(), nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), nidas::core::SampleScanner::readBuffer(), nidas::core::DatagramSampleScanner::readBuffer(), and nidas::core::SampleScanner::~SampleScanner().
Referenced by nidas::core::SampleScanner::clearBuffer(), nidas::core::SampleScanner::getBytesInBuffer(), nidas::core::DriverSampleScanner::nextSample(), nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), nidas::core::SampleScanner::readBuffer(), and nidas::core::DatagramSampleScanner::readBuffer().
Referenced by nidas::core::SampleScanner::clearBuffer(), nidas::core::SampleScanner::getBytesInBuffer(), nidas::core::DriverSampleScanner::nextSample(), nidas::core::DatagramSampleScanner::nextSample(), nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), nidas::core::SampleScanner::readBuffer(), and nidas::core::DatagramSampleScanner::readBuffer().
|
privateinherited |
|
privateinherited |
|
privateinherited |
|
protectedinherited |
Referenced by nidas::core::DriverSampleScanner::nextSample().
|
privateinherited |
|
protectedinherited |
|
protectedinherited |
|
privateinherited |
|
privateinherited |
|
protectedinherited |
Referenced by nidas::core::DriverSampleScanner::nextSample(), nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), nidas::core::MessageStreamScanner::requestBiggerSample(), and nidas::core::SampleScanner::~SampleScanner().
|
protectedinherited |
Referenced by nidas::core::DriverSampleScanner::nextSample().
|
privateinherited |
Referenced by nidas::core::SampleScanner::calcStatistics(), nidas::core::SampleScanner::getMaxSampleLength(), nidas::core::SampleScanner::getMinSampleLength(), nidas::core::SampleScanner::getObservedDataRate(), nidas::core::SampleScanner::getObservedSamplingRate(), and nidas::core::SampleScanner::resetStatistics().
|
privateinherited |
Observed number of samples per second.
Referenced by nidas::core::SampleScanner::calcStatistics(), nidas::core::SampleScanner::getObservedSamplingRate(), and nidas::core::SampleScanner::resetStatistics().
|
protectedinherited |
messageSeparator in a C string.
Referenced by nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), nidas::core::MessageStreamScanner::setMessageParameters(), and nidas::core::SampleScanner::~SampleScanner().
|
protectedinherited |
|
protectedinherited |
Length of messageSeparator.
Referenced by nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), setMessageParameters(), and nidas::core::MessageStreamScanner::setMessageParameters().
|
privateinherited |
Buffer size for reading from sensor.
Referenced by nidas::core::SampleScanner::readBuffer(), and nidas::core::DatagramSampleScanner::readBuffer().