Revision 4784 trunk/extensions/extGPS/src/org/gvsig/gps/GPSDriver.java

View differences:

GPSDriver.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.6  2006-04-07 12:45:55  jaume
46
* Revision 1.7  2006-04-10 11:21:52  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.6  2006/04/07 12:45:55  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.5  2006/04/07 11:10:26  jaume
50 53
* *** empty log message ***
51 54
*
......
76 79
import gnu.io.SerialPort;
77 80
import gnu.io.UnsupportedCommOperationException;
78 81

  
82
import java.awt.geom.Point2D;
79 83
import java.io.BufferedWriter;
80 84
import java.io.File;
81 85
import java.io.FileWriter;
......
87 91
import java.util.Hashtable;
88 92
import java.util.Iterator;
89 93

  
94
import org.gvsig.gps.exceptions.GPSReceiverException;
90 95
import org.gvsig.gps.listeners.GPSEventListener;
91 96
import org.gvsig.gps.parser.NMEA.GGASentence;
97
import org.gvsig.gps.parser.NMEA.GSASentence;
92 98
import org.gvsig.gps.parser.NMEA.IllegalSentenceException;
93 99
import org.gvsig.gps.parser.NMEA.NMEASentence;
94 100
import org.gvsig.gps.parser.NMEA.NMEASentenceFactory;
95 101
import org.gvsig.gps.parser.NMEA.RMCSentence;
96 102
import org.gvsig.gps.parser.NMEA.VTGSentence;
97 103

  
104
import com.iver.andami.PluginServices;
105

  
98 106
/**
99 107
 * Singleton class that handles the communication within the application and the
100 108
 * GPS receiver. It opens the port set with the setPort() method and establishes
......
123 131

  
124 132
	private double lonOffset = 0D;
125 133
	private double latOffset = 0D;
134

  
135
	private Point2D currentPos;
126 136
	
127 137
	private static GPSDriver instance = null;
128 138
	
......
203 213
					line = new StringBuffer();
204 214
					line.append(str.substring(i+1,str.length()));
205 215
				}
206
//				if (stop)
207
//					break;
208 216
			}
209 217
		} catch (IOException e) {
210 218
			e.printStackTrace();
......
230 238
					line = new StringBuffer();
231 239
					line.append(str.substring(i+1,str.length()));
232 240
				}
233
//				if (stop)
234
//					break;
241
				break;
235 242
			}
236 243
		} catch (IOException e) {
237 244
			e.printStackTrace();
......
285 292
									e.printStackTrace();
286 293
								}
287 294
							}
288
							l.newLonLatPositionReceived(s.getLongitude(), s.getLatitude());
295
							fireLonLatPositionReceived(l, s.getLongitude(), s.getLatitude());
296
							
297
							l.precisionChanged(-1, s.getHDOP(), -1);
298
							l.signalQualityChanged(0, s.getSatelliteCount(), s.getQualityStatus());
299
							l.altitudeChanged(s.getAltitude());
300
						} else if (aux instanceof GSASentence) {
301
							GSASentence s = (GSASentence) aux;
302
							float[] dissolutions = s.getPrecisionDisolutions();
303
							l.precisionChanged(dissolutions[0], dissolutions[1], dissolutions[2]);
304
							s.getUsedSatellites();
289 305
						} else if (aux instanceof RMCSentence) {
290 306
							l.unhandledMessage(aux.toString());
291 307
						} else if (aux instanceof VTGSentence) {
......
305 321
		}
306 322
	}
307 323
	
324
	private void fireLonLatPositionReceived(GPSEventListener listener, double longitude, double latitude) {
325
		currentPos = new Point2D.Double(longitude, latitude);
326
		listener.newLonLatPositionReceived(longitude,latitude);
327
	}
328

  
308 329
	private boolean isCurrent(NMEASentence n) {
309 330
		return System.currentTimeMillis() - n.getTime() < timeOut;
310 331
	}
......
347 368
								System.out.println("NEW LONLAT POSITION RECEIVED: ("+lon+", "+lat+")");
348 369
							}
349 370

  
350
							public void signalLevelChanged(float level) {
351
								System.out.println("NEW SIGNAL LEVEL: "+level);
371
							public void signalQualityChanged(float level, int satellites, String qualityStatus) {
372
								System.out.println("NEW SIGNAL LEVEL: "+level+" ("+satellites+" satellites in view)");
352 373
							}
353 374

  
354 375
							public void speedChanged(float speed, short course) {
......
359 380
								System.out.println("ESTIMATED POSITION ERROR CHANGED: "+e);
360 381
							}
361 382

  
362
							public void heightChanged(float height) {
383
							public void altitudeChanged(float height) {
363 384
								System.out.println("HEIGHT CHANGED: "+height);
364 385
							}
365 386

  
......
407 428
	 * 
408 429
	 * @param lonOffset
409 430
	 * @param latOffset
431
	 * @throws GPSReceiverException 
410 432
	 */
411
	public void setPosOffset(double lonOffset, double latOffset) {
412
		this.lonOffset = lonOffset;
413
		this.latOffset = latOffset;
433
	public void setPosOffset(double lonOffset, double latOffset) throws GPSReceiverException {
434
		if (currentPos!=null) {
435
			this.lonOffset = currentPos.getX() - lonOffset;
436
			this.latOffset = currentPos.getY() - latOffset;
437
		} else throw new GPSReceiverException(PluginServices.getText(this, "not_yet_available"));
414 438
	}
415 439
}

Also available in: Unified diff