pops.ale.codec
Class EpcCodec

java.lang.Object
  extended by pops.ale.codec.EpcCodec
Direct Known Subclasses:
Sgln96Codec, Sgtin96Codec

public abstract class EpcCodec
extends java.lang.Object


Field Summary
protected static byte[] boundaryLeftMasks
          This look-up table gives the mask to use for getting from 1 up to 7 Most significant bits of a byte
protected static byte[] boundaryRightMasks
          This look-up table gives the mask to use for getting from 1 up to 7 Least significant bits of a byte
protected static byte[] boundaryShifts
          This look-up table gives the shift to use for getting 1 to 7 Most significant bits of a bytes
protected static java.lang.String COMMON_HEADER
           
protected static boolean MSB_FIRST
           
protected static boolean MSB_LAST
           
static byte SGLN_96_HEADER
          Header of an SGTLN96
static byte SGTIN_96_HEADER
          Header values of an SGTIN_96.
 
Constructor Summary
EpcCodec()
           
 
Method Summary
protected static void appendUri(java.lang.StringBuffer uri, long data, byte digits)
          Utility for facilitating the construction of an URI.
protected static int ByteArrayToInt(byte[] bytes, boolean msbFirst)
          General purpose utility for converting an array of 4 bytes to an integer.
protected static long ByteArrayToLong(byte[] bytes, boolean msbFirst)
          General purpose utility for converting an array of 8 bytes to a long.
protected static int byteToInt(byte data)
          Safe byte to int conversion : without bit sign problem ;).
protected static long byteToLong(byte data)
          Safe byte to long conversion : without bit sign problem ;).
protected static java.lang.String convertToRawDecUri(byte[] tagData)
           
protected static java.lang.String convertToRawHexUri(byte[] tagData)
           
static byte decodeHeader(byte[] tagData)
          Validates and decodes header.
protected static long extractLongField(byte[] bytes, int from, byte trailingBits, int to, byte leadingBits)
          Extracts a long (64-bit max) value from an array of bytes.
protected static long getCompanyPrefix(byte[] tagData, byte M, byte L)
          Utility for decoding company prefix.
static EncScheme getEncodingScheme(byte[] tagData)
          Validates and decodes header.
protected static byte getFilterValue(byte[] tagData)
          Decode filter Value.
protected static int getItemReference(byte[] tagData, byte M, byte N)
          Utility for decoding company an item reference.
protected static byte getPartition(byte[] tagData)
          Decode Partition Number.
abstract  java.lang.String getPureUri()
           
protected static long getSerialNumber(byte[] tagData, byte M, byte N)
          Utility for decoding company a Serial number.
abstract  java.lang.String getTagUri()
           
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SGTIN_96_HEADER

public static final byte SGTIN_96_HEADER
Header values of an SGTIN_96.

See Also:
Constant Field Values

SGLN_96_HEADER

public static final byte SGLN_96_HEADER
Header of an SGTLN96

See Also:
Constant Field Values

MSB_FIRST

protected static final boolean MSB_FIRST
See Also:
Constant Field Values

MSB_LAST

protected static final boolean MSB_LAST
See Also:
Constant Field Values

COMMON_HEADER

protected static final java.lang.String COMMON_HEADER
See Also:
Constant Field Values

boundaryLeftMasks

protected static final byte[] boundaryLeftMasks
This look-up table gives the mask to use for getting from 1 up to 7 Most significant bits of a byte


boundaryRightMasks

protected static final byte[] boundaryRightMasks
This look-up table gives the mask to use for getting from 1 up to 7 Least significant bits of a byte


boundaryShifts

protected static final byte[] boundaryShifts
This look-up table gives the shift to use for getting 1 to 7 Most significant bits of a bytes

Constructor Detail

EpcCodec

public EpcCodec()
Method Detail

decodeHeader

public static byte decodeHeader(byte[] tagData)
Validates and decodes header.

Parameters:
tagData - tag data bytes.
Returns:
the header byte or 0xFF if unknown header

getEncodingScheme

public static EncScheme getEncodingScheme(byte[] tagData)
Validates and decodes header.

Parameters:
tagData - tag data bytes.
Returns:
the header byte

getFilterValue

protected static byte getFilterValue(byte[] tagData)
Decode filter Value. The 3 bits following the header(Last Byte).

Parameters:
tagData - tag data bytes.
Returns:
the filter value

getPartition

protected static byte getPartition(byte[] tagData)
Decode Partition Number. The 3 bits following the filter Value

Parameters:
tagData - tag data bytes.
Returns:
the filter value

getCompanyPrefix

protected static long getCompanyPrefix(byte[] tagData,
                                       byte M,
                                       byte L)
Utility for decoding company prefix.

Parameters:
tagData - tag data bytes.
M - Bits of company prefix.
L - Digits of company prefix.
Returns:
the company prefix

getItemReference

protected static int getItemReference(byte[] tagData,
                                      byte M,
                                      byte N)
Utility for decoding company an item reference.

Parameters:
tagData - tag data bytes.
M - Bits of company prefix.
N - Bits of item reference
Returns:
the item reference.

getSerialNumber

protected static long getSerialNumber(byte[] tagData,
                                      byte M,
                                      byte N)
Utility for decoding company a Serial number.

Parameters:
tagData - tag data bytes.
M - Bits of company prefix.
N - Bits of item reference
Returns:
the serial number.

extractLongField

protected static long extractLongField(byte[] bytes,
                                       int from,
                                       byte trailingBits,
                                       int to,
                                       byte leadingBits)
Extracts a long (64-bit max) value from an array of bytes. The latter is arranged in LSB first.

Parameters:
bytes - array of bytes containing data
from - index of the 'first' byte to use
trailingBits - number of most significant bits to take. Range : 1..8.
to - index of the 'last' byte to use
leadingBits - number of least significant bits to take in 'last' byte. Range : 1..8.
Returns:
the long number.

ByteArrayToInt

protected static int ByteArrayToInt(byte[] bytes,
                                    boolean msbFirst)
General purpose utility for converting an array of 4 bytes to an integer. Note : the MSB is first byte.


ByteArrayToLong

protected static long ByteArrayToLong(byte[] bytes,
                                      boolean msbFirst)
General purpose utility for converting an array of 8 bytes to a long. Note : the MSB is first byte.


byteToLong

protected static long byteToLong(byte data)
Safe byte to long conversion : without bit sign problem ;).


byteToInt

protected static int byteToInt(byte data)
Safe byte to int conversion : without bit sign problem ;).


appendUri

protected static void appendUri(java.lang.StringBuffer uri,
                                long data,
                                byte digits)
Utility for facilitating the construction of an URI. It appends a data represented on a given number of digits to a string buffer, by adding leading zeros if necessary.

Parameters:
uri - String buffer to complete
data - data to append
digits - maximum digits for data
Throws:
java.lang.IllegalArgumentException - if data is greater than 10^digits

convertToRawDecUri

protected static java.lang.String convertToRawDecUri(byte[] tagData)

convertToRawHexUri

protected static java.lang.String convertToRawHexUri(byte[] tagData)

getPureUri

public abstract java.lang.String getPureUri()

getTagUri

public abstract java.lang.String getTagUri()

main

public static void main(java.lang.String[] args)