nidas v1.2.3
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Private Attributes | List of all members
FileSim Class Reference

Read serial records from a file and send them at a given rate or after a prompt. More...

Inheritance diagram for FileSim:
Inheritance graph
[legend]

Public Member Functions

 FileSim (n_u::SerialPort *p, const string &path, enum sep_type septype, string separator, bool prompted, string prompt, float rate, int nmessages, bool once, bool verbose=false)
 
 FileSim (n_u::SerialPort *p, const string &path, float rate, bool once, bool verbose=false)
 
void open ()
 
void close ()
 
void rewind ()
 
void sendMessage ()
 Implement this to send a message from the simulated sensor.
 
void sendASCIIMessage ()
 
void sendBinaryMessage ()
 
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 ()
 

Protected Attributes

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

Static Protected Attributes

static Looper_looper = 0
 

Private Member Functions

 FileSim (const FileSim &)
 
FileSimoperator= (const FileSim &)
 

Private Attributes

string _path
 
std::ifstream _infile
 
std::istream * _in
 
std::string _msg
 
enum sep_type _septype
 
string _separator
 
bool _reopen
 
bool _onceThru
 
bool _verbose
 
bool _binary
 

Detailed Description

Read serial records from a file and send them at a given rate or after a prompt.

Constructor & Destructor Documentation

◆ FileSim() [1/3]

FileSim::FileSim ( n_u::SerialPort * p,
const string & path,
enum sep_type septype,
string separator,
bool prompted,
string prompt,
float rate,
int nmessages,
bool once,
bool verbose = false )
inline

References open().

◆ FileSim() [2/3]

FileSim::FileSim ( n_u::SerialPort * p,
const string & path,
float rate,
bool once,
bool verbose = false )
inline

References open().

◆ FileSim() [3/3]

FileSim::FileSim ( const FileSim & )
private

Member Function Documentation

◆ close()

void FileSim::close ( )
inline

References _in, and _infile.

Referenced by open(), rewind(), and sendASCIIMessage().

◆ getLooper()

Looper * SensorSimulator::getLooper ( )
protectedinherited

◆ interrupt()

void SensorSimulator::interrupt ( )
inlineinherited

◆ isInterrupted()

bool SensorSimulator::isInterrupted ( ) const
inlineinherited

◆ looperNotify()

void SensorSimulator::looperNotify ( )
overrideprotectedvirtualinherited

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 SensorSimulator::_interrupted, SensorSimulator::_looper, SensorSimulator::_nmessages, nidas::core::getSample(), SensorSimulator::interrupt(), and SensorSimulator::sendMessage().

◆ open()

void FileSim::open ( )
inline

References _in, _infile, _path, _reopen, _verbose, and close().

Referenced by FileSim(), FileSim(), and rewind().

◆ operator=()

FileSim & FileSim::operator= ( const FileSim & )
private

◆ port()

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

◆ readPrompts()

void SensorSimulator::readPrompts ( )
protectedinherited

◆ rewind()

void FileSim::rewind ( )
inline

References _infile, _path, _reopen, _verbose, close(), and open().

Referenced by sendASCIIMessage().

◆ run()

void SensorSimulator::run ( )
virtualinherited

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 SensorSimulator::_looper, SensorSimulator::_prompted, SensorSimulator::_rate, SensorSimulator::getLooper(), nidas::core::getSample(), MSECS_PER_SEC, and SensorSimulator::readPrompts().

◆ sendASCIIMessage()

void FileSim::sendASCIIMessage ( )

◆ sendBinaryMessage()

void FileSim::sendBinaryMessage ( )

◆ sendMessage()

void FileSim::sendMessage ( )
virtual

Implement this to send a message from the simulated sensor.

Exceptions
nidas::util::IOException

Implements SensorSimulator.

References _binary, sendASCIIMessage(), and sendBinaryMessage().

◆ writeMessage() [1/2]

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

overloaded function useful for writing binary data

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

◆ writeMessage() [2/2]

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

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

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

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

Member Data Documentation

◆ _binary

bool FileSim::_binary
private

Referenced by sendMessage().

◆ _in

std::istream* FileSim::_in
private

◆ _infile

std::ifstream FileSim::_infile
private

Referenced by close(), open(), and rewind().

◆ _interrupted

bool SensorSimulator::_interrupted
protectedinherited

◆ _looper

Looper * SensorSimulator::_looper = 0
staticprotectedinherited

◆ _msg

std::string FileSim::_msg
private

Referenced by sendASCIIMessage().

◆ _nmessages

int SensorSimulator::_nmessages
protectedinherited

◆ _onceThru

bool FileSim::_onceThru
private

Referenced by sendASCIIMessage().

◆ _path

string FileSim::_path
private

Referenced by open(), and rewind().

◆ _port

n_u::SerialPort* SensorSimulator::_port
protectedinherited

◆ _prompt

string SensorSimulator::_prompt
protectedinherited

◆ _prompted

bool SensorSimulator::_prompted
protectedinherited

Referenced by SensorSimulator::run().

◆ _rate

float SensorSimulator::_rate
protectedinherited

◆ _reopen

bool FileSim::_reopen
private

Referenced by open(), rewind(), and sendASCIIMessage().

◆ _separator

string FileSim::_separator
private

Referenced by sendASCIIMessage().

◆ _septype

enum sep_type FileSim::_septype
private

Referenced by sendASCIIMessage().

◆ _verbose

bool FileSim::_verbose
private

Referenced by open(), rewind(), and sendASCIIMessage().


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