CZT
2023-09-26 d52037b84cd6689b1cc03b47a5cd43fcb6b7342f
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
53
54
55
56
57
package com.ld.igds.protocol.beibo.grain.builder;
 
import com.ld.igds.protocol.beibo.grain.util.BeiboGrainServerUtils;
import com.ld.igds.util.BytesUtil;
 
/**
 * 根据接收到的信息进行封装
 *
 * @author czt
 */
public class ReMessageBuilder {
 
    private final static ReMessageBuilder instance = new ReMessageBuilder();
 
    private ReMessageBuilder() {
    }
 
    public static ReMessageBuilder getInstance() {
        return instance;
    }
 
    /**
     * @param strMsg
     * @return
     */
    public ReMessage buildMessage(String strMsg) {
 
        ReMessage message = new ReMessage();
        message.setStrMsg(strMsg);
        //设置起始符
        message.setStartStr(strMsg.substring(0, 9*2-1));
 
        //设置粮情分机地址
        String str = strMsg.substring(9*2-1, 10*2-1);
        int i = BytesUtil.hexToInt(str);
        String serId = String.valueOf(i - BeiboGrainServerUtils.BM);
        message.setSerId(serId);
 
        //粮情数据
        str = strMsg.substring(10*2-1, 1034*2 -1);
        message.setGrainStr(str);
 
        //温度数据
        str = strMsg.substring(1034*2 -1, 1052*2-1);
        message.setThStr(str);
 
        //扩充数据
        str = strMsg.substring(strMsg.length()-14*2, strMsg.length()-4*2);
        message.setExpand(str);
 
        //检验码
        str = strMsg.substring(strMsg.length()-4*2);
        message.setHexCrc16(str);
 
        return message;
    }
}