org.jscience.devices.gps.garmin
Class GarminPacket

java.lang.Object
  extended by org.jscience.devices.gps.garmin.GarminPacket
Direct Known Subclasses:
LapDataPacket, PositionDataPacket, ProductDataPacket, ProtocolDataPacket, PVTDataPacket, RecordsPacket, TimeDataPacket, TrackpointDataPacket, WaypointDataPacket

public class GarminPacket
extends java.lang.Object

A class that encapsulates the basic functionality of a packet.


Field Summary
static int Cmnd_Abort_Transfer
          Abort current transfer.
static int Cmnd_Start_Pvt_Data
          Start transmitting PVT (Position, velocity, time) Data.
static int Cmnd_Stop_Pvt_Data
          Stop transmitting PVT (Position, velocity, time) Data.
static int Cmnd_Transfer_Alm
          Transfer almanac.
static int Cmnd_Transfer_Laps
          Transfer Laps
static int Cmnd_Transfer_Posn
          Transfer position.
static int Cmnd_Transfer_Prx
          Transfer proximity waypoints.
static int Cmnd_Transfer_Rte
          Transfer routes.
static int Cmnd_Transfer_Time
          Transfer time.
static int Cmnd_Transfer_Trk
          Transfer track log.
static int Cmnd_Transfer_Wpt
          Transfer waypoints.
static int Cmnd_Turn_Off_Pwr
          Turn off power.
static int DLE
          Data link escape.
static int ETX
          End of text.
protected  int[] packet
          The packet in byte-form.
static int Pid_Ack_Byte
          DOCUMENT ME!
static int Pid_Command_Data
          DOCUMENT ME!
static int Pid_Date_Time_Data
          DOCUMENT ME!
static int Pid_Lap
          DOCUMENT ME!
static int Pid_Nak_Byte
          DOCUMENT ME!
static int Pid_Position_Data
          DOCUMENT ME!
static int Pid_Product_Data
          DOCUMENT ME!
static int Pid_Product_Rqst
          DOCUMENT ME!
static int Pid_Protocol_Array
          DOCUMENT ME!
static int Pid_Prx_Wpt_Data
          DOCUMENT ME!
static int Pid_Pvt_Data
          DOCUMENT ME!
static int Pid_Records
          DOCUMENT ME!
static int Pid_Trk_data
          DOCUMENT ME!
static int Pid_Trk_Hdr
          DOCUMENT ME!
static int Pid_Wpt_Data
          DOCUMENT ME!
static int Pid_Xfer_Cmplt
          DOCUMENT ME!
protected  int pointer
          pointer - the current position of the pointer to which byte is being read
 
Constructor Summary
GarminPacket(int[] p)
          Creates a new GarminPacket with the contents of p.
GarminPacket(int[] p, boolean calcChecksum)
          Creates a new GarminPacket with the contents of p. if calcChecksum is true, the packet will have it's checksum recalculated.
 
Method Summary
 int calcChecksum()
          Calculates the checksum for the packet.
static GarminPacket createBasicPacket(int type, int[] data)
          This method is capable of making the data-packets from L000 (basic link protocol).
static GarminPacket createCommandPacket(int type)
          This is a factory-method capable of creating instances the commandpackets from A010.
protected  int getByte(int i)
          Returns the packet-byte at position i.
 int getDataLength()
          Returns the amount of bytes in the data-field of this packet.
 int getID()
          Returns the ID (ie. type) of the packet.
protected  int getLength()
          Returns the length of the entire packet in bytes.
protected  int[] getPacket()
          Returns the packet in it's original byte-form.
protected  int getPointer()
           
 java.lang.String getRawPacket()
          Debug-method.
static java.lang.String idToString(int id)
          Method that translates a packet-id into a human-readable string.
 int isLegal()
          Checks if the packet is valid with regards to header, footer,data-field-length and checksum.
protected  boolean readBoolean()
           
protected  boolean readBoolean(int packet_index)
          Method that reads a Garmin-long in the packet and returns it as an int.
protected  short readByte()
           
protected  short readByte(int packet_index)
          Method that reads a Garmin-byte in the packet and returns it as a short.
protected  double readDouble()
           
protected  double readDouble(int packet_index)
          Method that reads a Garmin-double in the packet and returns it as a double.
protected  float readFloat()
           
protected  float readFloat(int packet_index)
          Method that reads a Garmin-float in the packet and returns it as a float.
protected  int readLong()
           
protected  int readLong(int packet_index)
          Method that reads a Garmin-long in the packet and returns it as an int.
protected  java.lang.String readNullTerminatedString()
           
protected  java.lang.String readNullTerminatedString(int packet_index)
          Method that reads a null-terminated string.
protected  Position readPosition()
           
protected  Position readPosition(int packet_index)
           
protected  int readWord()
           
protected  int readWord(int packet_index)
          Method that reads a Garmin-word in the packet and returns it as an int.
protected  void setPointer(int moveTo)
           
 java.lang.String toString()
          Returns a human-readable string with information to the packet's contents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

Pid_Ack_Byte

public static final int Pid_Ack_Byte
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Nak_Byte

public static final int Pid_Nak_Byte
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Protocol_Array

public static final int Pid_Protocol_Array
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Product_Rqst

public static final int Pid_Product_Rqst
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Product_Data

public static final int Pid_Product_Data
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Command_Data

public static final int Pid_Command_Data
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Xfer_Cmplt

public static final int Pid_Xfer_Cmplt
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Date_Time_Data

public static final int Pid_Date_Time_Data
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Position_Data

public static final int Pid_Position_Data
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Prx_Wpt_Data

public static final int Pid_Prx_Wpt_Data
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Records

public static final int Pid_Records
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Trk_data

public static final int Pid_Trk_data
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Wpt_Data

public static final int Pid_Wpt_Data
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Pvt_Data

public static final int Pid_Pvt_Data
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Trk_Hdr

public static final int Pid_Trk_Hdr
DOCUMENT ME!

See Also:
Constant Field Values

Pid_Lap

public static final int Pid_Lap
DOCUMENT ME!

See Also:
Constant Field Values

Cmnd_Abort_Transfer

public static final int Cmnd_Abort_Transfer
Abort current transfer.

See Also:
Constant Field Values

Cmnd_Transfer_Alm

public static final int Cmnd_Transfer_Alm
Transfer almanac.

See Also:
Constant Field Values

Cmnd_Transfer_Posn

public static final int Cmnd_Transfer_Posn
Transfer position.

See Also:
Constant Field Values

Cmnd_Transfer_Prx

public static final int Cmnd_Transfer_Prx
Transfer proximity waypoints.

See Also:
Constant Field Values

Cmnd_Transfer_Rte

public static final int Cmnd_Transfer_Rte
Transfer routes.

See Also:
Constant Field Values

Cmnd_Transfer_Time

public static final int Cmnd_Transfer_Time
Transfer time.

See Also:
Constant Field Values

Cmnd_Transfer_Trk

public static final int Cmnd_Transfer_Trk
Transfer track log.

See Also:
Constant Field Values

Cmnd_Transfer_Wpt

public static final int Cmnd_Transfer_Wpt
Transfer waypoints.

See Also:
Constant Field Values

Cmnd_Turn_Off_Pwr

public static final int Cmnd_Turn_Off_Pwr
Turn off power.

See Also:
Constant Field Values

Cmnd_Start_Pvt_Data

public static final int Cmnd_Start_Pvt_Data
Start transmitting PVT (Position, velocity, time) Data.

See Also:
Constant Field Values

Cmnd_Stop_Pvt_Data

public static final int Cmnd_Stop_Pvt_Data
Stop transmitting PVT (Position, velocity, time) Data.

See Also:
Constant Field Values

Cmnd_Transfer_Laps

public static final int Cmnd_Transfer_Laps
Transfer Laps

See Also:
Constant Field Values

DLE

public static final int DLE
Data link escape. Packet boundary.

See Also:
Constant Field Values

ETX

public static final int ETX
End of text. Packet boundary.

See Also:
Constant Field Values

packet

protected int[] packet
The packet in byte-form. It is required that the array-length is trimmed to the size of the packet.


pointer

protected int pointer
pointer - the current position of the pointer to which byte is being read

Constructor Detail

GarminPacket

public GarminPacket(int[] p)
Creates a new GarminPacket with the contents of p. Throws InvalidPacketException if packet is malformed.


GarminPacket

public GarminPacket(int[] p,
                    boolean calcChecksum)
Creates a new GarminPacket with the contents of p. if calcChecksum is true, the packet will have it's checksum recalculated. Throws InvalidPacketException if packet is malformed.

Method Detail

createCommandPacket

public static GarminPacket createCommandPacket(int type)
This is a factory-method capable of creating instances the commandpackets from A010. (Device Command Protocol 1) returns null if it can't make a packet from the argument supplied.
type can be one of the following constants:
  • Cmnd_Turn_Off_Pwr
  • Cmnd_Transfer_Posn
  • Cmnd_Transfer_Time
  • Cmnd_Abort_Transfer
  • Cmnd_Transfer_Alm
  • Cmnd_Transfer_Prx
  • Cmnd_Transfer_Rte
  • Cmnd_Transfer_Trk
  • Cmnd_Transfer_Wpt
  • Cmnd_Start_Pvt_Data
  • Cmnd_Stop_Pvt_Data


createBasicPacket

public static GarminPacket createBasicPacket(int type,
                                             int[] data)
This method is capable of making the data-packets from L000 (basic link protocol).
type can be one of the following constants:
  • Pid_Ack_Byte
  • Pid_Nak_Byte
  • Pid_Protocol_Array
  • Pid_Product_Rqst
  • Pid_Product_Data
The argument data is an array of int that will be put in the data-field of the packet.


calcChecksum

public int calcChecksum()
Calculates the checksum for the packet. Does not insert it into the correct position of the int[] packet array.
The method assumes that the packet is a valid Garmin-packet with all values containing their final values.


isLegal

public int isLegal()
Checks if the packet is valid with regards to header, footer,data-field-length and checksum. Returns the index of the illegal byte. If packet is ok, -1 is returned.


getID

public int getID()
Returns the ID (ie. type) of the packet.


idToString

public static java.lang.String idToString(int id)
Method that translates a packet-id into a human-readable string.


getDataLength

public int getDataLength()
Returns the amount of bytes in the data-field of this packet.


getRawPacket

public java.lang.String getRawPacket()
Debug-method. Returns a String-representation of the bytes in the packet.


getByte

protected int getByte(int i)
Returns the packet-byte at position i.


getPacket

protected int[] getPacket()
Returns the packet in it's original byte-form.
Note: The array returned is a clone of the array contained in the class. Changing the values in the array will not affect the contents of the class.


getLength

protected int getLength()
Returns the length of the entire packet in bytes.


setPointer

protected void setPointer(int moveTo)

getPointer

protected int getPointer()

readWord

protected int readWord(int packet_index)
Method that reads a Garmin-word in the packet and returns it as an int. This method can be used to read both int and word from a Garmin-packet.


readWord

protected int readWord()

readLong

protected int readLong(int packet_index)
Method that reads a Garmin-long in the packet and returns it as an int.


readLong

protected int readLong()

readBoolean

protected boolean readBoolean(int packet_index)
Method that reads a Garmin-long in the packet and returns it as an int.


readBoolean

protected boolean readBoolean()

readNullTerminatedString

protected java.lang.String readNullTerminatedString(int packet_index)
Method that reads a null-terminated string.

NOTE: ANY CHANGES TO THIS MUST BE REFLECTED BELOW IN OTHER METHOD SIGNATURE. Due to the nature of the pointer incrementing code. This method is left for backward compatability


readNullTerminatedString

protected java.lang.String readNullTerminatedString()

readByte

protected short readByte(int packet_index)
Method that reads a Garmin-byte in the packet and returns it as a short.


readByte

protected short readByte()

readDouble

protected double readDouble(int packet_index)
Method that reads a Garmin-double in the packet and returns it as a double.


readDouble

protected double readDouble()

readFloat

protected float readFloat(int packet_index)
Method that reads a Garmin-float in the packet and returns it as a float.


readFloat

protected float readFloat()

readPosition

protected Position readPosition(int packet_index)

readPosition

protected Position readPosition()

toString

public java.lang.String toString()
Returns a human-readable string with information to the packet's contents.

Overrides:
toString in class java.lang.Object