tags:

views:

113

answers:

3

Hi out there,

I am bashing around with android localization and already figured out how to receive NMEA data. Unfortunately, the results seem to be very chaotic. I do only need the GPRMC sentence but get GPGGA, GPVTG etc. returned. Is there any way to control the onNmeaReceived() function?

public class TrackingService extends Service {

private Intent broadcastIntent = new Intent("com.example.locationlogger.TestBroadcastReceiver");
private LocationManager lm;
private LocationListener ll = new LocationListener(){
       //sample listener...
};

GpsStatus.NmeaListener nl = new GpsStatus.NmeaListener() {
   @Override
   public void onNmeaReceived(long timestamp, String nmea) {
      /*
       * Broadcast a message..
       */
      broadcastIntent.putExtra("TESTVAR", "Received some nmea strings: " + nmea);
      sendBroadcast(broadcastIntent);
   }
};

@Override
public void onCreate() {
   lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
}

@Override
public void onStart(Intent intent, int startId) {   
   lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, interval * 1000, 0, ll);
   lm.addNmeaListener(nl);
}

}

A: 
Christopher
What I meant by "chaotic" is the fact that I get four times in a row the GPGSV, then a GPVTG, sometimes a valid GPRMC followed by two times GPGSV etc. I cannot see a structure behind the returned data and that's what makes it hard to process. I was hoping to be able to set some sort of interval or filter. But it seems that I've to do that by myself :-(
Martin Horvath
A: 

Receiving multiple GPGSV sentences in a row is to be expected and I think if you check they are not identical, but parts of a single message as all the info for satellites does not fit into a single NMEA sentence. There is a sentence sequence number and the number of total sentences that make up the message at the first two positions of the message.

GPRMC are just single sentences with each containing the 'recommended minimum' fix data.

ludwig
+1  A: 

Thank you for your answers - all valid points. Acutally I solved it with a regex pattern and used matcher.find() to filter relevant sentences. In my case, this was the GPRMC sentence and only this if it included valid data. Here's the java regex string - maybe someone can re-use this.

public static Pattern p = Pattern.compile("(\\$GPRMC)\\,((\\d{6})\\.?\\d*)\\,([AV]{1})\\,(\\d*\\.?\\d*)\\,([NS]{1})\\,(\\d*\\.?\\d*)\\,([EW]{1})\\,([0-9]*\\.?[0-9]*)\\,([0-9]*\\.?[0-9]*)\\,([0-9]{6})\\,([0-9]*\\.?[0-9]*)\\,([EW]?)\\,([ADEMSN]{1}.*.[0-9A-F]{2})");

To see how I grouped the regex, use this regex string

(\$GPRMC)\,((\d{6}).?\d*)\,([AV]{1})\,(\d*.?\d*)\,([NS]{1})\,(\d*.?\d*)\,([EW]{1})\,([0-9].?[0-9])\,([0-9].?[0-9])\,([0-9]{6})\,([0-9].?[0-9])\,([EW]?)\,([ADEMSN]{1}.*.[0-9A-F]{2})

at this website

http://www.regexplanet.com/simple/index.html

with this NMEA sentence

$GPRMC,090248,A,4745.012742,N,01304.143827,E,0.0,0.0,310710,5.3,E,A*48

Regards, Martin

Martin Horvath
Are the sentences received often invalid? By "filter" in my answer, I was thinking more of `sentence.startsWith("$GPRMC");` :) Anyway, certainly a useful regex!
Christopher
In case of my app, "activate" the GPS device in my phone by using requestLocationUpdates(..) and then add the NmeaListener. Actually the NmeaListner produces output as soon as it is initialized (sentences without coordinates) and also some invalid sentences came across my way when processing. That's the reason for the full regex solution.
Martin Horvath