ptolemy.actor.kiel
Class ModelRailwayIO

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.InstantiableNamedObj
          extended by ptolemy.kernel.Entity
              extended by ptolemy.kernel.ComponentEntity
                  extended by ptolemy.actor.AtomicActor
                      extended by ptolemy.actor.TypedAtomicActor
                          extended by ptolemy.actor.kiel.ModelRailwayIO
All Implemented Interfaces:
Serializable, Cloneable, ptolemy.actor.Actor, ptolemy.actor.Executable, ptolemy.actor.FiringsRecordable, ptolemy.actor.Initializable, ptolemy.actor.TypedActor, ptolemy.kernel.util.Changeable, ptolemy.kernel.util.Debuggable, ptolemy.kernel.util.DebugListener, ptolemy.kernel.util.Derivable, ptolemy.kernel.util.Instantiable, ptolemy.kernel.util.ModelErrorHandler, ptolemy.kernel.util.MoMLExportable, ptolemy.kernel.util.Moveable, ptolemy.kernel.util.Nameable

public class ModelRailwayIO
extends ptolemy.actor.TypedAtomicActor

Interacts with the Model Railway (and its simulation) of the Department of Computer Science of Kiel University, Germany. The Model Railway can be found here: http://www.informatik.uni-kiel.de/~railway/ The simulation of the Model Railway can be found here: http://rtsys.informatik.uni-kiel.de/~biblio/downloads/theses/cmot-st.pdf Input track, point and signal commands as RecordTokens of the following form: port={track2={motormode=1,speed=100}} where motormode can be off(0), primary(1), secondary(2) or brake(3) DEFAULT is primary(1) and speed is a value between 0 .. 100 DEFAULT is 0 port={point2={turn=0}} where a turn value of 0 indicates straight and a turn value of 1 indicates turn position DEFAULT is straight(0) port={signal2a={lights=2}} where a means first and b means second in default driving direction of the selected track (here 2) and lights can be off(0), red(1), yellowgreen(2), green(4) DEFAULT is red(1) Output of this actor are two ArrayTokens contact and occupied that can be used to obtain information about the triggered reed contacts or the occupied track segments with the following meaning of values: contact: not triggered(-1), triggered first(0) and triggered second(1) in default driving direction occupied: not occupied(0) or occupied(1)

Since:
Ptolemy II 0.2
See Also:
Serialized Form
Pt.AcceptedRating:
Red (cmot)
Rating red

Nested Class Summary
 class ModelRailwayIO.RailwayInterface
           
 
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
ptolemy.kernel.Entity.ContainedObjectsIterator
 
Field Summary
 ptolemy.actor.TypedIOPort contact
          This will hold ArrayTokens of reed contact values of not triggered(-1), triggered first(0) and triggered second(1) in default driving direction
 ptolemy.data.expr.Parameter host
          The host and port to make the connection to, i.e., where the Model Railway interface program is running.
 ptolemy.actor.TypedIOPort occupied
          This will hold ArrayTokens of occupied values of not occupied(0) or occupied(1)
 ptolemy.actor.TypedIOPort points
          Set a point using RecordTokens like port={point21={turn=0}} where a turn value of 0 indicates straight and a turn value of 1 indicates turn position DEFAULT is straight(0)
 ptolemy.data.expr.Parameter port
           
 ptolemy.actor.TypedIOPort signals
          Set a signal using RecordTokens like port={signal2a={lights=2}} where a means first and b second signal in default driving direction of the selected track (here 2) and lights can be off(0), red(1), yellowgreen(2), green(4) DEFAULT is red(1)
 ptolemy.actor.TypedIOPort tracks
          Set the speed of some tracks using RecordTokens like port={track5={motormode=1,speed=100} where motormode can be off(0), primary(1), secondary(2) or brake(3) DEFAULT is primary(1) and speed is a value between 0 ..
 ptolemy.actor.TypedIOPort trigger
          This may trigger the actor in a DE domain.
 
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
 
Constructor Summary
ModelRailwayIO(ptolemy.kernel.CompositeEntity container, String name)
          Construct an actor with the given container and name.
 
Method Summary
 void fire()
          Collect the trigger Token first, then process possible speed, point or signal commands.
 void initialize()
          Set the RailwayInterface and open a TCP connection to the Model Railway interface program w/ the given host and port parameters.
 void wrapup()
          Terminate the TCP connection of the Model Railway interface.
 
Methods inherited from class ptolemy.actor.TypedAtomicActor
_addPort, _fireAt, _fireAt, attributeTypeChanged, clone, newPort, typeConstraintList, typeConstraints
 
Methods inherited from class ptolemy.actor.AtomicActor
_actorFiring, _actorFiring, addActorFiringListener, addInitializable, clone, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, setContainer, stop, stopFire, terminate
 
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
 
Methods inherited from class ptolemy.kernel.Entity
_description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
 
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
 
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
 
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable
 
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
 
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
 

Field Detail

host

public ptolemy.data.expr.Parameter host
The host and port to make the connection to, i.e., where the Model Railway interface program is running. Often this is set to the string value 'localhost' for the host and 2000 for the port.


port

public ptolemy.data.expr.Parameter port

trigger

public ptolemy.actor.TypedIOPort trigger
This may trigger the actor in a DE domain.


tracks

public ptolemy.actor.TypedIOPort tracks
Set the speed of some tracks using RecordTokens like port={track5={motormode=1,speed=100} where motormode can be off(0), primary(1), secondary(2) or brake(3) DEFAULT is primary(1) and speed is a value between 0 .. 100 DEFAULT is 0


points

public ptolemy.actor.TypedIOPort points
Set a point using RecordTokens like port={point21={turn=0}} where a turn value of 0 indicates straight and a turn value of 1 indicates turn position DEFAULT is straight(0)


signals

public ptolemy.actor.TypedIOPort signals
Set a signal using RecordTokens like port={signal2a={lights=2}} where a means first and b second signal in default driving direction of the selected track (here 2) and lights can be off(0), red(1), yellowgreen(2), green(4) DEFAULT is red(1)


contact

public ptolemy.actor.TypedIOPort contact
This will hold ArrayTokens of reed contact values of not triggered(-1), triggered first(0) and triggered second(1) in default driving direction


occupied

public ptolemy.actor.TypedIOPort occupied
This will hold ArrayTokens of occupied values of not occupied(0) or occupied(1)

Constructor Detail

ModelRailwayIO

public ModelRailwayIO(ptolemy.kernel.CompositeEntity container,
                      String name)
               throws ptolemy.kernel.util.NameDuplicationException,
                      ptolemy.kernel.util.IllegalActionException
Construct an actor with the given container and name. In addition to invoking the base class constructors, construct the host and port parameters, the speed, point and signal input ports and the contact and occupied output ports. Initialize host to StringToken with value 'localhost', and port to IntToken with value 2000.

Parameters:
container - The container.
name - The name of this actor.
Throws:
ptolemy.kernel.util.IllegalActionException - If the actor cannot be contained by the proposed container.
ptolemy.kernel.util.NameDuplicationException - If the container already has an actor with this name.
Method Detail

fire

public void fire()
          throws ptolemy.kernel.util.IllegalActionException
Collect the trigger Token first, then process possible speed, point or signal commands. After that collect the reed contact values to an ArrayToken. Also do this for the occupied track states.

Specified by:
fire in interface ptolemy.actor.Executable
Overrides:
fire in class ptolemy.actor.AtomicActor
Throws:
ptolemy.kernel.util.IllegalActionException - If calling send() or super.fire() throws it.

initialize

public void initialize()
                throws ptolemy.kernel.util.IllegalActionException
Set the RailwayInterface and open a TCP connection to the Model Railway interface program w/ the given host and port parameters.

Specified by:
initialize in interface ptolemy.actor.Initializable
Overrides:
initialize in class ptolemy.actor.AtomicActor
Throws:
ptolemy.kernel.util.IllegalActionException - If the parent class throws it.

wrapup

public void wrapup()
            throws ptolemy.kernel.util.IllegalActionException
Terminate the TCP connection of the Model Railway interface. Set RI object to null so that for the next execution a new connection will be made.

Specified by:
wrapup in interface ptolemy.actor.Initializable
Overrides:
wrapup in class ptolemy.actor.AtomicActor
Throws:
ptolemy.kernel.util.IllegalActionException - Not thrown in this base class.