自动化立体仓库 - WCS系统
pang.jiabao
2024-04-22 32b905ac1f907fd0f58784acd8f609e691b2ea6e
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
package com.zy.core.netty.handle;
 
import com.zy.utils.News;
import com.zy.core.netty.AbstractInboundHandler;
import com.zy.core.netty.cache.ChannelCache;
import com.zy.core.netty.domain.ChPackage;
import com.zy.core.netty.properties.TcpProperties;
import com.zy.core.properties.SlaveProperties;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
/**
 * 国标业务处理handler
 * Created by vincent on 2019-04-02
 */
@Slf4j
@Component
@ChannelHandler.Sharable
public class PackageServerHandler extends AbstractInboundHandler<ChPackage> {
 
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
    private TcpProperties tcpProperties;
 
    @Override
    protected boolean channelRead0(ChannelHandlerContext ctx, ChPackage pac) {
//        log.info("读码器【IP:{}】 上行数据 ===>> {}", pac.getIp(), pac.getAscii());
//        //扫码上传数据格式必须2个#开头,如:##12345678
//        String msg = pac.getAscii().replaceAll("#", "");
//        if(!Cools.isEmpty(msg) && msg.length()>=tcpProperties.getBarcodeLen()){
//            msg = msg.substring(0,tcpProperties.getBarcodeLen());
//
//            for (Slave slave : slaveProperties.getBarcode()) {
//                if (slave.getIp().equals(pac.getIp())) {
//                    BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, slave.getId());
//                    if (barcodeThread == null) { continue; }
//                    barcodeThread.setBarcode(msg);
//                    break;
//                }
//            }
//        }
 
        return true;
    }
 
    /**
     * 数据下行
     */
    public static void write(ChPackage chPackage){
        String uuid = chPackage.getUuid();
        Channel channel = ChannelCache.getChannel(uuid);
        if (null == channel){
            News.warn("通道uuid={} 不在线", uuid);
            return;
        }
        channel.writeAndFlush(chPackage);
    }
}