com.rapplogic.xbee.api
Class PacketParser

java.lang.Object
  extended by com.rapplogic.xbee.api.PacketParser
All Implemented Interfaces:
IPacketParser, IIntInputStream

public class PacketParser
extends java.lang.Object
implements IIntInputStream, IPacketParser

Reads a packet from the input stream, verifies checksum and creates an XBeeResponse object

Notes:

Escaped bytes increase packet length but packet stated length only indicates un-escaped bytes. Stated length includes all bytes after Length bytes, not including the checksum

Author:
Andrew Rapp

Constructor Summary
PacketParser(IIntInputStream in)
           
PacketParser(java.io.InputStream in)
           
 
Method Summary
 ApiId getApiId()
           
 int getBytesRead()
          Does not include any escape bytes
 int getChecksum()
           
 int getFrameDataBytesRead()
          Returns number of bytes remaining, relative to the stated packet length (not including checksum).
 int getIntApiId()
           
 XBeePacketLength getLength()
           
 int getRemainingBytes()
          Number of bytes remaining to be read, including the checksum
 boolean isDone()
           
 XBeeAddress16 parseAddress16()
           
 XBeeAddress64 parseAddress64()
           
 XBeeResponse parsePacket()
          This method is guaranteed (unless I screwed up) to return an instance of XBeeResponse and should never throw an exception If an exception occurs, it will be packaged and returned as an ErrorResponse.
 int read()
          This method reads bytes from the underlying input stream and performs the following tasks: 1.
 int read(java.lang.String context)
          Same as read() but logs the context of the byte being read.
 int[] readRemainingBytes()
          Reads all remaining bytes except for checksum
 void setBytesRead(int bytesRead)
           
 void setDone(boolean done)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PacketParser

public PacketParser(java.io.InputStream in)

PacketParser

public PacketParser(IIntInputStream in)
Method Detail

parsePacket

public XBeeResponse parsePacket()
This method is guaranteed (unless I screwed up) to return an instance of XBeeResponse and should never throw an exception If an exception occurs, it will be packaged and returned as an ErrorResponse.

Returns:

read

public int read(java.lang.String context)
         throws java.io.IOException
Same as read() but logs the context of the byte being read. useful for debugging

Specified by:
read in interface IPacketParser
Specified by:
read in interface IIntInputStream
Throws:
java.io.IOException

read

public int read()
         throws java.io.IOException
This method reads bytes from the underlying input stream and performs the following tasks: 1. Keeps track of how many bytes we've read 2. Un-escapes bytes if necessary and verifies the checksum.

Specified by:
read in interface IIntInputStream
Throws:
java.io.IOException

readRemainingBytes

public int[] readRemainingBytes()
                         throws java.io.IOException
Reads all remaining bytes except for checksum

Specified by:
readRemainingBytes in interface IPacketParser
Returns:
Throws:
java.io.IOException

parseAddress64

public XBeeAddress64 parseAddress64()
                             throws java.io.IOException
Specified by:
parseAddress64 in interface IPacketParser
Throws:
java.io.IOException

parseAddress16

public XBeeAddress16 parseAddress16()
                             throws java.io.IOException
Specified by:
parseAddress16 in interface IPacketParser
Throws:
java.io.IOException

getFrameDataBytesRead

public int getFrameDataBytesRead()
Returns number of bytes remaining, relative to the stated packet length (not including checksum).

Specified by:
getFrameDataBytesRead in interface IPacketParser
Returns:

getRemainingBytes

public int getRemainingBytes()
Number of bytes remaining to be read, including the checksum

Specified by:
getRemainingBytes in interface IPacketParser
Returns:

getBytesRead

public int getBytesRead()
Does not include any escape bytes

Specified by:
getBytesRead in interface IPacketParser
Returns:

setBytesRead

public void setBytesRead(int bytesRead)

isDone

public boolean isDone()

setDone

public void setDone(boolean done)

getChecksum

public int getChecksum()

getLength

public XBeePacketLength getLength()
Specified by:
getLength in interface IPacketParser

getApiId

public ApiId getApiId()
Specified by:
getApiId in interface IPacketParser

getIntApiId

public int getIntApiId()
Specified by:
getIntApiId in interface IPacketParser