Answer the question
In order to leave comments, you need to log in
How to parse NMEA string?
In an Android application, I receive data from a satellite in NMEA format. I'm trying to parse these lines, but somehow it doesn't work out very well.
Line example: $GPGSA,A,3,04,11,19,32,01,,,,,,,,8.16,6.83,4.47*0B
I need to extract satellite numbers from this line, in this example it is: 04, 11, 19,32,01. I do parsing like this:
nmea = "$GPGSA,A,3,04,11,19,32,01,,,,,,,,8.16,6.83,4.47*0B";
String[] subs = new String[10];
StringTokenizer st = new StringTokenizer(nmea, ",");
int i=0;
while (st.hasMoreElements()){
Pattern p = Pattern.compile("\\d{2}");
Matcher m = p.matcher(st.nextElement().toString());
if(m.matches()){
subs[i] = st.nextElement().toString();
Log.d(LOG_TAG, "Элемент "+i+": " + subs[i]);
i++;
}
}
Answer the question
In order to leave comments, you need to log in
Reading the description of nmea$GPGSA
nmea = "$GPGSA,A,3,04,11,19,32,01,,,,,,,,8.16,6.83,4.47*0B";
String[] parts = nmea.split('[,*]');
String[] PRNs = new String[12];
for (int i = 0; i < 12 && parts[i+3] != ''; i++) {
PRNs[i] = parts[i+3];
Log.d(LOG_TAG, "Элемент "+Integer.toString(i)+": "+PRNs[i];
}
Thanks, that's how it works! But still so interesting, why my condition does not work? After all, if we remove the \\d{2} match check, then all elements separated by commas, except for empty ones, are displayed in the log.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question