public abstract class XBeePacket extends Object
Derived classes should implement their own payload generation depending on their type.
Generic actions like checksum compute or packet length calculation is performed here.
| Modifier and Type | Method and Description | 
|---|---|
byte[] | 
generateByteArray()
Generates the XBee packet byte array. 
 | 
byte[] | 
generateByteArrayEscaped()
Generates the XBee packet byte array escaping the special bytes. 
 | 
int | 
getChecksum()
Returns the packet checksum. 
 | 
abstract byte[] | 
getPacketData()
Returns the packet data. 
 | 
int | 
getPacketLength()
Returns the packet length. 
 | 
LinkedHashMap<String,String> | 
getParameters()
Returns a map with the XBee packet parameters and their values. 
 | 
static XBeePacket | 
parsePacket(byte[] packet,
           OperatingMode mode)
Parses the given byte array and returns a Generic XBee packet. 
 | 
static XBeePacket | 
parsePacket(String packet,
           OperatingMode mode)
Parses the given hexadecimal string and returns a Generic XBee packet. 
 | 
String | 
toPrettyString()
Returns a pretty string representing the packet. 
 | 
String | 
toString()  | 
public byte[] generateByteArray()
Use only while working in API mode 1. If API mode is 2, use 
 generateByteArrayEscaped().
generateByteArrayEscaped()public byte[] generateByteArrayEscaped()
Use only while working in API mode 2. If API mode is 1 use 
 generateByteArray().
generateByteArray()public int getChecksum()
To calculate: Not including frame delimiters and length, add all 
 bytes keeping only the lowest 8 bits of the result and subtract the 
 result from 0xFF.
public abstract byte[] getPacketData()
public int getPacketLength()
public LinkedHashMap<String,String> getParameters()
public static XBeePacket parsePacket(byte[] packet, OperatingMode mode) throws InvalidPacketException
packet - The byte array to parse.mode - The operating mode to parse the packet (API 1 or API 2).IllegalArgumentException - if mode != OperatingMode.API  and
                                  if mode != OperatingMode.API_ESCAPE 
                                  or if packet.length == 0.InvalidPacketException - if the given byte array does not represent 
                                a valid frame: invalid checksum, length, 
                                start delimiter, etc.NullPointerException - if packet == null.OperatingMode.API, 
OperatingMode.API_ESCAPEpublic static XBeePacket parsePacket(String packet, OperatingMode mode) throws InvalidPacketException
The string can contain white spaces.
packet - The hexadecimal string to parse.mode - The operating mode to parse the packet (API 1 or API 2).IllegalArgumentException - if mode != OperatingMode.API  and
                                  if mode != OperatingMode.API_ESCAPE.InvalidPacketException - if the given string does not represent a 
                                valid frame: invalid checksum, length, 
                                start delimiter, etc.NullPointerException - if packet == null.OperatingMode.API, 
OperatingMode.API_ESCAPEpublic String toPrettyString()
© Copyright 2014–2014 Digi International Inc. All rights reserved.