

PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 
java.lang.Object avrora.sim.FiniteStateMachine
The FiniteStateMachine
class represents a model of a finite state machine that
allows probing and monitoring the state of a device.
Nested Class Summary  
static interface 
FiniteStateMachine.Probe
The Probe interface allows observation of the state changes of a finite
state machine. 
protected class 
FiniteStateMachine.State
The State class represents a state of the finite state machine, including its
name as a String, the transition time to each of the other states, and a list of any
probes attached to this state. 
protected class 
FiniteStateMachine.TransitionEvent
The TransitionEvent class is used internally by the finite state machine for transitions
that take 1 more more clock cycles. 
Field Summary  
protected Clock 
clock

protected int 
curState

protected MulticastFSMProbe 
globalProbe

static int 
IN_TRANSITION

protected int 
numStates

protected int 
startState

protected FiniteStateMachine.State[] 
states

protected FiniteStateMachine.TransitionEvent 
transEvent

Constructor Summary  
FiniteStateMachine(Clock c,
int ss,
java.lang.String[] nm,
int tt)
This constructor for the FiniteStateMachine class creates a new finite state machine with
the number of states corresponding to the length of the array containing the names of the states. 

FiniteStateMachine(Clock c,
int ss,
java.lang.String[] nm,
int[][] ttm)
This constructor for the FiniteStateMachine class creates a new finite state machine with
the number of states corresponding to the length of the array containing the names of the states. 
Method Summary  
static int[][] 
buildBimodalTTM(int size,
int ds,
int[] tf,
int[] tt)
The buildBimodalTTM() method builds a transition time matrix
that corresponds to a finite state machine with two modes. 
static int[][] 
buildSparseTTM(int size,
int tt)
The buildSparseTTM() method builds a transition time matrix
that is uniform but sparse; the machine can transition from any state to any
other state with the given transition time. 
static int[][] 
buildUniformTTM(int size,
int tt)
The buildUniformTTM() method builds a transition time
matrix that is uniform; the machine can transition from any state to any other
state with the given transition time. 
Clock 
getClock()
The getClock() method gets the underlying clock driving the device. 
int 
getCurrentState()
The getCurrentState() method returns an integer that represents the state that the machine
is currently in. 
java.lang.String 
getCurrentStateName()
The getCurrentStateName() method retrieves the name for the current state. 
int 
getNumberOfStates()
The getNumberOfStates() method returns the total number of states that this machine
has. 
int 
getStartState()
The getStartState() method returns the state in which the machine starts operation. 
java.lang.String 
getStateName(int state)
The getStateName() method retrieves the name for the specified state. 
int 
getTransitionTime(int beforeState,
int afterState)
The getTransitionTime() method retrieves the transition time between the two states
specified from the transition time matrix. 
void 
insertProbe(FiniteStateMachine.Probe p)
The insertProbe() method allows the insertion of a probe for each state transition of this
finite state machine. 
void 
insertProbe(FiniteStateMachine.Probe p,
int state)
The insertProbe() method allows the insertion of a probe for transitions that involve a
particular state, either transitioning from this state or from this state. 
static int[][] 
newTTM(int size)
The newTTM() method is a utility function for building a new
transition time matrix. 
void 
removeProbe(FiniteStateMachine.Probe p)
The removeProbe() method removes a probe that has been inserted for all state transitions. 
void 
removeProbe(FiniteStateMachine.Probe p,
int state)
The removeProbe() method removes a probe that has been inserted for particular state transitions. 
static int[][] 
setCircularTTM(int[][] ttm,
int[] perm,
int[] tt)
The setCircularTTM() method builds a transition time matrix
that represents a finite state machine arranged in a ring; each state can transition
to one other state, wrapping around. 
static int[][] 
setDiagonal(int[][] ttm,
int diag)
The setDiagonal() method sets the diagonal of the given transition
time matrix to the specified value. 
void 
transition(int newState)
The transition() method transitions the machine from the current state to a new state.

Methods inherited from class java.lang.Object 
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait 
Field Detail 
public static final int IN_TRANSITION
protected final int numStates
protected final int startState
protected final Clock clock
protected final FiniteStateMachine.TransitionEvent transEvent
protected final MulticastFSMProbe globalProbe
protected FiniteStateMachine.State[] states
protected int curState
Constructor Detail 
public FiniteStateMachine(Clock c, int ss, java.lang.String[] nm, int tt)
FiniteStateMachine
class creates a new finite state machine with
the number of states corresponding to the length of the array containing the names of the states. The transition
time matrix is uniform, with all entries being initialized to the same specified value.
c
 the clock driving this finite state machiness
 the starting state of this machinenm
 an array of strings that name each of the states in this machinett
 the transition time for any state to any other statepublic FiniteStateMachine(Clock c, int ss, java.lang.String[] nm, int[][] ttm)
FiniteStateMachine
class creates a new finite state machine with
the number of states corresponding to the length of the array containing the names of the states. The
transition time matrix is specified explicitly. Note that this constructor DOES NOT copy the
transition time matrix, so care should be taken not to modify the transition time matrix after the
creation of this finite state machine.
c
 the clock that drives this finite state machiness
 the starting state of this machinenm
 an array of strings that name each of the states in this machinettm
 the transition time matrix for this machine; this matrix is NOT COPIED for internal use.Method Detail 
public void insertProbe(FiniteStateMachine.Probe p)
insertProbe()
method allows the insertion of a probe for each state transition of this
finite state machine.
p
 the probe to insert that will be called before and after each transition, including
selftransitions (transitions from one state to the same state)public void removeProbe(FiniteStateMachine.Probe p)
removeProbe()
method removes a probe that has been inserted for all state transitions.
p
 the probe to removepublic void insertProbe(FiniteStateMachine.Probe p, int state)
insertProbe()
method allows the insertion of a probe for transitions that involve a
particular state, either transitioning from this state or from this state.
p
 the probe to insert that will be called before and after each transition to or from the
specified state, including selftransitions (transitions from this state to the same state)state
 the state for which to insert the probepublic void removeProbe(FiniteStateMachine.Probe p, int state)
removeProbe()
method removes a probe that has been inserted for particular state transitions.
p
 the probe to removestate
 the state for which to remove this probepublic int getNumberOfStates()
getNumberOfStates()
method returns the total number of states that this machine
has.
public int getStartState()
getStartState()
method returns the state in which the machine starts operation.
public int getCurrentState()
getCurrentState()
method returns an integer that represents the state that the machine
is currently in. If the machine is current in transition between two states, this method will return
the value IN_TRANSITION
public void transition(int newState)
transition()
method transitions the machine from the current state to a new state.
This transition is only legal if the corresponding entry in the transition time matrix is nonnegative.
This method should only be called by the "controller" of the machine, and not by clients interested
in probing the state of the device. If the transition time matrix for this transition is greater than
zero, then this method will change the state to IN_TRANSITION
and insert a transition
event into the queue of the underlying clock for this device. That event will complete the transition.
This method will not allow any transitions when the machine is already in transition.
newState
 the new state to transition to
Avrora.InternalError
 if it is illegal to transition between the current state and the new state
according to the transition time matrix; or if the machine is already in a transitional statepublic int getTransitionTime(int beforeState, int afterState)
getTransitionTime()
method retrieves the transition time between the two states
specified from the transition time matrix.
beforeState
 the state transitioning fromafterState
 the state transitioning to
public java.lang.String getStateName(int state)
getStateName()
method retrieves the name for the specified state.
state
 the state to get the string name for
public java.lang.String getCurrentStateName()
getCurrentStateName()
method retrieves the name for the current state.
public Clock getClock()
getClock()
method gets the underlying clock driving the device.
public static int[][] buildUniformTTM(int size, int tt)
buildUniformTTM()
method builds a transition time
matrix that is uniform; the machine can transition from any state to any other
state with the given transition time.
size
 the size of the transition time matrixtt
 the transition time for each edge
public static int[][] buildSparseTTM(int size, int tt)
buildSparseTTM()
method builds a transition time matrix
that is uniform but sparse; the machine can transition from any state to any
other state with the given transition time. However, the internal representation
shares the underlying integer arrays, avoiding large space overhead. Due to this
storage sharing, DO NOT ATTEMPT TO UPDATE THE SPARSE TTM AFTER CONSTRUCTING IT
UNLESS YOU UNDERSTAND THAT ALL ROWS WILL BE THE SAME.
size
 the size of the matrixtt
 the transition time for each edge.
public static int[][] buildBimodalTTM(int size, int ds, int[] tf, int[] tt)
buildBimodalTTM()
method builds a transition time matrix
that corresponds to a finite state machine with two modes. One special state
is the "default" state. The machine can transition from the default state to
any other state, and from any other state back to the default state, but not
between any other two states.
size
 the size of the transition time matrixds
 the default statetf
 the transition times from each state back to the default statett
 the transition times from the default state to each other state
public static int[][] setCircularTTM(int[][] ttm, int[] perm, int[] tt)
setCircularTTM()
method builds a transition time matrix
that represents a finite state machine arranged in a ring; each state can transition
to one other state, wrapping around. For example, a finite state machine of consisting
of states S1, S2, and S3 could have a cycle S1 > S2 > S3 > S1.
ttm
 the original transition time matrixperm
 an array of integers representing the order of the state transitions in
the ringtt
 the transition time between the corresponding states in the ring
public static int[][] newTTM(int size)
newTTM()
method is a utility function for building a new
transition time matrix. It will create a new transition time matrix (TTM) where
each entry is 1
, indicating that there are no legal state transitions.
size
 the size of matrix, i.e. the number of rows, which is equal to the
number of columns
public static int[][] setDiagonal(int[][] ttm, int diag)
setDiagonal()
method sets the diagonal of the given transition
time matrix to the specified value. This is useful for finite state machines where
transitions from one state to the same state is either impossible or a noop.
ttm
 the original transition time matrixdiag
 the value to set the diagonal entries to


PREV CLASS NEXT CLASS  FRAMES NO FRAMES  
SUMMARY: NESTED  FIELD  CONSTR  METHOD  DETAIL: FIELD  CONSTR  METHOD 