... the user friendly GPS tool


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ASCII-Daten importieren
#2
Hallo Michael,

kannst Du reguläre Ausdrücke lesen ;-) ?

private static final Pattern RMC_PATTERN = Pattern.
compile(BEGIN_OF_LINE + "RMC" + SEPARATOR +
"([\\d\\.]*)" + SEPARATOR + // UTC Time
"[AV]" + SEPARATOR +
"([\\d\\.]+)" + SEPARATOR + "([NS])" + SEPARATOR +
"([\\d\\.]+)" + SEPARATOR + "([WE])" + SEPARATOR +
"[\\d\\.]*" + SEPARATOR + // Speed over ground, knots
"[\\d\\.]*" + SEPARATOR +
"(\\d*)" + SEPARATOR + // Date, ddmmyy
"[\\d\\.]*" + SEPARATOR +
"[\\d\\.]*" + SEPARATOR + "?" +
"[AEW]?" +
END_OF_LINE);

RouteConverter interpretiert:
$GPRMC,180114,A,4808.9490,N,00928.9610,E,000.0,000.0,160607,, ,A*76
$GPRMC,140403.000,A,4837.5194,N,00903.4022,E,15.00,0.00,260707,, *3E

sowie:
$GPGGA,130441.89,5239.3154,N,00907.7011,E,1,08,1.25,16.76,M,46.79,M,,*6D
$GPWPL,5334.169,N,01001.920,E,STATN1*22
$GPZDA,032910,07,08,2004,00,00*48
$PMGNTRK,4914.967,N,00651.208,E,000199,M,152224,A,KLLERTAL-RADWEG,210307*48

D.h. für Dich aus

A,5038.4251,N,00944.5372,E,055.6,009.8,A

wird

$GPRMC,180114,A,5038.4251,N,00944.5372,E,055.6,009.8,160607,,*AB

wobei

180114 die Uhrzeit im Format HHMMSS,
160607 das Datum im Format TTMMYY sowie
AB die Checksumme (die RouteConverter ignoriert, da sie meist falsch ist :-()

Die Checksumme berechnet sich so:

private byte computeChecksum(String line) {
byte result = 0;
for (int i = 0; i < line.length(); i++) {
result ^= line.charAt(i);
}
return result;
}

private boolean hasValidChecksum(String line) {
String lineForChecksum = line.substring(1, line.length() - 3);
byte expected = computeChecksum(lineForChecksum);
String actualStr = line.substring(line.length() - 2);
byte[] actual = HexDecoder.decodeBytes(actualStr);
if (actual.length != 1 || actual[0] != expected) {
String expectedStr = HexEncoder.encodeByte(expected);
log.severe("Checksum of '" + line + "' is invalid. Expected '" + expectedStr + "' but found '" + actualStr + "'");
return false;
}
return true;
}

Ich hoffe, das hilft.

Gruss
Christian

PS: Wäre das nicht etwas fürs Forum?
--
Christian
Reply


Messages In This Thread
ASCII-Daten importieren - by routeconverter - 04.04.2008, 09:25
RE: ASCII-Daten importieren - by routeconverter - 04.04.2008, 09:26

Forum Jump:


Users browsing this thread: 1 Guest(s)