/** * Internal helper method to aid in the subclass architecture. Overwrites the superclass method * and calls it internally. * * @param header * @param s */ protected void sentenceChooser(String header, String s) { if (header.equals(RMCSentence.HEADER)) { rmcSentence.setSentence(s); notifyListeners(this.rmcSentence); } else if (header.equals(GSVSentence.HEADER)) { // TODO: I wonder what happens if say 2 of 4 are received and parse is called? // Because 2 would be new data, 2 would be old data. // Can't happen because parse() only called when not null. // BUT what if it is in the middle of parsing and new data comes in? // Solution: Sync GSVSentence.parse()? checkRefresh() is already synced though. // 0. Get StringTokenizer to read info from NMEASentence: StringTokenizer st = new StringTokenizer(s, ","); st.nextToken(); // Skip header $GPGSV // 1.1 Find out how many sentences in sequence. gsvSentenceTotal = Integer.parseInt(st.nextToken()); // 1.2 Find out which sentence this is. gsvSentenceNumber = Integer.parseInt(st.nextToken()); // 2. Assign sentence to GSVSentence in order. gsvSentence.setSentence(s, gsvSentenceNumber, gsvSentenceTotal); // 3. If last sentence: if (gsvSentenceTotal == gsvSentenceNumber) { // 3a. setSentence() to last one so it is not null gsvSentence.setSentence(s); // 3b. Notify GPSListener notifyListeners(this.gsvSentence); } } else super.sentenceChooser(header, s); // Check superclass sentences. }
/** * 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; i < prns.length; i++) { if (prns[i] == s.getPRN()) tracked = true; break; } s.setTracked(tracked); return s; }
/** * The satellites in view is a list of satellites the GPS could theoretically connect to (i.e. * satellites that are not over the earth's horizon). The getSatellitesInView() method will always * return an equal or greater number than getSatellitesTracked(). * * @return Number of satellites e.g. 8 */ public int getSatellitesInView() { return gsvSentence.getSatellitesInView(); }