package art.servers.colorsserver.M.protocol;
|
|
import art.library.utils.common.*;
|
import static art.servers.colorsserver.M.protocol.M_ProtocolWriter.DET;
|
import static art.servers.colorsserver.M.protocol.M_ProtocolWriter.PRH;
|
|
|
public class M_Message
|
{
|
public int[] data;
|
private int pointer = 0;
|
public boolean isAck = false;
|
public boolean isNack = false;
|
public boolean isTrcam = false;
|
public int directive = 0;
|
public int controller = 0;
|
public int table = 0;
|
|
|
public void fillInformation ()
|
{
|
if (data[0] == M_ProtocolAnalyser.STX)
|
{
|
controller = data[1] & 0x7F;
|
directive = data[2] & 0x7F;
|
if (directive == M_ProtocolWriter.M_READ_TABLE_FULL)
|
{
|
table = data[3] & 0x7F;
|
}
|
}
|
}
|
|
|
public void setData(byte[] input)
|
{
|
data = new int[input.length];
|
for (int i=0; i<data.length; i++)
|
{
|
data[i] = (int)input[i];
|
}
|
}
|
|
|
public void setData(int[] input)
|
{
|
data = new int[input.length];
|
for (int i=0; i<data.length; i++)
|
{
|
data[i] = input[i];
|
}
|
}
|
|
|
public void reset ()
|
{
|
pointer = 0;
|
}
|
|
|
public int length ()
|
{
|
return(data.length);
|
}
|
|
|
public int readByte () throws Exception
|
{
|
return (data[pointer++]);
|
}
|
|
|
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 byte[] toByteArray()
|
{
|
return(ArrayUtils.toByteArray(data));
|
}
|
|
|
public boolean isCountingDetectorQuery()
|
{
|
return(data[0] == DET);
|
}
|
|
|
public boolean isPRHQuery()
|
{
|
return(data[0] == PRH);
|
}
|
|
|
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);
|
}
|
|
}
|