自动化立体仓库 - WCS系统
zc
4 天以前 f11edf2a41cd186ce46581f0b72ebccfc650674f
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
package com.zy.core.thread.impl;
 
import com.zy.common.model.MatDto;
import com.zy.core.Slave;
import com.zy.core.cache.MessageQueue;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.LedSlave;
import com.zy.core.model.Task;
import com.zy.core.model.command.LedCommand;
import com.zy.core.thread.LedThread;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
 
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
@Data
@Slf4j
@SuppressWarnings("all")
public class NormalLedThread implements LedThread, Runnable {
 
    private Slave slave;
    private Set<Integer> workNos = new HashSet<>();
 
    private boolean ledMk = false;
    private boolean resetStatus = false;    // 复位状态
 
    // 显示器
    private StringBuffer stringBuffer = new StringBuffer();
    private List<LedCommand> commandList;
 
    private StringBuffer errorMsg = new StringBuffer();
 
    public NormalLedThread(LedSlave ledSlave) {
        this.slave = ledSlave;
    }
 
 
    @Override
    @SuppressWarnings({"InfiniteLoopStatement", "unchecked"})
    public void run() {
        while (true) {
            try {
                Task task = MessageQueue.poll(SlaveType.Led, slave.getId());
                if (task != null) {
                    switch (task.getStep()) {
                        // 写数据
                        case 1:
                            write((List<LedCommand>) task.getData());
                            break;
                        // 复位
                        case 2:
                            reset();
                            break;
                        case 3:
                            error((String) task.getData());
                            break;
                        case 4:
                            errorReset();
                            break;
                        default:
                            break;
                    }
                }
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
    public void write(List<LedCommand> list) {
        commandList = list;
 
        StringBuilder sb = new StringBuilder();
        for (LedCommand command : list) {
            sb.append(command.getTitle()).append("(").append(command.getWorkNo()).append(")").append("\n");
            sb.append("源库位:").append(command.getSourceLocNo()).append("\n");
            sb.append("目标站:").append(command.getStaNo()).append("\n");
            if (!command.isEmptyMk()) {
                for (MatDto matDto : command.getMatDtos()) {
                    sb.append("物料编码:").append(matDto.getMatNo()).append("\n");
                    sb.append("名称:").append(matDto.getMaknx()).append("\n");
                    sb.append("数量:").append(matDto.getCount()).append("\n");
                    sb.append("规格:").append(matDto.getSpecs()).append("\n");
                }
            }
            sb.append("\n");
        }
        stringBuffer.delete(0, stringBuffer.length());
        stringBuffer.append(sb.toString());
 
        errorReset();
    }
 
 
    public void reset() {
        commandList = null;
 
        stringBuffer.delete(0, stringBuffer.length());
    }
 
 
    public void error(String msg) {
        errorMsg.delete(0, errorMsg.length());
        errorMsg.append(msg);
    }
 
    public void errorReset() {
        this.errorMsg.delete(0, errorMsg.length());
    }
 
    @Override
    public void setLedMk(boolean mk) {
        this.ledMk = mk;
    }
 
    @Override
    public boolean isLedMk() {
        return false;
    }
 
    @Override
    public boolean connect() {
        return true;
    }
 
    @Override
    public void close() {
    }
}