COSA
An Object-Oriented Platform for Arduino Programming
FSM Class Reference

#include <FSM.hh>

Inheritance diagram for FSM:
Inheritance graph
Collaboration diagram for FSM:
Collaboration graph

Public Types

typedef bool(* StateHandler) (FSM *fsm, uint8_t type)
 

Public Member Functions

 FSM (StateHandler init, Job::Scheduler *scheduler=NULL, uint16_t period=0)
 
void state (StateHandler fn)
 
StateHandler state () const
 
void period (uint8_t ms)
 
void get (uint16_t &param) const
 
void get (void *&param) const
 
void send (uint8_t type, uint16_t value=0)
 
void send (uint8_t type, void *value)
 
bool begin ()
 
void end ()
 
void set_timer (uint16_t ms)
 
void cancel_timer ()
 

Protected Member Functions

void expire_at (uint32_t time)
 
uint32_t expire_at () const
 
void expire_after (uint32_t time)
 
int32_t expire_after () const
 
uint32_t time () const
 
bool is_started () const
 
bool start ()
 
bool stop ()
 
virtual void on_expired ()
 
virtual void run ()
 
void detach ()
 
Linkagesucc () const
 
Linkagepred () const
 
void attach (Linkage *pred)
 

Protected Attributes

uint32_t m_expires
 
Schedulerm_scheduler
 
Linkagem_succ
 
Linkagem_pred
 

Detailed Description

Finite State Machine support class. States are represented as an Event handler. Supports timeout events and period timed state machines.

Acknowledgements

The design of FSM is inspired by UML-2 State Machines, QP by Miro Samek, and ObjecTime by Brian Selic.

Definition at line 37 of file FSM.hh.

Member Typedef Documentation

typedef bool(* FSM::StateHandler) (FSM *fsm, uint8_t type)

State handler function prototype. Should return true(1) if the event was handled otherwise false(0). This allows common and hierarchical state handlers.

Parameters
[in]fsmfinite state machine.
[in]typethe type of event.
Returns
bool.

Definition at line 47 of file FSM.hh.

Constructor & Destructor Documentation

FSM::FSM ( StateHandler  init,
Job::Scheduler scheduler = NULL,
uint16_t  period = 0 
)
inline

Construct state machine with given initial state.

Parameters
[in]initinitial state handler.
[in]schedulerfor timeout handling (default no timout handling).
[in]periodtimeout in all states (default no timeout).

Definition at line 55 of file FSM.hh.

Member Function Documentation

void Linkage::attach ( Linkage pred)
inlineinherited

Attach given linkage as predecessor. Will check and detach if already attached.

Parameters
[in]predlinkage to attach.
Note
atomic

Definition at line 71 of file Linkage.hh.

bool FSM::begin ( )
inline

Start the state machine with an Event::BEGIN_TYPE.

Definition at line 135 of file FSM.hh.

void FSM::cancel_timer ( )
inline

Cancel a timer request. This is performed by default on a timeout event.

Definition at line 170 of file FSM.hh.

void Link::detach ( )
inlineinherited

Detach this link. Unlink from any list.

Definition at line 125 of file Linkage.hh.

void FSM::end ( )
inline

End the state machine with an Event::END_TYPE.

Definition at line 148 of file FSM.hh.

void Job::expire_after ( uint32_t  time)
inlineinherited

Set expire time relative to latest expire time.

Parameters
[in]timeto add to latest expire time.

Definition at line 111 of file Job.hh.

int32_t Job::expire_after ( ) const
inlineinherited

Get time remaining before expired.

Returns
time.

Definition at line 129 of file Job.hh.

void Job::expire_at ( uint32_t  time)
inlineinherited

Set expire time. Absolute time in scheduler time unit.

Parameters
[in]timeto expire.

Definition at line 102 of file Job.hh.

uint32_t Job::expire_at ( ) const
inlineinherited

Get expire time.

Returns
time.

Definition at line 120 of file Job.hh.

void FSM::get ( uint16_t &  param) const
inline

Get event parameter.

Parameters
[out]paramevent parameter

Definition at line 96 of file FSM.hh.

void FSM::get ( void *&  param) const
inline

Get event parameter.

Parameters
[out]paramevent parameter

Definition at line 105 of file FSM.hh.

bool Job::is_started ( ) const
inlineinherited

Return true(1) if the job is queued otherwise false(0).

Returns
bool.

Definition at line 149 of file Job.hh.

virtual void Job::on_expired ( )
inlinevirtualinherited

Job member function that is called Scheduler::dispatch() when the job time has expired. This function is normally called from an interrupt service routine. The default implementation will push a timeout event with the job as target. The default event handler will call the job run() virtual member function. Override this function if the job should be executed during the interrupt service routine.

Definition at line 185 of file Job.hh.

void FSM::period ( uint8_t  ms)
inline

Set timeout period for all states.

Parameters
[in]mstimeout.

Definition at line 87 of file FSM.hh.

Linkage* Linkage::pred ( ) const
inlineinherited

Return predecessor in sequence.

Returns
predecessor linkage.

Definition at line 60 of file Linkage.hh.

virtual void Job::run ( )
inlinevirtualinherited

The job run() virtual member function; sub-class should define. Called by the scheduler (via event handler) when the time expires. May set an new expire time and start the job again, or even start other jobs.

Reimplemented in Button, Keypad, and Touch.

Definition at line 210 of file Job.hh.

void FSM::send ( uint8_t  type,
uint16_t  value = 0 
)
inline

Send an event to the state machine.

Parameters
[in]typethe type of event.
[in]valuethe event value.

Definition at line 115 of file FSM.hh.

void FSM::send ( uint8_t  type,
void *  value 
)
inline

Send an event to the state machine.

Parameters
[in]typethe type of event.
[in]valuethe event value.

Definition at line 126 of file FSM.hh.

void FSM::set_timer ( uint16_t  ms)
inline

Set timer for time out events and possible state transitions.

Parameters
[in]mstimeout period.

Definition at line 158 of file FSM.hh.

bool Job::start ( )
inlineinherited

Start the job. Returns true(1) if scheduled otherwise false(0).

Returns
bool.

Definition at line 159 of file Job.hh.

void FSM::state ( StateHandler  fn)
inline

Set new state handler for next event.

Parameters
[in]fnstate handler.
Precondition
fn != NULL

Definition at line 67 of file FSM.hh.

StateHandler FSM::state ( ) const
inline

Get state handler for next event.

Definition at line 77 of file FSM.hh.

bool Job::stop ( )
inlineinherited

Stop the job. Returns true(1) if scheduled otherwise false(0).

Returns
bool.

Definition at line 169 of file Job.hh.

Linkage* Linkage::succ ( ) const
inlineinherited

Return successor in sequence.

Returns
successor linkage.

Definition at line 51 of file Linkage.hh.

uint32_t Job::time ( ) const
inlineinherited

Get current scheduler time. May be used to set relative expire time.

Returns
time.

Definition at line 139 of file Job.hh.

Member Data Documentation

uint32_t Job::m_expires
protectedinherited

Expire time. Scale (us, ms, s) depends on scheduler.

Definition at line 214 of file Job.hh.

Linkage* Linkage::m_pred
protectedinherited

Definition at line 94 of file Linkage.hh.

Scheduler* Job::m_scheduler
protectedinherited

Job scheduler.

Definition at line 217 of file Job.hh.

Linkage* Linkage::m_succ
protectedinherited

Double linked list pointers.

Definition at line 93 of file Linkage.hh.


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