All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lejos.hardware.gps.GPS Maven / Gradle / Ivy

Go to download

leJOS (pronounced like the Spanish word "lejos" for "far") is a tiny Java Virtual Machine. In 2013 it was ported to the LEGO EV3 brick.

The newest version!
package lejos.hardware.gps;

import java.io.InputStream;
import java.util.Date;
  
/**
 * This class manages data received from a GPS Device.
 * GPS Class manages the following NMEA Sentences:
 *  
 * GPRMC
 * GPGSV
 * GPGSA
 * GPGGA (superclass)
 * GPVTG (superclass)
 * 
 * @author BB
 * @author Juan Antonio Brenha Moral
 *
 */
/*
 * DEVELOPER NOTES: More NMEA sentence types that can be added if there is demand for them:
 * http://www.gpsinformation.org/dale/nmea.htm
 */
public class GPS extends SimpleGPS {
	
	//Classes which manages GGA, RMC, VTG, GSV, GSA Sentences
	private RMCSentence rmcSentence;
	//TODO device sends a sequence of complementary gsv sentences
	// this class only remembers the last one
	private GSVSentence gsvSentence;

	//Date Object with use GGA & RMC Sentence
	private Date date;
	
	/**
	 * The constructor. It needs an InputStream
	 * 
	 * @param in An input stream from the GPS receiver
	 */
	public GPS(InputStream in) {
		super(in);
		rmcSentence = new RMCSentence();
		gsvSentence = new GSVSentence();
		
		date = new Date();
	}
	

	/* GETTERS & SETTERS */

	/**
	 * Return Compass Degrees
	 * in a range: 0.0-359.9
	 * 
	 * @return the compass degrees
	 */
	public float getCompassDegrees(){
		return rmcSentence.getCompassDegrees();	
	}
	
	/**
	 * Return a Date Object with data from GGA and RMC NMEA Sentence
	 * 
	 * @return the date
	 */
	public Date getDate(){
		// TODO: Would be more proper to return a new Date object instead of recycled Date.
		updateDate();
		updateTime();
		return date;
	}

	/**
	 * 
	 * Get NMEA Satellite. The satellite list is retrieved from the almanac data. Satellites are
	 * ordered by their elevation: highest elevation (index 0) -> lowest elevation.
	 * 
	 * @param index the satellite index
	 * @return the NMEASaltellite object for the selected satellite
	 */
	public Satellite getSatellite(int index){
		Satellite s = gsvSentence.getSatellite(index); 
		// Compare getPRN() with this satellite, fill in setTracked():
		// TODO: This fails because most satellites are set to 0 when this is called. Not synced yet.
		boolean tracked = false;
		int [] prns = getPRN();
		for(int i=0;i0) {
			int hh = timeStamp / 10000;
			int mm = (timeStamp / 100) % 100;
			int ss = timeStamp % 100;
		
			date.setHours(hh);
			date.setMinutes(mm);
			date.setSeconds(ss);
		}
	}

	/**
	 * Update Date values
	 */
	private void updateDate(){
		int dateStamp = rmcSentence.getDate();
		
		if(dateStamp > 0) {
			int dd = dateStamp / 10000;
			int mm = (dateStamp / 100) % 100;
			int yy = dateStamp % 100;
			
			date.setDate(dd);
			date.setMonth(mm);
			date.setYear(yy);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy