Revision 29427
tags/gvsig_topologia-1.0.1-1231/extensions/extGPS/lib/Windows/i368-mingw32/README | ||
---|---|---|
1 |
Wed Mar 1 12:01:05 MST 2006 |
|
2 |
rxtxSerial.dll had to be recomopiled to link in missing native methods. |
|
3 |
|
|
0 | 4 |
tags/gvsig_topologia-1.0.1-1231/extensions/extGPS/src/org/gvsig/gps/GPSDriver.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.14 2007-09-19 16:01:40 jaume |
|
47 |
* removed unnecessary imports |
|
48 |
* |
|
49 |
* Revision 1.13 2006/09/14 07:06:00 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.12 2006/04/20 17:13:35 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* Revision 1.11 2006/04/12 10:03:32 jaume |
|
56 |
* *** empty log message *** |
|
57 |
* |
|
58 |
* Revision 1.10 2006/04/11 20:01:18 jaume |
|
59 |
* *** empty log message *** |
|
60 |
* |
|
61 |
* Revision 1.9 2006/04/11 13:25:54 jaume |
|
62 |
* *** empty log message *** |
|
63 |
* |
|
64 |
* Revision 1.8 2006/04/11 13:19:51 jaume |
|
65 |
* *** empty log message *** |
|
66 |
* |
|
67 |
* Revision 1.7 2006/04/10 11:21:52 jaume |
|
68 |
* *** empty log message *** |
|
69 |
* |
|
70 |
* Revision 1.6 2006/04/07 12:45:55 jaume |
|
71 |
* *** empty log message *** |
|
72 |
* |
|
73 |
* Revision 1.5 2006/04/07 11:10:26 jaume |
|
74 |
* *** empty log message *** |
|
75 |
* |
|
76 |
* Revision 1.4 2006/04/07 08:27:48 jaume |
|
77 |
* *** empty log message *** |
|
78 |
* |
|
79 |
* Revision 1.3 2006/04/06 10:34:46 jaume |
|
80 |
* *** empty log message *** |
|
81 |
* |
|
82 |
* Revision 1.1 2006/04/05 17:08:18 jaume |
|
83 |
* *** empty log message *** |
|
84 |
* |
|
85 |
* Revision 1.2 2006/04/03 21:07:35 jaume |
|
86 |
* *** empty log message *** |
|
87 |
* |
|
88 |
* Revision 1.1 2006/04/03 16:10:27 jaume |
|
89 |
* *** empty log message *** |
|
90 |
* |
|
91 |
* Revision 1.1 2006/03/31 09:55:34 jaume |
|
92 |
* *** empty log message *** |
|
93 |
* |
|
94 |
* |
|
95 |
*/ |
|
96 |
package org.gvsig.gps; |
|
97 |
|
|
98 |
import gnu.io.CommPortIdentifier; |
|
99 |
import gnu.io.PortInUseException; |
|
100 |
import gnu.io.SerialPort; |
|
101 |
import gnu.io.UnsupportedCommOperationException; |
|
102 |
|
|
103 |
import java.awt.geom.Point2D; |
|
104 |
import java.io.BufferedWriter; |
|
105 |
import java.io.File; |
|
106 |
import java.io.FileWriter; |
|
107 |
import java.io.IOException; |
|
108 |
import java.io.InputStream; |
|
109 |
import java.io.OutputStream; |
|
110 |
import java.util.ArrayList; |
|
111 |
import java.util.Enumeration; |
|
112 |
import java.util.Hashtable; |
|
113 |
import java.util.Iterator; |
|
114 |
|
|
115 |
import org.gvsig.gps.exceptions.GPSReceiverException; |
|
116 |
import org.gvsig.gps.listeners.GPSEventListener; |
|
117 |
import org.gvsig.gps.parser.NMEA.GGASentence; |
|
118 |
import org.gvsig.gps.parser.NMEA.GSASentence; |
|
119 |
import org.gvsig.gps.parser.NMEA.IllegalSentenceException; |
|
120 |
import org.gvsig.gps.parser.NMEA.NMEASentence; |
|
121 |
import org.gvsig.gps.parser.NMEA.NMEASentenceFactory; |
|
122 |
import org.gvsig.gps.parser.NMEA.RMCSentence; |
|
123 |
import org.gvsig.gps.parser.NMEA.VTGSentence; |
|
124 |
|
|
125 |
/** |
|
126 |
* <p> |
|
127 |
* Singleton class that handles the communication within the application and the |
|
128 |
* GPS receiver. It opens the port set with the setPort() method and establishes |
|
129 |
* the comunication via NMEA protocol.<br> |
|
130 |
* </p> |
|
131 |
|
|
132 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
133 |
* |
|
134 |
*/ |
|
135 |
public class GPSDriver extends Thread { |
|
136 |
private boolean connected = false; |
|
137 |
private ArrayList eventListeners = new ArrayList(); |
|
138 |
|
|
139 |
// The timeOut field specifies how long a value received from the device |
|
140 |
// is valid. After this time, no more events of the corresponding class |
|
141 |
// will be fired. |
|
142 |
private static final long timeOut = 60 * 1000; // 60 seconds. |
|
143 |
|
|
144 |
private SerialPort serialPort = null; |
|
145 |
private InputStream inputStream; |
|
146 |
private OutputStream outputStream; |
|
147 |
|
|
148 |
private Hashtable register = new Hashtable(); |
|
149 |
private int rate = 1000; |
|
150 |
private long lastSampleTime; |
|
151 |
private boolean eventsEnabled; |
|
152 |
|
|
153 |
private static double lonOffset = 0D; |
|
154 |
private static double latOffset = 0D; |
|
155 |
private Point2D currentPos; |
|
156 |
|
|
157 |
private static GPSDriver instance = null; |
|
158 |
private static String fileName = "c:/gps points.txt"; |
|
159 |
static BufferedWriter bw ; |
|
160 |
|
|
161 |
/** |
|
162 |
* Public instantiation of the driver is forbidden. |
|
163 |
*/ |
|
164 |
private GPSDriver() {}; |
|
165 |
|
|
166 |
/** |
|
167 |
* <p> |
|
168 |
* This is a singleton object. Use this method to get the only one instance allowed.<br> |
|
169 |
* </p> |
|
170 |
* <p> |
|
171 |
* The use of the GPSDriver is very simple. Just set the port and the communciation |
|
172 |
* attributes through the setPort(...) method. Register a new listener into the driver |
|
173 |
* using the addEventListener(GPSEventListener) method. Then call start, stop as far |
|
174 |
* as it is a thread and your listeners will be notified about any event received |
|
175 |
* from the device. |
|
176 |
* </p> |
|
177 |
* @return |
|
178 |
*/ |
|
179 |
public static GPSDriver getInstance() { |
|
180 |
if (instance == null) |
|
181 |
instance = new GPSDriver(); |
|
182 |
if (bw == null) |
|
183 |
try { |
|
184 |
bw = new BufferedWriter(new FileWriter(new File(fileName))); |
|
185 |
} catch (IOException e) { |
|
186 |
e.printStackTrace(); |
|
187 |
} |
|
188 |
return instance; |
|
189 |
} |
|
190 |
|
|
191 |
/** |
|
192 |
* Sets the port and its attributes used to comunicate to the receiver. |
|
193 |
* @param CommPortIdentifier portID, the port identifier |
|
194 |
* @param int portSpeed, the port speed expressed in bauds |
|
195 |
* @param int dataBits, value for the communication's data bits |
|
196 |
* (one of SerialPort.DATABITS_5, SerialPort.DATABITS_6, |
|
197 |
* SerialPort.DATABITS_7, or SerialPort.DATABITS_8) |
|
198 |
* @param int stopBits, value for the communication's stop bits |
|
199 |
* (one of SerialPort.STOPBITS_1, SerialPort.STOPBITS_1_5, or SerialPort.STOPBITS_2) |
|
200 |
* @param int parity, value for the communication's parity |
|
201 |
* (one of SerialPort.PARITY_EVEN, SerialPort.PARITY_MARK, |
|
202 |
* SerialPort.PARITY_NONE, SerialPort.PARITY_ODD, or |
|
203 |
* SerialPort.PARITY_SPACE). |
|
204 |
* @throws PortInUseException |
|
205 |
*/ |
|
206 |
public void setPort(CommPortIdentifier portID, int portSpeed, int dataBits, int stopBits, int parity) throws PortInUseException{ |
|
207 |
close(); |
|
208 |
getInstance().serialPort = (SerialPort) portID.open("gvSIG", portSpeed); |
|
209 |
try { |
|
210 |
getInstance().inputStream = getInstance().serialPort.getInputStream(); |
|
211 |
getInstance().outputStream = getInstance().serialPort.getOutputStream(); |
|
212 |
getInstance().serialPort.setSerialPortParams( |
|
213 |
portSpeed, |
|
214 |
dataBits, |
|
215 |
stopBits, |
|
216 |
parity |
|
217 |
); |
|
218 |
} catch (UnsupportedCommOperationException e) { |
|
219 |
e.printStackTrace(); |
|
220 |
} catch (IOException e) { |
|
221 |
e.printStackTrace(); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
/** |
|
226 |
* Tells the driver to start monitoring and capturing data from the device. |
|
227 |
*/ |
|
228 |
public void connect() { |
|
229 |
getInstance().eventsEnabled = true; |
|
230 |
|
|
231 |
if (!getInstance().isAlive()) { |
|
232 |
System.out.println("start"); |
|
233 |
getInstance().start(); |
|
234 |
} |
|
235 |
} |
|
236 |
|
|
237 |
public void run() { |
|
238 |
byte[] readBuffer = new byte[2048]; |
|
239 |
StringBuffer line = new StringBuffer(); |
|
240 |
try { |
|
241 |
for (int bytes = getInstance().inputStream.read(readBuffer); bytes>-1; bytes = getInstance().inputStream.read(readBuffer)){ |
|
242 |
|
|
243 |
// Notify the listeners that the GPS is connected. |
|
244 |
Iterator it = eventListeners.iterator(); |
|
245 |
while (!getInstance().connected && getInstance().eventsEnabled && it.hasNext()) { |
|
246 |
GPSEventListener l = (GPSEventListener) it.next(); |
|
247 |
l.connectionEstablished(); |
|
248 |
|
|
249 |
} |
|
250 |
getInstance().connected = true; |
|
251 |
|
|
252 |
// Creates a new buffer to contain the previous readed bytes and the next bunch of bytes |
|
253 |
String str = new String(readBuffer).substring(0, bytes); |
|
254 |
int i = str.indexOf("\n"); |
|
255 |
if (i == -1) { |
|
256 |
line.append(str); |
|
257 |
} else { |
|
258 |
line.append(str.substring(0,i)); |
|
259 |
analyzeMessage(line.toString()); |
|
260 |
|
|
261 |
line = new StringBuffer(); |
|
262 |
line.append(str.substring(i+1,str.length())); |
|
263 |
} |
|
264 |
} |
|
265 |
System.err.println("Sending request"); |
|
266 |
getInstance().outputStream.write(new String("$PMCAG,005,1,GGA,001").getBytes()); |
|
267 |
for (int bytes = getInstance().inputStream.read(readBuffer); bytes>-1; bytes = getInstance().inputStream.read(readBuffer)){ |
|
268 |
// Creates a new buffer to contain the previous readed bytes and the next bunch of bytes |
|
269 |
String str = new String(readBuffer).substring(0, bytes); |
|
270 |
int i = str.indexOf("\n"); |
|
271 |
if (i == -1) { |
|
272 |
line.append(str); |
|
273 |
} else { |
|
274 |
line.append(str.substring(0,i)); |
|
275 |
analyzeMessage(line.toString()); |
|
276 |
|
|
277 |
line = new StringBuffer(); |
|
278 |
line.append(str.substring(i+1,str.length())); |
|
279 |
} |
|
280 |
break; |
|
281 |
} |
|
282 |
getInstance().inputStream = null; |
|
283 |
getInstance().outputStream = null; |
|
284 |
} catch (IOException e) { |
|
285 |
e.printStackTrace(); |
|
286 |
} catch (NullPointerException e) { |
|
287 |
} |
|
288 |
|
|
289 |
// Connection lost, will notify the listeners |
|
290 |
getInstance().connected = false; |
|
291 |
Iterator it = getInstance().eventListeners.iterator(); |
|
292 |
while (getInstance().eventsEnabled && it.hasNext()) { |
|
293 |
GPSEventListener l = (GPSEventListener) it.next(); |
|
294 |
l.connectionLost(); |
|
295 |
} |
|
296 |
|
|
297 |
} |
|
298 |
|
|
299 |
/** |
|
300 |
* Parses the specific NMEA message. |
|
301 |
* @param line |
|
302 |
*/ |
|
303 |
private void analyzeMessage(String line) { |
|
304 |
try { |
|
305 |
System.out.println("Analizing: "+line); |
|
306 |
NMEASentence data = NMEASentenceFactory.createFromString(line); |
|
307 |
NMEASentence oldData = (NMEASentence) getInstance().register.get(data.getName()); |
|
308 |
boolean mustNotifyListeners = !data.isEquivalentTo(oldData); |
|
309 |
getInstance().register.put(data.getName(), data); |
|
310 |
//if (mustNotifyListeners) |
|
311 |
fireEvents(); |
|
312 |
} catch (IllegalSentenceException e) { |
|
313 |
} |
|
314 |
|
|
315 |
} |
|
316 |
|
|
317 |
public static void sleep(long millis) { |
|
318 |
getInstance().sleep(millis); |
|
319 |
} |
|
320 |
|
|
321 |
public static void sleep(long millis, long nanos) { |
|
322 |
getInstance().sleep(millis, nanos); |
|
323 |
} |
|
324 |
|
|
325 |
/** |
|
326 |
* Sets the minimum interval between events in milliseconds. |
|
327 |
* @param millis |
|
328 |
*/ |
|
329 |
public void setSampleRate(int millis) { |
|
330 |
getInstance().rate = millis; |
|
331 |
} |
|
332 |
|
|
333 |
/** |
|
334 |
* Registers a new listener that will be notified about any event occured from |
|
335 |
* the gps receiver. |
|
336 |
* @param GPSEventListener l |
|
337 |
*/ |
|
338 |
public void addEventListener(GPSEventListener l) { |
|
339 |
getInstance().eventListeners.add(l); |
|
340 |
} |
|
341 |
|
|
342 |
/** |
|
343 |
* Iterates over the message registry and notifies the listeners |
|
344 |
*/ |
|
345 |
private void fireEvents() { |
|
346 |
Iterator it = getInstance().eventListeners.iterator(); |
|
347 |
while (getInstance().eventsEnabled && it.hasNext()) { |
|
348 |
GPSEventListener l = (GPSEventListener) it.next(); |
|
349 |
if (System.currentTimeMillis() - getInstance().lastSampleTime >= getInstance().rate ) { |
|
350 |
Iterator i = getInstance().register.keySet().iterator(); |
|
351 |
while (i.hasNext()) { |
|
352 |
NMEASentence aux = (NMEASentence) getInstance().register.get(i.next()); |
|
353 |
if (isCurrent(aux)) { |
|
354 |
// This is a valid record |
|
355 |
if (aux instanceof GGASentence) { |
|
356 |
GGASentence s = (GGASentence) aux; |
|
357 |
{ |
|
358 |
try { |
|
359 |
bw.write(s.getLongitude() + "," + s.getLatitude()+"\n"); |
|
360 |
bw.flush(); |
|
361 |
} catch (IOException e) { |
|
362 |
// TODO Auto-generated catch block |
|
363 |
e.printStackTrace(); |
|
364 |
} |
|
365 |
} |
|
366 |
getInstance().fireLonLatPositionReceived(l, s.getLongitude(), s.getLatitude()); |
|
367 |
|
|
368 |
l.precisionChanged(-1, s.getHDOP(), -1); |
|
369 |
l.signalQualityChanged(0, s.getSatelliteCount(), s.getQualityStatus()); |
|
370 |
l.altitudeChanged(s.getAltitude()); |
|
371 |
} else if (aux instanceof GSASentence) { |
|
372 |
GSASentence s = (GSASentence) aux; |
|
373 |
float[] dissolutions = s.getPrecisionDisolutions(); |
|
374 |
l.precisionChanged(dissolutions[0], dissolutions[1], dissolutions[2]); |
|
375 |
s.getUsedSatellites(); |
|
376 |
} else if (aux instanceof RMCSentence) { |
|
377 |
l.unhandledMessage(aux.toString()); |
|
378 |
} else if (aux instanceof VTGSentence) { |
|
379 |
VTGSentence s = (VTGSentence) aux; |
|
380 |
l.speedChanged(s.getSpeed(), s.getCourse()); |
|
381 |
} else { |
|
382 |
l.unhandledMessage(aux.toString()); |
|
383 |
} |
|
384 |
} else { |
|
385 |
// This record is too old. |
|
386 |
getInstance().register.remove(aux); |
|
387 |
} |
|
388 |
} |
|
389 |
|
|
390 |
getInstance().lastSampleTime = System.currentTimeMillis(); |
|
391 |
} |
|
392 |
} |
|
393 |
} |
|
394 |
|
|
395 |
/** |
|
396 |
* Saves the position that is going to be delivered and notifies to the |
|
397 |
* listener passed in the first agument that a new position has been received. |
|
398 |
* This is a convenience method and should not be called outside the fireEvents |
|
399 |
* method. |
|
400 |
* @param listener |
|
401 |
* @param longitude |
|
402 |
* @param latitude |
|
403 |
*/ |
|
404 |
private void fireLonLatPositionReceived(GPSEventListener listener, double longitude, double latitude) { |
|
405 |
getInstance().currentPos = new Point2D.Double(longitude, latitude); |
|
406 |
listener.newLonLatPositionReceived(longitude - lonOffset, latitude - latOffset); |
|
407 |
} |
|
408 |
|
|
409 |
/** |
|
410 |
* Tells if the sentence is considered as up-to-date. |
|
411 |
* @param NMEASentence |
|
412 |
* @return boolean |
|
413 |
*/ |
|
414 |
private boolean isCurrent(NMEASentence n) { |
|
415 |
return System.currentTimeMillis() - n.getTime() < timeOut; |
|
416 |
} |
|
417 |
|
|
418 |
/** |
|
419 |
* Silences the event firing. To resume the event firing just call <b>start()</b> method. |
|
420 |
*/ |
|
421 |
public void silence() { |
|
422 |
getInstance().eventsEnabled = false; |
|
423 |
} |
|
424 |
|
|
425 |
/** |
|
426 |
* Closes the connection and frees any resource that the driver could be using. |
|
427 |
*/ |
|
428 |
public void close() { |
|
429 |
stop(); |
|
430 |
if (getInstance().serialPort != null) { |
|
431 |
getInstance().serialPort.notifyOnDataAvailable(false); |
|
432 |
getInstance().serialPort.removeEventListener(); |
|
433 |
if (getInstance().inputStream != null) { |
|
434 |
try { |
|
435 |
getInstance().inputStream.close(); |
|
436 |
} |
|
437 |
catch (IOException e) {} |
|
438 |
} |
|
439 |
if (getInstance().outputStream != null) { |
|
440 |
try { |
|
441 |
getInstance().outputStream.close(); |
|
442 |
getInstance().outputStream = null; |
|
443 |
} |
|
444 |
catch (IOException e) {} |
|
445 |
} |
|
446 |
getInstance().serialPort.close(); |
|
447 |
getInstance().serialPort = null; |
|
448 |
} |
|
449 |
getInstance().connected = false; |
|
450 |
Iterator it = getInstance().eventListeners.iterator(); |
|
451 |
while (getInstance().eventsEnabled && it.hasNext()) { |
|
452 |
GPSEventListener l = (GPSEventListener) it.next(); |
|
453 |
l.connectionLost(); |
|
454 |
} |
|
455 |
instance = null; |
|
456 |
|
|
457 |
} |
|
458 |
|
|
459 |
/** |
|
460 |
* Sets the offset of the GPS receiver. By default it is 0, but sometimes it |
|
461 |
* is useful to calibrate it. |
|
462 |
* |
|
463 |
* @param lonOffset |
|
464 |
* @param latOffset |
|
465 |
* @throws GPSReceiverException |
|
466 |
*/ |
|
467 |
public void setPosOffset(double lonOffset, double latOffset) { |
|
468 |
GPSDriver.lonOffset = lonOffset; |
|
469 |
GPSDriver.latOffset = latOffset; |
|
470 |
} |
|
471 |
|
|
472 |
/** |
|
473 |
* The very last position that the driver has delivered to the listeners. |
|
474 |
* @return point2D |
|
475 |
*/ |
|
476 |
public Point2D getCurrentPosition() { |
|
477 |
return currentPos; |
|
478 |
} |
|
479 |
|
|
480 |
/** |
|
481 |
* Returns the current sample rate set. |
|
482 |
* @return |
|
483 |
*/ |
|
484 |
public int getSampleRate() { |
|
485 |
return rate; |
|
486 |
} |
|
487 |
|
|
488 |
public static void main(String[] args) { |
|
489 |
if (args.length < 4) { |
|
490 |
System.out.print("GPSReader port portSpeed\n"); |
|
491 |
System.exit(-1); |
|
492 |
} |
|
493 |
Enumeration portList = CommPortIdentifier.getPortIdentifiers(); |
|
494 |
while (portList.hasMoreElements()) { |
|
495 |
CommPortIdentifier myPortId = (CommPortIdentifier) portList.nextElement(); |
|
496 |
if (myPortId.getPortType() == CommPortIdentifier.PORT_SERIAL) { |
|
497 |
if (myPortId.getName().equals(args[0])) { |
|
498 |
try { |
|
499 |
GPSDriver driver = GPSDriver.getInstance(); |
|
500 |
driver.setPort(myPortId, Integer.parseInt(args[1]), SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); |
|
501 |
driver.setSampleRate(100); |
|
502 |
driver.addEventListener(new GPSEventListener() { |
|
503 |
public void unhandledMessage(String msg) { |
|
504 |
System.out.println("UNHANDLED: "+msg); |
|
505 |
} |
|
506 |
|
|
507 |
public void connectionLost() { |
|
508 |
System.out.println("CONNECTION LOST"); |
|
509 |
} |
|
510 |
|
|
511 |
public void connectionEstablished() { |
|
512 |
System.out.println("CONNECTION ESTABLISHED"); |
|
513 |
} |
|
514 |
|
|
515 |
public void newLonLatPositionReceived(double lon, double lat) { |
|
516 |
System.out.println("NEW LONLAT POSITION RECEIVED: ("+lon+", "+lat+")"); |
|
517 |
} |
|
518 |
|
|
519 |
public void signalQualityChanged(float level, int satellites, String qualityStatus) { |
|
520 |
System.out.println("NEW SIGNAL LEVEL: "+level+" ("+satellites+" satellites in view)"); |
|
521 |
} |
|
522 |
|
|
523 |
public void speedChanged(float speed, short course) { |
|
524 |
System.out.println("SPEED/COURSE CHANGED: ( "+speed+" Km/h, "+course+" degrees)"); |
|
525 |
} |
|
526 |
|
|
527 |
public void estimatedPosErrorChanged(double e) { |
|
528 |
System.out.println("ESTIMATED POSITION ERROR CHANGED: "+e); |
|
529 |
} |
|
530 |
|
|
531 |
public void altitudeChanged(float height) { |
|
532 |
System.out.println("HEIGHT CHANGED: "+height); |
|
533 |
} |
|
534 |
|
|
535 |
public void precisionChanged(float pDop, float hDop, float vDop) { |
|
536 |
System.out.println("PRECISION CHANGED: "+pDop+", "+hDop+", "+vDop+")"); |
|
537 |
} |
|
538 |
|
|
539 |
}); |
|
540 |
driver.connect(); |
|
541 |
} catch (PortInUseException e) { |
|
542 |
System.err.println("Port busy"); |
|
543 |
} |
|
544 |
|
|
545 |
} |
|
546 |
} |
|
547 |
} |
|
548 |
} |
|
549 |
|
|
550 |
} |
|
0 | 551 |
tags/gvsig_topologia-1.0.1-1231/extensions/extGPS/src/org/gvsig/gps/GPSExtension.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.21 2007-05-17 09:43:04 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.20 2007/01/10 17:05:23 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.19 2006/10/18 07:56:51 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* Revision 1.18 2006/10/02 06:34:51 jaume |
|
56 |
* refactoring gvSIG documents |
|
57 |
* |
|
58 |
* Revision 1.17 2006/09/29 14:12:51 luisw2 |
|
59 |
* CRSFactory.getCRS substitutes ProjectionPool.get |
|
60 |
* |
|
61 |
* Revision 1.16 2006/09/20 13:21:14 jaume |
|
62 |
* *** empty log message *** |
|
63 |
* |
|
64 |
* Revision 1.15 2006/09/18 08:02:46 jaume |
|
65 |
* *** empty log message *** |
|
66 |
* |
|
67 |
* Revision 1.14 2006/09/14 07:06:00 jaume |
|
68 |
* *** empty log message *** |
|
69 |
* |
|
70 |
* Revision 1.13 2006/08/29 11:52:17 jaume |
|
71 |
* *** empty log message *** |
|
72 |
* |
|
73 |
* Revision 1.12 2006/08/29 07:45:35 jaume |
|
74 |
* *** empty log message *** |
|
75 |
* |
|
76 |
* Revision 1.11 2006/07/31 06:46:02 jaume |
|
77 |
* *** empty log message *** |
|
78 |
* |
|
79 |
* Revision 1.9 2006/05/02 15:57:53 jorpiell |
|
80 |
* Se ha cambiado la interfaz Extension por dos clases: una interfaz (IExtension) y una clase abstract(Extension). A partir de ahora todas las extensiones deben heredar de Extension |
|
81 |
* |
|
82 |
* Revision 1.8 2006/04/10 11:21:52 jaume |
|
83 |
* *** empty log message *** |
|
84 |
* |
|
85 |
* Revision 1.7 2006/04/07 12:45:55 jaume |
|
86 |
* *** empty log message *** |
|
87 |
* |
|
88 |
* Revision 1.6 2006/04/07 11:10:26 jaume |
|
89 |
* *** empty log message *** |
|
90 |
* |
|
91 |
* Revision 1.5 2006/04/07 08:27:48 jaume |
|
92 |
* *** empty log message *** |
|
93 |
* |
|
94 |
* Revision 1.4 2006/04/06 10:34:58 jaume |
|
95 |
* *** empty log message *** |
|
96 |
* |
|
97 |
* Revision 1.3 2006/04/05 17:08:18 jaume |
|
98 |
* *** empty log message *** |
|
99 |
* |
|
100 |
* Revision 1.2 2006/04/05 16:02:09 jaume |
|
101 |
* *** empty log message *** |
|
102 |
* |
|
103 |
* Revision 1.1 2006/04/03 16:10:27 jaume |
|
104 |
* *** empty log message *** |
|
105 |
* |
|
106 |
* Revision 1.1 2006/03/31 09:55:34 jaume |
|
107 |
* *** empty log message *** |
|
108 |
* |
|
109 |
* |
|
110 |
*/ |
|
111 |
package org.gvsig.gps; |
|
112 |
|
|
113 |
import java.awt.Color; |
|
114 |
import java.awt.geom.Point2D; |
|
115 |
import java.io.BufferedReader; |
|
116 |
import java.io.File; |
|
117 |
import java.io.FileReader; |
|
118 |
import java.util.ArrayList; |
|
119 |
|
|
120 |
import org.cresques.cts.ICoordTrans; |
|
121 |
import org.cresques.cts.IProjection; |
|
122 |
import org.gvsig.gps.panel.GPSControlPanel; |
|
123 |
|
|
124 |
import com.iver.andami.PluginServices; |
|
125 |
import com.iver.andami.plugins.Extension; |
|
126 |
import com.iver.andami.ui.mdiManager.IWindow; |
|
127 |
import com.iver.cit.gvsig.fmap.MapControl; |
|
128 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
|
129 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
130 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
131 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
|
132 |
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
|
133 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
|
134 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
|
135 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
|
136 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
|
137 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
|
138 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
|
139 |
|
|
140 |
public class GPSExtension extends Extension{ |
|
141 |
|
|
142 |
public void execute(String actionCommand) { |
|
143 |
if (actionCommand.equals("GPS_CONTROL_PANEL")) |
|
144 |
PluginServices.getMDIManager().addWindow(GPSControlPanel.getInstance()); |
|
145 |
else if (actionCommand.equals("PAINT_POINTS")) { |
|
146 |
paintPointsFromFile(null, null, new File("c:/gps-capture")); |
|
147 |
} |
|
148 |
|
|
149 |
} |
|
150 |
|
|
151 |
public boolean isEnabled() { |
|
152 |
return true; |
|
153 |
} |
|
154 |
|
|
155 |
public boolean isVisible() { |
|
156 |
return true; |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* Takes an array of gvSIG views and draws an symbol in the specified location. |
|
161 |
* If views[] is empty (vies.length == 0) then no drawing in applied. |
|
162 |
* If views[] is null, then the symbol is drawn in every view in the project. |
|
163 |
* If the symbol is null, then a simple point is used as symbol. |
|
164 |
* @param views |
|
165 |
* @param location |
|
166 |
* @param symbol |
|
167 |
* @param refreshing, tells if the view will be refreshed (old points will be removed) |
|
168 |
*/ |
|
169 |
public void drawSymbol(View[] views, ISymbol symbol, Point2D location, boolean refreshing) { |
|
170 |
if (location == null || location.getX()==0 || location.getY()==0) return; |
|
171 |
if (views == null) |
|
172 |
{ |
|
173 |
IWindow[] aViews = PluginServices.getMDIManager().getAllWindows(); |
|
174 |
ArrayList gvViews = new ArrayList(); |
|
175 |
for (int i = 0; i < aViews.length; i++) { |
|
176 |
if (aViews[i] instanceof View) { |
|
177 |
gvViews.add((View) aViews[i]); |
|
178 |
} |
|
179 |
} |
|
180 |
views = (View[]) gvViews.toArray(new View[0]); |
|
181 |
} |
|
182 |
|
|
183 |
// if (symbol == null) { |
|
184 |
// symbol = new FSymbol(FShape.CIRCLE, Color.ORANGE); |
|
185 |
// ((FSymbol) symbol).setSizeInPixels(true); |
|
186 |
// ((FSymbol) symbol).setSize(10); |
|
187 |
// } |
|
188 |
if (symbol == null) { |
|
189 |
symbol = SymbologyFactory.createDefaultSymbolByShapeType(FShape.POINT, Color.ORANGE); |
|
190 |
((IMarkerSymbol) symbol).setSize(10); |
|
191 |
} |
|
192 |
|
|
193 |
for (int i = 0; i < views.length; i++) { |
|
194 |
MapControl mc = views[i].getMapControl(); |
|
195 |
GraphicLayer graph = mc.getMapContext().getGraphicsLayer(); |
|
196 |
|
|
197 |
if (refreshing) { |
|
198 |
// Remove old graphics |
|
199 |
graph.clearAllGraphics(); |
|
200 |
graph.clearSymbolsGraphics(); |
|
201 |
mc.drawGraphics(); |
|
202 |
} |
|
203 |
|
|
204 |
// Obtain the current view's projection |
|
205 |
IProjection reqProj = mc.getProjection(); |
|
206 |
|
|
207 |
// the geodesic projection |
|
208 |
IProjection latLonProj = CRSFactory.getCRS("EPSG:4326"); |
|
209 |
|
|
210 |
// create a translator from geodesic to the current view's projection |
|
211 |
ICoordTrans ct = latLonProj.getCT(reqProj); |
|
212 |
|
|
213 |
Point2D pDst = new Point2D.Double(); |
|
214 |
|
|
215 |
// reproject the point |
|
216 |
pDst = ct.convert(location, pDst); |
|
217 |
|
|
218 |
// add and draw the FSymbol to the reprojected location. |
|
219 |
graph.addSymbol(symbol); |
|
220 |
graph.addGraphic(new FGraphic(ShapeFactory.createPoint2D(new FPoint2D(pDst)), 0)); |
|
221 |
mc.drawGraphics(); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
private void paintPointsFromFile(View[] views, FSymbol symbol, File f){ |
|
226 |
try { |
|
227 |
|
|
228 |
BufferedReader br = new BufferedReader(new FileReader(f)); |
|
229 |
String line; |
|
230 |
for (line = br.readLine(); line!=null; line = br.readLine()){ |
|
231 |
String[] numbers = line.split(","); |
|
232 |
|
|
233 |
double lon = Double.parseDouble(numbers[0]); |
|
234 |
double lat = Double.parseDouble(numbers[1]); |
|
235 |
drawSymbol(views, symbol, new Point2D.Double(lon, lat), false); |
|
236 |
} |
|
237 |
} catch (Exception e) { |
|
238 |
e.printStackTrace(); |
|
239 |
} |
|
240 |
} |
|
241 |
|
|
242 |
public void initialize() { |
|
243 |
} |
|
244 |
} |
|
0 | 245 |
tags/gvsig_topologia-1.0.1-1231/extensions/extGPS/src/org/gvsig/gps/listeners/GPSEventListener.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.3 2006-04-10 11:21:52 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.2 2006/04/06 10:35:07 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.1 2006/04/03 16:10:27 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* Revision 1.1 2006/03/31 09:55:34 jaume |
|
56 |
* *** empty log message *** |
|
57 |
* |
|
58 |
* |
|
59 |
*/ |
|
60 |
package org.gvsig.gps.listeners; |
|
61 |
|
|
62 |
/** |
|
63 |
* Inteface defining all the events received from the GPSDriver. |
|
64 |
* |
|
65 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
66 |
*/ |
|
67 |
public interface GPSEventListener { |
|
68 |
/** |
|
69 |
* Invoked when a message that has not been analyzed (in purpose or because |
|
70 |
* the analyzer could not make it) |
|
71 |
* @param msg, a string containing the NMEA message. |
|
72 |
*/ |
|
73 |
public void unhandledMessage(String msg); |
|
74 |
|
|
75 |
/** |
|
76 |
* Invoked when the value for the position in longitude and latitude. |
|
77 |
* @param longitude in degrees (decimal fractions). |
|
78 |
* @param latitude in degrees (decimal fractions). |
|
79 |
*/ |
|
80 |
public void newLonLatPositionReceived(double lon, double lat); |
|
81 |
|
|
82 |
/** |
|
83 |
* Invoked when the connection was lost. |
|
84 |
*/ |
|
85 |
public void connectionLost(); |
|
86 |
|
|
87 |
/** |
|
88 |
* Invoked when a connection was established. |
|
89 |
*/ |
|
90 |
public void connectionEstablished(); |
|
91 |
|
|
92 |
/** |
|
93 |
* Invoked when the signal strenght has changed. |
|
94 |
* @param level |
|
95 |
* @param qualityStatus TODO |
|
96 |
* @param satellites, the amount of satellites currently in view |
|
97 |
*/ |
|
98 |
public void signalQualityChanged(float level, int satellites, String qualityStatus); |
|
99 |
|
|
100 |
/** |
|
101 |
* Invoked when the speed and/or the course have changed. |
|
102 |
* @param speed, in km/h |
|
103 |
* @param course, from 0 to 359 |
|
104 |
*/ |
|
105 |
public void speedChanged(float speed, short course); |
|
106 |
|
|
107 |
/** |
|
108 |
* Invoked when the estimated error has changed. |
|
109 |
* @param e, TODO: what exactly it is? |
|
110 |
*/ |
|
111 |
public void estimatedPosErrorChanged(double e); |
|
112 |
|
|
113 |
/** |
|
114 |
* Invoked when the value for the height (z) changes |
|
115 |
* @param height, in meters. |
|
116 |
*/ |
|
117 |
public void altitudeChanged(float height); |
|
118 |
|
|
119 |
/** |
|
120 |
* Invoked when the any of the values of the position, horizontal, |
|
121 |
* or vertical precision have changed |
|
122 |
* @param pDop, position precision. |
|
123 |
* @param hDop, horizontal precision. |
|
124 |
* @param vDop, vertical precision. |
|
125 |
*/ |
|
126 |
public void precisionChanged(float pDop, float hDop, float vDop); |
|
127 |
|
|
128 |
} |
|
0 | 129 |
tags/gvsig_topologia-1.0.1-1231/extensions/extGPS/src/org/gvsig/gps/parser/NMEA/IllegalSentenceException.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.1 2006-04-03 16:10:27 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.1 2006/03/31 09:55:34 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* |
|
53 |
*/ |
|
54 |
package org.gvsig.gps.parser.NMEA; |
|
55 |
|
|
56 |
public class IllegalSentenceException extends Exception { |
|
57 |
public IllegalSentenceException() { |
|
58 |
super(); |
|
59 |
} |
|
60 |
|
|
61 |
public IllegalSentenceException(String msg) { |
|
62 |
super(msg); |
|
63 |
} |
|
64 |
} |
|
0 | 65 |
tags/gvsig_topologia-1.0.1-1231/extensions/extGPS/src/org/gvsig/gps/parser/NMEA/NMEASentenceFactory.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.2 2006-04-03 21:07:35 jaume |
|
47 |
* *** empty log message *** |
|
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 |
* Builds NMEASentence instances. |
|
60 |
* |
|
61 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
62 |
* |
|
63 |
*/ |
|
64 |
public class NMEASentenceFactory { |
|
65 |
|
|
66 |
/** |
|
67 |
* Given a NMEA sentence it returns an instance of the corresponding |
|
68 |
* object wrapped into an NMEASentence class. |
|
69 |
* @param s, the NMEA sentence |
|
70 |
* @return an instance of the object that handles such sentence |
|
71 |
* @throws IllegalSentenceException, if the sentence is not supported yet. |
|
72 |
*/ |
|
73 |
public static NMEASentence createFromString(String s) throws IllegalSentenceException { |
|
74 |
NMEASentence st = null; |
|
75 |
try { |
|
76 |
String stName = s.substring(3,6); |
|
77 |
Class c = Class.forName("org.gvsig.gps.parser.NMEA."+stName+"Sentence"); |
|
78 |
st = (NMEASentence) c.newInstance(); |
|
79 |
st.setData(s); |
|
80 |
st.setTime(System.currentTimeMillis()); |
|
81 |
} catch (StringIndexOutOfBoundsException e) { |
|
82 |
throw new IllegalSentenceException(); |
|
83 |
} catch (ClassNotFoundException e) { |
|
84 |
throw new IllegalSentenceException(); |
|
85 |
} catch (NumberFormatException e) { |
|
86 |
throw new IllegalSentenceException(); |
|
87 |
} catch (InstantiationException e) { |
|
88 |
e.printStackTrace(); |
|
89 |
} catch (IllegalAccessException e) { |
|
90 |
e.printStackTrace(); |
|
91 |
} |
|
92 |
|
|
93 |
return st; |
|
94 |
} |
|
95 |
} |
|
0 | 96 |
tags/gvsig_topologia-1.0.1-1231/extensions/extGPS/src/org/gvsig/gps/parser/NMEA/GSASentence.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.2 2006-04-10 11:21:52 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.1 2006/04/05 16:02:09 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* |
|
53 |
*/ |
|
54 |
package org.gvsig.gps.parser.NMEA; |
|
55 |
|
|
56 |
/** |
|
57 |
* <p> |
|
58 |
* The GSA message contains GPS DOP and active satellite information. |
|
59 |
* Only satellites used in the position computation are output. |
|
60 |
* Null fields are present when data is unavailable due to the number |
|
61 |
* of satellites tracked.<br> |
|
62 |
* </p> |
|
63 |
* <p> |
|
64 |
* $GPGSA,a,b,cc,dd,ee,ff,gg,hh,ii,jj,kk,mm,nn,oo,p.p,q.q,r.r |
|
65 |
* </p> |
|
66 |
* <p> |
|
67 |
* <ol> |
|
68 |
* <li><b>a</b>, Satellite acquisition mode M = manually forced to 2D or 3D, A = automatic swap between 2D and 3D |
|
69 |
* <li><b>b</b>, Position mode, 1 = fix not available, 2 = 2D fix, 3 = 3D fix |
|
70 |
* <li><b>cc</b>, to oo Satellites used in the position solution, a null field occurs if a channel is unused |
|
71 |
* <li><b>p.p</b>, Position Dilution of Precision (PDOP) = 1.0 to 9.9 |
|
72 |
* <li><b>q.q</b>, Horizontal Dilution of Precision (HDOP) = 1.0 to 9.9 |
|
73 |
* <li><b>r.r</b>, Vertical Dilution of Precision (VDOP) = 1.0 to 9.9 |
|
74 |
* </ol> |
|
75 |
* </p> |
|
76 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
|
77 |
*/ |
|
78 |
public class GSASentence extends NMEASentence { |
|
79 |
private char adquisitionMode; |
|
80 |
private byte positionMode; |
|
81 |
private float pdop, hdop, vdop; |
|
82 |
private String[] satellites = new String[12]; |
|
83 |
|
|
84 |
public void parse() throws IllegalSentenceException { |
|
85 |
final short FIELD_SATELLITE_ADQUISITION_MODE = 1; |
|
86 |
final short FIELD_POSITION_MODE = 2; |
|
87 |
final short FIELD_POSITION_DILUTION = (short) (getFieldCount()-2); |
|
88 |
final short FIELD_HORIZONTAL_DILUTION = (short) (getFieldCount()-1); |
|
89 |
final short FIELD_VERTICAL_DILUTION = (short) getFieldCount(); |
|
90 |
try { |
|
91 |
for (int i = 0; i < getFieldCount(); i++) { |
|
92 |
String val = getFieldValue(i); |
|
93 |
if (i == FIELD_SATELLITE_ADQUISITION_MODE) { |
|
94 |
adquisitionMode = val.toUpperCase().charAt(0); |
|
95 |
} else if (i == FIELD_POSITION_MODE) { |
|
96 |
positionMode = Byte.parseByte(val); |
|
97 |
} else if (i == FIELD_POSITION_DILUTION) { |
|
98 |
pdop = Float.parseFloat(val); |
|
99 |
} else if (i == FIELD_HORIZONTAL_DILUTION) { |
|
100 |
hdop = Float.parseFloat(val); |
|
101 |
} else if (i == FIELD_VERTICAL_DILUTION) { |
|
102 |
vdop = Float.parseFloat(val); |
|
103 |
} else { |
|
104 |
int satId = i - 3; |
|
105 |
satellites[satId] = val; |
|
106 |
} |
|
107 |
} |
|
108 |
} catch (ArrayIndexOutOfBoundsException e) { |
|
109 |
throw new IllegalSentenceException(); |
|
110 |
} |
|
111 |
} |
|
112 |
|
|
113 |
/** |
|
114 |
* Don't know what to write here. Just the name of the method? |
|
115 |
* @return String: one of "FIX_NOT_AVAILABLE", |
|
116 |
* "2D_FIX", |
|
117 |
* "3D_FIX", |
|
118 |
* or null (if no value available) |
|
119 |
*/ |
|
120 |
public String getPositionMode() { |
|
121 |
switch (positionMode) { |
|
122 |
case 1: |
|
123 |
return "FIX_NOT_AVAILABLE"; |
|
124 |
case 2: |
|
125 |
return "2D_FIX"; |
|
126 |
case 3: |
|
127 |
return "3D_FIX"; |
|
128 |
default: |
|
129 |
return null; |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* returns the satellites used in the position solution, a null field occurs if a channel is unused |
|
135 |
* @return String[] |
|
136 |
*/ |
|
137 |
public String[] getUsedSatellites() { |
|
138 |
return satellites; |
|
139 |
} |
|
140 |
|
|
141 |
/** |
|
142 |
* Returns the value for the three disolutions of precision |
|
143 |
* @return float[] where: <p> |
|
144 |
* float[0] = position disolution <br> |
|
145 |
* float[1] = horizontal disolution <br> |
|
146 |
* float[2] = vertical disolution. |
|
147 |
* </p> |
|
148 |
*/ |
|
149 |
public float[] getPrecisionDisolutions(){ |
|
150 |
return new float[] { pdop, hdop, vdop }; |
|
151 |
} |
|
152 |
|
|
153 |
public boolean isEquivalentTo(NMEASentence otherSentence) { |
|
154 |
if (otherSentence instanceof GSASentence) { |
|
155 |
GSASentence other = (GSASentence) otherSentence; |
|
156 |
if ( (adquisitionMode == other.adquisitionMode) |
|
157 |
&& (hdop == other.hdop) |
|
158 |
&& (pdop == other.pdop) |
|
159 |
&& (vdop == other.vdop) |
|
160 |
&& (positionMode == other.positionMode) ) { |
|
161 |
|
|
162 |
for (int i = 0; i < satellites.length; i++) { |
|
163 |
if (!satellites[i].equals(other.satellites[i])) |
|
164 |
return false; |
|
165 |
} |
|
166 |
} |
|
167 |
return true; |
|
168 |
} |
|
169 |
return false; |
|
170 |
} |
|
171 |
|
|
172 |
} |
|
0 | 173 |
tags/gvsig_topologia-1.0.1-1231/extensions/extGPS/src/org/gvsig/gps/parser/NMEA/GGASentence.java | ||
---|---|---|
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$ |
|
45 |
* $Log$ |
|
46 |
* Revision 1.3 2006-04-10 11:21:52 jaume |
|
47 |
* *** empty log message *** |
|
48 |
* |
|
49 |
* Revision 1.2 2006/04/06 10:35:59 jaume |
|
50 |
* *** empty log message *** |
|
51 |
* |
|
52 |
* Revision 1.1 2006/04/03 16:10:27 jaume |
|
53 |
* *** empty log message *** |
|
54 |
* |
|
55 |
* Revision 1.1 2006/03/31 09:55:34 jaume |
|
56 |
* *** empty log message *** |
|
57 |
* |
|
58 |
* |
Also available in: Unified diff