edu.udayton.udri.asset.gps/src/edu/udayton/udri/asset/gps/GpsObservationThread.java
private Coordinates parseNMEA(final String nmea)
    {
        final SentenceFactory factory = SentenceFactory.getInstance();
        Coordinates currentLocation = null;
        if (SentenceValidator.isValid(nmea)) 
        {
            final Sentence s = factory.createParser(nmea);
            Logging.log(LogService.LOG_DEBUG, "RAW: " + s.toString());
            Logging.log(LogService.LOG_DEBUG, "SID: " + s.getSentenceId());
              
            final LatitudeWgsDegrees lat = new LatitudeWgsDegrees();
            final LongitudeWgsDegrees lon = new LongitudeWgsDegrees();
            final HaeMeters alt = new HaeMeters();
            
            final HeadingDegrees heading = new HeadingDegrees();
            heading.setValue(0); 
            final DistanceMeters semiMajorAxis = new DistanceMeters();
            semiMajorAxis.setValue(0);
            final DistanceMeters semiMinorAxis = new DistanceMeters();
            semiMinorAxis.setValue(0);
            final Ellipse ellipseRegion = new Ellipse(semiMajorAxis, semiMinorAxis, heading);
          
            try
            {
                switch (s.getSentenceId()) 
                {
                    //You can read more about NMEA sentence types here http://www.gpsinformation.org/dale/nmea.htm#nmea
                    //RMC is speed/velocity and position (recommended minimum)
                    case "RMC": 
                        currentLocation = new Coordinates();
                        final RMCSentence rmc = (RMCSentence)factory.createParser(nmea); 
                        Logging.log(LogService.LOG_DEBUG, "RMC TRANSLATED: " + rmc.getPosition().toString());
                        Logging.log(LogService.LOG_DEBUG, "RMC ALL (TRANSLATED?): " + rmc.toString());
                        final Position pos = rmc.getPosition();
                          
                        lat.setValue(pos.getLatitude());
                        lon.setValue(pos.getLongitude());
                        alt.setValue(pos.getAltitude());
                        heading.setValue(rmc.getCourse());
                          
                        currentLocation.setLatitude(lat);
                        currentLocation.setLongitude(lon);
                        currentLocation.setAltitude(alt);
                          
                        ellipseRegion.setRotation(heading);
                        currentLocation.setEllipseRegion(ellipseRegion);
                        break;
                    //GGA fix information
                    case "GGA":
                        final GGASentence gga = (GGASentence)factory.createParser(nmea);
                        Logging.log(LogService.LOG_DEBUG, "GGA TRANSLATED: " + gga.getPosition().toString());
                        Logging.log(LogService.LOG_DEBUG, "GGA Satellite Count: " + gga.getSatelliteCount());
                        Logging.log(LogService.LOG_DEBUG, "GGA Fix Quality: " + gga.getFixQuality().toString());
                          
                        break;
                    //GSA satellite data    
                    case "GSA":
                        final GSASentence gsa = (GSASentence)factory.createParser(nmea);
                        Logging.log(LogService.LOG_DEBUG, "GSA TRANSLATED: " + gsa.toString());
                        final double gsaHorizontalDOP = gsa.getHorizontalDOP();
                        final double gsaVerticalDOP = gsa.getVerticalDOP();
                        final double gsaPositionDOP = gsa.getPositionDOP();
                          
                        Logging.log(LogService.LOG_DEBUG, "~~Dilution of Precision~~");
                        Logging.log(LogService.LOG_DEBUG, "Horizontal DOP: " + gsaHorizontalDOP);
                        Logging.log(LogService.LOG_DEBUG, "Vertical DOP: " + gsaVerticalDOP);
                        Logging.log(LogService.LOG_DEBUG, "Positional DOP: " + gsaPositionDOP);
                          
                        break;
                    //GSV detailed satellite info
                    case "GSV":
                        final GSVSentence gsv = (GSVSentence)factory.createParser(nmea);
                        Logging.log(LogService.LOG_DEBUG, "GSV TRANSLATED: " + gsv.toString());
                        Logging.log(LogService.LOG_DEBUG, "GSV Satellite Count: " + gsv.getSatelliteCount());
                        try
                        {
                            Logging.log(LogService.LOG_DEBUG, "GSV Satellite Info: " 
                                    + gsv.getSatelliteInfo().toString());
                        }
                        catch (final IndexOutOfBoundsException e)
                        {
                            Logging.log(LogService.LOG_ERROR, 
                                    "NMEA Marine IndexOutOfBoundsException when counting satelites.", null, e);
                        }
                        break;
            
                    //GLL lat/lon data
                    case "GLL":
                        currentLocation = new Coordinates();
                        final GLLSentence gll = (GLLSentence)factory.createParser(nmea);
                        Logging.log(LogService.LOG_DEBUG, "GLL TRANSLATED: " + gll.getPosition().toString());
                          
                        final Position gllPos = gll.getPosition();
                        lat.setValue(gllPos.getLatitude());
                        lon.setValue(gllPos.getLongitude());
                        alt.setValue(gllPos.getAltitude());
                          
                        currentLocation.setLatitude(lat);
                        currentLocation.setLongitude(lon);
                        currentLocation.setAltitude(alt);
                        break;
                    default:
                        Logging.log(LogService.LOG_WARNING, "Unknown or unsupported NMEA sentence type detected.");
                        return null; 
                }
            } 
            catch (final DataNotAvailableException e)
            {
                Logging.log(LogService.LOG_WARNING, "Incomplete NMEA Sentence "
                        + "- Please move to a location with better satelite service.");
                return null;
            }
        }
        return currentLocation;
    }
/**
     * Parses a NMEA string using Java Marine Sentences.
     * @param nmea - String that represtents a NMEA sentence.
     * @return Coordinates object - if a NMEA sentence does not provide enough data for a full Coordinates
     *      object a value of 0 will be assumed for the missing parameters.
     */
Parses a NMEA string using Java Marine Sentences.
@param nmea - String that represtents a NMEA sentence.
@return Coordinates object - if a NMEA sentence does not provide enough data for a full Coordinates
object a value of 0 will be assumed for the missing parameters.
Parses a NMEA string using Java Marine Sentences . @param nmea - String that represtents a NMEA sentence . @return Coordinates object - if a NMEA sentence does not provide enough data for a full Coordinates object a value of 0 will be assumed for the missing parameters .
private Coordinates parseNMEA(final String nmea)
    {
        final SentenceFactory factory = SentenceFactory.getInstance();
        Coordinates currentLocation = null;
        if (SentenceValidator.isValid(nmea)) 
        {
            final Sentence s = factory.createParser(nmea);
            Logging.log(LogService.LOG_DEBUG, "RAW: " + s.toString());
            Logging.log(LogService.LOG_DEBUG, "SID: " + s.getSentenceId());
            final LatitudeWgsDegrees lat = new LatitudeWgsDegrees();
            final LongitudeWgsDegrees lon = new LongitudeWgsDegrees();
            final HaeMeters alt = new HaeMeters();
            final HeadingDegrees heading = new HeadingDegrees();
            heading.setValue(0); 
            final DistanceMeters semiMajorAxis = new DistanceMeters();
            semiMajorAxis.setValue(0);
            final DistanceMeters semiMinorAxis = new DistanceMeters();
            semiMinorAxis.setValue(0);
            final Ellipse ellipseRegion = new Ellipse(semiMajorAxis, semiMinorAxis, heading);
            try
            {
                switch (s.getSentenceId()) 
                {
                    case "RMC": 
                        currentLocation = new Coordinates();
                        final RMCSentence rmc = (RMCSentence)factory.createParser(nmea); 
                        Logging.log(LogService.LOG_DEBUG, "RMC TRANSLATED: " + rmc.getPosition().toString());
                        Logging.log(LogService.LOG_DEBUG, "RMC ALL (TRANSLATED?): " + rmc.toString());
                        final Position pos = rmc.getPosition();
                        lat.setValue(pos.getLatitude());
                        lon.setValue(pos.getLongitude());
                        alt.setValue(pos.getAltitude());
                        heading.setValue(rmc.getCourse());
                        currentLocation.setLatitude(lat);
                        currentLocation.setLongitude(lon);
                        currentLocation.setAltitude(alt);
                        ellipseRegion.setRotation(heading);
                        currentLocation.setEllipseRegion(ellipseRegion);
                        break;
                    case "GGA":
                        final GGASentence gga = (GGASentence)factory.createParser(nmea);
                        Logging.log(LogService.LOG_DEBUG, "GGA TRANSLATED: " + gga.getPosition().toString());
                        Logging.log(LogService.LOG_DEBUG, "GGA Satellite Count: " + gga.getSatelliteCount());
                        Logging.log(LogService.LOG_DEBUG, "GGA Fix Quality: " + gga.getFixQuality().toString());
                        break;
                    case "GSA":
                        final GSASentence gsa = (GSASentence)factory.createParser(nmea);
                        Logging.log(LogService.LOG_DEBUG, "GSA TRANSLATED: " + gsa.toString());
                        final double gsaHorizontalDOP = gsa.getHorizontalDOP();
                        final double gsaVerticalDOP = gsa.getVerticalDOP();
                        final double gsaPositionDOP = gsa.getPositionDOP();
                        Logging.log(LogService.LOG_DEBUG, "~~Dilution of Precision~~");
                        Logging.log(LogService.LOG_DEBUG, "Horizontal DOP: " + gsaHorizontalDOP);
                        Logging.log(LogService.LOG_DEBUG, "Vertical DOP: " + gsaVerticalDOP);
                        Logging.log(LogService.LOG_DEBUG, "Positional DOP: " + gsaPositionDOP);
                        break;
                    case "GSV":
                        final GSVSentence gsv = (GSVSentence)factory.createParser(nmea);
                        Logging.log(LogService.LOG_DEBUG, "GSV TRANSLATED: " + gsv.toString());
                        Logging.log(LogService.LOG_DEBUG, "GSV Satellite Count: " + gsv.getSatelliteCount());
                        try
                        {
                            Logging.log(LogService.LOG_DEBUG, "GSV Satellite Info: " 
                                    + gsv.getSatelliteInfo().toString());
                        }
                        catch (final IndexOutOfBoundsException e)
                        {
                            Logging.log(LogService.LOG_ERROR, 
                                    "NMEA Marine IndexOutOfBoundsException when counting satelites.", null, e);
                        }
                        break;
                    case "GLL":
                        currentLocation = new Coordinates();
                        final GLLSentence gll = (GLLSentence)factory.createParser(nmea);
                        Logging.log(LogService.LOG_DEBUG, "GLL TRANSLATED: " + gll.getPosition().toString());
                        final Position gllPos = gll.getPosition();
                        lat.setValue(gllPos.getLatitude());
                        lon.setValue(gllPos.getLongitude());
                        alt.setValue(gllPos.getAltitude());
                        currentLocation.setLatitude(lat);
                        currentLocation.setLongitude(lon);
                        currentLocation.setAltitude(alt);
                        break;
                    default:
                        Logging.log(LogService.LOG_WARNING, "Unknown or unsupported NMEA sentence type detected.");
                        return null; 
                }
            } 
            catch (final DataNotAvailableException e)
            {
                Logging.log(LogService.LOG_WARNING, "Incomplete NMEA Sentence "
                        + "- Please move to a location with better satelite service.");
                return null;
            }
        }
        return currentLocation;
    }
private Coordinates parseNMEA ( final String nmea ) { final SentenceFactory factory = SentenceFactory . getInstance ( ) ; Coordinates currentLocation = null ; if ( SentenceValidator . isValid ( nmea ) ) { final Sentence s = factory . createParser ( nmea ) ; Logging . log ( LogService . LOG_DEBUG , "RAW: " + s . toString ( ) ) ; Logging . log ( LogService . LOG_DEBUG , "SID: " + s . getSentenceId ( ) ) ; final LatitudeWgsDegrees lat = new LatitudeWgsDegrees ( ) ; final LongitudeWgsDegrees lon = new LongitudeWgsDegrees ( ) ; final HaeMeters alt = new HaeMeters ( ) ; final HeadingDegrees heading = new HeadingDegrees ( ) ; heading . setValue ( 0 ) ; final DistanceMeters semiMajorAxis = new DistanceMeters ( ) ; semiMajorAxis . setValue ( 0 ) ; final DistanceMeters semiMinorAxis = new DistanceMeters ( ) ; semiMinorAxis . setValue ( 0 ) ; final Ellipse ellipseRegion = new Ellipse ( semiMajorAxis , semiMinorAxis , heading ) ; try { switch ( s . getSentenceId ( ) ) { case "RMC" : currentLocation = new Coordinates ( ) ; final RMCSentence rmc = ( RMCSentence ) factory . createParser ( nmea ) ; Logging . log ( LogService . LOG_DEBUG , "RMC TRANSLATED: " + rmc . getPosition ( ) . toString ( ) ) ; Logging . log ( LogService . LOG_DEBUG , "RMC ALL (TRANSLATED?): " + rmc . toString ( ) ) ; final Position pos = rmc . getPosition ( ) ; lat . setValue ( pos . getLatitude ( ) ) ; lon . setValue ( pos . getLongitude ( ) ) ; alt . setValue ( pos . getAltitude ( ) ) ; heading . setValue ( rmc . getCourse ( ) ) ; currentLocation . setLatitude ( lat ) ; currentLocation . setLongitude ( lon ) ; currentLocation . setAltitude ( alt ) ; ellipseRegion . setRotation ( heading ) ; currentLocation . setEllipseRegion ( ellipseRegion ) ; break ; case "GGA" : final GGASentence gga = ( GGASentence ) factory . createParser ( nmea ) ; Logging . log ( LogService . LOG_DEBUG , "GGA TRANSLATED: " + gga . getPosition ( ) . toString ( ) ) ; Logging . log ( LogService . LOG_DEBUG , "GGA Satellite Count: " + gga . getSatelliteCount ( ) ) ; Logging . log ( LogService . LOG_DEBUG , "GGA Fix Quality: " + gga . getFixQuality ( ) . toString ( ) ) ; break ; case "GSA" : final GSASentence gsa = ( GSASentence ) factory . createParser ( nmea ) ; Logging . log ( LogService . LOG_DEBUG , "GSA TRANSLATED: " + gsa . toString ( ) ) ; final double gsaHorizontalDOP = gsa . getHorizontalDOP ( ) ; final double gsaVerticalDOP = gsa . getVerticalDOP ( ) ; final double gsaPositionDOP = gsa . getPositionDOP ( ) ; Logging . log ( LogService . LOG_DEBUG , "~~Dilution of Precision~~" ) ; Logging . log ( LogService . LOG_DEBUG , "Horizontal DOP: " + gsaHorizontalDOP ) ; Logging . log ( LogService . LOG_DEBUG , "Vertical DOP: " + gsaVerticalDOP ) ; Logging . log ( LogService . LOG_DEBUG , "Positional DOP: " + gsaPositionDOP ) ; break ; case "GSV" : final GSVSentence gsv = ( GSVSentence ) factory . createParser ( nmea ) ; Logging . log ( LogService . LOG_DEBUG , "GSV TRANSLATED: " + gsv . toString ( ) ) ; Logging . log ( LogService . LOG_DEBUG , "GSV Satellite Count: " + gsv . getSatelliteCount ( ) ) ; try { Logging . log ( LogService . LOG_DEBUG , "GSV Satellite Info: " + gsv . getSatelliteInfo ( ) . toString ( ) ) ; } catch ( final IndexOutOfBoundsException e ) { Logging . log ( LogService . LOG_ERROR , "NMEA Marine IndexOutOfBoundsException when counting satelites." , null , e ) ; } break ; case "GLL" : currentLocation = new Coordinates ( ) ; final GLLSentence gll = ( GLLSentence ) factory . createParser ( nmea ) ; Logging . log ( LogService . LOG_DEBUG , "GLL TRANSLATED: " + gll . getPosition ( ) . toString ( ) ) ; final Position gllPos = gll . getPosition ( ) ; lat . setValue ( gllPos . getLatitude ( ) ) ; lon . setValue ( gllPos . getLongitude ( ) ) ; alt . setValue ( gllPos . getAltitude ( ) ) ; currentLocation . setLatitude ( lat ) ; currentLocation . setLongitude ( lon ) ; currentLocation . setAltitude ( alt ) ; break ; default : Logging . log ( LogService . LOG_WARNING , "Unknown or unsupported NMEA sentence type detected." ) ; return null ; } } catch ( final DataNotAvailableException e ) { Logging . log ( LogService . LOG_WARNING , "Incomplete NMEA Sentence " + "- Please move to a location with better satelite service." ) ; return null ; } } return currentLocation ; }
Parses a NMEA string using Java Marine Sentences.
Parses a NMEA string using Java Marine Sentences .
//You can read more about NMEA sentence types here http://www.gpsinformation.org/dale/nmea.htm#nmea //RMC is speed/velocity and position (recommended minimum) //GGA fix information //GSA satellite data     //GSV detailed satellite info //GLL lat/lon data