dk.itu.haas.GPS.Garmin
Class GarminPacket

java.lang.Object
  |
  +--dk.itu.haas.GPS.Garmin.GarminPacket
Direct Known Subclasses:
PositionDataPacket, ProductDataPacket, ProtocolDataPacket, PVTDataPacket, RecordsPacket, TimeDataPacket, 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_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
           
static int Pid_Command_Data
           
static int Pid_Date_Time_Data
           
static int Pid_Nak_Byte
           
static int Pid_Position_Data
           
static int Pid_Product_Data
           
static int Pid_Product_Rqst
           
static int Pid_Protocol_Array
           
static int Pid_Pvt_Data
           
static int Pid_Records
           
static int Pid_Wpt_Data
           
static int Pid_Xfer_Cmplt
           
 
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.
 
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.
 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  short readByte(int packet_index)
          Method that reads a Garmin-byte in the packet and returns it as a short.
protected  double readDouble(int packet_index)
          Method that reads a Garmin-double in the packet and returns it as a double.
protected  float readFloat(int packet_index)
          Method that reads a Garmin-float in the packet and returns it as a float.
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(int packet_index)
          Method that reads a null-terminated string.
protected  int readWord(int packet_index)
          Method that reads a Garmin-word in the packet and returns it as an int.
 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
See Also:
Constant Field Values

Pid_Nak_Byte

public static final int Pid_Nak_Byte
See Also:
Constant Field Values

Pid_Protocol_Array

public static final int Pid_Protocol_Array
See Also:
Constant Field Values

Pid_Product_Rqst

public static final int Pid_Product_Rqst
See Also:
Constant Field Values

Pid_Product_Data

public static final int Pid_Product_Data
See Also:
Constant Field Values

Pid_Command_Data

public static final int Pid_Command_Data
See Also:
Constant Field Values

Pid_Xfer_Cmplt

public static final int Pid_Xfer_Cmplt
See Also:
Constant Field Values

Pid_Date_Time_Data

public static final int Pid_Date_Time_Data
See Also:
Constant Field Values

Pid_Position_Data

public static final int Pid_Position_Data
See Also:
Constant Field Values

Pid_Records

public static final int Pid_Records
See Also:
Constant Field Values

Pid_Wpt_Data

public static final int Pid_Wpt_Data
See Also:
Constant Field Values

Pid_Pvt_Data

public static final int Pid_Pvt_Data
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

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.

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

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.


getID

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


getDataLength

public int getDataLength()
Returns the amount of bytes in the data-field of this 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.


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.


readLong

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


readNullTerminatedString

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


idToString

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


getRawPacket

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


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.


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.


readByte

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


readDouble

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


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

readFloat

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