net.sf.marineapi.nmea.sentence
Class Checksum

java.lang.Object
  extended by net.sf.marineapi.nmea.sentence.Checksum

public final class Checksum
extends Object

Provides Sentence checksum calculation and utilities.

Version:
$Revision: 40 $
Author:
Kimmo Tuukkanen

Method Summary
static String add(String sentence)
          Calculates and adds a checksum to specified sentence String.
static String calculate(String nmea)
          Calculates the checksum of sentence String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

add

public static String add(String sentence)
Calculates and adds a checksum to specified sentence String. Existing checksum will be replaced with the new one.

For example,
$GPGLL,6011.552,N,02501.941,E,120045,A
results in
$GPGLL,6011.552,N,02501.941,E,120045,A*26

$GPGLL,6011.552,N,02501.941,E,120045,A*00
results in
$GPGLL,6011.552,N,02501.941,E,120045,A*26

Parameters:
sentence - Sentence in String representation
Returns:
The specified String with checksum added.

calculate

public static String calculate(String nmea)
Calculates the checksum of sentence String. Checksum is a XOR of each character between, but not including, the $ and * characters. The resulting hex value is returned as a String in two digit format, padded with a leading zero if necessary. The method will calculate the checksum for any given String and the sentence validity is not checked.

Parameters:
nmea - NMEA Sentence with or without checksum.
Returns:
Checksum hex value, padded with leading zero if necessary.


Copyright (C) 2010-2011 Java Marine API author(s). All Rights Reserved.