|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--org.flightgear.fgfsclient.FGFSConnection
A connection to a running instance of FlightGear.
This class currently uses the FlightGear telnet interface, though it may be modified to use a different TCP/IP interface in the future. Client applications can use this library to examine and modify internal FlightGear properties.
To start FlightGear with the telnet server activated, use a command like this (to listen on port 9000):
fgfs --telnet=9000
Then create a connection to FlightGear from your Java client application:
FGFSConnection fgfs = new FGFSConnection("localhost", 9000);
Now you can use the connection to get and set FlightGear properties:
double altitude = fgfs.getDouble("/position/altitude-ft");
fgfs.setDouble("/orientation/heading", 270.0);
All methods that communicate directly with FlightGear are synchronized, since they must work over a single telnet connection.
| Constructor Summary | |
FGFSConnection(String host,
int port)
Constructor. |
|
| Method Summary | |
void |
close()
Close the connection to FlightGear. |
String |
get(String name)
Get the raw string value for a property. |
boolean |
getBoolean(String name)
Get a property value as a boolean. |
double |
getDouble(String name)
Get a property value as a double. |
float |
getFloat(String name)
Get a property value as a float. |
int |
getInt(String name)
Get a property value as an integer. |
long |
getLong(String name)
Get a property value as a long. |
void |
set(String name,
String value)
Set the raw string value for a property. |
void |
setBoolean(String name,
boolean value)
Set a property value from a boolean. |
void |
setDouble(String name,
double value)
Set a property value from a double. |
void |
setFloat(String name,
float value)
Set a property value from a float. |
void |
setInt(String name,
int value)
Set a property value from an int. |
void |
setLong(String name,
long value)
Set a property value from a long. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public FGFSConnection(String host,
int port)
throws IOException
Create a new connection to a running FlightGear program. The program must have been started with the --telnet=<port> command-line option.
host - The host name or IP address to connect to.port - The port number where FlightGear is listening.IOException - If it is not possible to connect to
a FlightGear process.| Method Detail |
public void close()
throws IOException
The client application should always invoke this method when it has finished with a connection, to allow cleanup.
IOException - If there is an error closing the
connection.
public String get(String name)
throws IOException
This is the primitive method for all property lookup;
everything comes in as a string, and is only later converted by
methods like getDouble(String). As a result, if you
need the value as a string anyway, it makes sense to use this
method directly rather than forcing extra conversions.
name - The FlightGear property name to look up.IOException - If there is an error communicating with
FlightGear or if the connection is lost.getBoolean(String),
getInt(String),
getLong(String),
getFloat(String),
getDouble(String)
public void set(String name,
String value)
throws IOException
This is the primitive method for all property modification;
everything goes out as a string, after it has been converted by
methods like setDouble(String,double). As a result, if
you have the value as a string already, it makes sense to use
this method directly rather than forcing extra conversions.
name - The FlightGear property name to modify or create.value - The new value for the property, as a string.IOException - If there is an error communicating with
FlightGear or if the connection is lost.setBoolean(String,boolean),
setInt(String,int),
setLong(String,long),
setFloat(String,float),
setDouble(String,double)
public boolean getBoolean(String name)
throws IOException
name - The property name to look up.get(String)
public int getInt(String name)
throws IOException
name - The property name to look up.get(String)
public long getLong(String name)
throws IOException
name - The property name to look up.get(String)
public float getFloat(String name)
throws IOException
name - The property name to look up.get(String)
public double getDouble(String name)
throws IOException
name - The property name to look up.get(String)
public void setBoolean(String name,
boolean value)
throws IOException
name - The property name to create or modify.value - The new property value as a boolean.set(String,String)
public void setInt(String name,
int value)
throws IOException
name - The property name to create or modify.value - The new property value as an int.set(String,String)
public void setLong(String name,
long value)
throws IOException
name - The property name to create or modify.value - The new property value as a long.set(String,String)
public void setFloat(String name,
float value)
throws IOException
name - The property name to create or modify.value - The new property value as a float.set(String,String)
public void setDouble(String name,
double value)
throws IOException
name - The property name to create or modify.value - The new property value as a double.set(String,String)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||