nidas v1.2.3
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
SensorSimulator Class Referenceabstract

Base class for sensor simulators. More...

Inheritance diagram for SensorSimulator:
Inheritance graph
[legend]

Public Member Functions

 SensorSimulator (n_u::SerialPort *p, bool prompted, string prompt, float rate, int nmessages)
 
virtual void sendMessage ()=0
 Implement this to send a message from the simulated sensor.
 
virtual void writeMessage (const std::string &msg)
 Subclasses generate the message to send, then call writeMessage() to send it out.
 
virtual void writeMessage (const char *buf, std::streamsize l)
 overloaded function useful for writing binary data
 
virtual void run ()
 Default implementation of run will call the sendMessage() method either after receipt of a prompt or at the given rate if the sensor is not prompted.
 
void interrupt ()
 Stop the simulation.
 
bool isInterrupted () const
 
n_u::SerialPortport ()
 

Protected Member Functions

LoopergetLooper ()
 
void looperNotify () override
 Method called by Looper.
 
void readPrompts ()
 
 SensorSimulator (const SensorSimulator &)
 
SensorSimulatoroperator= (const SensorSimulator &)
 

Protected Attributes

n_u::SerialPort_port
 
bool _prompted
 
string _prompt
 
float _rate
 
int _nmessages
 
bool _interrupted
 

Static Protected Attributes

static Looper_looper = 0
 

Detailed Description

Base class for sensor simulators.

Constructor & Destructor Documentation

◆ SensorSimulator() [1/2]

SensorSimulator::SensorSimulator ( n_u::SerialPort * p,
bool prompted,
string prompt,
float rate,
int nmessages )
inline

◆ SensorSimulator() [2/2]

SensorSimulator::SensorSimulator ( const SensorSimulator & )
protected

Member Function Documentation

◆ getLooper()

Looper * SensorSimulator::getLooper ( )
protected

References _looper.

Referenced by run().

◆ interrupt()

void SensorSimulator::interrupt ( )
inline

◆ isInterrupted()

bool SensorSimulator::isInterrupted ( ) const
inline

References _interrupted.

Referenced by readPrompts().

◆ looperNotify()

void SensorSimulator::looperNotify ( )
overrideprotectedvirtual

Method called by Looper.

This method should not be a heavy user of resources, since the notification of other clients is delayed until this method finishes. If much work is to be done, this method should post a semaphore for another worker thread to proceed.

Implements nidas::core::LooperClient.

References _interrupted, _looper, _nmessages, nidas::core::getSample(), interrupt(), and sendMessage().

◆ operator=()

SensorSimulator & SensorSimulator::operator= ( const SensorSimulator & )
protected

◆ port()

n_u::SerialPort * SensorSimulator::port ( )
inline

References _port.

◆ readPrompts()

void SensorSimulator::readPrompts ( )
protected

◆ run()

void SensorSimulator::run ( )
virtual

Default implementation of run will call the sendMessage() method either after receipt of a prompt or at the given rate if the sensor is not prompted.

run() will return when isInterrupted() is true.

Reimplemented in Csat3Sim.

References _looper, _prompted, _rate, getLooper(), nidas::core::getSample(), MSECS_PER_SEC, and readPrompts().

◆ sendMessage()

virtual void SensorSimulator::sendMessage ( )
pure virtual

Implement this to send a message from the simulated sensor.

Exceptions
nidas::util::IOException

Implemented in FixedSim, FileSim, and Csat3Sim.

Referenced by looperNotify(), and readPrompts().

◆ writeMessage() [1/2]

virtual void SensorSimulator::writeMessage ( const char * buf,
std::streamsize l )
inlinevirtual

overloaded function useful for writing binary data

References _port, and nidas::util::SerialPort::write().

◆ writeMessage() [2/2]

virtual void SensorSimulator::writeMessage ( const std::string & msg)
inlinevirtual

Subclasses generate the message to send, then call writeMessage() to send it out.

References _port, and nidas::util::SerialPort::write().

Referenced by FileSim::sendASCIIMessage(), FileSim::sendBinaryMessage(), and FixedSim::sendMessage().

Member Data Documentation

◆ _interrupted

bool SensorSimulator::_interrupted
protected

◆ _looper

Looper * SensorSimulator::_looper = 0
staticprotected

Referenced by getLooper(), looperNotify(), and run().

◆ _nmessages

int SensorSimulator::_nmessages
protected

◆ _port

n_u::SerialPort* SensorSimulator::_port
protected

◆ _prompt

string SensorSimulator::_prompt
protected

Referenced by readPrompts().

◆ _prompted

bool SensorSimulator::_prompted
protected

Referenced by run().

◆ _rate

float SensorSimulator::_rate
protected

Referenced by run(), and Csat3Sim::run().


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