wonderly.jeaprs.aprs.packet
Class APRSPacket

java.lang.Object
  |
  +--wonderly.jeaprs.aprs.packet.APRSPacket
All Implemented Interfaces:
java.io.Serializable

public class APRSPacket
extends java.lang.Object
implements java.io.Serializable

This is an APRS packet. It contains 5 pieces of information that are useful to applications. The from Callsign, the TNC path, the type character, the rest of the packet info as a string which includes the type character on the front (because most existing parsers work with data starting at that point). Finally, the checksum of the packet is returned by the hashCode() method and is computed once. equals() compares the from and the packet "info" or data. Thus, duplicate packets can be detected by checking for hashCode() the same first (which is very efficient), and then equals() if so and unequal packets are found by checking the hashCode(), if not the same the packets are not the same. If hashCode() is the same, then equals() will return false for unequal packets and true for equal packets. Using hashCode() as a shortcut first comparison is a speed optimization.

Version:
1.0
Author:
Gregg Wonderly - The information contained in this document is Copyright 2001-2003, Gregg Wonderly, all rights reserved.
See Also:
Serialized Form

Field Summary
protected  wonderly.jeaprs.ByteString from
           
protected  wonderly.jeaprs.ByteString info
           
protected  wonderly.jeaprs.ByteString path
           
protected  int sum
           
protected  byte type
           
 
Constructor Summary
APRSPacket(wonderly.jeaprs.ByteString from, wonderly.jeaprs.ByteString path, byte type, wonderly.jeaprs.ByteString info)
          Construct a new packet object.
 
Method Summary
 boolean equals(java.lang.Object obj)
          Compares from and info of packets for equality.
 byte[] getData()
          Returns the packet data as a byte array.
 wonderly.jeaprs.ByteString getFrom()
           
 wonderly.jeaprs.ByteString getInfo()
           
 wonderly.jeaprs.ByteString getPath()
           
 byte getType()
          Returns the packet type character
 int hashCode()
           
 void setType(byte ch)
           
 wonderly.jeaprs.ByteString toByteString()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

from

protected wonderly.jeaprs.ByteString from

path

protected wonderly.jeaprs.ByteString path

type

protected byte type

info

protected wonderly.jeaprs.ByteString info

sum

protected transient int sum
Constructor Detail

APRSPacket

public APRSPacket(wonderly.jeaprs.ByteString from,
                  wonderly.jeaprs.ByteString path,
                  byte type,
                  wonderly.jeaprs.ByteString info)
Construct a new packet object.

Parameters:
from - the from call sign
path - the ax.25 path the packet traveled
type - the character packet type.
info - the packet data contents including 'type' as first character
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Compares from and info of packets for equality.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
Returns:
result of (getPath()+getInfo()).hashCode(). The value is computed once in constructor, so this method is very efficient as opposed to the ByteString.hashCode() implementation.

toByteString

public wonderly.jeaprs.ByteString toByteString()

getFrom

public wonderly.jeaprs.ByteString getFrom()
Returns:
the from callsign

setType

public void setType(byte ch)

getPath

public wonderly.jeaprs.ByteString getPath()
Returns:
the TNC path from the packet

getInfo

public wonderly.jeaprs.ByteString getInfo()
Returns:
the data portion of the packet including the 'type char' as the first character in the string. i.e. if the packet was
KD5KGR-7>APJEAP,ITULSA*::KA9MVA-9 :Hello Steve{0
this method would return :KA9MVA-9 :Hello Steve{0

getType

public byte getType()
Returns the packet type character


getData

public byte[] getData()
Returns the packet data as a byte array. This is the whole original packet, reassembled from the pieces it was constructed with.