严智鑫
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
221
222
223
224
225
226
227
228
package com.northglass.service.message;
 
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
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.StateConstants.CountMachineTaskState;
import com.northglass.entity.GaoliweiMachine;
import com.northglass.entity.GaoliweiMachineTask;
import com.northglass.entity.GaoliweiStatu;
import com.northglass.entity.LiedownMachine;
import com.northglass.entity.MachineStatu;
import com.northglass.entity.RawPackageTxt;
import com.northglass.entity.ShelfStatu;
import com.northglass.entity.TransferMachine;
import com.northglass.entity.TransferMachineTask;
import com.northglass.repository.GaoliweiMachineDao;
import com.northglass.repository.GaoliweiMachineTaskDao;
import com.northglass.repository.MachineStatuDao;
import com.northglass.repository.RawPackageTxtDao;
import com.northglass.repository.ShelfStatuDao;
import com.northglass.repository.TransferMachineTaskDao;
import com.northglass.util.HexUtil;
 
@Component
@Transactional
public class LiedownMessageProcessor extends AbstractMessageProcessor {
 
    private static final Logger LOGGER = LoggerFactory.getLogger(LiedownMessageProcessor.class);
    @Autowired
    private ShelfStatuDao shelfStatuDao;
 
    public String generateReturnMessage(String sendMessageHex, LiedownMachine liedownMachine) {
        // 请求信号
         //LOGGER.debug("收到立转卧信息:" + sendMessageHex);
        if (sendMessageHex.length() == 24) {
            String string = sendMessageHex.substring(8, 16);
            if (string.equals("00060110")) {
                 LOGGER.debug("消息发送成功!");
                return "";
            } else {
                 LOGGER.debug("消息发送失败!");
                return "";
            }
        } else if (sendMessageHex.length() == 198) {
            try {
                String message=sendMessageHex.substring(18);
                String result[]=ResultTexts(sendMessageHex.substring(18));
                ShelfStatu statu=shelfStatuDao.findByMachine("liedown");
                statu.setMessage(message);
                statu.setSetTime(new Date());
                shelfStatuDao.save(statu);
                
                /*FindMachineIOData("liedown",45,36,0,"片台减速光电");//片台减速光电
                FindMachineIOData("liedown",45,36,1,"立转卧水平前端");//立转卧水平前端
                FindMachineIOData("liedown",45,36,2,"立转卧水平减速");//立转卧水平减速
                FindMachineIOData("liedown",45,36,3,"立转卧水平末端");//立转卧水平末端
                FindMachineIOData("liedown",45,36,4,"立转卧下翻减速");//立转卧下翻减速
                FindMachineIOData("liedown",45,36,5,"立转卧下翻限位");//立转卧下翻限位
                FindMachineIOData("liedown",45,36,6,"立转卧上翻限位");//立转卧上翻限位
                FindMachineIOData("liedown",45,36,7,"立转卧下翻停止");//立转卧下翻停止
                FindMachineIOData("liedown",45,36,8,"立转卧上翻减速");//立转卧上翻减速
*///                String font="";
//                for(int i=0;i<result.length;i++){
//                    font+="\n第"+(i+1)+"个字------十六进制:"+result[i]+",十进制:"+Integer.valueOf(result[i],16);
//                }
//                System.out.println(font);
                
                /*if(result[35].equals("0001")){
                     LOGGER.debug("当前传送台处于手动状态!");
                     return "";
                }else if(result[35].equals("0002")||result[35].equals("0003")){
                    if(result[35].equals("0002")){
                         LOGGER.debug("当前立转卧处于单机状态!");
                    }else{
                         LOGGER.debug("当前立转卧处于MES自动状态!");
                    }
                }else if(result[35].equals("0004")){
                     LOGGER.debug("当前立转卧处于故障状态!");
                     return "";
                }else if(result[35].equals("0005")){
                     LOGGER.debug("当前立转卧处于维护保养状态!");
                     return "";
                }else{
                     LOGGER.debug("未读取到可操作的立转卧可选模式!");
                     return "";
                }*/
//                String Length=result[10];     //长
//                String Width=result[10];      //宽        
//                String Thickness=result[10];  //厚        
//                RawPackageTxt rawPackageTxt=rawPackageTxtDao.findAcceptedByGroup("1");
//                String Begin=statu.getPoint();      //开始字   1为下发任务 2为停止任务   3为已发送  0不处理(基本等同于3)
                //下发任务
//                if("1".equals(Begin)){
//                        //长+宽+厚+空空+开始+结束
//                        String data="";
//                        data+=HexUtil.intTo2ByteHex(new Double(rawPackageTxt.getWidth()).intValue());
//                        data+=HexUtil.intTo2ByteHex(new Double(rawPackageTxt.getHeight()).intValue());
//                        data+=HexUtil.intTo2ByteHex(new Double(rawPackageTxt.getThiness()).intValue());
//                        data+="0000"+"0000";
//                        data+="0001";
//                        statu.setPoint("3");
//                        shelfStatuDao.save(statu);
//                        return message(data,"0000");
//                }else if("2".equals(Begin)){
//                    String data="0000"+"0000"+"0000"+"0000"+"0000"+"0000"+"0001";
//                    return message(data,"0000");
//                }
            } catch (Exception e) {
                System.out.println("请检查LiedownMessageProcessor.generateReturnMessage!错误原因:"+getStackTraceInfo(e));
            }
        }
        return "";
    }
    //得到所有的45个字
    private String[] ResultTexts(String Str) {
        String []InfoTex =new String[45];
        for(int i=0;i<45;i++){
            InfoTex[i]=Str.substring(0,4);
            Str=Str.substring(4);
        }
        return InfoTex;
    }
    
    
    /****
    /****
     * 根据机器名称,word长度获取所有的信息。使用方法:通过【下标】获取16进制的一个字
     * 用途:机器IO信号读取
     * @param machineName
     * @param index
     * @return
     */
        public  String[] GetMachineSign(String machineName,int index){
            ShelfStatu machinestu=shelfStatuDao.findByMachine(machineName);
            String message=machinestu.getMessage();
            String []InfoTex =new String[index];
            for(int i=0;i<index;i++){
                InfoTex[i]=message.substring(0,4);
                message=message.substring(4);
            }
            return InfoTex;    
        }
        /****
         * 根据shelfStatu表里的机器名、word数,要获取的字的位置,以及对应Io信号的下标,返回String类型的0000或者0001
         * @param machineName
         * @param wordCount
         * @param position
         * @param index
         * @return
         */
        public String FindMachineIOData(String machineName,int wordCount,int position,int index,String outTip){
            String result[]=GetMachineSign(machineName,wordCount);
            String IOdata= HexUtil.getReturnStr(HexUtil.GetHextoBinReverse(result[position]).charAt(index));
            System.out.println(outTip+"------"+IOdata);
            return IOdata;
        }
 
        /*****
         * 得到16进制的对应机器里的信息,非2进制转化后的。返回类型为String 类型   传入参数:机器名、word总数量、获取的下标位置
         * @param machineName
         * @param wordCount
         * @param position
         * @return
         */
        public String FindMachineIOData(String machineName,int wordCount,int position,String outTip){
            String result[]=GetMachineSign(machineName,wordCount);
            String machineSign=result[position];
            System.out.println(outTip+"------"+machineSign);
            return machineSign;
        }
    
    
    /**
     * 获取e.printStackTrace() 的具体信息,赋值给String 变量,并返回
     * 
     * @param e
     *            Exception
     * @return e.printStackTrace() 中 的信息
     */
    public static String getStackTraceInfo(Exception e) {
        StringWriter sw = null;
        PrintWriter pw = null;
        try {
            sw = new StringWriter();
            pw = new PrintWriter(sw);
            e.printStackTrace(pw);//将出错的栈信息输出到printWriter中
            pw.flush();
            sw.flush();
            return sw.toString();
        } catch (Exception ex){
            return "printStackTrace()转换错误";
        } finally {
            if (sw != null) {
                try {
                    sw.close();
                } catch (IOException e1){
                    e1.printStackTrace();
                }
            }
            if (pw != null) {
                pw.close();
            }
        }
 
    }
    /****
     * 
     * senddate 返回信息 address 返回信息地址
     * 
     **/
    private String message(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;
    }
}