|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.marineapi.nmea.parser.SentenceParser
public class SentenceParser
Base sentence parser for all NMEA sentence types. Provides general services such as sentence validation and data field setters and getters with formatting.
NMEA data is transmitted in form of ASCII Strings that are called
sentences. Each sentence starts with a '$', a two letter
talker ID, a three letter sentence ID, followed by a number
of data fields separated by commas, and terminated by an
optional checksum, and a carriage return/line feed. A sentence may
contain up to 82 characters including the '$' and CR/LF
. If data
for a field is not available, the field is simply omitted, but the commas
that would delimit it are still sent, with no space between them.
Sentence structure:
$<id>,<field #0>,<field #1>,...,<field #n>*<checksum>(CR/LF)
For more details, see NMEA FAQ by Peter Bennett or NMEA Revealed by Eric S. Raymond. Java Marine API is based mostly on these documents.
Field Summary |
---|
Fields inherited from interface net.sf.marineapi.nmea.sentence.Sentence |
---|
ADDRESS_FIELD, BEGIN_CHAR, CHECKSUM_DELIMITER, FIELD_DELIMITER, MAX_LENGTH, TERMINATOR |
Constructor Summary | |
---|---|
|
SentenceParser(String nmea)
Creates a new instance of SentenceParser. |
protected |
SentenceParser(String nmea,
String type)
Creates a new instance of SentenceParser. |
protected |
SentenceParser(TalkerId talker,
String type,
int size)
Creates a new empty sentence with specified talker and sentence IDs. |
Method Summary | |
---|---|
boolean |
equals(Object obj)
|
protected char |
getCharValue(int index)
Parse a single character from the specified sentence field. |
protected double |
getDoubleValue(int index)
Parse double value from the specified sentence field. |
int |
getFieldCount()
Returns the current number of data fields in sentence, excluding ID field and checksum. |
protected int |
getIntValue(int index)
Parse integer value from the specified sentence field. |
String |
getSentenceId()
Get the sentence ID that specifies the sentence type and data it holds. |
protected String |
getStringValue(int index)
Get contents of a data field as a String. |
TalkerId |
getTalkerId()
Gets the talker ID of the sentence. |
int |
hashCode()
|
protected boolean |
hasValue(int index)
Tells is if the field specified by the given index contains a value. |
boolean |
isProprietary()
Tells if the sentence is of proprietary format. |
boolean |
isValid()
Tells if the sentence formatting matches NMEA 0183 format. |
protected void |
setCharValue(int index,
char value)
Set a character in specified field. |
protected void |
setDoubleValue(int index,
double value)
Set double value in specified field. |
protected void |
setDoubleValue(int index,
double value,
int leading,
int decimals)
Set double value in specified field, with given number of digits before and after the decimal separator ('.'). |
protected void |
setIntValue(int index,
int value)
Set integer value in specified field. |
protected void |
setIntValue(int index,
int value,
int leading)
Set integer value in specified field, with specified minimum number of digits. |
protected void |
setStringValue(int index,
String value)
Set String value in specified data field. |
protected void |
setStringValues(int first,
String[] newFields)
Replace multiple fields with given String array, starting at the specified index. |
void |
setTalkerId(TalkerId id)
Set the talker ID of the sentence. |
String |
toSentence()
Formats and validates the String representation of sentence without the line terminator CR/LF. |
String |
toString()
Returns the String representation of the sentence (without line terminator CR/LR). |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SentenceParser(String nmea)
nmea
- A valid NMEA 0183 sentence
IllegalArgumentException
- If the specified sentence is invalid or
if sentence type is not supported.protected SentenceParser(String nmea, String type)
nmea
contains a valid NMEA 0183 sentence of the
specified type
.
For example, GGA sentence parser should specify "GGA" as the type.
nmea
- NMEA 0183 sentence Stringtype
- Expected type of the sentence in nmea
parameter
IllegalArgumentException
- If the specified sentence is not a valid
or is not of expected type.protected SentenceParser(TalkerId talker, String type, int size)
talker
- Talker type Id, e.g. "GP" or "LC".type
- Sentence type Id, e.g. "GGA or "GLL".size
- Number of data fieldsMethod Detail |
---|
public boolean equals(Object obj)
equals
in class Object
public final int getFieldCount()
Sentence
getFieldCount
in interface Sentence
public final String getSentenceId()
Sentence
$GPGGA
the method returns SentenceId.GGA
.
getSentenceId
in interface Sentence
SentenceId
public final TalkerId getTalkerId()
Sentence
$
in sentence address field. For example, in case of
$GPGGA
, the method returns TalkerId.GP
.
getTalkerId
in interface Sentence
public int hashCode()
hashCode
in class Object
public boolean isProprietary()
Sentence
isProprietary
in interface Sentence
public boolean isValid()
Sentence
isValid
in interface Sentence
public final void setTalkerId(TalkerId id)
Sentence
setTalkerId
in interface Sentence
id
- TalkerId to setpublic final String toSentence()
Sentence
toSentence
in interface Sentence
Sentence.toString()
public String toString()
toSentence()
to also
validate the result.
toString
in interface Sentence
toString
in class Object
protected final char getCharValue(int index)
index
- Data field index in sentence
ParseException
- If field contains more than one characterprotected final double getDoubleValue(int index)
index
- Data field index in sentence
Double.parseDouble(String)
protected final int getIntValue(int index)
index
- Field index in sentence
Integer.parseInt(String)
protected final String getStringValue(int index)
$GPGGA
) and checksum at the end are
not considered as a data fields and cannot therefore be fetched with this
method.
Field indexing, let i = 1:
$<id>,<i>,<i+1>,<i+2>,...,<i+n>*<checksum>
index
- Field index
DataNotAvailableException
- If the field is emptyprotected final boolean hasValue(int index)
index
- Field index
protected final void setCharValue(int index, char value)
index
- Field indexvalue
- Value to setprotected final void setDoubleValue(int index, double value)
index
- Field indexvalue
- Value to setsetDoubleValue(int, double, int, int)
protected final void setDoubleValue(int index, double value, int leading, int decimals)
index
- Field indexvalue
- Value to setleading
- Number of digits before decimal separatordecimals
- Maximum number of digits after decimal separatorsetDoubleValue(int, double)
protected final void setIntValue(int index, int value)
index
- Field indexvalue
- Value to setprotected final void setIntValue(int index, int value, int leading)
index
- Field indexvalue
- Value to setleading
- Number of digits to use.protected final void setStringValue(int index, String value)
index
- Field indexvalue
- String to set, null
converts to empty String.protected final void setStringValues(int first, String[] newFields)
first
is zero, all sentence
fields are replaced.
If the length of newFields
does not fit in the sentence
field count or it contains less values, fields are removed or added
accordingly. As the result, total number of fields may increase or
decrease. Thus, if the sentence field count must not change, you may need
to add empty Strings to newFields
in order to preserve the
original number of fields. Also, all existing values after
first
are lost.
first
- Index of first field to setnewFields
- Array of Strings to set
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |