vince
2025-07-09 6495040bbda5308c86e852ad1b080097bfa916a9
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package com.fzzy.protocol.bhzn.cmd;
 
 
import com.fzzy.api.utils.BytesUtil;
import com.fzzy.protocol.bhzn.server.BhznGrainV2ServerUtils;
 
/**
 * 命令生成
 *
 * @author vince
 */
public class CommandBuild {
 
    private final static CommandBuild instance = new CommandBuild();
 
    private CommandBuild() {
    }
 
    public static CommandBuild getInstance() {
        return instance;
    }
 
    /**
     * PC回复 心跳啊 收到信息
     *
     * @param grainAddr
     * @return
     */
    public static String getMsgHeartReply(String grainAddr) {
 
        StringBuffer sb = new StringBuffer();
 
        //开始符号
        sb.append(BhznGrainV2ServerUtils.MSG_START);
        sb.append(BhznGrainV2ServerUtils.MSG_START2);
 
        //分机地址
        int i = Integer.parseInt(grainAddr);
        sb.append(BytesUtil.tran_LH(BytesUtil.intToHexStr(i)));
 
        //发送方地址
        sb.append("0001");
 
        //命令ID
        sb.append(BhznGrainV2ServerUtils.FUNCTION_ID_F2);
 
        //数据长度-01
        sb.append("01");
 
        //数据区--任意值
        sb.append("01");
 
        //获取校验码
        sb.append(BhznGrainV2ServerUtils.getCheck(sb.toString()));
 
        //结尾符
        sb.append(BhznGrainV2ServerUtils.MSG_END_16);
 
        return sb.toString();
    }
 
    /**
     * 粮情采集命令
     *
     * @param grainAddr 粮情分机地址
     * @param deptId    仓库编号地址
     * @return
     */
    public static String getMsgCheck(String grainAddr, String deptId) {
 
        StringBuffer sb = new StringBuffer();
 
        //开始符号
        sb.append(BhznGrainV2ServerUtils.MSG_START);
        sb.append(BhznGrainV2ServerUtils.MSG_START2);
 
        //分机地址
        int i = Integer.parseInt(grainAddr);
        sb.append(BytesUtil.tran_LH(BytesUtil.intToHexStr(i)));
 
        //发送方地址
        sb.append("0001");
 
        //命令ID
        sb.append(BhznGrainV2ServerUtils.FUNCTION_ID_83);
 
        //数据长度-01
        sb.append("01");
 
        //数据区--主机里面配置的仓库编码
        i = Integer.parseInt(deptId);
        sb.append(BytesUtil.intToHexStr1(i));
 
        //获取校验码
        sb.append(BhznGrainV2ServerUtils.getCheck(sb.toString()));
 
        //结尾符
        sb.append(BhznGrainV2ServerUtils.MSG_END_16);
 
        return sb.toString();
    }
 
    /**
     * PC回复 仓温仓湿 收到信息
     *
     * @param grainAddr
     * @return
     */
    public static String getMsgTHReply(String grainAddr) {
 
        StringBuffer sb = new StringBuffer();
 
        //开始符号
        sb.append(BhznGrainV2ServerUtils.MSG_START);
        sb.append(BhznGrainV2ServerUtils.MSG_START2);
 
        //分机地址
        int i = Integer.parseInt(grainAddr);
        sb.append(BytesUtil.tran_LH(BytesUtil.intToHexStr(i)));
 
        //发送方地址
        sb.append("0001");
 
        //命令ID
        sb.append(BhznGrainV2ServerUtils.FUNCTION_ID_93);
 
        //数据长度-01
        sb.append("01");
 
        //数据区--任意值
        sb.append("01");
 
        //获取校验码
        sb.append(BhznGrainV2ServerUtils.getCheck(sb.toString()));
 
        //结尾符
        sb.append(BhznGrainV2ServerUtils.MSG_END_16);
 
        return sb.toString();
    }
 
    /**
     * PC回复粮温收到信息
     *
     * @param grainAddr
     * @return
     */
    public static String getMsgGrainReply(String grainAddr) {
        StringBuffer sb = new StringBuffer();
 
        //开始符号
        sb.append(BhznGrainV2ServerUtils.MSG_START);
        sb.append(BhznGrainV2ServerUtils.MSG_START2);
 
        //分机地址
        int i = Integer.parseInt(grainAddr);
        sb.append(BytesUtil.tran_LH(BytesUtil.intToHexStr(i)));
 
        //发送方地址
        sb.append("0001");
 
        //命令ID
        sb.append(BhznGrainV2ServerUtils.FUNCTION_ID_92);
 
        //数据长度-01
        sb.append("01");
 
        //数据区--任意值
        sb.append("01");
 
        //获取校验码
        sb.append(BhznGrainV2ServerUtils.getCheck(sb.toString()));
 
        //结尾符
        sb.append(BhznGrainV2ServerUtils.MSG_END_16);
 
        return sb.toString();
    }
}