location.generators
Class RealGPSMonitor

java.lang.Object
  extended bylocation.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

Field Summary
(package private)  double altitude
           
(package private)  double course
           
(package private)  java.util.Date date
           
private  boolean done
          Should the GPS thread exit.
private  java.util.Vector gps_listeners
          The GPSListeners that are waiting for GPSInfoEvents.
private  java.io.InputStreamReader inputSR
          The reader to convert the input stream to a reader
private  java.io.InputStream inputStream
          The input stream to the serial port
(package private)  boolean isValid
           
(package private)  Latitude latitude
           
private  java.util.Vector listeners
          The GPSListeners that are waiting for GPSEvents.
(package private)  Longitude longitude
           
(package private)  java.lang.String mode
           
(package private)  double mps
           
(package private)  LocationEvent prevLE
          The previous LocationEvent that was broadcasted
private  int safe
           
(package private)  java.util.Vector Sat
           
private  javax.comm.SerialPort serialPort
          The serial port to read from
private  boolean start
           
(package private)  java.lang.String time
           
(package private)  java.lang.String usedSat
           
(package private)  java.lang.String validity
           
(package private)  java.lang.String viewedSat
           
 
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.
(package private)  void broadcastInformation()
          Send a new location information to the registered listeners.
 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.
private  void parseString(java.lang.String readSentence)
          Parses the string of characters recieved from the GPS unit to get the new GPS location and other useful info
 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
 

Field Detail

inputStream

private java.io.InputStream inputStream
The input stream to the serial port


inputSR

private java.io.InputStreamReader inputSR
The reader to convert the input stream to a reader


serialPort

private javax.comm.SerialPort serialPort
The serial port to read from


listeners

private java.util.Vector listeners
The GPSListeners that are waiting for GPSEvents.


gps_listeners

private java.util.Vector gps_listeners
The GPSListeners that are waiting for GPSInfoEvents.


done

private boolean done
Should the GPS thread exit.


prevLE

LocationEvent prevLE
The previous LocationEvent that was broadcasted


Sat

java.util.Vector Sat

viewedSat

java.lang.String viewedSat

validity

java.lang.String validity

usedSat

java.lang.String usedSat

altitude

double altitude

mode

java.lang.String mode

time

java.lang.String time

isValid

boolean isValid

latitude

Latitude latitude

longitude

Longitude longitude

mps

double mps

course

double course

date

java.util.Date date

start

private boolean start

safe

private int safe
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

broadcastInformation

void broadcastInformation()
Send a new location information to the registered listeners.


parseString

private void parseString(java.lang.String readSentence)
Parses the string of characters recieved from the GPS unit to get the new GPS location and other useful info


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