nidas v1.2.3
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes | List of all members
nidas::dynld::ModbusRTU::ModbusMessageStreamScanner Class Reference

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>

Inheritance diagram for nidas::dynld::ModbusRTU::ModbusMessageStreamScanner:
Inheritance graph
[legend]

Public Member Functions

 ModbusMessageStreamScanner ()
 
SamplenextSampleSepBOM (DSMSensor *sensor)
 Method to read input and break it into samples where the message separator occurs at the beginning of the message.
 
void setMessageParameters (unsigned int len, const std::string &val, bool eom)
 
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
 
unsigned int getMessageLength () const
 Returns 0.
 
void setNullTerminate (bool val)
 
bool getNullTerminate () const
 Should the SampleScanner append a null character, '\0', to the messages.
 
SamplenextSample (DSMSensor *sensor)
 Extract the next sample from the buffer.
 
size_t readBuffer (DSMSensor *sensor, bool &exhausted)
 
size_t readBuffer (DSMSensor *sensor, bool &exhausted, int msecTimeout)
 
void 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.
 
void warnBackwardsStepTimeTag (const DSMSensor *sensor, dsm_time_t badtt, unsigned int nbad)
 
virtual void init ()
 Initialize the scanner.
 
void setUsecsPerByte (int val)
 
int getUsecsPerByte () const
 
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 Member Functions

virtual SamplenextSampleSepEOM (DSMSensor *sensor)
 Method to read input and break it into samples where the message separator occurs at the end of the message.
 
SamplenextSampleByLength (DSMSensor *sensor)
 Method to read input and break it into samples strictly by record length.
 
SamplerequestBiggerSample (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
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ModbusMessageStreamScanner()

nidas::dynld::ModbusRTU::ModbusMessageStreamScanner::ModbusMessageStreamScanner ( )
inline

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 MessageStreamScanner::getBackslashedMessageSeparator ( ) const
virtualinherited

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::MessageStreamScanner::getMessageLength ( ) const
inlinevirtualinherited

◆ getMessageSeparator()

const std::string & nidas::core::MessageStreamScanner::getMessageSeparator ( ) const
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.

◆ getMessageSeparatorAtEOM()

bool nidas::core::MessageStreamScanner::getMessageSeparatorAtEOM ( ) const
inlinevirtualinherited

◆ getMinSampleLength()

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

◆ getNullTerminate()

bool nidas::core::MessageStreamScanner::getNullTerminate ( ) const
inlinevirtualinherited

◆ 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 * nidas::core::MessageStreamScanner::nextSample ( DSMSensor * sensor)
inlinevirtualinherited

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.

◆ nextSampleByLength()

Sample * MessageStreamScanner::nextSampleByLength ( DSMSensor * sensor)
protectedinherited

◆ nextSampleSepBOM()

Sample * nidas::dynld::ModbusRTU::ModbusMessageStreamScanner::nextSampleSepBOM ( DSMSensor * sensor)
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.

◆ nextSampleSepEOM()

Sample * MessageStreamScanner::nextSampleSepEOM ( DSMSensor * sensor)
protectedvirtualinherited

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

◆ readBuffer() [1/2]

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

◆ readBuffer() [2/2]

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

◆ requestBiggerSample()

Sample * MessageStreamScanner::requestBiggerSample ( unsigned int nc)
protectedinherited

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

◆ resetStatistics()

void SampleScanner::resetStatistics ( )
virtualinherited

◆ setMessageParameters()

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

◆ setNullTerminate()

void nidas::core::MessageStreamScanner::setNullTerminate ( bool val)
inlineinherited

◆ setUsecsPerByte()

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

◆ warnBackwardsStepTimeTag()

void MessageStreamScanner::warnBackwardsStepTimeTag ( const DSMSensor * sensor,
dsm_time_t badtt,
unsigned int nbad )
inherited

◆ warnNonIncrTimeTag()

void MessageStreamScanner::warnNonIncrTimeTag ( const DSMSensor * sensor,
dsm_time_t badtt,
dsm_time_t cortt,
unsigned int nbad )
inherited

Member Data Documentation

◆ _badTimeTags

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

◆ _bomtt

dsm_time_t nidas::core::MessageStreamScanner::_bomtt
protectedinherited

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

◆ _lastBufferTime

dsm_time_t nidas::core::MessageStreamScanner::_lastBufferTime
protectedinherited

◆ _lastSampleTime

dsm_time_t nidas::core::MessageStreamScanner::_lastSampleTime
protectedinherited

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

◆ _nbytesDiscarded

int nidas::dynld::ModbusRTU::ModbusMessageStreamScanner::_nbytesDiscarded
private

◆ _nextSampleFunc

Sample *(MessageStreamScanner::* nidas::core::MessageStreamScanner::_nextSampleFunc) (DSMSensor *)
protectedinherited

◆ _nonIncrTimeTag

unsigned int nidas::core::MessageStreamScanner::_nonIncrTimeTag
protectedinherited

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

◆ _nsamples

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

◆ _nsmallSamples

int nidas::core::MessageStreamScanner::_nsmallSamples
protectedinherited

Count of number of consecutive samples smaller than _sampleLengthAlloc.

Referenced by nidas::core::MessageStreamScanner::nextSampleSepBOM(), and nidas::core::MessageStreamScanner::nextSampleSepEOM().

◆ _nullTerminate

bool nidas::core::MessageStreamScanner::_nullTerminate
protectedinherited

◆ _osamp

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

◆ _outSampDataPtr

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

◆ _outSampLengthAlloc

unsigned int nidas::core::MessageStreamScanner::_outSampLengthAlloc
protectedinherited

◆ _outSampRead

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

◆ _outSampToRead

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

◆ _reportIndex

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

◆ _sampleLengthAlloc

unsigned int nidas::core::MessageStreamScanner::_sampleLengthAlloc
protectedinherited

◆ _sampleOverflows

int nidas::core::MessageStreamScanner::_sampleOverflows
protectedinherited

◆ _sampleRateObs

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

◆ _separator

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

◆ _separatorAtEOM

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

◆ _separatorCnt

int nidas::core::MessageStreamScanner::_separatorCnt
protectedinherited

◆ _separatorLen

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

◆ _stepBackTimeTag

unsigned int nidas::core::MessageStreamScanner::_stepBackTimeTag
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().

◆ _stepBackwards

bool nidas::core::MessageStreamScanner::_stepBackwards
protectedinherited

◆ _tfirstchar

dsm_time_t nidas::core::MessageStreamScanner::_tfirstchar
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().

◆ MAX_MESSAGE_STREAM_SAMPLE_SIZE

const unsigned int nidas::core::MessageStreamScanner::MAX_MESSAGE_STREAM_SAMPLE_SIZE
protectedinherited

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