严智鑫
2025-11-13 945bc394f40d8af1072a53da9a94f24207124e6d
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package com.northglass.service.message;
 
import java.util.Date;
import java.util.List;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
 
import com.northglass.constants.ShelfTaskType;
import com.northglass.constants.StateConstants.LoadMachineRackState;
import com.northglass.constants.StateConstants.LoadMachineTaskState;
import com.northglass.constants.StateConstants.ShelfRankState;
import com.northglass.constants.StateConstants.ShelfTaskState;
import com.northglass.entity.LoadMachine;
import com.northglass.entity.LoadMachineRack;
import com.northglass.entity.LoadMachineTask;
import com.northglass.entity.MeasureMachine;
import com.northglass.entity.OptPattern;
import com.northglass.entity.RawPackage;
import com.northglass.entity.ShelfRank;
import com.northglass.entity.ShelfTask;
import com.northglass.repository.LoadMachineRackDao;
import com.northglass.repository.LoadMachineTaskDao;
import com.northglass.repository.OptPatternDao;
import com.northglass.repository.RawPackageDao;
import com.northglass.repository.ShelfTaskDao;
import com.northglass.service.loadmachine.LoadMachineService;
import com.northglass.service.shelf.ShelfService;
import com.northglass.service.shelfrank.ShelfRankService;
import com.northglass.util.HexUtil;
 
@Component
@Transactional
public class MeasureMachineMessageProcessor extends AbstractMessageProcessor {
 
    private static final Logger LOGGER = LoggerFactory.getLogger(MeasureMachineMessageProcessor.class);
    @Autowired
    private LoadMachineService loadMachineService;
 
    @Autowired
    private ShelfService shelfService;
 
    @Autowired
    private ShelfRankService shelfRankService;
 
    @Autowired
    private RawPackageDao rawPackageDao;
 
    @Autowired
    private OptPatternDao optPatternDao;
 
    @Autowired
    private LoadMachineTaskDao loadMachineTaskDao;
 
    @Autowired
    private ShelfTaskDao shelfTaskDao;
 
    @Autowired
    private LoadMachineRackDao loadMachineRackDao;
 
    private boolean sendingGlass = false;
 
    private OptPattern waitoptPattern = null;
 
    private LoadMachineRack loadMachineRackTwo = null;
 
    private RawPackage currentRawPackageTwo = null;
 
    private ShelfRank shelfRank = null;
 
    // 请求信号
    private static final int TASK_ASK_START = 18;
    private static final int TASK_ASK_END = 21;
    // 请求ID
    private static final int TASK_ASK_TD_START = 22;
    private static final int TASK_ASK_ID_END = 25;
 
    // 任务汇报字
    private static final int TASK_FINISH_PLC_START = 38;
    private static final int TASK_FINISH_PLC_END = 41;
 
    // 任务汇报ID
    private static final int TASK_FINISH_PLC_ID_START = 42;
    private static final int TASK_FINISH_PLC_ID_END = 45;
 
    // 任务发送字
    private static final int TASK_MES_START = 58;
    private static final int TASK_MES_END = 61;
 
    // 任务确认字
    private static final int TASK_SURE_START = 98;
    private static final int TASK_SURE_END = 101;
 
    // 任务报警字
    private static final int TASK_WARN_START = 138;
    private static final int TASK_WARN_END = 141;
 
    // 完成步骤
    private static final int FINISH_STEP_START = 178;
    private static final int FINISH_STEP_END = 181;
 
    /**
     * 解析16进制消息,转译为描述信息
     * 
     * @param messageHex
     * @return
     */
    public String parse(String messageHex) {
        LOGGER.trace("> Start parse");
 
        if (messageHex.length() < 84) {
            return "无效消息:" + messageHex;
        }
 
        String startSign = messageHex.substring(START_SIGN_START, START_SIGN_END + 1);
        if (!startSign.equals("3c5354413e")) {
            return "无效消息:" + messageHex;
        }
 
        StringBuffer messageDescription = new StringBuffer();
 
        // 消息长度
        messageDescription.append(parseInt(messageHex, MESSAGE_LENGTH_START, MESSAGE_LENGTH_END, "消息长度"));
 
        // 订单编号
        messageDescription.append(parseString(messageHex, ORDER_NUMBER_START, ORDER_NUMBER_END, "订单编号"));
 
        // 功能号
        messageDescription.append(parseString(messageHex, FUNCTION_NUMBER_START, FUNCTION_NUMBER_END, "功能号"));
 
        // 加密方式
        messageDescription.append(parseString(messageHex, ENCRYPT_START, ENCRYPT_END, "加密方式"));
 
        // 发送时刻
        messageDescription.append(parseTime(messageHex, SEND_TIME_START, SEND_TIME_END, "发送时刻"));
 
        // 解析数据区
        messageDescription.append(parseData(messageHex));
 
        // LOGGER.trace("> End parse");
        return messageDescription.toString();
    }
 
    private String parseData(String messageHex) {
        return "无法解析数据区";
    }
 
    public String generateReturnMessage(String sendMessageHex, MeasureMachine measureMachine) {
        LOGGER.debug("收到测量台的信息:" + sendMessageHex);
        if (sendMessageHex.length() == 24) {
            String string = sendMessageHex.substring(8, 15);
            if (string.equals("00060010")) {
                LOGGER.debug("上次消息发送成功!");
                return "";
            } else {
                LOGGER.debug("上次消息发送失败!");
                return "";
            }
        } else if (sendMessageHex.length() == 198) {
            // 请求信号
            String taskAsk = sendMessageHex.substring(TASK_ASK_START, TASK_ASK_END + 1);
            // 请求ID
            String taskIdAsk = sendMessageHex.substring(TASK_ASK_TD_START, TASK_ASK_ID_END + 1);
            // 任务汇报字
            String taskFinish = sendMessageHex.substring(TASK_FINISH_PLC_START, TASK_FINISH_PLC_END + 1);
            // 任务汇报字ID
            String taskFinishId = sendMessageHex.substring(TASK_FINISH_PLC_ID_START, TASK_FINISH_PLC_ID_END + 1);
            // 任务发送字
            String taskMes = sendMessageHex.substring(TASK_MES_START, TASK_MES_END + 1);
            // 任务确认字
            String taskSure = sendMessageHex.substring(TASK_SURE_START, TASK_SURE_END + 1);
            // 任务报警字
            String taskWarning = sendMessageHex.substring(TASK_WARN_START, TASK_WARN_END + 1);
            // 完成步骤
            String finishStep = sendMessageHex.substring(FINISH_STEP_START, FINISH_STEP_END + 1);
            LOGGER.debug("请求信号:" + taskAsk + "| 请求ID:" + taskIdAsk + "| 任务汇报字:" + taskFinish + "| 任务汇报字ID:"
                    + taskFinishId + "| 任务发送字:" + taskMes + "| 任务确认字:" + taskSure + "| 任务报警字:" + taskWarning + "| 完成步骤:"
                    + finishStep);
            // LOGGER.debug("请求ID:"+taskIdAsk);
            // LOGGER.debug("任务汇报字:"+taskFinish);
            // LOGGER.debug("任务汇报字ID:"+taskFinishId);
            // LOGGER.debug("任务发送字:"+taskMes);
            // LOGGER.debug("任务确认字:"+taskSure);
            // LOGGER.debug("任务报警字:"+taskWarning);
            // LOGGER.debug("完成步骤:"+finishStep);
            // 获取上片机正在执行的任务
            // 收到请求
            //测量台结束产生我们需要的数据
            if (taskFinish.equals("0001")) {
                
            } else if (taskFinish.equals("0000")) {
                
            }
 
            return "";
        } else {
            LOGGER.debug("接收的信息和设置的不一致,请查找原因,长度为:" + sendMessageHex.length());
            return "";
        }
    }
 
    /**
     * 消息发送
     * 
     * @param task
     * @return
     */
    private String sendMessage(String senddate, String address) {
        String Herd = "0010" + address;
        int length = senddate.length() / 4;
        String dates = Herd + HexUtil.intTo2ByteHex(length) + HexUtil.intTo1ByteHex(length * 2) + senddate;
        int lengths = dates.length() / 2;
        String date = "00000000" + HexUtil.intTo2ByteHex(lengths) + dates;
        LOGGER.debug("发送信息内容:" + date);
        return date;
    }
}