jaron.flightgear
Class FlightGearReceiver

java.lang.Object
  extended by java.lang.Thread
      extended by jaron.flightgear.FlightGearReceiver
All Implemented Interfaces:
java.lang.Runnable

public class FlightGearReceiver
extends java.lang.Thread

The FlightGearReceiver class provides a TCP/IP connection to the FlightGear flight simulator (FG) via the FG generic output interface.
FlightGearReceiver runs as a thread and by instantiating it waits for the incoming connection of FG (at port 5555 by default).
The instantiating has to be done before FG starts up, else FG reports a connection error and terminates.
At the moment the FlightGearReceiver is limited to receiving numeric data.
Be aware that running FG and a Java application that uses the FlightGearReceiver needs a computer with sufficient performance. The consequence of a lack of performance is, that some of the data sent by FG could be lost because of timing issues. In this case you could run FG and the Java application on two different machines via a network connection.

Since:
1.0
Version:
1.2
Author:
jarontec gmail com

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static int DEFAULT_PORT
          The default port that is used for the incoming connection.
static float DEFAULT_UPDATE_FREQUENCY
          The default update frequency of the FlightGearReceiver is 10.0fHz.
static java.lang.String kAileron
          A string constant that is used to reference a FG XML ouput value.
static java.lang.String kAirSpeed
          A string constant that is used to reference a FG XML ouput value.
static java.lang.String kAltitude
          A string constant that is used to reference a FG XML ouput value.
static java.lang.String kElevator
          A string constant that is used to reference a FG XML ouput value.
static java.lang.String kPitch
          A string constant that is used to reference a FG XML ouput value.
static java.lang.String kPitchRate
          A string constant that is used to reference a FG XML ouput value.
static java.lang.String kRoll
          A string constant that is used to reference a FG XML ouput value.
static java.lang.String kRollRate
          A string constant that is used to reference a FG XML ouput value.
static java.lang.String kRudder
          A string constant that is used to reference a FG XML ouput value.
static java.lang.String kThrottle
          A string constant that is used to reference a FG XML ouput value.
static java.lang.String kVerticalSpeed
          A string constant that is used to reference a FG XML ouput value.
static java.lang.String kYawRate
          A string constant that is used to reference a FG XML ouput value.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
FlightGearReceiver()
          Creates a new FlightGearReceiver and starts a Thread that listens for incoming connections.
FlightGearReceiver(int port)
          Creates a new FlightGearReceiver and starts a Thread that listens for incoming connections.
 
Method Summary
 void addSignalListener(java.lang.String key, SignalListener listener)
          Adds a listener to a FlightGear (FG) signal that is identified by a key.
 void run()
           
 void setDebug(java.lang.Boolean debug)
          Sets the debugging flag which determines if the debugging informations should be printed to the console.
 void setUpdateFrequency(float updateFrequency)
          Sets the update frequency for the FlightGearReceiver.
 void shutDown()
          Shuts this receiver down and disconnects the client.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_UPDATE_FREQUENCY

public static final float DEFAULT_UPDATE_FREQUENCY
The default update frequency of the FlightGearReceiver is 10.0fHz.

See Also:
Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
The default port that is used for the incoming connection. At the moment this is port 5555 but this could change in the future.

See Also:
Constant Field Values

kElevator

public static final java.lang.String kElevator
A string constant that is used to reference a FG XML ouput value.

See Also:
Constant Field Values

kAileron

public static final java.lang.String kAileron
A string constant that is used to reference a FG XML ouput value.

See Also:
Constant Field Values

kRudder

public static final java.lang.String kRudder
A string constant that is used to reference a FG XML ouput value.

See Also:
Constant Field Values

kThrottle

public static final java.lang.String kThrottle
A string constant that is used to reference a FG XML ouput value.

See Also:
Constant Field Values

kPitch

public static final java.lang.String kPitch
A string constant that is used to reference a FG XML ouput value.

See Also:
Constant Field Values

kRoll

public static final java.lang.String kRoll
A string constant that is used to reference a FG XML ouput value.

See Also:
Constant Field Values

kPitchRate

public static final java.lang.String kPitchRate
A string constant that is used to reference a FG XML ouput value.

See Also:
Constant Field Values

kRollRate

public static final java.lang.String kRollRate
A string constant that is used to reference a FG XML ouput value.

See Also:
Constant Field Values

kYawRate

public static final java.lang.String kYawRate
A string constant that is used to reference a FG XML ouput value.

See Also:
Constant Field Values

kAirSpeed

public static final java.lang.String kAirSpeed
A string constant that is used to reference a FG XML ouput value.

See Also:
Constant Field Values

kVerticalSpeed

public static final java.lang.String kVerticalSpeed
A string constant that is used to reference a FG XML ouput value.

See Also:
Constant Field Values

kAltitude

public static final java.lang.String kAltitude
A string constant that is used to reference a FG XML ouput value.

See Also:
Constant Field Values
Constructor Detail

FlightGearReceiver

public FlightGearReceiver(int port)
Creates a new FlightGearReceiver and starts a Thread that listens for incoming connections.

Parameters:
port - the port the receiver listens to

FlightGearReceiver

public FlightGearReceiver()
Creates a new FlightGearReceiver and starts a Thread that listens for incoming connections. It listens on the default port DEFAULT_PORT.

See Also:
DEFAULT_PORT
Method Detail

addSignalListener

public void addSignalListener(java.lang.String key,
                              SignalListener listener)
Adds a listener to a FlightGear (FG) signal that is identified by a key. The key is the designator that is used in the FG configuration file for a certain output data.
In case of a change of the signal's value, all the listeners are informed through the EventListener mechanism.

Parameters:
key - a string that identifies the FG ouput data
listener - the listener to be added
See Also:
SignalListener

setUpdateFrequency

public void setUpdateFrequency(float updateFrequency)
Sets the update frequency for the FlightGearReceiver. The default update frequency is set to 10.0fHz.

Parameters:
updateFrequency - the new frequency in Hz

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

setDebug

public void setDebug(java.lang.Boolean debug)
Sets the debugging flag which determines if the debugging informations should be printed to the console. This is for debugging purpose only.

Parameters:
debug - set to true if additional debugging information should be printed

shutDown

public void shutDown()
Shuts this receiver down and disconnects the client.