package test.protocol.musatel;
|
|
public class MusatelProtocol
|
{
|
public static final byte ACK_DEM_USE = (byte)0x81;
|
public static final byte ACK_DEM_SER = (byte)0x82;
|
public static final byte ACK_ENV_ALA = (byte)0x83;
|
public static final byte ORD_FON_ON = (byte)0x41;
|
public static final byte ORD_FON_OFF = (byte)0x42;
|
public static final byte ORD_TON_ON = (byte)0x43;
|
public static final byte ORD_TON_OFF = (byte)0x44;
|
public static final byte ORD_TST_FON = (byte)0x45;
|
public static final byte ORD_TST_MAN = (byte)0x46;
|
public static final byte ORD_ESC_HOR = (byte)0x47;
|
public static final byte ORD_ESC_IO = (byte)0x48;
|
public static final byte ORD_LEC_IO = (byte)0x49;
|
public static final byte ORD_VOZ_ON = (byte)0x4A;
|
public static final byte ORD_VOZ_OFF = (byte)0x4B;
|
public static final byte ORD_ADJ_VOL = (byte)0x4C;
|
public static final byte ORD_POS_ATE = (byte)0x4D;
|
public static final byte DEM_USE = (byte)0x21;
|
public static final byte DEM_SER = (byte)0x22;
|
public static final byte ENV_ALA = (byte)0x23;
|
public static final byte ACK_FON_ON = (byte)0x84;
|
public static final byte ACK_FON_OFF = (byte)0x85;
|
public static final byte ACK_TON_ON = (byte)0x86;
|
public static final byte ACK_TON_OFF = (byte)0x87;
|
public static final byte RES_TST_FON = (byte)0x88;
|
public static final byte RES_TST_MAN = (byte)0x89;
|
public static final byte ACK_ESC_HOR = (byte)0x8A;
|
public static final byte ACK_ESC_IO = (byte)0x8B;
|
public static final byte ACK_LEC_IO = (byte)0x8C;
|
public static final byte ACK_VOZ_ON = (byte)0x8D;
|
public static final byte ACK_ADJ_VOL = (byte)0x8E;
|
public static final byte P_MAS = (byte)0x90;
|
public static final byte P_ESC = (byte)0x91;
|
public static final byte L_ESP = (byte)0x51;
|
public static final byte L_FON = (byte)0x52;
|
public static final byte T_LLA = (byte)0x53;
|
public static final byte T_COM = (byte)0x54;
|
public static final byte MEM_FUE_SER = (byte)0x55;
|
public static final byte MEM_LLA_ESP = (byte)0x56;
|
public static final byte TST_OK = (byte)0x57;
|
public static final byte TST_FAL = (byte)0x58;
|
public static final byte RES_POS_ATE = (byte)0x0F;
|
public static final byte ORD_MOD_ON = (byte)0x4E;
|
public static final byte ACK_MOD_ON = (byte)0xA0;
|
public static final byte ORD_MOD_OFF = (byte)0x4F;
|
public static final byte ACK_MOD_OFF = (byte)0xA1;
|
public static final byte ORD_REN_ON = (byte)0x60;
|
public static final byte ACK_VOZ_OFF = (byte)0x92;
|
public static final byte ACK_REN_ON = (byte)0x93;
|
public static final byte ORD_ADJ_ATE = (byte)0xE0;
|
public static final byte ACK_ADJ_ATE = (byte)0xF0;
|
public static final byte ORD_ADJ_ATS = (byte)0xE1;
|
public static final byte ACK_ADJ_ATS = (byte)0xF1;
|
public static final byte ORD_POS_ATS = (byte)0xE2;
|
public static final byte RES_POS_ATS = (byte)0xF2;
|
public static final byte ORD_CONF_PER = (byte)0xE3;
|
public static final byte ACK_CONF_PER = (byte)0xF3;
|
public static final byte ORD_PARTICULAR = (byte)0xC3;
|
public static final byte ASIGNAR_CC = (byte)0xB4;
|
public static final byte NACK = (byte)0x15;
|
public static final byte OTRO_CC_ASIGNADO = (byte)0x10;
|
|
|
/******************************************************************************
|
* Compilation: javac CRC16CCITT
|
* Reads in a sequence of bytes and prints out its 16 bit
|
* Cylcic Redundancy Check (CRC-CCIIT 0xFFFF).
|
* 1 + x + x^5 + x^12 + x^16 is irreducible polynomial.
|
* % java CRC16-CCITT 123456789
|
* CRC16-CCITT = 29b1
|
******************************************************************************/
|
|
|
protected int CRC(byte[] data)
|
{
|
int crc = 0xFFFF;
|
int polynomial = 0x1021;
|
|
// byte[] testBytes = "123456789".getBytes("ASCII");
|
|
for (byte b : data)
|
{
|
for (int i = 0; i < 8; i++)
|
{
|
boolean bit = ((b >> (7-i) & 1) == 1);
|
boolean c15 = ((crc >> 15 & 1) == 1);
|
crc <<= 1;
|
if (c15 ^ bit) crc ^= polynomial;
|
}
|
}
|
|
crc &= 0xffff;
|
return crc;
|
}
|
|
|
|
}
|