自动化立体仓库 - WCS系统
#
18516761980
2022-08-10 61b35e3e6203cc43c444b85dae17daa5ce7b39b0
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
package com.zy.core.netty.handle;
 
import com.zy.asrs.service.impl.MainServiceImpl;
import com.zy.core.netty.AbstractInboundHandler;
import com.zy.core.netty.cache.ChannelCache;
import com.zy.core.netty.constant.Constant;
import com.zy.core.netty.constant.FireDataType;
import com.zy.core.netty.domain.ChPackage;
import com.zy.core.netty.domain.fire.Fire_3030;
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 MainServiceImpl mainService;
 
    @Override
    protected boolean channelRead0(ChannelHandlerContext ctx, ChPackage pac) {
        FireDataType dataType = FireDataType.get(pac.getBytes()[1], pac.getBytes()[2]);
        switch (dataType) {
            case HEARTBEAT:
                Fire_3030 fire3030 = new Fire_3030().readFromBytes(pac.getBytes());
                String now = "20" + fire3030.getYear() + "-" + fire3030.getMonth() + "-" + fire3030.getDay()
                        + " " + fire3030.getHour() + ":" + fire3030.getMinute() + ":" + fire3030.getSeconds();
 
                ChannelCache.setChannel(String.valueOf(fire3030.getNo()), ctx.channel());
                Constant.errorMap.remove(fire3030.getNo());
                break;
            case FIRE_ALARM:
 
                break;
            default:
                break;
        }
        return true;
    }
 
    /**
     * 数据下行
     */
    public static void write(ChPackage chPackage){
        String uuid = chPackage.getUuid();
        Channel channel = ChannelCache.getChannel(uuid);
        if (null == channel){
            log.warn("通道uuid={} 不在线", uuid);
            return;
        }
        channel.writeAndFlush(chPackage);
    }
 
    /******************************************************************************************/
    /**************************************** 测试专用 *****************************************/
    /*****************************************************************************************/
    public static void main(String[] args){
        byte[] bytes = new byte[]{(byte)0x82, 0x38, 0x30, 0x32, 0x34, 0x30, 0x38, 0x38, 0x3B, 0x30, 0x31, 0x31, 0x31,
                                    0x30, 0x33, 0x30, 0x38, 0x31, 0x30, 0x30, 0x34, 0x30, 0x38, 0x38, 0x30, (byte)0x83};
        Fire_3030 fire3030 = new Fire_3030().readFromBytes(bytes);
        String now = "20" + fire3030.getYear() + "-" + fire3030.getMonth() + "-" + fire3030.getDay()
                + " " + fire3030.getHour() + ":" + fire3030.getMinute() + ":" + fire3030.getSeconds();
        //消防IO点编号
        String fireNo = fire3030.getNo().toString() + fire3030.getLoop().toString() + fire3030.getPartNo().toString();
        System.out.println(fireNo);
        String aa="";
    }
}