nidas
v1.2-1520
|
A scanner of sample data. More...
#include <SampleScanner.h>
Public Member Functions | |
SampleScanner (int bufsize=8192) | |
virtual | ~SampleScanner () |
virtual void | init () |
Initialize the scanner. More... | |
virtual void | setMessageParameters (unsigned int len, const std::string &val, bool eom)=0 throw (nidas::util::InvalidParameterException) |
Set the parameters associated with scanning of character messages. More... | |
virtual const std::string & | getMessageSeparator () const |
Returns an empty string. More... | |
virtual const std::string | getBackslashedMessageSeparator () const |
Returns an empty string. More... | |
virtual bool | getMessageSeparatorAtEOM () const |
virtual unsigned int | getMessageLength () const |
Returns 0. 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 () |
virtual Sample * | nextSample (DSMSensor *sensor)=0 |
Extract the next sample from the buffer. More... | |
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... | |
Private Member Functions | |
SampleScanner (const SampleScanner &) | |
No copy (could be added if needed). More... | |
SampleScanner & | operator= (const SampleScanner &) |
No assignment (could be added if needed). More... | |
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. More... | |
float | _dataRateObs |
int | _usecsPerByte |
A scanner of sample data.
Provides a readBuffer() method to read data from a DSMSensor into an internal buffer. Then defines a virtual nextSample() method to extract all available samples from that buffer.
Currently there are four implementations of SampleScanner, which differ in how they extract samples from the internal buffer:
DriverSampleScanner: A SampleScanner for reading samples that have been pre-formatted by a device driver - they already have a header consisting of a timetag, and a data length. This can be used, for example, to read samples from a driver supporting an A/D converter.
MessageSampleScanner: Subclass of DriverSampleScanner, supporting the set/get of the message separation parameters. This scanner does not itself break the input into samples, since this has been done by the driver module.
MessageStreamScanner: Provides sets and gets of message separation parameters used in parsing input messages from a sensor. Parses the stream input, breaking it into samples, by recognizing separators in the message stream.
DatagramSampleScanner: Creates samples from input datagrams, a simple task since the OS maintains the separation of the input datagrams. Each datagram becomes a separate sample, with a timetag taken from the system clock at the time the scanner has determined that there is data available.
SampleScanner::SampleScanner | ( | int | bufsize = 8192 | ) |
References resetStatistics().
|
virtual |
References _buffer, _osamp, _separator, and nidas::core::Sample::freeReference().
|
private |
No copy (could be added if needed).
|
inline |
References _nbytes.
|
inline |
References _currentIndex, _maxSampleLength, _minSampleLength, and _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().
|
virtual |
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 _currentIndex, _dataRateObs, _maxSampleLength, _minSampleLength, _nbytes, _nsamples, _reportIndex, _sampleRateObs, and USECS_PER_SEC.
Referenced by nidas::core::DSMSensor::calcStatistics().
|
virtual |
References _bufhead, and _buftail.
Referenced by nidas::core::DSMSensor::clearBuffer().
|
inlinevirtual |
Returns an empty string.
Reimplemented in nidas::core::MessageStreamScanner, and nidas::core::MessageSampleScanner.
References _emptyString.
|
inline |
References _badTimeTags.
Referenced by nidas::core::DSMSensor::getBadTimeTagCount().
|
inline |
|
inline |
References _maxSampleLength, and _reportIndex.
Referenced by nidas::core::DSMSensor::getMaxSampleLength().
|
inlinevirtual |
Returns 0.
Reimplemented in nidas::core::MessageStreamScanner, and nidas::core::MessageSampleScanner.
|
inlinevirtual |
Returns an empty string.
Reimplemented in nidas::core::MessageStreamScanner, and nidas::core::MessageSampleScanner.
References _emptyString.
|
inlinevirtual |
Reimplemented in nidas::core::MessageStreamScanner, and nidas::core::MessageSampleScanner.
|
inline |
References _maxSampleLength, _minSampleLength, and _reportIndex.
Referenced by nidas::core::DSMSensor::getMinSampleLength().
|
inlinevirtual |
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 |
References _currentIndex, _dataRateObs, _initialTimeSecs, _nbytes, and _reportIndex.
Referenced by nidas::core::DSMSensor::getObservedDataRate().
float SampleScanner::getObservedSamplingRate | ( | ) | const |
References _currentIndex, _initialTimeSecs, _nsamples, _reportIndex, and _sampleRateObs.
Referenced by nidas::core::DSMSensor::getObservedSamplingRate().
|
inline |
|
inline |
References _badTimeTags.
Referenced by nidas::core::DriverSampleScanner::nextSample().
|
virtual |
Initialize the scanner.
Must be called by a user of SampleScanner prior to calling readSamples().
References resetStatistics().
Extract the next sample from the buffer.
Returns NULL if there are no more samples in the buffer.
Implemented in nidas::core::DatagramSampleScanner, nidas::core::MessageStreamScanner, and nidas::core::DriverSampleScanner.
Referenced by nidas::core::DSMSensor::nextSample().
|
private |
No assignment (could be added if needed).
|
virtual |
Read from the sensor into the internal buffer of this SampleScanner.
Reimplemented in nidas::core::DatagramSampleScanner, and nidas::core::MessageStreamScanner.
References DLOG, nidas::core::Project::getInstance(), and len.
Referenced by readBuffer(), nidas::core::MessageStreamScanner::readBuffer(), and nidas::core::DSMSensor::readBuffer().
|
virtual |
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 readBuffer().
|
virtual |
References _badTimeTags, _currentIndex, _dataRateObs, _initialTimeSecs, _maxSampleLength, _minSampleLength, _nbytes, _nsamples, _reportIndex, and _sampleRateObs.
Referenced by init(), and SampleScanner().
|
pure virtual |
Set the parameters associated with scanning of character messages.
Implemented in nidas::core::DatagramSampleScanner, nidas::core::MessageStreamScanner, nidas::core::MessageSampleScanner, and nidas::core::DriverSampleScanner.
Referenced by nidas::core::CharacterSensor::buildSampleScanner().
|
inline |
References _usecsPerByte.
Referenced by nidas::core::SerialSensor::buildSampleScanner(), and nidas::dynld::GPS_NMEA_Serial::buildSampleScanner().
|
private |
Referenced by getBadTimeTagCount(), incrementBadTimeTags(), and resetStatistics().
|
protected |
Referenced by nidas::core::DriverSampleScanner::nextSample(), nidas::core::DatagramSampleScanner::nextSample(), nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), and ~SampleScanner().
|
protected |
|
protected |
Referenced by clearBuffer(), getBytesInBuffer(), nidas::core::DriverSampleScanner::nextSample(), nidas::core::DatagramSampleScanner::nextSample(), nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), and nidas::core::MessageStreamScanner::nextSampleSepEOM().
|
private |
Referenced by addSampleToStats(), calcStatistics(), getObservedDataRate(), getObservedSamplingRate(), and resetStatistics().
|
private |
Referenced by calcStatistics(), getObservedDataRate(), and resetStatistics().
|
private |
Referenced by getBackslashedMessageSeparator(), and getMessageSeparator().
|
protected |
Referenced by nidas::core::DriverSampleScanner::nextSample().
|
private |
Referenced by getObservedDataRate(), getObservedSamplingRate(), and resetStatistics().
|
private |
Referenced by addSampleToStats(), calcStatistics(), getMaxSampleLength(), getMinSampleLength(), and resetStatistics().
|
protected |
|
protected |
|
private |
Referenced by addSampleToStats(), calcStatistics(), getMinSampleLength(), and resetStatistics().
|
private |
Referenced by addNumBytesToStats(), calcStatistics(), getObservedDataRate(), and resetStatistics().
|
private |
Referenced by addSampleToStats(), calcStatistics(), getObservedSamplingRate(), and resetStatistics().
|
protected |
Referenced by nidas::core::DriverSampleScanner::nextSample(), nidas::core::MessageStreamScanner::nextSampleByLength(), nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), nidas::core::MessageStreamScanner::requestBiggerSample(), and ~SampleScanner().
|
protected |
|
protected |
|
protected |
Referenced by nidas::core::DriverSampleScanner::nextSample().
|
private |
|
private |
Observed number of samples per second.
Referenced by calcStatistics(), getObservedSamplingRate(), and resetStatistics().
|
protected |
messageSeparator in a C string.
Referenced by nidas::core::MessageStreamScanner::nextSampleSepBOM(), nidas::core::MessageStreamScanner::nextSampleSepEOM(), and ~SampleScanner().
|
protected |
|
protected |
Length of messageSeparator.
Referenced by nidas::core::MessageStreamScanner::nextSampleSepBOM(), and nidas::core::MessageStreamScanner::nextSampleSepEOM().
|
private |
Referenced by getUsecsPerByte(), and setUsecsPerByte().
|
protected |
Buffer size for reading from sensor.