org.opengts.util
Class Nmea0183

java.lang.Object
  extended by org.opengts.util.Nmea0183

public class Nmea0183
extends java.lang.Object

A container for a NMEA-0183 record


Field Summary
static java.lang.String DNAME_GPGGA
           
static java.lang.String DNAME_GPRMC
           
static java.lang.String DNAME_GPVTG
           
static java.lang.String DNAME_GPZDA
           
static long FIELD_ALTITUDE
           
static long FIELD_DDMMYY
           
static long FIELD_FIX_TYPE
           
static long FIELD_HDOP
           
static long FIELD_HEADING
           
static long FIELD_HHMMSS
           
static long FIELD_LATITUDE
           
static long FIELD_LONGITUDE
           
static long FIELD_NUMBER_SATS
           
static long FIELD_RECORD_TYPE
           
static long FIELD_SPEED
           
static long FIELD_VALID_FIX
           
static double KILOMETERS_PER_KNOT
           
static double KNOTS_PER_KILOMETER
           
static java.lang.String NAME_GPGGA
           
static java.lang.String NAME_GPRMC
           
static java.lang.String NAME_GPVTG
           
static java.lang.String NAME_GPZDA
           
static java.lang.String NAME_NONE
           
static long TYPE_GPGGA
           
static long TYPE_GPRMC
           
static long TYPE_GPVTG
           
static long TYPE_GPZDA
           
static long TYPE_NONE
           
 
Constructor Summary
Nmea0183()
          Constructor
Nmea0183(java.lang.String rcd)
          Constructor
Nmea0183(java.lang.String[] rcds)
          Constructor
Nmea0183(java.lang.String[] rcds, boolean ignoreChecksum)
          Constructor
Nmea0183(java.lang.String rcd, boolean ignoreChecksum)
          Constructor
 
Method Summary
static int calcXORChecksum(java.lang.String str, boolean includeAll)
          Calculates/Returns the checksum for a NMEA-0183 formatted String
 boolean didIgnoreInvalidGPS()
          Returns true if ignoring invalid GPS flags, and the flag indicator was not "A"
 double getAltitudeMeters()
          Gets the altitude in meters
static long getCurrentHHMMSS(java.util.TimeZone tz)
          Returns the current HHMMSS
 long getDDMMYY()
          Gets the day/month/year of the fix
 java.lang.String[] getExtraData()
          Gets any data that may follow the checksum
 long getFieldMask()
          Gets the mask of available fields
 long getFixtime()
          Gets the epoch fix time
 long getFixtime(boolean dftToCurrentTOD)
          Gets the epoch fix time
 int getFixType()
          Gets the "$GPGGA" fix type (0=no fix, 1=GPS, 2=DGPS, 3=PPS?, 6=dead-reckoning)
 GeoPoint getGeoPoint()
          Gets the lat/lon as a GeoPoint
 double getHDOP()
          Gets the horizontal-dilution-of-precision
 double getHeading()
          Gets the heading/course in degrees
 long getHHMMSS()
          Gets the hour/minute/seconds of the fix
 boolean getIgnoreInvalidGpsFlag()
          gets whether the A|V (valid|invalid) GPS location flag should be ignored.
 java.lang.String getLastRecordType()
          Gets the last record type
 double getLatitude()
          Gets the latitude
 double getLongitude()
          Gets the longitude
 double getMagneticVariation()
          Gets the magnetic variation in degrees
 int getNumberOfSatellites()
          Gets the number of satellites used in fix
 long getParsedRecordTypes()
          Gets all parsed record types (mask)
 double getSpeedKnots()
          Returns the speed in knots
 double getSpeedKPH()
          Gets the speed in KPH
static java.lang.String GetTypeNames(long type)
          Gets the message type String from a type mask
 boolean hasAltitude()
          Returns true if the altitude has been defined
 boolean hasField(long fld)
          Returns true if specified field is available
 boolean hasFixtime()
          Returns true if the fixtime has been defined
 boolean hasGeoPoint()
          Returns true if the latitude/longitude have been defined
 boolean hasGPRMC()
          Returns true if a $GPRMC record has been parsed
 boolean hasHeading()
          Returns true if the heading has been defined
 boolean hasLatitude()
          Returns true if the latitude has been defined
 boolean hasLongitude()
          Returns true if the longitude has been defined
 boolean hasSpeed()
          Returns true if the speed has been defined
 boolean isValidChecksum()
          Returns true if the checksum is valid
 boolean isValidGPS()
          Returns true if the GPS fix is valid
static void main(java.lang.String[] argv)
          Main entry point for testing/debugging
 boolean parse(java.lang.String rcd)
          Parses a NMEA-0183 record
 boolean parse(java.lang.String[] rcds)
          Parses a NMEA-0183 record
 boolean parse(java.lang.String[] rcds, boolean ignoreChecksum)
          Parses a NMEA-0183 record
 boolean parse(java.lang.String rcd, boolean ignoreChecksum)
          Parses a NMEA-0183 record
static long parseFixtime(long ddmmyy, long hhmmss, boolean dftToCurrentTOD)
          Returns the parsed epoch fix time
static long parseFixtime(java.lang.String DDMMYY, java.lang.String HHMMSS, boolean dftToCurrentTOD)
          Returns the parsed epoch fix time
static double ParseLatitude(java.lang.String s, java.lang.String d)
          Parses latitude given values from GPS device.
static double ParseLatitude(java.lang.String s, java.lang.String d, double dft)
          Parses latitude given values from GPS device.
static double ParseLongitude(java.lang.String s, java.lang.String d)
          Parses longitude given values from GPS device.
static double ParseLongitude(java.lang.String s, java.lang.String d, double dft)
          Parses longitude given values from GPS device.
 void setDDMMYY(long ddmmyy)
          Sets the day/month/year (for "$GPGGA" records)
 void setGeoPoint(GeoPoint gp)
          Sets the lat/lon as a GeoPoint
 void setIgnoreInvalidGpsFlag(boolean ignore)
          Sets whether the A|V (valid|invalid) GPS location flag should be ignored.
Setting to "true" is not recommended as invalid GPS locations may be returned.
 java.lang.String toGPRMC()
          Return a formatted $GPRMC record from the values in this instance
 java.lang.String toString()
          Returns a string representation of this object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NAME_NONE

public static final java.lang.String NAME_NONE
See Also:
Constant Field Values

NAME_GPRMC

public static final java.lang.String NAME_GPRMC
See Also:
Constant Field Values

NAME_GPGGA

public static final java.lang.String NAME_GPGGA
See Also:
Constant Field Values

NAME_GPVTG

public static final java.lang.String NAME_GPVTG
See Also:
Constant Field Values

NAME_GPZDA

public static final java.lang.String NAME_GPZDA
See Also:
Constant Field Values

DNAME_GPRMC

public static final java.lang.String DNAME_GPRMC
See Also:
Constant Field Values

DNAME_GPGGA

public static final java.lang.String DNAME_GPGGA
See Also:
Constant Field Values

DNAME_GPVTG

public static final java.lang.String DNAME_GPVTG
See Also:
Constant Field Values

DNAME_GPZDA

public static final java.lang.String DNAME_GPZDA
See Also:
Constant Field Values

TYPE_NONE

public static final long TYPE_NONE
See Also:
Constant Field Values

TYPE_GPRMC

public static final long TYPE_GPRMC
See Also:
Constant Field Values

TYPE_GPGGA

public static final long TYPE_GPGGA
See Also:
Constant Field Values

TYPE_GPVTG

public static final long TYPE_GPVTG
See Also:
Constant Field Values

TYPE_GPZDA

public static final long TYPE_GPZDA
See Also:
Constant Field Values

FIELD_RECORD_TYPE

public static final long FIELD_RECORD_TYPE
See Also:
Constant Field Values

FIELD_VALID_FIX

public static final long FIELD_VALID_FIX
See Also:
Constant Field Values

FIELD_DDMMYY

public static final long FIELD_DDMMYY
See Also:
Constant Field Values

FIELD_HHMMSS

public static final long FIELD_HHMMSS
See Also:
Constant Field Values

FIELD_LATITUDE

public static final long FIELD_LATITUDE
See Also:
Constant Field Values

FIELD_LONGITUDE

public static final long FIELD_LONGITUDE
See Also:
Constant Field Values

FIELD_SPEED

public static final long FIELD_SPEED
See Also:
Constant Field Values

FIELD_HEADING

public static final long FIELD_HEADING
See Also:
Constant Field Values

FIELD_HDOP

public static final long FIELD_HDOP
See Also:
Constant Field Values

FIELD_NUMBER_SATS

public static final long FIELD_NUMBER_SATS
See Also:
Constant Field Values

FIELD_ALTITUDE

public static final long FIELD_ALTITUDE
See Also:
Constant Field Values

FIELD_FIX_TYPE

public static final long FIELD_FIX_TYPE
See Also:
Constant Field Values

KILOMETERS_PER_KNOT

public static final double KILOMETERS_PER_KNOT
See Also:
Constant Field Values

KNOTS_PER_KILOMETER

public static final double KNOTS_PER_KILOMETER
See Also:
Constant Field Values
Constructor Detail

Nmea0183

public Nmea0183()
Constructor


Nmea0183

public Nmea0183(java.lang.String rcd)
Constructor

Parameters:
rcd - The NMEA-0183 record

Nmea0183

public Nmea0183(java.lang.String[] rcds)
Constructor

Parameters:
rcds - An array of NMEA-0183 records

Nmea0183

public Nmea0183(java.lang.String rcd,
                boolean ignoreChecksum)
Constructor

Parameters:
rcd - The NMEA-0183 record
ignoreChecksum - True if the record's checksum is to be ignored

Nmea0183

public Nmea0183(java.lang.String[] rcds,
                boolean ignoreChecksum)
Constructor

Parameters:
rcds - An array of NMEA-0183 records
ignoreChecksum - True if the record's checksum is to be ignored
Method Detail

GetTypeNames

public static java.lang.String GetTypeNames(long type)
Gets the message type String from a type mask

Parameters:
type - The message type
Returns:
The type as a string

getFieldMask

public long getFieldMask()
Gets the mask of available fields

Returns:
The mask of available fields

hasField

public boolean hasField(long fld)
Returns true if specified field is available

Returns:
True if specified field is available

getParsedRecordTypes

public long getParsedRecordTypes()
Gets all parsed record types (mask)

Returns:
all parsed record types (mask)

getLastRecordType

public java.lang.String getLastRecordType()
Gets the last record type

Returns:
The last record type

isValidChecksum

public boolean isValidChecksum()
Returns true if the checksum is valid

Returns:
True if the checksum is valid

setDDMMYY

public void setDDMMYY(long ddmmyy)
Sets the day/month/year (for "$GPGGA" records)

Parameters:
ddmmyy - The day/month/year [CHECK](as what?)

getDDMMYY

public long getDDMMYY()
Gets the day/month/year of the fix

Returns:
The day/month/year of the fix

getHHMMSS

public long getHHMMSS()
Gets the hour/minute/seconds of the fix

Returns:
The hour/minute/seconds of the fix

hasFixtime

public boolean hasFixtime()
Returns true if the fixtime has been defined

Returns:
True if the fixtime has been defined

getFixtime

public long getFixtime()
Gets the epoch fix time

Returns:
the epoch fix time

getFixtime

public long getFixtime(boolean dftToCurrentTOD)
Gets the epoch fix time

Returns:
the epoch fix time

setIgnoreInvalidGpsFlag

public void setIgnoreInvalidGpsFlag(boolean ignore)
Sets whether the A|V (valid|invalid) GPS location flag should be ignored.
Setting to "true" is not recommended as invalid GPS locations may be returned.


getIgnoreInvalidGpsFlag

public boolean getIgnoreInvalidGpsFlag()
gets whether the A|V (valid|invalid) GPS location flag should be ignored.

Returns:
True if the GPS A|V flag should be ignored, false otherwise.

didIgnoreInvalidGPS

public boolean didIgnoreInvalidGPS()
Returns true if ignoring invalid GPS flags, and the flag indicator was not "A"

Returns:
True if ignoring invalid GPS flags, and the flag indicator was not "A"

isValidGPS

public boolean isValidGPS()
Returns true if the GPS fix is valid

Returns:
True if the GPS fix is valid

hasLatitude

public boolean hasLatitude()
Returns true if the latitude has been defined

Returns:
Ttrue if the latitude has have been defined

getLatitude

public double getLatitude()
Gets the latitude

Returns:
The latitude

hasLongitude

public boolean hasLongitude()
Returns true if the longitude has been defined

Returns:
Ttrue if the longitude has have been defined

getLongitude

public double getLongitude()
Gets the longitude

Returns:
The longitude

hasGeoPoint

public boolean hasGeoPoint()
Returns true if the latitude/longitude have been defined

Returns:
Ttrue if the latitude/longitude have been defined

getGeoPoint

public GeoPoint getGeoPoint()
Gets the lat/lon as a GeoPoint

Returns:
the lat/lon as a GeoPoint

setGeoPoint

public void setGeoPoint(GeoPoint gp)
Sets the lat/lon as a GeoPoint

Parameters:
gp - The GeoPoint

hasSpeed

public boolean hasSpeed()
Returns true if the speed has been defined

Returns:
True if the speed has been defined

getSpeedKnots

public double getSpeedKnots()
Returns the speed in knots

Returns:
The speed in knots

getSpeedKPH

public double getSpeedKPH()
Gets the speed in KPH

Returns:
The speed in KPH

hasHeading

public boolean hasHeading()
Returns true if the heading has been defined

Returns:
True if the heading has been defined

getHeading

public double getHeading()
Gets the heading/course in degrees

Returns:
The heading/course in degrees

getFixType

public int getFixType()
Gets the "$GPGGA" fix type (0=no fix, 1=GPS, 2=DGPS, 3=PPS?, 6=dead-reckoning)

Returns:
The "$GPGGA fix type

getNumberOfSatellites

public int getNumberOfSatellites()
Gets the number of satellites used in fix

Returns:
The number of satellites used in fix

getHDOP

public double getHDOP()
Gets the horizontal-dilution-of-precision

Returns:
The horizontal-dilution-of-precision

hasAltitude

public boolean hasAltitude()
Returns true if the altitude has been defined

Returns:
True if the altitude has been defined

getAltitudeMeters

public double getAltitudeMeters()
Gets the altitude in meters

Returns:
The altitude in meters

getMagneticVariation

public double getMagneticVariation()
Gets the magnetic variation in degrees

Returns:
The magnetic variation in degrees

getExtraData

public java.lang.String[] getExtraData()
Gets any data that may follow the checksum

Returns:
Any data that may follow the checksum (may be null)

toString

public java.lang.String toString()
Returns a string representation of this object

Overrides:
toString in class java.lang.Object
Returns:
A string representation of this object

toGPRMC

public java.lang.String toGPRMC()
Return a formatted $GPRMC record from the values in this instance

Returns:
A formatted $GPRMC record

parse

public boolean parse(java.lang.String[] rcds)
Parses a NMEA-0183 record

Parameters:
rcds - An array of NMEA-0183 records to parse
Returns:
True if this record was successfully parsed

parse

public boolean parse(java.lang.String rcd)
Parses a NMEA-0183 record

Parameters:
rcd - the NMEA-0183 record to parse
Returns:
True if this record was successfully parsed

parse

public boolean parse(java.lang.String[] rcds,
                     boolean ignoreChecksum)
Parses a NMEA-0183 record

Parameters:
rcds - An array of NMEA-0183 records to parse
ignoreChecksum - True to ignore the terminating checksum
Returns:
True if this record was successfully parsed

parse

public boolean parse(java.lang.String rcd,
                     boolean ignoreChecksum)
Parses a NMEA-0183 record

Parameters:
rcd - the NMEA-0183 record to parse
ignoreChecksum - True to ignore the terminating checksum
Returns:
True if this record was successfully parsed

hasGPRMC

public boolean hasGPRMC()
Returns true if a $GPRMC record has been parsed


getCurrentHHMMSS

public static long getCurrentHHMMSS(java.util.TimeZone tz)
Returns the current HHMMSS

Returns:
The current HHMMSS

parseFixtime

public static long parseFixtime(java.lang.String DDMMYY,
                                java.lang.String HHMMSS,
                                boolean dftToCurrentTOD)
Returns the parsed epoch fix time

Parameters:
DDMMYY - The String representation of the "DDMMYY"
HHMMSS - The String representation of the "HHMMSS"
dftToCurrentTOD - True to default to current time-of-day
Returns:
The parsed epoch fix time

parseFixtime

public static long parseFixtime(long ddmmyy,
                                long hhmmss,
                                boolean dftToCurrentTOD)
Returns the parsed epoch fix time

Parameters:
ddmmyy - The Integer representation of the "DDMMYY"
hhmmss - The Integer representation of the "HHMMSS"
Returns:
The parsed epoch fix time

ParseLatitude

public static double ParseLatitude(java.lang.String s,
                                   java.lang.String d)
Parses latitude given values from GPS device.

Parameters:
s - Latitude String from GPS device in ddmm.mm format.
d - Latitude hemisphere, "N" for northern, "S" for southern.
Returns:
Latitude parsed from GPS data, with appropriate sign based on hemisphere or '90.0' if invalid latitude provided.

ParseLatitude

public static double ParseLatitude(java.lang.String s,
                                   java.lang.String d,
                                   double dft)
Parses latitude given values from GPS device.

Parameters:
s - Latitude String from GPS device in ddmm.mm format.
d - Latitude hemisphere, "N" for northern, "S" for southern.
dft - The default latitude, if the specified latitude cannot be parsed
Returns:
Latitude parsed from GPS data, with appropriate sign based on hemisphere or 'dft' if invalid latitude provided.

ParseLongitude

public static double ParseLongitude(java.lang.String s,
                                    java.lang.String d)
Parses longitude given values from GPS device.

Parameters:
s - Longitude String from GPS device in ddmm.mm format.
d - Longitude hemisphere, "E" for eastern, "W" for western.
Returns:
Longitude parsed from GPS data, with appropriate sign based on hemisphere or '180.0' if invalid longitude provided.

ParseLongitude

public static double ParseLongitude(java.lang.String s,
                                    java.lang.String d,
                                    double dft)
Parses longitude given values from GPS device.

Parameters:
s - Longitude String from GPS device in ddmm.mm format.
d - Longitude hemisphere, "E" for eastern, "W" for western.
dft - The default latitude, if the specified latitude cannot be parsed
Returns:
Longitude parsed from GPS data, with appropriate sign based on hemisphere or 'dft' if invalid longitude provided.

calcXORChecksum

public static int calcXORChecksum(java.lang.String str,
                                  boolean includeAll)
Calculates/Returns the checksum for a NMEA-0183 formatted String

Parameters:
str - NMEA-0183 formatted String to be checksummed.
Returns:
Checksum computed from input.

main

public static void main(java.lang.String[] argv)
Main entry point for testing/debugging

Parameters:
argv - Comand-line arguments