public final class SerialComCRCUtil extends Object
Utility class to calculate and generate CRC values for a given message. This can be used in X/Y/Z modem etc protocol implementations and in developing custom protocols for transmitting data over serial port.
| Constructor and Description |
|---|
SerialComCRCUtil()
Allocates a new SerialComCRCUtil object.
|
| Modifier and Type | Method and Description |
|---|---|
byte |
getChecksumValue(byte[] data,
int start,
int end)
Calculates 8 bit checksum value for the data bytes given.
|
int |
getCRC16CCITTValue(byte[] data,
int start,
int end)
Calculates CRC-16-CCITT value for the data bytes given.
|
int |
getCRC16DNPValue(byte[] data,
int start,
int end)
Calculates CRC-16-DNP value for the data bytes given.
|
int |
getCRC16IBMValue(byte[] data,
int start,
int end)
Calculates CRC-16-IBM value for the data bytes given.
|
int |
getCRC16Value(byte[] data,
int start,
int end)
Calculates CRC-16 value for the data bytes given.
|
int |
getCRC8Dallas1WireValue(byte[] data,
int start,
int end)
Calculates CRC-8 Dallas 1-wire value for the data bytes given.
|
byte |
getLRCCheckSum(byte[] data,
int offset,
int length)
Calculates longitudinal redundancy checksum value for the given byte array.
|
public SerialComCRCUtil()
Allocates a new SerialComCRCUtil object.
public byte getChecksumValue(byte[] data,
int start,
int end)
Calculates 8 bit checksum value for the data bytes given. The data bytes at start and end index are included in calculation. The checksum returned is the sum of all bytes in the data packet modulo 256.
data - byte type buffer for whom checksum is to be calculated.start - offset in supplied data buffer from where checksum calculation should start.end - offset in data buffer till which checksum should be calculated.public byte getLRCCheckSum(byte[] data,
int offset,
int length)
Calculates longitudinal redundancy checksum value for the given byte array.
data - byte type buffer for whom LRC checksum is to be calculated.offset - position in supplied data buffer from where LRC calculation should start.length - position in data buffer till which LRC should be calculated from offset.NullPointerException - if data is null.IndexOutOfBoundsException - if offset is negative, length is negative, or length is
greater than data.length - offset.IllegalArgumentException - if data is not a byte type array.public int getCRC8Dallas1WireValue(byte[] data,
int start,
int end)
Calculates CRC-8 Dallas 1-wire value for the data bytes given. The data bytes at start and end index are included in calculation. It uses pre-defined table for speedily calculating CRC8-1-wire value of the given data.
data - byte type buffer for whom CRC is to be calculated.start - offset in supplied data buffer from where CRC calculation should start.end - offset in data buffer till which CRC should be calculated.public int getCRC16Value(byte[] data,
int start,
int end)
Calculates CRC-16 value for the data bytes given. The data bytes at start and end index are included in calculation. It uses pre-defined table for speedily calculating CRC-16 value of the given data.
data - byte type buffer for whom CRC is to be calculated.start - offset in supplied data buffer from where CRC calculation should start.end - offset in data buffer till which CRC should be calculated.public int getCRC16CCITTValue(byte[] data,
int start,
int end)
Calculates CRC-16-CCITT value for the data bytes given. The data bytes at start and end index are included in calculation. It uses pre-defined table for speedily calculating CRC-16-CCITT value of the given data. This algorithm is used in implementing Xmodem protocol.
data - byte type buffer for whom CRC is to be calculated.start - offset in supplied data buffer from where CRC calculation should start.end - offset in data buffer till which CRC should be calculated.public int getCRC16DNPValue(byte[] data,
int start,
int end)
Calculates CRC-16-DNP value for the data bytes given. The data bytes at start and end index are included in calculation. It uses pre-defined table for speedily calculating CRC-16-DNP value of the given data.
data - byte type buffer for whom CRC is to be calculated.start - offset in supplied data buffer from where CRC calculation should start.end - offset in data buffer till which CRC should be calculated.public int getCRC16IBMValue(byte[] data,
int start,
int end)
Calculates CRC-16-IBM value for the data bytes given. The data bytes at start and end index are included in calculation. It uses pre-defined table for speedily calculating CRC-16-IBM (modbus) value of the given data.
data - byte type buffer for whom CRC is to be calculated.start - offset in supplied data buffer from where CRC calculation should start.end - offset in data buffer till which CRC should be calculated.Copyright © 2016. All rights reserved.