package art.servers.etdserver.protocols.skp3;
|
|
import art.library.utils.common.*;
|
import art.servers.etdserver.Shared;
|
|
public class SKP3_Message
|
{
|
private int[] data;
|
private int pointer = 0;
|
|
|
public void setData(byte[] input)
|
{
|
data = new int[input.length];
|
for (int i=0; i<data.length; i++)
|
{
|
data[i] = (int)input[i];
|
}
|
|
data = SKP3_ProtocolAnalyser.unapplyMask(data);
|
}
|
|
|
public void setData(int[] input)
|
{
|
data = new int[input.length];
|
for (int i=0; i<data.length; i++)
|
{
|
data[i] = input[i];
|
}
|
|
data = SKP3_ProtocolAnalyser.unapplyMask(data);
|
}
|
|
|
public void reset ()
|
{
|
pointer = 0;
|
}
|
|
|
public int length ()
|
{
|
return(data.length);
|
}
|
|
|
public int readByte () throws Exception
|
{
|
int v = data[pointer++];
|
if (v < 0) v += 256;
|
return (v);
|
}
|
|
|
public int readShort () throws Exception
|
{
|
return (readByte() + (readByte() << 8));
|
}
|
|
|
|
public int readShortHigh () throws Exception
|
{
|
return ((readByte() << 8) + readByte());
|
}
|
|
|
|
public int readInt () throws Exception
|
{
|
return (readByte() + (readByte() << 8) + (readByte() << 16) + (readByte() << 24));
|
}
|
|
|
public int readIntHigh () throws Exception
|
{
|
return ((readByte() << 24) + (readByte() << 16) + (readByte() << 8) + readByte());
|
}
|
|
|
public int[] readFully () throws Exception
|
{
|
int[] resultado = new int[data.length - pointer];
|
System.arraycopy(data, pointer, resultado, 0, resultado.length);
|
return resultado;
|
}
|
|
|
|
public int[] readIntArray (int count) throws Exception
|
{
|
int[] resultado = new int[count];
|
System.arraycopy(data, pointer, resultado, 0, resultado.length);
|
pointer = pointer + count;
|
return resultado;
|
}
|
|
|
|
public boolean eof()
|
{
|
return (pointer >= data.length-1);
|
}
|
|
|
|
public boolean eofCRC()
|
{
|
return (pointer >= data.length-2);
|
}
|
|
|
public void check() throws Exception
|
{
|
if (readByte() != SKP3_ProtocolWriter.STX)
|
{
|
throw new Exception(Shared.getMessage("Message not start with 0x7E"));
|
}
|
|
int S = readByte();
|
if (S != 'S')
|
{
|
throw new Exception(Shared.getMessage("Message has not S byte of SKP3: " + S));
|
}
|
|
int K = readByte();
|
if (K != 'K')
|
{
|
throw new Exception(Shared.getMessage("Message has not K byte of SKP3: " + K));
|
}
|
|
int P = readByte();
|
if (P != 'P')
|
{
|
throw new Exception(Shared.getMessage("Message has not P byte of SKP3: " + P));
|
}
|
|
int V = readByte();
|
if (V != '3')
|
{
|
throw new Exception(Shared.getMessage("Message has not 3 byte of SKP3: " + V));
|
}
|
}
|
|
|
public byte[] toByteArray()
|
{
|
return(ArrayUtils.toByteArray(data));
|
}
|
|
|
public String toString()
|
{
|
String result = "";
|
|
try
|
{
|
for (int i=0; i<data.length; i++)
|
{
|
String svalue = String.format("%02X", data[i] & 0xFF);
|
result += svalue + " ";
|
}
|
}
|
catch (Exception e)
|
{
|
|
}
|
|
return(result);
|
}
|
|
}
|