nidas v1.2.3
|
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>
Protected Member Functions | |
virtual Sample * | nextSampleSepBOM (DSMSensor *sensor) |
Method to read input and break it into samples where the message separator occurs at the beginning of the message. | |
virtual Sample * | nextSampleSepEOM (DSMSensor *sensor) |
Method to read input and break it into samples where the message separator occurs at the end of the message. | |
Sample * | nextSampleByLength (DSMSensor *sensor) |
Method to read input and break it into samples strictly by record length. | |
Sample * | requestBiggerSample (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 |
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.
MessageStreamScanner::MessageStreamScanner | ( | int | bufsize = 4096 | ) |
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(), nextSampleByLength(), nextSampleSepBOM(), nextSampleSepEOM(), and 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.
Referenced by nextSampleByLength(), nextSampleSepBOM(), nextSampleSepEOM(), and setMessageParameters().
|
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 |
Reimplemented from nidas::core::SampleScanner.
References nidas::core::SampleScanner::_separatorAtEOM.
Referenced by setMessageParameters().
|
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().
|
inherited |
|
inherited |
|
inlineinherited |
References nidas::core::SampleScanner::_usecsPerByte.
Referenced by nextSampleByLength(), nextSampleSepBOM(), nextSampleSepEOM(), readBuffer(), and 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 _nextSampleFunc.
Method to read input and break it into samples strictly by record length.
References nidas::core::SampleScanner::_buffer, nidas::core::SampleScanner::_bufhead, nidas::core::SampleScanner::_buftail, _lastSampleTime, _nonIncrTimeTag, nidas::core::SampleScanner::_osamp, nidas::core::SampleScanner::_outSampDataPtr, _outSampLengthAlloc, nidas::core::SampleScanner::_outSampRead, _sampleLengthAlloc, _separatorCnt, _stepBackTimeTag, _stepBackwards, _tfirstchar, nidas::core::SampleScanner::addSampleToStats(), nidas::core::Sample::getAllocByteLength(), nidas::core::DSMSensor::getId(), getMessageLength(), nidas::core::getSample(), nidas::core::SampleScanner::getUsecsPerByte(), nidas::core::Sample::getVoidDataPtr(), requestBiggerSample(), nidas::core::Sample::setId(), nidas::core::Sample::setTimeTag(), warnBackwardsStepTimeTag(), and warnNonIncrTimeTag().
Referenced by setMessageParameters().
Method to read input and break it into samples where the message separator occurs at the beginning of the message.
Reimplemented in nidas::dynld::ModbusRTU::ModbusMessageStreamScanner.
References _bomtt, nidas::core::SampleScanner::_buffer, nidas::core::SampleScanner::_bufhead, nidas::core::SampleScanner::_buftail, _lastSampleTime, _nonIncrTimeTag, _nsmallSamples, nidas::core::SampleScanner::_osamp, nidas::core::SampleScanner::_outSampDataPtr, _outSampLengthAlloc, nidas::core::SampleScanner::_outSampRead, _sampleLengthAlloc, nidas::core::SampleScanner::_separator, _separatorCnt, nidas::core::SampleScanner::_separatorLen, _stepBackTimeTag, _stepBackwards, _tfirstchar, nidas::core::SampleScanner::addSampleToStats(), nidas::core::Sample::getAllocByteLength(), nidas::core::DSMSensor::getId(), getMessageLength(), getNullTerminate(), nidas::core::getSample(), nidas::core::SampleScanner::getUsecsPerByte(), nidas::core::Sample::getVoidDataPtr(), MAX_MESSAGE_STREAM_SAMPLE_SIZE, nextSampleSepBOM(), requestBiggerSample(), nidas::core::Sample::setDataLength(), nidas::core::Sample::setId(), nidas::core::Sample::setTimeTag(), warnBackwardsStepTimeTag(), and warnNonIncrTimeTag().
Referenced by nextSampleSepBOM(), and setMessageParameters().
Method to read input and break it into samples where the message separator occurs at the end of the message.
References nidas::core::SampleScanner::_buffer, nidas::core::SampleScanner::_bufhead, nidas::core::SampleScanner::_buftail, _lastSampleTime, _nonIncrTimeTag, _nsmallSamples, nidas::core::SampleScanner::_osamp, nidas::core::SampleScanner::_outSampDataPtr, _outSampLengthAlloc, nidas::core::SampleScanner::_outSampRead, _sampleLengthAlloc, nidas::core::SampleScanner::_separator, _separatorCnt, nidas::core::SampleScanner::_separatorLen, _stepBackTimeTag, _stepBackwards, _tfirstchar, nidas::core::SampleScanner::addSampleToStats(), nidas::core::Sample::getAllocByteLength(), nidas::core::DSMSensor::getId(), getMessageLength(), getNullTerminate(), nidas::core::getSample(), nidas::core::SampleScanner::getUsecsPerByte(), nidas::core::Sample::getVoidDataPtr(), MAX_MESSAGE_STREAM_SAMPLE_SIZE, requestBiggerSample(), nidas::core::Sample::setDataLength(), nidas::core::Sample::setId(), nidas::core::Sample::setTimeTag(), warnBackwardsStepTimeTag(), and warnNonIncrTimeTag().
Referenced by setMessageParameters().
nidas::util::IOException |
Reimplemented from nidas::core::SampleScanner.
References _lastBufferTime, _stepBackwards, _tfirstchar, nidas::core::getSample(), nidas::util::getSystemTime(), nidas::core::SampleScanner::getUsecsPerByte(), and nidas::core::SampleScanner::readBuffer().
|
virtual |
nidas::util::IOException |
Reimplemented from nidas::core::SampleScanner.
References _lastBufferTime, _stepBackwards, _tfirstchar, nidas::core::getSample(), nidas::util::getSystemTime(), nidas::core::SampleScanner::getUsecsPerByte(), and nidas::core::SampleScanner::readBuffer().
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().
|
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 |
nidas::util::InvalidParameterException |
Implements nidas::core::SampleScanner.
References nidas::core::SampleScanner::_messageLength, nidas::core::SampleScanner::_messageSeparator, _nextSampleFunc, _sampleLengthAlloc, nidas::core::SampleScanner::_separator, nidas::core::SampleScanner::_separatorAtEOM, nidas::core::SampleScanner::_separatorLen, getMessageLength(), getMessageSeparatorAtEOM(), getNullTerminate(), nidas::core::getSample(), len, MAX_MESSAGE_STREAM_SAMPLE_SIZE, nextSampleByLength(), nextSampleSepBOM(), nextSampleSepEOM(), nidas::util::replaceBackslashSequences(), and setNullTerminate().
References _nullTerminate, and nidas::core::getSample().
Referenced by setMessageParameters().
References nidas::core::SampleScanner::_usecsPerByte, and nidas::core::getSample().
Referenced by nidas::dynld::ModbusRTU::open().
void MessageStreamScanner::warnBackwardsStepTimeTag | ( | const DSMSensor * | sensor, |
dsm_time_t | badtt, | ||
unsigned int | nbad ) |
References nidas::util::UTime::format(), nidas::core::DSMSensor::getDSMId(), nidas::core::DSMSensor::getName(), nidas::core::DSMSensor::getSensorId(), and WLOG.
Referenced by nextSampleByLength(), nextSampleSepBOM(), and nextSampleSepEOM().
void MessageStreamScanner::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.
References nidas::util::UTime::format(), nidas::core::DSMSensor::getDSMId(), nidas::core::DSMSensor::getName(), nidas::core::DSMSensor::getSensorId(), USECS_PER_SEC, and WLOG.
Referenced by nextSampleByLength(), nextSampleSepBOM(), and nextSampleSepEOM().
|
protected |
Referenced by nextSampleSepBOM().
|
protectedinherited |
Referenced by nidas::core::DriverSampleScanner::nextSample(), nidas::core::DatagramSampleScanner::nextSample(), nextSampleByLength(), nextSampleSepBOM(), 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(), nextSampleByLength(), nextSampleSepBOM(), 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(), nextSampleByLength(), nextSampleSepBOM(), nextSampleSepEOM(), nidas::core::SampleScanner::readBuffer(), and nidas::core::DatagramSampleScanner::readBuffer().
|
privateinherited |
|
privateinherited |
|
privateinherited |
|
protectedinherited |
Referenced by nidas::core::DriverSampleScanner::nextSample().
|
privateinherited |
|
protected |
Referenced by readBuffer(), and readBuffer().
|
protected |
Referenced by nextSampleByLength(), nextSampleSepBOM(), and nextSampleSepEOM().
|
protectedinherited |
|
protectedinherited |
|
privateinherited |
|
protected |
Referenced by nextSample(), and setMessageParameters().
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().
|
privateinherited |
|
protected |
Count of number of consecutive samples smaller than _sampleLengthAlloc.
Referenced by nextSampleSepBOM(), and nextSampleSepEOM().
|
protected |
Referenced by getNullTerminate(), and setNullTerminate().
|
protectedinherited |
|
protectedinherited |
Number of bytes allocated in data portion of current output sample.
Referenced by nextSampleByLength(), nextSampleSepBOM(), nextSampleSepEOM(), and requestBiggerSample().
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().
Size of samples to allocate.
Referenced by nextSampleByLength(), nextSampleSepBOM(), nextSampleSepEOM(), and setMessageParameters().
|
protected |
Referenced by requestBiggerSample().
|
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 nextSampleSepBOM(), nextSampleSepEOM(), setMessageParameters(), and nidas::core::SampleScanner::~SampleScanner().
|
protectedinherited |
|
protected |
Referenced by nextSampleByLength(), nextSampleSepBOM(), and nextSampleSepEOM().
|
protectedinherited |
Length of messageSeparator.
Referenced by nextSampleSepBOM(), nextSampleSepEOM(), nidas::core::MessageSampleScanner::setMessageParameters(), and setMessageParameters().
Number of time tags that were not monotonically increasing, due to backward step changes.
Referenced by nextSampleByLength(), nextSampleSepBOM(), and nextSampleSepEOM().
|
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().
|
protected |
Referenced by nextSampleByLength(), nextSampleSepBOM(), nextSampleSepEOM(), readBuffer(), and readBuffer().
|
privateinherited |
Buffer size for reading from sensor.
Referenced by nidas::core::SampleScanner::readBuffer(), and nidas::core::DatagramSampleScanner::readBuffer().
Referenced by nextSampleSepBOM(), nextSampleSepEOM(), requestBiggerSample(), and setMessageParameters().