jiazx0107@163.com
2023-12-24 c8ff96af8647474b1d03f5f374bb18eb59f65987
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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;
    }
}