location.generators
Class RealGPSMonitor

java.lang.Object
  |
  +--location.generators.RealGPSMonitor
All Implemented Interfaces:
java.util.EventListener, LocationGenerator, javax.comm.SerialPortEventListener

public class RealGPSMonitor
extends java.lang.Object
implements LocationGenerator, javax.comm.SerialPortEventListener

This class monitors the GPS information provided by the Garmin GPS unit on the serial port. It uses the javax.comm package to connect to the serial port and read data from it.

Version:
2.0
Author:
Chien-Liang Fok

Constructor Summary
RealGPSMonitor(java.lang.String commName, int baud)
          The constructor sets the instance variables and sets up the serial port to be read from.
 
Method Summary
 void addGpsInfoListener(GpsInfoListener gps)
          Add a GpsInfo listener.
 void addLocationListener(LocationListener ll)
          Add a Location listener.
 LocationEvent getLocation()
          Returns the current location reading of the GPS receiver or null of the no reading has been received yet.
 void kill()
          Stops this RealGPSMonitor.
 void removeGpsInfoListener(GpsInfoListener gps)
          Remove a GpsInfo listener.
 void removeLocationListener(LocationListener ll)
          Remove a location listener.
 void serialEvent(javax.comm.SerialPortEvent event)
          This method implements the serialEvent(....) method required by SerialPortEventListener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RealGPSMonitor

public RealGPSMonitor(java.lang.String commName,
                      int baud)
The constructor sets the instance variables and sets up the serial port to be read from. It takes the provided parameters, and assigns their values. It then gets the available ports on the host. If one of the available ports matches the port requested by the user, a connection to the port is opened and the stream and its reader are initialized. If no matching port is found, an error is printed and the program exits. If the port is successfully initialized, its parameters are set and then a Thread is spawned to deal with the events generated by the javax.comm package.
Parameters:
commName - the String name of the serial port to connect to. For example, to connect to COM port 1, specify "COM1".
baud - the baud rate of the GPS unit's communication
Method Detail

addLocationListener

public void addLocationListener(LocationListener ll)
Add a Location listener.
Specified by:
addLocationListener in interface LocationGenerator
Parameters:
ll - the new location listener.
Returns:
true if the operation was successful.

removeLocationListener

public void removeLocationListener(LocationListener ll)
Remove a location listener.
Specified by:
removeLocationListener in interface LocationGenerator
Parameters:
ll - the location listener to remove.
Returns:
true if the operation was successful.

addGpsInfoListener

public void addGpsInfoListener(GpsInfoListener gps)
Add a GpsInfo listener.
Specified by:
addGpsInfoListener in interface LocationGenerator
Parameters:
gps - the new GpsInfo listener.
Returns:
true if the operation was successful.

removeGpsInfoListener

public void removeGpsInfoListener(GpsInfoListener gps)
Remove a GpsInfo listener.
Specified by:
removeGpsInfoListener in interface LocationGenerator
Parameters:
gps - the GpsInfo listener to remove.
Returns:
true if the operation was successful.

kill

public void kill()
Stops this RealGPSMonitor.
Specified by:
kill in interface LocationGenerator

getLocation

public LocationEvent getLocation()
Returns the current location reading of the GPS receiver or null of the no reading has been received yet.
Specified by:
getLocation in interface LocationGenerator
Returns:
the current GPS location reading or null if no reading received yet

serialEvent

public void serialEvent(javax.comm.SerialPortEvent event)
This method implements the serialEvent(....) method required by SerialPortEventListener. It describes what action should be taken when an event occurs on the port.
Specified by:
serialEvent in interface javax.comm.SerialPortEventListener
Parameters:
event - the event generated by the serial port
See Also:
SerialPortEventListener