#include <iop_sdevice.h>

Classes

struct  Edges
 
struct  Levels
 

Public Types

typedef AttributeSignalInput::Trigger Trigger
 
typedef AttributeSignalOutput::Action Action
 
typedef AttributeSignalOutput::Value Value
 
- Public Types inherited from faudes::vDevice
enum  DeviceState { Down , StartUp , Up , ShutDown }
 

Public Member Functions

 sDevice (void)
 
 sDevice (const sDevice &rOtherDevice)
 
virtual ~sDevice (void)
 
virtual void Clear (void)
 
virtual void Compile (void)
 
void InsInputEvent (const std::string &event)
 
void AppendTrigger (const std::string &event, const Trigger &trigger)
 
void InsOutputEvent (const std::string &event)
 
void AppendAction (const std::string &event, const Action &action)
 
int MaxBitAddress (void) const
 
virtual void Start (void)
 
virtual void Stop (void)
 
virtual void Reset (void)
 
virtual void WriteOutput (Idx output)
 
void WriteSignal (int bitaddr, bool value)
 
bool ReadSignal (int bitaddr)
 
virtual int CycleTime () const
 
virtual void CycleTime (int cycleTime)
 
- Public Member Functions inherited from faudes::vDevice
 vDevice (void)
 
virtual ~vDevice (void)
 
void Name (const std::string &rName)
 
const std::string & Name (void) const
 
void Tolerance (Time::Type maxgap)
 
Time::Type Tolerance (void)
 
virtual void TimeScale (unsigned int scale)
 
virtual int TimeScale (void)
 
virtual void Configure (Idx event, const AttributeDeviceEvent &attr)
 
virtual void Configure (const EventSet &rPhysicalEvents)
 
virtual const EventSetOutputs (void) const
 
virtual const EventSetInputs (void) const
 
virtual bool ResetRequest (void)
 
virtual DeviceState Status (void)
 
virtual std::string StatusString (void)
 
virtual void FlushOutputs (void)
 
virtual Idx ReadInput (void)
 
virtual Idx PeekInput (void)
 
virtual bool InputReady (void)
 
virtual bool WaitInputs (Time::Type duration)
 
virtual bool WaitInputsMs (long int duration)
 
virtual Time::Type CurrentTime (void)
 
virtual long int CurrentTimeMs (void)
 
virtual void CurrentTime (Time::Type now)
 
virtual void CurrentTimeMs (long int nowms)
 
virtual faudes_systime_t FtuToSystemTime (Time::Type duration)
 
void UseCondition (faudes_mutex_t *wmutex, faudes_cond_t *wcond)
 
void UseBuffer (faudes_mutex_t *bmutex, std::deque< Idx > *bbuffer)
 
virtual std::string EStr (Idx ev)
 
SampledDensityFunction Performance (void)
 
void ResetPerformance (void)
 
void WritePerformance (void)
 
- Public Member Functions inherited from faudes::Type
 Type (void)
 
 Type (const Type &rType)
 
virtual ~Type (void)
 
virtual TypeNew (void) const
 
virtual TypeCopy (void) const
 
virtual const TypeCast (const Type *pOther) const
 
virtual TypeAssign (const Type &rSrc)
 
Typeoperator= (const Type &rSrc)
 
virtual bool Equal (const Type &rOther) const
 
bool operator== (const Type &rOther) const
 
bool operator!= (const Type &rOther) const
 
virtual const std::string & TypeName (void) const
 
void Write (const Type *pContext=0) const
 
void Write (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0, std::ios::openmode openmode=std::ios::out|std::ios::trunc) const
 
void Write (const std::string &pFileName, std::ios::openmode openmode) const
 
void Write (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void XWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
 
void XWrite (const Type *pContext=0) const
 
void XWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
std::string ToString (const std::string &rLabel="", const Type *pContext=0) const
 
std::string ToText (const std::string &rLabel="", const Type *pContext=0) const
 
void DWrite (const Type *pContext=0) const
 
void DWrite (const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0, std::ios::openmode openmode=std::ios::out|std::ios::trunc) const
 
void DWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
void SWrite (TokenWriter &rTw) const
 
void SWrite (void) const
 
std::string ToSText (void) const
 
void Read (const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
 
void FromString (const std::string &rString, const std::string &rLabel="", const Type *pContext=0)
 
void Read (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 

Protected Member Functions

void DoWritePreface (TokenWriter &rTw, const std::string &rLabel, const Type *pContext=0) const
 
virtual void DoReadPreface (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 
virtual bool DoReadSignalsPre (void)
 
virtual void DoReadSignalsPost (void)
 
virtual bool DoReadSignal (int bitaddr)=0
 
virtual bool DoWriteSignalsPre (void)
 
virtual void DoWriteSignalsPost (void)
 
virtual void DoWriteSignal (int bitaddr, bool value)=0
 
virtual void DoLoopCallback (void)
 
- Protected Member Functions inherited from faudes::vDevice
virtual void DoWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoWriteConfiguration (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoRead (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 
virtual void DoReadConfiguration (TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
 
virtual long int FtuToMs (Time::Type faudes_time)
 
virtual Time::Type MsToFtu (long int real_time)
 
- Protected Member Functions inherited from faudes::Type
void DoAssign (const Type &rSrc)
 
bool DoEqual (const Type &rOther) const
 
virtual void DoXWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoDWrite (TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
 
virtual void DoSWrite (TokenWriter &rTw) const
 
virtual const TypeDefinitionTypeDefinitionp (void) const
 
virtual Token XBeginTag (const std::string &rLabel="", const std::string &rFallbackLabel="") const
 

Protected Attributes

TaNameSet< AttributeSignalEvent > * pConfiguration
 
std::map< int, EventSetmInputPosEdgeIndexMap
 
std::map< int, EventSetmInputNegEdgeIndexMap
 
std::map< int, EventSetmOutputLevelIndexMap
 
int mMaxBitAddress
 
faudes_mutex_t mMutex
 
bool mSyncWrite
 
- Protected Attributes inherited from faudes::vDevice
std::string mDefaultLabel
 
std::string mName
 
EventSetmpConfiguration
 
EventSet mInputs
 
EventSet mOutputs
 
DeviceState mState
 
faudes_mutex_t mWaitMutex
 
faudes_cond_t mWaitCondition
 
faudes_mutex_t * pWaitMutex
 
faudes_cond_t * pWaitCondition
 
faudes_systime_t mTimeZero
 
int mTimeScale
 
Time::Type mMaxSyncGap
 
std::deque< IdxmInputBuffer
 
std::deque< Idx > * pInputBuffer
 
faudes_mutex_t mBufferMutex
 
faudes_mutex_t * pBufferMutex
 
bool mResetRequest
 
faudes_systime_t * mpPerformanceWaitEnter
 
faudes_systime_t * mpPerformanceWaitExit
 
int mPerformanceEndIterator
 
int mPerformanceBeginIterator
 

Private Member Functions

void ClrInputSignals (void)
 
void ClrOutputSignals (void)
 

Private Attributes

faudes_thread_t mThreadSynchro
 
int mCycleTime
 
int mCycleCount
 
int mRecentCycleCount
 
EdgesmpInputEdges
 
EdgesmpRecentInputEdges
 
bool mInputReady
 
LevelsmpOutputLevels
 
bool mCancelRequest
 

Friends

void * SDeviceSynchro (void *)
 

Additional Inherited Members

- Static Public Member Functions inherited from faudes::vDevice
static vDeviceFromTokenReader (TokenReader &rTr)
 
static vDeviceFromFile (const std::string &rFileName)
 
static void StopAll (void)
 

Detailed Description

An sDevice implements signal based semantics for faudes events.

The class is configured by AttributeSignalEvents, which in turn consist of either a AttributeSignalInput or a AttributeSignalOutput. Thus, we set and clear output signals for output events, while edges on input signals trigger input events.

Sensing edges is done by separate thread that is started by Start().

This class is still virtual in that it does not provide the code for actually reading or writing signals. See cDevice and pDevice for derived device classes that implement digital io via comedi or the parallel printer port, respectively.

Definition at line 287 of file iop_sdevice.h.

Member Typedef Documentation

◆ Action

◆ Trigger

◆ Value

Constructor & Destructor Documentation

◆ sDevice() [1/2]

faudes::sDevice::sDevice ( void  )

Default constructor

Definition at line 382 of file iop_sdevice.cpp.

◆ sDevice() [2/2]

faudes::sDevice::sDevice ( const sDevice rOtherDevice)

copy-constructor

◆ ~sDevice()

faudes::sDevice::~sDevice ( void  )
virtual

Explicit destructor.

Definition at line 408 of file iop_sdevice.cpp.

Member Function Documentation

◆ AppendAction()

void faudes::sDevice::AppendAction ( const std::string &  event,
const Action action 
)

Add an action. Note: you can only add a actions to an output event; you can only (re)-configure events while the device is down.

Parameters
eventEvent
actionAction to append

Definition at line 673 of file iop_sdevice.cpp.

◆ AppendTrigger()

void faudes::sDevice::AppendTrigger ( const std::string &  event,
const Trigger trigger 
)

Add a trigger condition. Note: you can only add a trigger condition to an input event; you can only (re)-configure events while the device is down.

Parameters
eventEvent
triggerTrigger to append

Definition at line 652 of file iop_sdevice.cpp.

◆ Clear()

void faudes::sDevice::Clear ( void  )
virtual

Clear all configuration. This implies Stop().

Reimplemented from faudes::vDevice.

Reimplemented in faudes::mbDevice.

Definition at line 573 of file iop_sdevice.cpp.

◆ ClrInputSignals()

void faudes::sDevice::ClrInputSignals ( void  )
private

clear all input states

Definition at line 1114 of file iop_sdevice.cpp.

◆ ClrOutputSignals()

void faudes::sDevice::ClrOutputSignals ( void  )
private

clear all output values

Definition at line 1169 of file iop_sdevice.cpp.

◆ Compile()

void faudes::sDevice::Compile ( void  )
virtual

Build up internal data-structure (e.g. signal-event - mapping)

Reimplemented from faudes::vDevice.

Reimplemented in faudes::mbDevice.

Definition at line 587 of file iop_sdevice.cpp.

◆ CycleTime() [1/2]

int faudes::sDevice::CycleTime ( void  ) const
virtual

Report cycle time

Returns
Actual cycle time in ussecs

Definition at line 686 of file iop_sdevice.cpp.

◆ CycleTime() [2/2]

void faudes::sDevice::CycleTime ( int  cycleTime)
virtual

Set cycle time

Parameters
cycleTimeDesired cycle time in usecs

Definition at line 693 of file iop_sdevice.cpp.

◆ DoLoopCallback()

virtual void faudes::sDevice::DoLoopCallback ( void  )
inlineprotectedvirtual

Loop hook. This function is called once during each cycle of the backgroud thread

Reimplemented in faudes::mbDevice.

Definition at line 605 of file iop_sdevice.h.

◆ DoReadPreface()

void faudes::sDevice::DoReadPreface ( TokenReader rTr,
const std::string &  rLabel = "",
const Type pContext = 0 
)
protectedvirtual

Reads non-event-related configuration from TokenReader

Device date is read bottom-to-top along the class-hierarchy; see also vDevice::DoReadPreface.

Note: in order to keep the inputfile-layout as simple as possible no label will be used to separate this data-section.

Parameters
rTrTokenReader to read from
rLabelSection to read
pContextRead context to provide contextual information

Reimplemented from faudes::vDevice.

Reimplemented in faudes::mbDevice.

Definition at line 443 of file iop_sdevice.cpp.

◆ DoReadSignal()

virtual bool faudes::sDevice::DoReadSignal ( int  bitaddr)
protectedpure virtual

Sample input signal.

Reimplement this function to implements actual harware access to sample an input signal. This function gets called from the periodic background thread to sense edges. It is guaranteed that the pre-hook was called befor and returned "true". The post-hook will be invoked after relevant signals have been sampled.

Parameters
bitaddrAbstract bit address
Returns
True for logic level high;

Implemented in faudes::mbDevice.

◆ DoReadSignalsPost()

virtual void faudes::sDevice::DoReadSignalsPost ( void  )
inlineprotectedvirtual

IO Hook, inputs

The background thread calls this hook after reading input signals. You may reimplement this method to e.g. release a process image.

Reimplemented in faudes::mbDevice.

Definition at line 543 of file iop_sdevice.h.

◆ DoReadSignalsPre()

virtual bool faudes::sDevice::DoReadSignalsPre ( void  )
inlineprotectedvirtual

IO Hook, inputs

The background thread calls this hook before reading input signals. You may reimplement this method to e.g. prepare a process image.

Returns
True on success, false on error

Reimplemented in faudes::mbDevice.

Definition at line 533 of file iop_sdevice.h.

◆ DoWritePreface()

void faudes::sDevice::DoWritePreface ( TokenWriter rTw,
const std::string &  rLabel,
const Type pContext = 0 
) const
protectedvirtual

Writes non-event-related configuration to TokenWriter

Device data will be written bottom-to-top along the class-hierarchy, see also vDevice::DoWritePreface.

Note: in order to keep the outputfile-layout as simple as possible no label will be used to separate this data-section.

Parameters
rTwTokenWriter to write
rLabelSection to write
pContextContext to provide contextual information

Reimplemented from faudes::vDevice.

Definition at line 423 of file iop_sdevice.cpp.

◆ DoWriteSignal()

virtual void faudes::sDevice::DoWriteSignal ( int  bitaddr,
bool  value 
)
protectedpure virtual

Reimplement this function in a derived class for actual harware access to set or clear an output signal. Hooks are executed appropriately. If the device is configured for synchronous write, the background task is used to write signals. Otherwise, signal values are written instantly.

Parameters
bitaddrAbstract bit address
valueTrue for active/high/1/set; false for passive/low/0/clr;

Implemented in faudes::mbDevice.

◆ DoWriteSignalsPost()

virtual void faudes::sDevice::DoWriteSignalsPost ( void  )
inlineprotectedvirtual

IO Hook, output

This hook is invoked after writing a signal value. You may reimplement this method to e.g. assemble a process image.

Reimplemented in faudes::mbDevice.

Definition at line 581 of file iop_sdevice.h.

◆ DoWriteSignalsPre()

virtual bool faudes::sDevice::DoWriteSignalsPre ( void  )
inlineprotectedvirtual

IO Hook, outputs

This hook is invoked before writing a signal value. You may reimplement this method to e.g. assemble a process image.

Returns
True on success, false on error

Reimplemented in faudes::mbDevice.

Definition at line 571 of file iop_sdevice.h.

◆ InsInputEvent()

void faudes::sDevice::InsInputEvent ( const std::string &  event)

Insert event as input event. Note: you can only configure events while the device is down.

Parameters
eventEvent by name.

Definition at line 642 of file iop_sdevice.cpp.

◆ InsOutputEvent()

void faudes::sDevice::InsOutputEvent ( const std::string &  event)

Insert event as output event. Note: you can only configure event while the device is down.

Parameters
eventEvent by name.

Definition at line 663 of file iop_sdevice.cpp.

◆ MaxBitAddress()

int faudes::sDevice::MaxBitAddress ( void  ) const
inline

Report max bit address.

Returns
Set of all configured inputs

Definition at line 381 of file iop_sdevice.h.

◆ ReadSignal()

bool faudes::sDevice::ReadSignal ( int  bitaddr)

Get input signal.

This function provides user level access to input signals. It executes the virtual pre and post hook methods and the virtual actual harware access to sample an input signal via DoReadSignal(int).

Parameters
bitaddrAbstract bit address
Returns
True for logic level high;

Definition at line 706 of file iop_sdevice.cpp.

◆ Reset()

void faudes::sDevice::Reset ( void  )
virtual

Clear dynamic data and restart device

Reimplemented from faudes::vDevice.

Definition at line 559 of file iop_sdevice.cpp.

◆ Start()

void faudes::sDevice::Start ( void  )
virtual

Activate the device. This function enables output execution and input reading. It starts the background thread for edge detection and input event buffer.

Exceptions
Exception
  • Not yet configured (id 551)

Reimplemented from faudes::vDevice.

Reimplemented in faudes::mbDevice.

Definition at line 514 of file iop_sdevice.cpp.

◆ Stop()

void faudes::sDevice::Stop ( void  )
virtual

Deactivate the device. This function disables output execution and input reading. It stops the backhround thread and resets all output signals to 0.

Reimplemented from faudes::vDevice.

Reimplemented in faudes::mbDevice.

Definition at line 534 of file iop_sdevice.cpp.

◆ WriteOutput()

void faudes::sDevice::WriteOutput ( Idx  output)
virtual

Run output command.

Exceptions
Exception
  • unknown output event (id 65)

Implements faudes::vDevice.

Definition at line 1053 of file iop_sdevice.cpp.

◆ WriteSignal()

void faudes::sDevice::WriteSignal ( int  bitaddr,
bool  value 
)

Set output signal.

This function provides user level access to output signals. It executes the virtual pre and post hook methods and the virtual actual harware access to set the signal level via DoWriteSignal(int,bool).

Parameters
bitaddrAbstract bit address
valueTrue for active/high/1/set; false for passive/low/0/clr;

Definition at line 734 of file iop_sdevice.cpp.

Friends And Related Function Documentation

◆ SDeviceSynchro

void* SDeviceSynchro ( void *  )
friend

Definition at line 772 of file iop_sdevice.cpp.

Member Data Documentation

◆ mCancelRequest

bool faudes::sDevice::mCancelRequest
private

Background: terminate-flag for background task

Definition at line 661 of file iop_sdevice.h.

◆ mCycleCount

int faudes::sDevice::mCycleCount
private

Background: cycle counter (shared)

Definition at line 623 of file iop_sdevice.h.

◆ mCycleTime

int faudes::sDevice::mCycleTime
private

Cycle time of background thread in nsecs (shared)

Definition at line 620 of file iop_sdevice.h.

◆ mInputNegEdgeIndexMap

std::map<int, EventSet> faudes::sDevice::mInputNegEdgeIndexMap
protected

Reverse input map: map signal edges to logical event sets

Definition at line 476 of file iop_sdevice.h.

◆ mInputPosEdgeIndexMap

std::map<int, EventSet> faudes::sDevice::mInputPosEdgeIndexMap
protected

Reverse input map: map signal edges to logical event sets

Definition at line 473 of file iop_sdevice.h.

◆ mInputReady

bool faudes::sDevice::mInputReady
private

Background: some input event did occur (shared)

Definition at line 646 of file iop_sdevice.h.

◆ mMaxBitAddress

int faudes::sDevice::mMaxBitAddress
protected

Address range

Definition at line 482 of file iop_sdevice.h.

◆ mMutex

faudes_mutex_t faudes::sDevice::mMutex
protected

Background: mutex for below shared variables

Definition at line 609 of file iop_sdevice.h.

◆ mOutputLevelIndexMap

std::map<int, EventSet> faudes::sDevice::mOutputLevelIndexMap
protected

Reverse output map: map signal addres to events that affect the resp. line

Definition at line 479 of file iop_sdevice.h.

◆ mpInputEdges

Edges* faudes::sDevice::mpInputEdges
private

Background: accumulated edges (shared)

Definition at line 640 of file iop_sdevice.h.

◆ mpOutputLevels

Levels* faudes::sDevice::mpOutputLevels
private

Background: accumulated output values (shared)

Definition at line 658 of file iop_sdevice.h.

◆ mpRecentInputEdges

Edges* faudes::sDevice::mpRecentInputEdges
private

Background: recently accumulated edges (global only)

Definition at line 643 of file iop_sdevice.h.

◆ mRecentCycleCount

int faudes::sDevice::mRecentCycleCount
private

Background: cycle count (global only)

Definition at line 626 of file iop_sdevice.h.

◆ mSyncWrite

bool faudes::sDevice::mSyncWrite
protected

True for synchronous output writes

Definition at line 612 of file iop_sdevice.h.

◆ mThreadSynchro

faudes_thread_t faudes::sDevice::mThreadSynchro
private

Background: thread handle (global)

Definition at line 617 of file iop_sdevice.h.

◆ pConfiguration

TaNameSet<AttributeSignalEvent>* faudes::sDevice::pConfiguration
protected

Overall configuration (with actual type)

Definition at line 470 of file iop_sdevice.h.


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

libFAUDES 2.33b --- 2025.05.07 --- c++ api documentaion by doxygen