| |
libFAUDES
Sections
Index
|
faudes::vDevice Class Reference |
Public Types | |
enum | DeviceState { Down, StartUp, Up, ShutDown } |
Enum for device stages. More... | |
Public Member Functions | |
vDevice (void) | |
Default constructor. | |
virtual | ~vDevice (void) |
Explicit destructor. | |
void | Name (const std::string &rName) |
Set the device name. | |
const std::string & | Name (void) const |
Get device name. | |
void | Tolerance (tpTime::Type maxgap) |
Set tolerance for time synchonisation. | |
int | Tolerance (void) |
Get tolerance. | |
virtual void | TimeScale (unsigned int scale) |
Set timescale. | |
virtual int | TimeScale (void) |
Get timescale. | |
virtual void | Clear (void) |
Clear all configuration. | |
virtual void | Configure (Idx event, const AttributeDeviceEvent &attr) |
Insert/edit sensor or actuator configuration. | |
virtual void | Configure (const EventSet &rPhysicalEvents) |
Configure by alphabet. | |
virtual void | Compile (void) |
Compile inner data-structures. | |
virtual const EventSet & | Actuators (void) const |
Get actuators as plain set. | |
virtual const EventSet & | Sensors (void) const |
Get sensors as plain set. | |
virtual void | Reset (void) |
Reset device. | |
virtual void | Start (void) |
Activate the device. | |
virtual void | Stop (void) |
Deactivate the device. | |
virtual DeviceState | Status (void) |
Get status. | |
virtual std::string | StatusString (void) |
Get status as infromal string. | |
virtual void | WriteActuator (Idx actuator)=0 |
Run actuator command. | |
virtual Idx | ReadSensor (void) |
Read sensed sensor events. | |
virtual Idx | PeekSensor (void) |
Peek for sensed events. | |
virtual bool | SensorReady (void) |
Report whether a sensor-event is ready. | |
virtual bool | WaitSensors (tpTime::Type duration) |
Wait for sensor trigger. | |
virtual bool | WaitSensorsMs (long int duration) |
Wait for sensor trigger. | |
virtual tpTime::Type | CurrentTime (void) |
Report physical time in ftu. | |
virtual long int | CurrentTimeMs (void) |
Report physical time in ms. | |
virtual void | CurrentTime (tpTime::Type now) |
Set physical time in ftu. | |
virtual void | CurrentTimeMs (long int nowms) |
Set physical time in ms. | |
virtual timespec | FtuToTimeSpec (tpTime::Type duration) |
Convert faudes time unit duration to a pthread time spec. | |
void | UseCondition (pthread_mutex_t *wmutex, pthread_cond_t *wcond) |
Tell the device which condition to use for waiting. | |
void | UseBuffer (pthread_mutex_t *bmutex, std::deque< Idx > *bbuffer) |
Tell the device which buffer to use for sensors. | |
virtual std::string | EStr (Idx ev) |
Convenience method. | |
SampledDensityFunction | Performance (void) |
Get performance (need compiletime option). | |
void | WritePerformance (void) |
Convenience method. | |
Static Public Member Functions | |
static vDevice * | FromTokenReader (TokenReader &rTr) |
Construct on heap from token reader. | |
static vDevice * | FromFile (const std::string &rFileName) |
Construct on heap from file. | |
static timeval | DiffTime (timeval end, timeval start) |
Compute time difference. | |
static timeval | SumTime (timeval start, timeval duration) |
Compute time sum. | |
static timespec | MsToTimeSpec (long int duration) |
Convert msec duration to pthread timespec. | |
static void | StopAll (void) |
Stop all devices. | |
Protected Member Functions | |
virtual void | DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const |
Token output, see Type::Write for public wrappers. | |
virtual void | DoWritePreface (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const |
Writes non-event-configuration data from TokenWriter. | |
virtual void | DoWriteConfiguration (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const |
Writes event-configuration to TokenWriter. | |
virtual void | DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0) |
Token input, see Type::DRead for public wrappers. | |
virtual void | DoReadPreface (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0) |
Reads non-event-configuration data from TokenReader. | |
virtual void | DoReadConfiguration (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0) |
Reads event-configuration data from TokenReader. | |
virtual long int | FtuToMs (tpTime::Type faudes_time) |
convert duration from fauDES-time units to ms | |
virtual tpTime::Type | MsToFtu (long int real_time) |
convert duration in ms to faudes-time units | |
Protected Attributes | |
std::string | mDefaultLabel |
Default label for token io. | |
std::string | mName |
Name. | |
EventSet * | mpConfiguration |
Overall event configuration (uses cast for type). | |
EventSet | mSensors |
All sensors. | |
EventSet | mActuators |
All actuators. | |
DeviceState | mState |
Status: running, starting etc. | |
pthread_mutex_t | mWaitMutex |
Default Wait Condition Mutex. | |
pthread_cond_t | mWaitCondition |
Default Wait Condition. | |
pthread_mutex_t * | pWaitMutex |
Actual Wait Condition Mutex. | |
pthread_cond_t * | pWaitCondition |
Actual Wait Condition. | |
timeval | mTimeZero |
physical timepoint zero | |
int | mTimeScale |
FauDES-time: scaling factor in ms/ftu. | |
tpTime::Type | mMaxSyncGap |
Toleance for time sync. | |
std::deque< Idx > | mSensorBuffer |
Default Fifo buffer for sensor readings. | |
std::deque< Idx > * | pSensorBuffer |
Actual Fifo buffer for sensor readings. | |
pthread_mutex_t | mBufferMutex |
Default mutex for sensor buffer (mutexted). | |
pthread_mutex_t * | pBufferMutex |
Actual mutex for sensor buffer (mutexted). | |
timeval * | mpPerformanceWaitEnter |
Structures to store time-samples in. | |
timeval * | mpPerformanceWaitExit |
int | mPerformanceIterator |
Global iterator. | |
Static Private Attributes | |
static std::set< vDevice * > | msAllDevices |
Friends | |
class | xDevice |
faudes::vDevice::vDevice | ( | void | ) |
faudes::vDevice::~vDevice | ( | void | ) | [virtual] |
vDevice * faudes::vDevice::FromTokenReader | ( | TokenReader & | rTr | ) | [static] |
Construct on heap from token reader.
This constructor examines the token strean, determines the coressponding class and constructs the device on the heap. Todo: the implementation of this function is a hack, there must be proper solution to this issue.
rTr | TokenReader to read from |
Exception |
|
Reimplemented in faudes::xDevice.
Definition at line 203 of file iop_vdevice.cpp.
vDevice * faudes::vDevice::FromFile | ( | const std::string & | rFileName | ) | [static] |
Construct on heap from file.
This constructor examines the file, determines the coressponding class and constructs the device on the heap.
rFileName | Filename |
Exception |
|
Reimplemented in faudes::xDevice.
Definition at line 258 of file iop_vdevice.cpp.
void faudes::vDevice::Name | ( | const std::string & | rName | ) | [virtual] |
Set the device name.
rName | Generator name |
Reimplemented from faudes::Type.
Definition at line 345 of file iop_vdevice.cpp.
const std::string & faudes::vDevice::Name | ( | void | ) | const [virtual] |
Get device name.
Reimplemented from faudes::Type.
Definition at line 351 of file iop_vdevice.cpp.
void faudes::vDevice::Tolerance | ( | tpTime::Type | maxgap | ) | [inline] |
Set tolerance for time synchonisation.
maxgap | Max acceptable amount of time by which the generator may be behind device time. |
Definition at line 317 of file iop_vdevice.h.
int faudes::vDevice::Tolerance | ( | void | ) | [inline] |
Get tolerance.
Definition at line 327 of file iop_vdevice.h.
virtual void faudes::vDevice::TimeScale | ( | unsigned int | scale | ) | [inline, virtual] |
Set timescale.
scale | Conversion factor in msecs/ftu (faudes time units) |
Definition at line 337 of file iop_vdevice.h.
virtual int faudes::vDevice::TimeScale | ( | void | ) | [inline, virtual] |
Get timescale.
Definition at line 347 of file iop_vdevice.h.
void faudes::vDevice::Clear | ( | void | ) | [virtual] |
Clear all configuration.
This implies Stop().
Reimplemented from faudes::Type.
Reimplemented in faudes::sDevice, faudes::nDevice, and faudes::xDevice.
Definition at line 331 of file iop_vdevice.cpp.
void faudes::vDevice::Configure | ( | Idx | event, | |
const AttributeDeviceEvent & | attr | |||
) | [virtual] |
Insert/edit sensor or actuator configuration.
For a nontrivial device, a dynamic cast is used to access the attribute parameter.
event | Sensor or actuator event by faudes index | |
attr | Configuration attribute |
Exception |
|
Reimplemented in faudes::xDevice.
Definition at line 464 of file iop_vdevice.cpp.
void faudes::vDevice::Configure | ( | const EventSet & | rPhysicalEvents | ) | [virtual] |
Configure by alphabet.
For a nontrivial device, a dynamic cast is used to access atributes of the alphabet parameter.
rPhysicalEvents | Event set with configuration attributes |
Exception |
|
Reimplemented in faudes::xDevice.
Definition at line 483 of file iop_vdevice.cpp.
void faudes::vDevice::Compile | ( | void | ) | [virtual] |
Compile inner data-structures.
As every derived class may have its own individual inner data-structures to set up, it has to reimplement its own Compile()-function if needed.
In the base class Compile() builds up the sensor- and actuator event set.
Reimplemented in faudes::sDevice, faudes::nDevice, and faudes::xDevice.
Definition at line 503 of file iop_vdevice.cpp.
const EventSet & faudes::vDevice::Actuators | ( | void | ) | const [virtual] |
Get actuators as plain set.
Definition at line 545 of file iop_vdevice.cpp.
const EventSet & faudes::vDevice::Sensors | ( | void | ) | const [virtual] |
Get sensors as plain set.
Definition at line 550 of file iop_vdevice.cpp.
void faudes::vDevice::Reset | ( | void | ) | [virtual] |
Reset device.
Resets any dynamic state such as edge detection. Since the vDevice only provides timing, it only resets the current faudes time to zero. Does not stop the device.
Reimplemented in faudes::sDevice, faudes::nDevice, and faudes::xDevice.
Definition at line 317 of file iop_vdevice.cpp.
void faudes::vDevice::Start | ( | void | ) | [virtual] |
Activate the device.
This function enables actuator execution and sensor reading. It will allocate device specific necessary resources eg start a background thread, initialise operating system device drivers etc.
Exception |
|
Reimplemented in faudes::sDevice, faudes::nDevice, and faudes::xDevice.
Definition at line 287 of file iop_vdevice.cpp.
void faudes::vDevice::Stop | ( | void | ) | [virtual] |
Deactivate the device.
This function disables actuator execution and sensor reading. Stop also runs Reset.
Reimplemented in faudes::sDevice, faudes::nDevice, and faudes::xDevice.
Definition at line 305 of file iop_vdevice.cpp.
virtual DeviceState faudes::vDevice::Status | ( | void | ) | [inline, virtual] |
Get status.
This function returns the current status of the device. In derived classes that use background threads for sensor reading etc, a device may change its status without notice. Stop runs Reset()
Reimplemented in faudes::xDevice.
Definition at line 446 of file iop_vdevice.h.
std::string faudes::vDevice::StatusString | ( | void | ) | [virtual] |
virtual void faudes::vDevice::WriteActuator | ( | Idx | actuator | ) | [pure virtual] |
Run actuator command.
Exception |
|
Implemented in faudes::sDevice, faudes::nDevice, and faudes::xDevice.
Idx faudes::vDevice::ReadSensor | ( | void | ) | [virtual] |
Read sensed sensor events.
Report the oldest event from the internal sensor buffer. The event is removed from the buffer. The function returns 0 if the buffer is empty.
Definition at line 819 of file iop_vdevice.cpp.
Idx faudes::vDevice::PeekSensor | ( | void | ) | [virtual] |
Peek for sensed events.
Report the oldest sensor-event from the buffer. However, dont remove the event.
Definition at line 839 of file iop_vdevice.cpp.
bool faudes::vDevice::SensorReady | ( | void | ) | [virtual] |
bool faudes::vDevice::WaitSensors | ( | tpTime::Type | duration | ) | [virtual] |
Wait for sensor trigger.
The default implementation assumes that sensors events are notified via the pthread condition signal. The duration to wait is specified in faudes time units (ftu) and is converted to a pthraed time spec by the scaling factor mTimeScale (ms/ftu).
Definition at line 721 of file iop_vdevice.cpp.
bool faudes::vDevice::WaitSensorsMs | ( | long int | duration | ) | [virtual] |
Wait for sensor trigger.
Same as WaitSensors, but with the maximum time to wait given in msecs.
Definition at line 771 of file iop_vdevice.cpp.
tpTime::Type faudes::vDevice::CurrentTime | ( | void | ) | [virtual] |
Report physical time in ftu.
The time elapsed since the last reset is retunred in faudes time units (ftu).
Reimplemented in faudes::xDevice.
Definition at line 655 of file iop_vdevice.cpp.
long int faudes::vDevice::CurrentTimeMs | ( | void | ) | [virtual] |
Report physical time in ms.
The time elapsed since the last reset is returned in msecs.
Reimplemented in faudes::xDevice.
Definition at line 678 of file iop_vdevice.cpp.
void faudes::vDevice::CurrentTime | ( | tpTime::Type | now | ) | [virtual] |
Set physical time in ftu.
now | physical time in faudes time units (ftu). |
Reimplemented in faudes::xDevice.
Definition at line 670 of file iop_vdevice.cpp.
void faudes::vDevice::CurrentTimeMs | ( | long int | nowms | ) | [virtual] |
Set physical time in ms.
nowms | physical time in msec |
Reimplemented in faudes::xDevice.
Definition at line 694 of file iop_vdevice.cpp.
timeval faudes::vDevice::DiffTime | ( | timeval | end, | |
timeval | start | |||
) | [static] |
Compute time difference.
end | end of time measurement | |
start | begin of time measurement |
Definition at line 555 of file iop_vdevice.cpp.
timeval faudes::vDevice::SumTime | ( | timeval | start, | |
timeval | duration | |||
) | [static] |
Compute time sum.
start | Summand 1 | |
duration | Summand 2 |
Definition at line 572 of file iop_vdevice.cpp.
timespec faudes::vDevice::FtuToTimeSpec | ( | tpTime::Type | duration | ) | [virtual] |
Convert faudes time unit duration to a pthread time spec.
Note: this helper function is not static since it refers to the parameter mTimeScale.
duration | Time in fauDes-time |
Definition at line 589 of file iop_vdevice.cpp.
timespec faudes::vDevice::MsToTimeSpec | ( | long int | duration | ) | [static] |
Convert msec duration to pthread timespec.
duration | Time in msec |
Definition at line 613 of file iop_vdevice.cpp.
void faudes::vDevice::UseCondition | ( | pthread_mutex_t * | wmutex, | |
pthread_cond_t * | wcond | |||
) |
void faudes::vDevice::UseBuffer | ( | pthread_mutex_t * | bmutex, | |
std::deque< Idx > * | bbuffer | |||
) |
virtual std::string faudes::vDevice::EStr | ( | Idx | ev | ) | [inline, virtual] |
SampledDensityFunction faudes::vDevice::Performance | ( | void | ) |
void faudes::vDevice::WritePerformance | ( | void | ) |
void faudes::vDevice::StopAll | ( | void | ) | [static] |
Stop all devices.
This function is intended to be called on ungraceful termination of a simulater application. It uses a global variable that tracks all device instances.
Definition at line 267 of file iop_vdevice.cpp.
void faudes::vDevice::DoWrite | ( | TokenWriter & | rTw, | |
const std::string & | rLabel = "" , |
|||
const Type * | pContext = 0 | |||
) | const [protected, virtual] |
Token output, see Type::Write for public wrappers.
The vDevice inplements token writing to consist of DoWritePreface (device name and time scale). and DoWriteConfiguration (device specific event attributes). The default label is taken from the member variable mDefaultLabel. Derived classes are meant to set mDefaultLabel in their constructor and to reimplement DoWritePreface to add additional data eg cycle time or network address. The parameter pContext is ignored and passed on.
rTw | Reference to TokenWriter | |
rLabel | Label of section to write, defaults to name of set | |
pContext | Write context to provide contextual information |
Reimplemented from faudes::Type.
Reimplemented in faudes::xDevice.
Definition at line 378 of file iop_vdevice.cpp.
void faudes::vDevice::DoWritePreface | ( | TokenWriter & | rTw, | |
const std::string & | rLabel = "" , |
|||
const Type * | pContext = 0 | |||
) | const [protected, virtual] |
Writes non-event-configuration data from TokenWriter.
This function is part of the non-event-configuration token-output mechanism. The vDevice will write its name and the time scale, derived classes are meant to first call the base class method and then add additional configuration parameter.
Note: in order to keep the inputfile-layout as easy as possible no label will be used to separate this data-section. Never the less a default-label ("Device") is specified.
rTw | TokenWriter to write to | |
rLabel | Section to read | |
pContext | Provide contextual information |
Reimplemented in faudes::sDevice, and faudes::nDevice.
Definition at line 409 of file iop_vdevice.cpp.
void faudes::vDevice::DoWriteConfiguration | ( | TokenWriter & | rTw, | |
const std::string & | rLabel = "" , |
|||
const Type * | pContext = 0 | |||
) | const [protected, virtual] |
Writes event-configuration to TokenWriter.
This function is part of the event-configuration token-output mechanism. It writes the device-specific event-configuration to provided TokenWriter. It uses the virtual interface of TBaseSet to figure the actual attribute type.
Note: the event-configuration will be labeled by "EventConfiguration"
rTw | TokenWriter to write to | |
rLabel | Section to write | |
pContext | Provide contextual information |
Definition at line 396 of file iop_vdevice.cpp.
void faudes::vDevice::DoRead | ( | TokenReader & | rTr, | |
const std::string & | rLabel = "" , |
|||
const Type * | pContext = 0 | |||
) | [protected, virtual] |
Token input, see Type::DRead for public wrappers.
The vDevice implkements token input to consist of DoReadPreface (name, time scale etc) and DoReadConfiguration (events attributes), followed by Compile (set up internal data structures). The default label is given by the member variable mDefaultLabel. Derived classes arte meant to set mDefaultLabel in their constructor and to reimplement DoReadPreface to cover additional parameters. The pContext parameter is ignored.
rTr | Reference to TokenReader | |
rLabel | Label of section to write, defaults to name of set | |
pContext | Write context to provide contextual information |
Reimplemented from faudes::Type.
Reimplemented in faudes::xDevice.
Definition at line 421 of file iop_vdevice.cpp.
void faudes::vDevice::DoReadPreface | ( | TokenReader & | rTr, | |
const std::string & | rLabel = "" , |
|||
const Type * | pContext = 0 | |||
) | [protected, virtual] |
Reads non-event-configuration data from TokenReader.
This function is part of the non-event-configuration token-input mechanism and located at the top of the class hierarchy. The vDevice will read its name and the time scale, derived classes are meant to first call the base class method and then read add additional configuration parameters.
Note: in order to keep the inputfile-layout as easy as possible no label will be used to separate this data-section. Never the less a default-label ("Device") is specified.
rTr | TokenReader to write | |
rLabel | Section to read | |
pContext | Provide contextual information |
Reimplemented in faudes::sDevice, and faudes::nDevice.
Definition at line 453 of file iop_vdevice.cpp.
void faudes::vDevice::DoReadConfiguration | ( | TokenReader & | rTr, | |
const std::string & | rLabel = "" , |
|||
const Type * | pContext = 0 | |||
) | [protected, virtual] |
Reads event-configuration data from TokenReader.
This function is part of the token-input mechanism and reads the device-specific event-configuration. It uses the virtual interface of TBaseSet to figure the actual attribute type. The section defaults to "EventConfiguration".
rTr | TokenReader to read | |
rLabel | Section to read | |
pContext | Provide contextual information |
Definition at line 442 of file iop_vdevice.cpp.
long int faudes::vDevice::FtuToMs | ( | tpTime::Type | faudes_time | ) | [protected, virtual] |
tpTime::Type faudes::vDevice::MsToFtu | ( | long int | real_time | ) | [protected, virtual] |
friend class xDevice [friend] |
Definition at line 237 of file iop_vdevice.h.
std::string faudes::vDevice::mDefaultLabel [protected] |
std::string faudes::vDevice::mName [protected] |
EventSet* faudes::vDevice::mpConfiguration [protected] |
EventSet faudes::vDevice::mSensors [protected] |
EventSet faudes::vDevice::mActuators [protected] |
DeviceState faudes::vDevice::mState [protected] |
pthread_mutex_t faudes::vDevice::mWaitMutex [protected] |
pthread_cond_t faudes::vDevice::mWaitCondition [protected] |
pthread_mutex_t* faudes::vDevice::pWaitMutex [protected] |
pthread_cond_t* faudes::vDevice::pWaitCondition [protected] |
timeval faudes::vDevice::mTimeZero [protected] |
int faudes::vDevice::mTimeScale [protected] |
tpTime::Type faudes::vDevice::mMaxSyncGap [protected] |
std::deque<Idx> faudes::vDevice::mSensorBuffer [protected] |
std::deque<Idx>* faudes::vDevice::pSensorBuffer [protected] |
pthread_mutex_t faudes::vDevice::mBufferMutex [protected] |
pthread_mutex_t* faudes::vDevice::pBufferMutex [protected] |
timeval* faudes::vDevice::mpPerformanceWaitEnter [protected] |
timeval* faudes::vDevice::mpPerformanceWaitExit [protected] |
Definition at line 806 of file iop_vdevice.h.
int faudes::vDevice::mPerformanceIterator [protected] |
std::set< vDevice * > faudes::vDevice::msAllDevices [static, private] |
Definition at line 815 of file iop_vdevice.h.
libFAUDES 2.14g --- 2009-12-3 --- c++ source docu by doxygen 1.5.6