package com.dd.model.protocol;
public class FieldDecoder
{
Field field;
private String serialData;
private byte serialByte[];
public FieldDecoder(byte serialByte[])
{
StringBuffer sb = new StringBuffer();
for (int i = 0; i < serialByte.length; i++)
{
sb.append(String.format("%02x", serialByte[i]));
}
this.serialData = sb.toString();
this.serialByte = serialByte;
}
public Field doDecoder()
{
TTLDecoder ttlDecoder = new TTLDecoder(getTTLbyteSerial());
TTL ttl = ttlDecoder.doDecoder();
ValueDecoder valueDecoder = new ValueDecoder(ttl.getType(),getValueByteSerial());
Value value = valueDecoder.doDecoder();
Field field = new Field( ttl, value);
return field;
}
private byte []getTTLbyteSerial()
{
byte [] result = new byte[6];//2+2+2
for (int i = 0; i < result.length; i++)
{
result[i] = serialByte[i];
}
return result;
}
private byte []getValueByteSerial()
{
int ttlByteLen = 6;//2+2+2
byte [] result = new byte[serialByte.length - ttlByteLen];
for (int i = 0; i < result.length; i++)
{
result[i] = serialByte[i+ttlByteLen];
}
return result;
}
}
阅读(877) | 评论(0) | 转发(0) |