svn-gvsig-desktop / trunk / extensions / extGPS / src / org / gvsig / gps / parser / NMEA / NMEASentence.java @ 5085
History | View | Annotate | Download (4.29 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: NMEASentence.java 5085 2006-05-08 11:54:50Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.2 2006-05-08 11:54:50 jaume
|
47 |
* small architecture aspects
|
48 |
*
|
49 |
* Revision 1.1 2006/04/03 16:10:27 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.1 2006/03/31 09:55:34 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
*
|
56 |
*/
|
57 |
package org.gvsig.gps.parser.NMEA; |
58 |
|
59 |
/**
|
60 |
* <p>
|
61 |
* NMEA messages have a common structure, consisting of a message header,
|
62 |
* data fields.
|
63 |
* </p>
|
64 |
* <p>
|
65 |
* <li><b>Example: $GPYYY,xxx,xxx,xxx?</b></li>
|
66 |
* </p><br>
|
67 |
* <p>This class implements an abstraction of these messages, it keeps track
|
68 |
* of the time the message is created, so you can treat it as a valid or
|
69 |
* otherwise as an old message.<br>
|
70 |
* </p>
|
71 |
* <p>
|
72 |
* Any specific class implementing a concrete NMEA message must extend NMEASentence
|
73 |
* and implement its abstract methods.
|
74 |
* </p>
|
75 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
76 |
*
|
77 |
*/
|
78 |
public abstract class NMEASentence { |
79 |
private String[] data; |
80 |
private byte checksum; |
81 |
protected long time; |
82 |
|
83 |
public final void setData(String sentence) throws IllegalSentenceException { |
84 |
int ind = sentence.indexOf('*'); |
85 |
checksum = Byte.decode("0x"+sentence.substring(ind+1, ind+3)).byteValue(); |
86 |
this.data = sentence.substring(0, ind).split(","); |
87 |
// TODO: checksum? maybe one day...
|
88 |
parse(); |
89 |
} |
90 |
|
91 |
/**
|
92 |
* The amount of fields that this sentence contains.<br>
|
93 |
* The first field (index=0) is the sentence name.
|
94 |
* @return The amount of fields
|
95 |
*/
|
96 |
public final int getFieldCount() { |
97 |
return data.length;
|
98 |
} |
99 |
|
100 |
/**
|
101 |
* The name of the NMEA sentence.
|
102 |
* @return A string containing the name.
|
103 |
*/
|
104 |
public final String getName() { |
105 |
return data[0]; |
106 |
} |
107 |
|
108 |
/**
|
109 |
* The time when this class was created. Typically, the GPS receivers are
|
110 |
* always sending data. Using this timestamp you can filter this messages
|
111 |
* by age.
|
112 |
* @return the difference, measured in milliseconds, between the time when it
|
113 |
* was set and midnight, January 1, 1970 UTC.
|
114 |
*/
|
115 |
public final long getTime() { |
116 |
return time;
|
117 |
} |
118 |
|
119 |
/**
|
120 |
* From the list of fields, extracts the field definded by the index.
|
121 |
* @param iField
|
122 |
* @return String containing the iField-th field data
|
123 |
*/
|
124 |
public final String getFieldValue(int iField) { |
125 |
return data[iField];
|
126 |
} |
127 |
|
128 |
/**
|
129 |
* Sets the timestamp. Usually, the value used for time is a typical
|
130 |
* System.currentTimeMillis() call.
|
131 |
* @param time, a long containing the amount of milliseconds.
|
132 |
*/
|
133 |
public final void setTime(long time) { |
134 |
this.time = time;
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* Parses the message and initializes the fields.
|
139 |
* @throws IllegalSentenceException
|
140 |
*/
|
141 |
public abstract void parse() throws IllegalSentenceException; |
142 |
|
143 |
/**
|
144 |
* Returns true, if this instance of NMEA is equivalent to other passed
|
145 |
* as argument regardless the time they both were created and -potentially-
|
146 |
* regardless other values in fields, too. Otherwise, it returns false.
|
147 |
* @param NMEASentenceTest otherSentence
|
148 |
* @return True, if they are equivalent. False, otherwise.
|
149 |
*/
|
150 |
public abstract boolean isEquivalentTo(NMEASentence otherSentence); |
151 |
|
152 |
public String toString() { |
153 |
String s = data[0]; |
154 |
for (int i = 1; i < data.length; i++) { |
155 |
s += ","+data[i];
|
156 |
} |
157 |
return s + "\n"; |
158 |
} |
159 |
} |