org.iu.gps
Class GPSDriver

java.lang.Object
  |
  +--org.iu.gps.GPSDriver
All Implemented Interfaces:
java.lang.Runnable

public class GPSDriver
extends java.lang.Object
implements java.lang.Runnable

This class realizes access to GPS devices over a serial line (NMEA0183 message format). GPSDriver has the following features: - auto-detection of the GPS device's serial line - logging of GPS information into a file - playback of previously logged GPS information (application transparent; application thinks data comes from GPS)


Constructor Summary
GPSDriver()
          Creates a close GPSDriver instance.
GPSDriver(java.lang.String port, int baudRate)
          Creates a new GPSDriver instance, open and listening on the given serial port with the specified baudRate.
 
Method Summary
 void addGPSListener(GPSListener gl)
          Add new GPS listener.
 void close()
          Close the GPS device.
static org.iu.gps.GPSDriver.Configuration detect()
          Tries to find the serial line + baudRate to which a GPS is connected to.
 void disableHardware()
          Disables GPS hardware reporting.
 void disableLogging()
          Disable logging.
 void disableRawLogging()
          Stops logging process.
 void disableReplay()
          Disables replay mode.
 void enableHardware()
          Enables GPS hardware reporting.
 void enableLogging(java.io.OutputStream s)
          Enables logging current GPS data into a stream.
 void enableRawLogging(java.io.OutputStream s)
          Start logging GPS information into the given output stream (usually a FileOutputStream will be used).
 void enableReplay(java.io.InputStream logStream)
          Enables replay from a previously logged stream.
static int[] getBaudrateList()
          Returns the list of all known baud rates.
 org.iu.gps.GPSDriver.Configuration getConfiguration()
          Return the current GPS configuration.
 GPSInfo getGPSInfo()
          Obtain the current GPS information.
static java.lang.String[] getPortList()
          Returns the list of all known serial ports.
 void gpsThread()
          Method
 boolean isAlive()
          Checks if the GPS is alive according to the following definition: There have been more than 5 valid NMEA messages on the current serial line.
 void logThread()
          Method
static void main(java.lang.String[] arg)
          The main program for the GPSDriver class
static void normGPSInfo(GPSInfo gi)
          Normalize GPS Information: convert from degrees/minutes to degrees only representation, convert from the GPS ellipsoid, and fill in the GaussKrueger coordinates
static double normLatLong(double c)
          Method
 void open(org.iu.gps.GPSDriver.Configuration cfg)
          Open the GPSDevice using the given configuration.
 void open(java.io.InputStream logStream)
          Open GPSDevice using an input stream to replay logged GPS information.
 void removeGPSListener(GPSListener gl)
          Remove GPS listener.
 void replayThread()
          Method
 void run()
          Main thread.
 void setSimulationInfo(GPSInfo gi)
          Simulate a GPS device that returns the given GPSInfo.
 void setSimulationPosition(double lat, double lon)
          Sets the current GPSInfo to the given position.
 void setupGPS(java.lang.String port, int baudRate)
          Setup the GPS hardware.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GPSDriver

public GPSDriver(java.lang.String port,
                 int baudRate)
          throws java.lang.Exception
Creates a new GPSDriver instance, open and listening on the given serial port with the specified baudRate.
Parameters:
port - Symbolic name of serial port to listen on (/dev/ttySX on UN*X, or COMx: on Win32)
baudRate - Baudrate to use in communication with the GPS device
Throws:
java.lang.Exception - Exception
java.lang.Exception - Throws various exceptions if comm. cannot be established, or if the port does not exist.

GPSDriver

public GPSDriver()
Creates a close GPSDriver instance.
Method Detail

getPortList

public static java.lang.String[] getPortList()
Returns the list of all known serial ports.
Returns:
List of ports.

getBaudrateList

public static int[] getBaudrateList()
Returns the list of all known baud rates.
Returns:
List of Baud rates.

main

public static void main(java.lang.String[] arg)
                 throws java.lang.Exception
The main program for the GPSDriver class
Parameters:
arg - The command line arguments
Throws:
java.lang.Exception - Exception

detect

public static org.iu.gps.GPSDriver.Configuration detect()
Tries to find the serial line + baudRate to which a GPS is connected to.
Returns:
GPS configuration, or null if no GPS was found.

normGPSInfo

public static void normGPSInfo(GPSInfo gi)
Normalize GPS Information: convert from degrees/minutes to degrees only representation, convert from the GPS ellipsoid, and fill in the GaussKrueger coordinates
Parameters:
gi - GPSInfo to normalize.

normLatLong

public static double normLatLong(double c)
Method
Parameters:
c - Parameter
Returns:
Returned Value

setSimulationInfo

public void setSimulationInfo(GPSInfo gi)
Simulate a GPS device that returns the given GPSInfo. Note: Disables hardware and replay modes.
Parameters:
gi - GPSInfo to use.

setSimulationPosition

public void setSimulationPosition(double lat,
                                  double lon)
Sets the current GPSInfo to the given position. The rest of the GPSInfo fields are set to default values. Note: This is a convenience method for setSimulationInfo(...)
Parameters:
lat - Latitude to use for simulation.
lon - Longitude to use for simulation.

setupGPS

public void setupGPS(java.lang.String port,
                     int baudRate)
              throws java.lang.Exception
Setup the GPS hardware.
Parameters:
port - Serial port.
baudRate - Baud rate of GPS device.
Throws:
java.lang.Exception -  

getConfiguration

public org.iu.gps.GPSDriver.Configuration getConfiguration()
Return the current GPS configuration.
Returns:
Configuration

isAlive

public boolean isAlive()
Checks if the GPS is alive according to the following definition: There have been more than 5 valid NMEA messages on the current serial line. This method can be used to search for the serial port.
Returns:
True if GPS is alive, false otherwise.

getGPSInfo

public GPSInfo getGPSInfo()
Obtain the current GPS information.
Returns:
GPS information.

open

public void open(org.iu.gps.GPSDriver.Configuration cfg)
          throws java.lang.Exception
Open the GPSDevice using the given configuration.
Parameters:
cfg - Configuration.
Throws:
java.lang.Exception - If comm. to GPS cannot be established.

open

public void open(java.io.InputStream logStream)
          throws java.lang.Exception
Open GPSDevice using an input stream to replay logged GPS information.
Parameters:
logStream - Input stream with logged GPS information.
Throws:
java.lang.Exception - If the stream is in error.

enableReplay

public void enableReplay(java.io.InputStream logStream)
                  throws java.lang.Exception
Enables replay from a previously logged stream. Automatically detects raw and our internal log formats.
Parameters:
logStream - Stream with logged information.
Throws:
java.lang.Exception - In case the stream cannnot be opened or the format cannot be detected, an IllegalArgumentException is thrown.

disableReplay

public void disableReplay()
Disables replay mode.

enableHardware

public void enableHardware()
Enables GPS hardware reporting.

disableHardware

public void disableHardware()
Disables GPS hardware reporting.

enableRawLogging

public void enableRawLogging(java.io.OutputStream s)
Start logging GPS information into the given output stream (usually a FileOutputStream will be used).
Parameters:
s - Output stream to use for logging.

disableRawLogging

public void disableRawLogging()
Stops logging process. Does nothing if logging was not enabled.

enableLogging

public void enableLogging(java.io.OutputStream s)
Enables logging current GPS data into a stream.
Parameters:
s - Stream to use for logging.

disableLogging

public void disableLogging()
Disable logging.

close

public void close()
           throws java.io.IOException
Close the GPS device.
Throws:
java.io.IOException -  

replayThread

public void replayThread()
Method

logThread

public void logThread()
Method

gpsThread

public void gpsThread()
Method

run

public void run()
Main thread.
Specified by:
run in interface java.lang.Runnable

addGPSListener

public void addGPSListener(GPSListener gl)
Add new GPS listener.
Parameters:
gl - GPSListener to add.

removeGPSListener

public void removeGPSListener(GPSListener gl)
Remove GPS listener.
Parameters:
gl - GPSListener to remove.