nidas v1.2.3
|
A subclass of MessageStreamScanner, with a modified nextSampleSepBOM() method that adjusts the sample time tag by the tranmission time of the number of bytes that were discarded between the libmodbus read and the data sent over the pipe. More...
#include <ModbusRTU.h>
Protected Member Functions | |
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 | |
int | _nbytesDiscarded |
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 subclass of MessageStreamScanner, with a modified nextSampleSepBOM() method that adjusts the sample time tag by the tranmission time of the number of bytes that were discarded between the libmodbus read and the data sent over the pipe.
From an email from Josh Carnes: A ModbusRTU response includes 1-byte address 1- byte function 1-byte Byte Count (X) X-byte data 2-byte CRC So, the response transmission length is 5-bytes longer than the data. In this application, that's 7 Bytes total.
The samples on the pipe after the modbus read consist of a 2-byte length and then the 2 byte sample word. So we need to adjust the sample time earlier by the transmission time of 3 bytes.
|
inline |
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().
|
virtualinherited |
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 nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), and nidas::core::MessageStreamScanner::setMessageParameters().
|
inlinevirtualinherited |
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.
|
inlinevirtualinherited |
Reimplemented from nidas::core::SampleScanner.
References nidas::core::SampleScanner::_separatorAtEOM.
Referenced by nidas::core::MessageStreamScanner::setMessageParameters().
|
inlinevirtualinherited |
Should the SampleScanner append a null character, '\0', to the messages.
Reimplemented from nidas::core::SampleScanner.
References nidas::core::MessageStreamScanner::_nullTerminate.
Referenced by nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), nidas::core::MessageStreamScanner::requestBiggerSample(), and nidas::core::MessageStreamScanner::setMessageParameters().
|
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::MessageStreamScanner::_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, nidas::core::MessageStreamScanner::_lastSampleTime, nidas::core::MessageStreamScanner::_nonIncrTimeTag, nidas::core::SampleScanner::_osamp, nidas::core::SampleScanner::_outSampDataPtr, nidas::core::MessageStreamScanner::_outSampLengthAlloc, nidas::core::SampleScanner::_outSampRead, nidas::core::MessageStreamScanner::_sampleLengthAlloc, nidas::core::MessageStreamScanner::_separatorCnt, nidas::core::MessageStreamScanner::_stepBackTimeTag, nidas::core::MessageStreamScanner::_stepBackwards, nidas::core::MessageStreamScanner::_tfirstchar, nidas::core::SampleScanner::addSampleToStats(), nidas::core::Sample::getAllocByteLength(), nidas::core::DSMSensor::getId(), nidas::core::MessageStreamScanner::getMessageLength(), nidas::core::getSample(), nidas::core::SampleScanner::getUsecsPerByte(), nidas::core::Sample::getVoidDataPtr(), nidas::core::MessageStreamScanner::requestBiggerSample(), nidas::core::Sample::setId(), nidas::core::Sample::setTimeTag(), nidas::core::MessageStreamScanner::warnBackwardsStepTimeTag(), and nidas::core::MessageStreamScanner::warnNonIncrTimeTag().
Referenced by nidas::core::MessageStreamScanner::setMessageParameters().
|
virtual |
Method to read input and break it into samples where the message separator occurs at the beginning of the message.
Reimplemented from nidas::core::MessageStreamScanner.
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, nidas::core::MessageStreamScanner::_lastSampleTime, nidas::core::MessageStreamScanner::_nonIncrTimeTag, nidas::core::MessageStreamScanner::_nsmallSamples, nidas::core::SampleScanner::_osamp, nidas::core::SampleScanner::_outSampDataPtr, nidas::core::MessageStreamScanner::_outSampLengthAlloc, nidas::core::SampleScanner::_outSampRead, nidas::core::MessageStreamScanner::_sampleLengthAlloc, nidas::core::SampleScanner::_separator, nidas::core::MessageStreamScanner::_separatorCnt, nidas::core::SampleScanner::_separatorLen, nidas::core::MessageStreamScanner::_stepBackTimeTag, nidas::core::MessageStreamScanner::_stepBackwards, nidas::core::MessageStreamScanner::_tfirstchar, nidas::core::SampleScanner::addSampleToStats(), nidas::core::Sample::getAllocByteLength(), nidas::core::DSMSensor::getId(), nidas::core::MessageStreamScanner::getMessageLength(), nidas::core::MessageStreamScanner::getNullTerminate(), nidas::core::getSample(), nidas::core::SampleScanner::getUsecsPerByte(), nidas::core::Sample::getVoidDataPtr(), nidas::core::MessageStreamScanner::MAX_MESSAGE_STREAM_SAMPLE_SIZE, nidas::core::MessageStreamScanner::requestBiggerSample(), nidas::core::Sample::setDataLength(), nidas::core::Sample::setId(), nidas::core::Sample::setTimeTag(), nidas::core::MessageStreamScanner::warnBackwardsStepTimeTag(), and nidas::core::MessageStreamScanner::warnNonIncrTimeTag().
Referenced by nidas::core::MessageStreamScanner::setMessageParameters().
nidas::util::IOException |
Reimplemented from nidas::core::SampleScanner.
References nidas::core::MessageStreamScanner::_lastBufferTime, nidas::core::MessageStreamScanner::_stepBackwards, nidas::core::MessageStreamScanner::_tfirstchar, nidas::core::getSample(), nidas::util::getSystemTime(), nidas::core::SampleScanner::getUsecsPerByte(), and nidas::core::SampleScanner::readBuffer().
|
virtualinherited |
nidas::util::IOException |
Reimplemented from nidas::core::SampleScanner.
References nidas::core::MessageStreamScanner::_lastBufferTime, nidas::core::MessageStreamScanner::_stepBackwards, nidas::core::MessageStreamScanner::_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, nidas::core::MessageStreamScanner::_outSampLengthAlloc, nidas::core::SampleScanner::_outSampRead, nidas::core::MessageStreamScanner::_sampleOverflows, nidas::core::SampleScanner::addSampleToStats(), nidas::core::Sample::freeReference(), nidas::core::Sample::getAllocByteLength(), nidas::core::Sample::getId(), nidas::core::MessageStreamScanner::getNullTerminate(), nidas::core::getSample(), nidas::core::Sample::getTimeTag(), nidas::core::Sample::getVoidDataPtr(), nidas::core::MessageStreamScanner::MAX_MESSAGE_STREAM_SAMPLE_SIZE, and nidas::core::Sample::setDataLength().
Referenced by nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), and nidas::core::MessageStreamScanner::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().
|
virtualinherited |
nidas::util::InvalidParameterException |
Implements nidas::core::SampleScanner.
References nidas::core::SampleScanner::_messageLength, nidas::core::SampleScanner::_messageSeparator, nidas::core::MessageStreamScanner::_nextSampleFunc, nidas::core::MessageStreamScanner::_sampleLengthAlloc, nidas::core::SampleScanner::_separator, nidas::core::SampleScanner::_separatorAtEOM, nidas::core::SampleScanner::_separatorLen, nidas::core::MessageStreamScanner::getMessageLength(), nidas::core::MessageStreamScanner::getMessageSeparatorAtEOM(), nidas::core::MessageStreamScanner::getNullTerminate(), nidas::core::getSample(), len, nidas::core::MessageStreamScanner::MAX_MESSAGE_STREAM_SAMPLE_SIZE, nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), nidas::util::replaceBackslashSequences(), and nidas::core::MessageStreamScanner::setNullTerminate().
References nidas::core::MessageStreamScanner::_nullTerminate, and nidas::core::getSample().
Referenced by nidas::core::MessageStreamScanner::setMessageParameters().
References nidas::core::SampleScanner::_usecsPerByte, and nidas::core::getSample().
Referenced by nidas::dynld::ModbusRTU::open().
|
inherited |
References nidas::util::UTime::format(), nidas::core::DSMSensor::getDSMId(), nidas::core::DSMSensor::getName(), nidas::core::DSMSensor::getSensorId(), and WLOG.
Referenced by nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), and nidas::core::MessageStreamScanner::nextSampleSepEOM().
|
inherited |
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 nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), and nidas::core::MessageStreamScanner::nextSampleSepEOM().
|
protectedinherited |
Referenced by nidas::core::MessageStreamScanner::nextSampleSepBOM().
|
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 |
|
protectedinherited |
|
protectedinherited |
Referenced by nidas::core::MessageSampleScanner::getBackslashedMessageSeparator(), nidas::core::MessageStreamScanner::getBackslashedMessageSeparator(), nidas::core::MessageSampleScanner::getMessageSeparator(), nidas::core::MessageStreamScanner::getMessageSeparator(), nidas::core::MessageSampleScanner::setMessageParameters(), and nidas::core::MessageStreamScanner::setMessageParameters().
|
privateinherited |
|
private |
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 nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), and nidas::core::MessageStreamScanner::nextSampleSepEOM().
|
privateinherited |
|
protectedinherited |
Count of number of consecutive samples smaller than _sampleLengthAlloc.
Referenced by nidas::core::MessageStreamScanner::nextSampleSepBOM(), and nidas::core::MessageStreamScanner::nextSampleSepEOM().
|
protectedinherited |
|
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 |
Number of bytes allocated in data portion of current output sample.
Referenced by nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), and nidas::core::MessageStreamScanner::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().
|
protectedinherited |
Referenced by nidas::core::MessageStreamScanner::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 nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), nidas::core::MessageStreamScanner::setMessageParameters(), and nidas::core::SampleScanner::~SampleScanner().
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
Number of time tags that were not monotonically increasing, due to backward step changes.
Referenced by nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), and nidas::core::MessageStreamScanner::nextSampleSepEOM().
|
protectedinherited |
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 nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), nidas::core::MessageStreamScanner::readBuffer(), and nidas::core::MessageStreamScanner::readBuffer().
|
protectedinherited |
|
privateinherited |
Buffer size for reading from sensor.
Referenced by nidas::core::SampleScanner::readBuffer(), and nidas::core::DatagramSampleScanner::readBuffer().