com.digi.xbee.api.packet

## Class XBeeChecksum

- java.lang.Object
- - com.digi.xbee.api.packet.XBeeChecksum

-     public class XBeeChecksum
      extends Object

  This class stores, computes and verifies the checksum of the API packets.

  To test data integrity, a checksum is calculated and verified on non-escaped API data.

  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`.

  To verify

  Add all bytes (include checksum, but not the delimiter and length). If the checksum is correct, the sum will equal `0xFF`.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `XBeeChecksum()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(byte[] data)` Adds the given data to the checksum.
    `void` | `add(int value)` Adds the given byte to the checksum.
    `int` | `generate()` Generates the checksum byte for the API packet.
    `void` | `reset()` Resets the checksum.
    `boolean` | `validate()` Validates the checksum.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### XBeeChecksum

          public XBeeChecksum()

  - ### Method Detail

    - #### add

          public void add(byte[] data)

      Adds the given data to the checksum.
      Parameters:
        `data` - Byte array to add.

    - #### add

          public void add(int value)

      Adds the given byte to the checksum.
      Parameters:
        `value` - Byte to add.

    - #### generate

          public int generate()

      Generates the checksum byte for the API packet.
      Returns:
        Checksum byte.

    - #### reset

          public void reset()

      Resets the checksum.

    - #### validate

          public boolean validate()

      Validates the checksum.
      Returns:
        `true` if checksum is valid, `false` otherwise.

© Copyright 2014–2014 Digi International Inc. All rights reserved.