courselog.gpsutils
Class PositionTracer

java.lang.Object
  extended by courselog.gpsutils.PositionTracer
All Implemented Interfaces:
ewe.ui.EventListener

public class PositionTracer
extends java.lang.Object
implements ewe.ui.EventListener

Traces the position obtained by a SerialGPSConnection into a logging file. Also provides calculations of the current duration, cumulative distance, average speed, average heading. About PositionTracer status : STATUS_OFF : The tracer is off, no recording. STATUS_RECORDING : The tracer is recording ReceiverEvents and generating trace. STATUS_HOLD : The tracer is on hold. If it restarts, a new Receiver may be activated, anyway, old records will be kept. Useful when the recorder is activated from time to time. STATUS_PAUSED : The tracer is not recording. Moves are not considered part of the trace. Useful when you are stopping your treck and want to make moves that are not interesting to record.


Field Summary
protected  byte[] buff
          Static buffer where logged data is written (256 chars).
 java.lang.String fileLogName
          Name of the logging file.
 ewe.io.FileOutputStream fLog
          Logging file.
protected  boolean isNextLogForced
          Flag to force next point to be logged, whatever the state.
protected  boolean isOutOfPause
          Flag indicating that next update of trace should consider that it is out of pause mode.
protected  double lastDownwards
          Last downwards value taken for reference.
 double lastReferenceAltitude
          Previous reference altitude.
 TrackPoint lastSignificantPoint
          Previous point, spaced at least by minDistance from current point.
protected  double lastUpwards
          Last upwards value taken for reference.
 double minAltitudeDifference
          Minimum altitude to count difference points.
 double minDistance
          Minimum distance between logged points.
 TrackPoint myCurrent
          Current point of the trace.
 SerialGPSConnection myGPS
          Connected GPS receiver.
 int myStatus
          PositionTracer status, see constants.
 TrackRecord myTrack
          Record of the current.
static int OPT_STATUSCHANGED
          Option indicating that the receiver state has changed
static int OPT_TRACECHANGED
          Option indicating that the track has changed
static int STATUS_HOLD
          Status when PositionTracer is on hold (==2).
static int STATUS_OFF
          Status when PositionTracer is not active (==0).
static int STATUS_PAUSED
          Status when PositionTracer is paused (==3).
static int STATUS_RECORDING
          Status when PositionTracer is not recording (==1).
protected  ewe.util.Vector vDisplayer
          Event Listener when state of the Tracer changes.
 
Constructor Summary
PositionTracer(SerialGPSConnection sGPS, int newStatus, java.lang.String logName)
          Creates a new instance of PositionTracer with a logging file
 
Method Summary
 void addDisplayer(XPositionDisplayer newDisp)
          Add a position displayer to this tracer.
 int getGPSStatus()
          The status of the GPS receiver.
 void initFromStateAndLog(int newStatus, java.lang.String log)
          Read initial attributes of this PositionTracer from a buffer content.
 void logAPoint(TrackPoint pt)
          Writes a point in the logging file.
 void onEvent(ewe.ui.Event rEv)
          Activated when a ReceiverEvent is generated by the GPS.
 void removeDisplayer(XPositionDisplayer newDisp)
          Remove a position displayer to this tracer.
 void setLogFileName(java.lang.String newName)
          Set the log file name.
 void setStatus(int newStatus)
          Change the status of the tracer.
 boolean updateTrace(MeasuredPoint pt)
          Called when a new event is received and tracer is not off, in order to update the tracer state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myGPS

public SerialGPSConnection myGPS
Connected GPS receiver.


vDisplayer

protected ewe.util.Vector vDisplayer
Event Listener when state of the Tracer changes. Use of a Dispatcher would have been prefered but did not work with windows 2005 Pocket (as the same code worked with Java under WinXP).


fLog

public ewe.io.FileOutputStream fLog
Logging file. Traces of points are placed here.


buff

protected byte[] buff
Static buffer where logged data is written (256 chars).


STATUS_OFF

public static final int STATUS_OFF
Status when PositionTracer is not active (==0).

See Also:
Constant Field Values

STATUS_RECORDING

public static final int STATUS_RECORDING
Status when PositionTracer is not recording (==1).

See Also:
Constant Field Values

STATUS_HOLD

public static final int STATUS_HOLD
Status when PositionTracer is on hold (==2).

See Also:
Constant Field Values

STATUS_PAUSED

public static final int STATUS_PAUSED
Status when PositionTracer is paused (==3).

See Also:
Constant Field Values

myStatus

public int myStatus
PositionTracer status, see constants. Use setStatus to set it. Read it publicly.


OPT_STATUSCHANGED

public static final int OPT_STATUSCHANGED
Option indicating that the receiver state has changed

See Also:
Constant Field Values

OPT_TRACECHANGED

public static final int OPT_TRACECHANGED
Option indicating that the track has changed

See Also:
Constant Field Values

myTrack

public TrackRecord myTrack
Record of the current.


myCurrent

public TrackPoint myCurrent
Current point of the trace.


lastSignificantPoint

public TrackPoint lastSignificantPoint
Previous point, spaced at least by minDistance from current point.


lastReferenceAltitude

public double lastReferenceAltitude
Previous reference altitude. To compare with minAltitudeDifference to count variations from current point.


lastUpwards

protected double lastUpwards
Last upwards value taken for reference.


lastDownwards

protected double lastDownwards
Last downwards value taken for reference.


isOutOfPause

protected boolean isOutOfPause
Flag indicating that next update of trace should consider that it is out of pause mode.


isNextLogForced

protected boolean isNextLogForced
Flag to force next point to be logged, whatever the state.


minDistance

public double minDistance
Minimum distance between logged points. As GPS involves measurement errors, only points separated by this distance are logged in order to reduce points in case you don't move.


minAltitudeDifference

public double minAltitudeDifference
Minimum altitude to count difference points. As GPS involves measurement errors, only altitudes separated by this distance are counted in the vertical moves in order to reduce false moves. Initial value 5.0 m.


fileLogName

public java.lang.String fileLogName
Name of the logging file.

Constructor Detail

PositionTracer

public PositionTracer(SerialGPSConnection sGPS,
                      int newStatus,
                      java.lang.String logName)
Creates a new instance of PositionTracer with a logging file

Parameters:
sGPS - GPS receiver associated to this trace.
newStatus - The status in case this tracer is created after another one.
logName - Name of the file where the log should be placed. If null, no file is written.
Method Detail

setLogFileName

public void setLogFileName(java.lang.String newName)
Set the log file name. This closes a previous log if any. Call this with newName==null to close the log file.

Parameters:
newName - New log file name.

setStatus

public void setStatus(int newStatus)
Change the status of the tracer.

Parameters:
newStatus - Should be one of STATUS_XXX values.

getGPSStatus

public int getGPSStatus()
The status of the GPS receiver.

Returns:
one value of SerialGPSConnection.STATUS_xxx.

initFromStateAndLog

public void initFromStateAndLog(int newStatus,
                                java.lang.String log)
Read initial attributes of this PositionTracer from a buffer content. Should be able to read a buffer formatted by formatInBuffer and restore the tracer status content.
 Significant fields are :
 - Date
 - Time (UTC)
 - Latitude
 - Longitude
 - Altitude
 - Total distance
 - Total time
 - Total up
 - Total down
 
A small discripancy in the usage of this hold mode : last reference altitude is the one from the last logged point, as, in continuous mode, it is the one from the last altitude used in reference.

Parameters:
newStatus - New value of status for the tracer.
log - Buffer from which we read in values.

onEvent

public void onEvent(ewe.ui.Event rEv)
Activated when a ReceiverEvent is generated by the GPS. My call its own listener with an event signalling the trace has changed.

Specified by:
onEvent in interface ewe.ui.EventListener
Parameters:
rEv - Event from the GPS.

addDisplayer

public void addDisplayer(XPositionDisplayer newDisp)
Add a position displayer to this tracer.

Parameters:
newDisp - New displayer to add.

removeDisplayer

public void removeDisplayer(XPositionDisplayer newDisp)
Remove a position displayer to this tracer.

Parameters:
newDisp - Displayer to remove.

updateTrace

public boolean updateTrace(MeasuredPoint pt)
Called when a new event is received and tracer is not off, in order to update the tracer state. If the point is distant enough from the last point, the trace log is updated.

Parameters:
pt - New point to take into account.
Returns:
True if the trace state has changed, false otherwise.

logAPoint

public void logAPoint(TrackPoint pt)
Writes a point in the logging file.

Parameters:
pt - Point to put in the log.