DUECA/DUSIME
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
dueca::RTWModule Class Reference

A base class from which users can derive Real-Time Workshop modules. More...

#include <RTWModule.hxx>

Inheritance diagram for dueca::RTWModule:
Inheritance graph
[legend]
Collaboration diagram for dueca::RTWModule:
Collaboration graph
[legend]

Public Member Functions

bool XmlSnapshotNow (const TimeSpec &ts)
 Returns true if an xml snapshot has to be taken in this cycle.
 
virtual void fillXmlSnapshot (const TimeSpec &ts, XmlSnapshot &snap)
 If xml snapshots are generated, this has to be implemented by a descendant.
 
virtual void loadXmlSnapshot (const TimeSpec &ts, const XmlSnapshot &snap)
 For restoring state, model parameters, and initial inputs from a previously generated xml file.
 
- Public Member Functions inherited from dueca::Module
virtual ~Module ()
 Destructor.
 
virtual bool complete ()
 Inform the module that all parameters have now been passed.
 
virtual bool isPrepared ()=0
 To check whether the module is ready for work.
 
virtual bool isInitialPrepared ()
 To check whether the module is prepared to be prepared.
 
ObjectType getObjectType () const
 The object type within DUECA.
 
virtual void startModule (const TimeSpec &time)=0
 Start the module's activity (activities)
 
virtual void stopModule (const TimeSpec &time)=0
 Stop the module's activity (activities)
 
virtual void initialStartModule (const TimeSpec &time)
 Initial start opportunity.
 
virtual void finalStopModule (const TimeSpec &time)
 Final stop command.
 
const Entity * getMyEntity ()
 Return a pointer to the entity to which this module belongs.
 
const ModuleStategetState ()
 Return the module state.
 
- Public Member Functions inherited from dueca::NamedObject
const std::string getEntity () const
 Returns the "entity" part of the name.
 
const std::string getClass () const
 Returns the "class" part of the name.
 
const std::string getPart () const
 Returns the sub-entity or "part" part of the name.
 
const NameSetgetNameSet () const
 This returns the complete name set.
 
const GlobalIdgetId () const
 This returns the id.
 

Protected Member Functions

 RTWModule (Entity *e, const char *m_class, const char *part, const IncoTable *table=NULL, int state_size=0)
 Constructor.
 
virtual ~RTWModule ()
 Destructor.
 
- Protected Member Functions inherited from dueca::SimulationModule
 SimulationModule (Entity *e, const char *m_class, const char *part, const IncoTable *table=NULL, int state_size=0)
 Constructor.
 
virtual ~SimulationModule ()
 Destructor.
 
SimulationState::Type getAndCheckState (const TimeSpec &ts, bool confirm_transition=true)
 Returns the state of the simulation at this time.
 
void transitionComplete ()
 If a transition was not (implicitly) confirmed in the getAndCheckState call (second argument false), confirm with this call that it is now complete.
 
SimulationState::Type getCurrentState ()
 If you "forgot" what the state from a previous getAndCheckState() call was, you can remember it here.
 
- Protected Member Functions inherited from dueca::DusimeModule
 DusimeModule (Entity *e, const char *m_class, const char *part, const IncoTable *inco_table, int state_size)
 Constructor.
 
virtual ~DusimeModule ()
 Destructor.
 
bool snapshotNow ()
 Returns true if a snapshot has to be taken in this cycle.
 
virtual void fillSnapshot (const TimeSpec &ts, Snapshot &snap, bool from_trim)
 If snapshots are generated, this has to be implemented by a descendant.
 
virtual void loadSnapshot (const TimeSpec &ts, const Snapshot &snap)
 For restoring the state from an old snapshot.
 
void trimCalculationCondition (TriggerPuller &cond)
 This can be used to specify the condition under which the trim calculation may take place, for example, data has to be received on trim calculation input channels.
 
virtual void trimCalculation (const TimeSpec &ts, const TrimMode &mode)
 This must be overridden if the module takes part in trim condition calculations.
 
- Protected Member Functions inherited from dueca::Module
 Module (const Entity *e, const char *m_class, const char *part)
 Constructor.
 
virtual void setSafetyStop ()
 Put a brake on this module's activities.
 
- Protected Member Functions inherited from dueca::NamedObject
 NamedObject (const GlobalId &id)
 Reserve for AssociateObject.
 
 NamedObject (const NameSet &ns)
 Normal constructor, protected, because it has no use to create a NamedObject by itself.
 
virtual ~NamedObject ()
 Destructor.
 

Additional Inherited Members

- Protected Attributes inherited from dueca::DusimeModule
SnapshotState snap_state
 State of the snapshot taking.
 
- Protected Attributes inherited from dueca::Module
ModuleState state
 Flag to remember whether we are stopped due to some error with hardware device manipulation.
 

Detailed Description

A base class from which users can derive Real-Time Workshop modules.

The RTWModule base class implements the basic communication for a DUSIME module. By deriving from this class, using its methods to dermine the simulation state, and re-implementing applicable virtual methods, a fully DUSIME-aware class can be made, and objects of this class have coordinated start-stop abilities, the ability to calculate initial conditions and the ability for saving and restoring simulation state. A RTWModule can also store and restore RTW model state and parameters, from and to an xml description. This enables translation of states and parametersets between your DUECA simulation and the MATLAB workspace.

Constructor & Destructor Documentation

◆ RTWModule()

dueca::RTWModule::RTWModule ( Entity * e,
const char * m_class,
const char * part,
const IncoTable * table = NULL,
int state_size = 0 )
protected

Constructor.

Parameters
ePointer to my entity
m_classString with name of the module class
partString with part name
tablePointer to the table with initial condition calculation definitions. If this class does not take part in calculation of initial conditions (other than possibly sendin on data), this pointer may be NULL.
state_sizeSize of the state, as sent in a snapshot.

Member Function Documentation

◆ XmlSnapshotNow()

bool dueca::RTWModule::XmlSnapshotNow ( const TimeSpec & ts)

Returns true if an xml snapshot has to be taken in this cycle.

If this returns true, you should keep a copy of the continuous and/or discrete states of the RTW model, at a location of your discretion. This copy will later be sent with the sendXmlSnapshot call.

◆ fillXmlSnapshot()

virtual void dueca::RTWModule::fillXmlSnapshot ( const TimeSpec & ts,
XmlSnapshot & snap )
virtual

If xml snapshots are generated, this has to be implemented by a descendant.

The default implementation for this function is included when generating a new RTW module with the 'new-module' command, and subsequently xml functionality is selected. Currently this is functional for RTW version 5.0 and up.

Parameters
tsFor your reference, the time specification of the snapshot command
snapThe XmlSnapshot that has to be filled.

◆ loadXmlSnapshot()

virtual void dueca::RTWModule::loadXmlSnapshot ( const TimeSpec & ts,
const XmlSnapshot & snap )
virtual

For restoring state, model parameters, and initial inputs from a previously generated xml file.

This should take the snapshot data, unpack it (so keep aligned with the sendXmlSnapshot routine), and use this to replace the current state, parameters, and inputs. Note that the model will not be running at this time, so – if you don't touch your state in HoldCurrent, as you should not – this can run in parallel to the simulation without locking. Default implementation for this function is included in the rtw model template.


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