ptolemy.actor.kiel
Class ModelRailwayIO

java.lang.Object
  extended by TypedAtomicActor
      extended by ptolemy.actor.kiel.ModelRailwayIO

public class ModelRailwayIO
extends 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
Pt.AcceptedRating:
Red (cmot)
Rating red

Nested Class Summary
 class ModelRailwayIO.RailwayInterface
           
 
Field Summary
 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
 Parameter host
          The host and port to make the connection to, i.e., where the Model Railway interface program is running.
 TypedIOPort occupied
          This will hold ArrayTokens of occupied values of not occupied(0) or occupied(1)
 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)
 Parameter port
           
 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)
 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 ..
 TypedIOPort trigger
          This may trigger the actor in a DE domain.
 
Constructor Summary
ModelRailwayIO(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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

host

public 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 Parameter port

trigger

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


tracks

public 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 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 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 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 TypedIOPort occupied
This will hold ArrayTokens of occupied values of not occupied(0) or occupied(1)

Constructor Detail

ModelRailwayIO

public ModelRailwayIO(CompositeEntity container,
                      String name)
               throws NameDuplicationException,
                      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:
IllegalActionException - If the actor cannot be contained by the proposed container.
NameDuplicationException - If the container already has an actor with this name.
Method Detail

fire

public void fire()
          throws 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.

Throws:
IllegalActionException - If calling send() or super.fire() throws it.

initialize

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

Throws:
IllegalActionException - If the parent class throws it.

wrapup

public void wrapup()
            throws 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.

Throws:
IllegalActionException - Not thrown in this base class.