Package lejos.hardware.gps
Class SimpleGPS
- java.lang.Object
-
- java.lang.Thread
-
- lejos.hardware.gps.SimpleGPS
-
- All Implemented Interfaces:
java.lang.Runnable
- Direct Known Subclasses:
GPS
public class SimpleGPS extends java.lang.ThreadThis class manages data received from a GPS Device. SimpleGPS Class manages the following NMEA Sentences which supply location, heading, and speed data:- GPGGA (location data)
- GPVTG (heading and speed data)
- GPGSA (accuracy information)
This class is primarily for use by the javax.microedition.location package. The preferred class to use for obtaining GPS data is the GPS class.
- Author:
- BB, Juan Antonio Bre??a Moral
-
-
Field Summary
Fields Modifier and Type Field Description protected GGASentenceggaSentenceprotected GSASentencegsaSentenceprotected VTGSentencevtgSentence
-
Constructor Summary
Constructors Constructor Description SimpleGPS(java.io.InputStream in)The constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddListener(GPSListener listener)add a listener to manage events with GPSvoidclose()Method used to close connection.floatgetAltitude()The altitude above mean sea levelfloatgetCourse()Get the course heading of the GPS unit.intgetFixMode()Fix quality: 0 = invalid 1 = GPS fix (SPS) 2 = DGPS fix 3 = PPS fix 4 = Real Time Kinematic 5 = Float RTK 6 = estimated (dead reckoning) (2.3 feature) 7 = Manual input mode 8 = Simulation modeintgetFixType()3D fix - values include: 1 = no fix 2 = 2D fix 3 = 3D fixfloatgetHDOP()Get the Horizontal Dilution of Precision (HDOP).doublegetLatitude()Get LatitudechargetLatitudeDirection()Get Latitude DirectiondoublegetLongitude()Get LongitudechargetLongitudeDirection()Get Longitude DirectionfloatgetPDOP()Get the 3D Position Dilution of Precision (PDOP).int[]getPRN()Get an Array of Pseudo-Random Noise codes (PRN).intgetSatellitesTracked()Returns the number of satellites being tracked to determine the coordinates.java.lang.StringgetSelectionType()Selection type of 2D or 3D fix 'M' = manual 'A' = automaticfloatgetSpeed()Get speed in kilometers per hourintgetTimeStamp()Get the last time stamp from the satellite for GGA sentence.floatgetVDOP()Get the Vertical Dilution of Precision (VDOP).protected static voidnotifyListeners(NMEASentence sen)static voidremoveListener(GPSListener listener)Remove a listenervoidrun()Keeps reading sentences from GPS receiver stream and extracting data.protected voidsentenceChooser(java.lang.String header, java.lang.String s)Internal helper method to aid in the subclass architecture.-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
ggaSentence
protected GGASentence ggaSentence
-
vtgSentence
protected VTGSentence vtgSentence
-
gsaSentence
protected GSASentence gsaSentence
-
-
Method Detail
-
getLatitude
public double getLatitude()
Get Latitude- Returns:
- the latitude
-
getLatitudeDirection
public char getLatitudeDirection()
Get Latitude Direction- Returns:
- the latitude direction
-
getLongitude
public double getLongitude()
Get Longitude- Returns:
- the longitude
-
getLongitudeDirection
public char getLongitudeDirection()
Get Longitude Direction- Returns:
- the longitude direction
-
getAltitude
public float getAltitude()
The altitude above mean sea level- Returns:
- Meters above sea level e.g. 545.4
-
getSatellitesTracked
public int getSatellitesTracked()
Returns the number of satellites being tracked to determine the coordinates.- Returns:
- Number of satellites e.g. 8
-
getFixMode
public int getFixMode()
Fix quality:- 0 = invalid
- 1 = GPS fix (SPS)
- 2 = DGPS fix
- 3 = PPS fix
- 4 = Real Time Kinematic
- 5 = Float RTK
- 6 = estimated (dead reckoning) (2.3 feature)
- 7 = Manual input mode
- 8 = Simulation mode
- Returns:
- the fix quality
-
getTimeStamp
public int getTimeStamp()
Get the last time stamp from the satellite for GGA sentence.- Returns:
- Time as a UTC integer. 123459 = 12:34:59 UTC
-
getSpeed
public float getSpeed()
Get speed in kilometers per hour- Returns:
- the speed in kilometers per hour
-
getCourse
public float getCourse()
Get the course heading of the GPS unit.- Returns:
- course (0.0 to 360.0)
-
getSelectionType
public java.lang.String getSelectionType()
Selection type of 2D or 3D fix- 'M' = manual
- 'A' = automatic
- Returns:
- selection type - either 'A' or 'M'
-
getFixType
public int getFixType()
3D fix - values include:- 1 = no fix
- 2 = 2D fix
- 3 = 3D fix
- Returns:
- fix type (1 to 3)
-
getPRN
public int[] getPRN()
Get an Array of Pseudo-Random Noise codes (PRN). You can look up a list of GPS satellites by this number at: http://en.wikipedia.org/wiki/List_of_GPS_satellite_launches Note: This number might be similar or identical to SVN.- Returns:
- array of PRNs
-
getPDOP
public float getPDOP()
Get the 3D Position Dilution of Precision (PDOP). When visible GPS satellites are close together in the sky, the geometry is said to be weak and the DOP value is high; when far apart, the geometry is strong and the DOP value is low. Thus a low DOP value represents a better GPS positional accuracy due to the wider angular separation between the satellites used to calculate a GPS unit's position. Other factors that can increase the effective DOP are obstructions such as nearby mountains or buildings.- Returns:
- The PDOP (PDOP * 6 meters = the error to expect in meters) -1 means PDOP is unavailable from the GPS.
-
getHDOP
public float getHDOP()
Get the Horizontal Dilution of Precision (HDOP). When visible GPS satellites are close together in the sky, the geometry is said to be weak and the DOP value is high; when far apart, the geometry is strong and the DOP value is low. Thus a low DOP value represents a better GPS positional accuracy due to the wider angular separation between the satellites used to calculate a GPS unit's position. Other factors that can increase the effective DOP are obstructions such as nearby mountains or buildings.- Returns:
- the HDOP (HDOP * 6 meters = the error to expect in meters) -1 means HDOP is unavailable from the GPS.
-
getVDOP
public float getVDOP()
Get the Vertical Dilution of Precision (VDOP). When visible GPS satellites are close together in the sky, the geometry is said to be weak and the DOP value is high; when far apart, the geometry is strong and the DOP value is low. Thus a low DOP value represents a better GPS positional accuracy due to the wider angular separation between the satellites used to calculate a GPS unit's position. Other factors that can increase the effective DOP are obstructions such as nearby mountains or buildings.- Returns:
- the VDOP (VDOP * 6 meters = the error to expect in meters) -1 means VDOP is unavailable from the GPS.
-
close
public void close() throws java.io.IOExceptionMethod used to close connection. There is no real need to call this method. Included in case programmer wants absolutely clean exit.- Throws:
java.io.IOException
-
notifyListeners
protected static void notifyListeners(NMEASentence sen)
-
addListener
public static void addListener(GPSListener listener)
add a listener to manage events with GPS- Parameters:
listener-
-
removeListener
public static void removeListener(GPSListener listener)
Remove a listener- Parameters:
listener-
-
run
public void run()
Keeps reading sentences from GPS receiver stream and extracting data. This is a daemon thread so when program ends it won't keep running.- Specified by:
runin interfacejava.lang.Runnable- Overrides:
runin classjava.lang.Thread
-
sentenceChooser
protected void sentenceChooser(java.lang.String header, java.lang.String s)Internal helper method to aid in the subclass architecture. Overwritten by subclass.- Parameters:
header-s-
-
-