package safeluck.drive.evaluation.platformMessage;
|
|
|
|
import com.safeluck.aykj.annotation.AnnotationRegister;
|
import com.safeluck.aykj.annotation.Int16;
|
import com.safeluck.aykj.annotation.Int8;
|
import com.safeluck.aykj.annotation.Length;
|
import com.safeluck.aykj.annotation.Order;
|
import com.safeluck.aykj.decoder.BitStateCoder;
|
import com.safeluck.aykj.decoder.Int16Coder;
|
import com.safeluck.aykj.message.BinMessageBase;
|
import com.safeluck.aykj.utils.BitState;
|
import com.safeluck.aykj.utils.BytesUtils;
|
|
import safeluck.drive.evaluation.bean.ExamPlatformData;
|
import safeluck.drive.evaluation.platformMessage.decoder.JWD;
|
import safeluck.drive.evaluation.platformMessage.decoder.JWDCoder;
|
import safeluck.drive.evaluation.platformMessage.decoder.Phone;
|
import safeluck.drive.evaluation.platformMessage.decoder.PhoneCoder;
|
import safeluck.drive.evaluation.platformMessage.decoder.SPEED;
|
import safeluck.drive.evaluation.platformMessage.decoder.SpeedCoder;
|
|
public class JK2019MessageBase extends BinMessageBase {
|
static {
|
AnnotationRegister.register(JWD.class, new JWDCoder());
|
AnnotationRegister.register(Phone.class, new PhoneCoder());
|
//增加speed 编码器
|
AnnotationRegister.register(SPEED.class, new SpeedCoder());
|
|
}
|
static Int16Coder coder = new Int16Coder();
|
public JK2019MessageBase()
|
{
|
this.messageNo = getMessageNo();
|
String message_name = this.getClass().getSimpleName();
|
if(message_name.startsWith("JKMessage"))
|
{
|
String message_id = message_name.substring(9,13);
|
if(message_id.equals("Unkn") ){
|
return;
|
}
|
this.messageId= coder.decode(message_id);
|
}
|
this.setMultiPacket(false);
|
}
|
|
|
@Override
|
public void parse(String hex){
|
|
BitStateCoder coder = new BitStateCoder();
|
this.props = coder.decode(hex.substring(8,12));
|
if(this.isMultiPacket())
|
{
|
this.removeDisableField("totalPacket");
|
this.removeDisableField("packetNo");
|
}
|
super.parse(hex);
|
}
|
|
@Override
|
public String toString()
|
{
|
if(!this.isMultiPacket())
|
{
|
this.registerDisableField("totalPacket");
|
this.registerDisableField("packetNo");
|
}
|
//计算消息体长度
|
String hex = super.toString();
|
// Log.i(PlatFormConstant.TAG, "toString: 消息体长度:"+hex);
|
int message_head_len = 19;
|
if(this.isMultiPacket())
|
{
|
message_head_len+=4;
|
}
|
int len2 = hex.length()/2-message_head_len;
|
this.setMessageLen(len2);
|
//计算校验
|
hex = super.toString();
|
byte[] bytes = BytesUtils.hexStringToBytes(hex);
|
bytes[bytes.length - 2] = BytesUtils.xor(bytes,1,bytes.length -2);
|
|
return BytesUtils.bytesToHexString(bytes);
|
}
|
@Order(1)
|
@Int8
|
public int head=0x7E;
|
@Order(2)
|
@Int8
|
public int protocalVer=0xEB;
|
@Order(3)
|
@Int16
|
public int messageId;
|
@Order(4)
|
@Length(2)
|
@com.safeluck.aykj.annotation.BitState
|
public BitState props = new BitState((short) 0);
|
@Order(5)
|
@Phone
|
public String phone= ExamPlatformData.getInstance().getPhone();
|
@Order(6)
|
@Int16
|
public int messageNo;
|
@Order(7)
|
@Int8
|
public int reserved = 0;
|
// @Order(8)
|
// @Int16
|
// public int totalPacket;
|
// @Order(9)
|
// @Int16
|
// public int packetNo;
|
|
|
@Order(Integer.MAX_VALUE-10001)
|
@Int8
|
public int checksum;
|
@Order(Integer.MAX_VALUE-10000)
|
@Int8
|
public int end=0x7E;
|
|
/**
|
* 是否消息经过分包处理
|
* @param b
|
*/
|
public void setMultiPacket(boolean b)
|
{
|
this.props.set(13,b);
|
}
|
public boolean isMultiPacket()
|
{
|
return this.props.get(13);
|
}
|
|
/**
|
* 获取属性中的消息体长度
|
* @return
|
*/
|
public int getMessageLen()
|
{
|
BitState state = new BitState((short)this.props.value);
|
for (int i = 0; i < 10; i++)
|
{
|
state.set(10 + i, false);
|
}
|
return (int) state.value;
|
}
|
|
/**
|
* 设置属性中的消息体长度
|
* @param len
|
*/
|
public void setMessageLen(int len)
|
{
|
BitState state = new BitState((short)len);
|
|
for (int i = 0; i < 10; i++)
|
{
|
this.props.set(i, state.get(i));
|
}
|
}
|
|
|
|
}
|