package com.fzzy.protocol.bhzn.cmd;
|
|
|
import com.fzzy.api.utils.BytesUtil;
|
import com.fzzy.protocol.bhzn.data.IoMessage;
|
|
/**
|
* 根据接收到的信息进行封装
|
*
|
* @author vince
|
*/
|
public class ReMessageBuilder {
|
|
|
public final static String ERROR_TAG = "3CF6";
|
public static double FAULT_CHECK_TAG = 85.0;
|
public static double MAX_TEMP = -50.0;
|
public static double MIN_TEMP = 50.0;
|
private final static ReMessageBuilder instance = new ReMessageBuilder();
|
|
private ReMessageBuilder() {
|
}
|
|
public static ReMessageBuilder getInstance() {
|
return instance;
|
}
|
|
/**
|
* @param message
|
* @return
|
*/
|
public IoMessage buildMessage(String message) throws Exception {
|
IoMessage ioMessage = new IoMessage();
|
|
//转换为数字,高低位转换(4位)
|
int i = BytesUtil.hexToBigInt(BytesUtil.tran_LH(message.substring(2, 6)));
|
ioMessage.setPcAddr(i + "");
|
i = BytesUtil.hexToBigInt(BytesUtil.tran_LH(message.substring(6, 10)));//高低位转换(4位)
|
ioMessage.setAddr(i + "");
|
|
ioMessage.setFunctionId(message.substring(10, 12));//功能码(2位),不用高低位转换
|
|
i = BytesUtil.hexToBigInt(message.substring(12, 14));//长度(1位)
|
ioMessage.setLength(i);
|
|
//获取消息体
|
ioMessage.setContent(message.substring(14, 14 + (i * 2)));
|
|
ioMessage.setCheck(message.substring(message.length() - 2));
|
return ioMessage;
|
}
|
}
|