#
whycq
2024-08-15 e54492fb532366faac8aa5d46ad8905ea3ff38d5
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
package com.example.agvcontroller.protocol;
 
 
import java.util.logging.Logger;
 
/**
 * Created by vincent on 2019-04-03
 */
public class ProtocolUtils {
 
    //private static final Logger log = LoggerFactory.getLogger(ProtocolUtils.class);
 
    // 下行协议报文组装
    public static AgvPackage installDownProtocol(AgvProtocol protocol){
 
 
        //ProtocolPojoType protocolPojo = ProtocolPojoType.query(protocol.getMessageBody().getClass());
 
        //assert protocolPojo !=   null;
 
        AgvPackage ackPackage = AgvPackage.valueOfEmpty();
        ackPackage.getHeader()
                .setStartSymbol((byte)0xEE)
                .setContentLength(0)
                //.setUniqueNo(protocol.getAgvNo())
                //.setTimestamp(protocol.getTimestamp())
                //.setProtocolType(protocolPojo.protocolType)
        ;
 
        //ackPackage.getBody().setMessageBody(protocol.getMessageBody());
 
        return ackPackage;
 
    }
 
    // 下行协议报文组装
    public static AgvPackage installDownProtocol(String uniqueNo, ProtocolType protocolType){
 
 
        AgvPackage ackPackage = AgvPackage.valueOfEmpty();
        ackPackage.getHeader()
                .setStartSymbol((byte)0xEE)
                .setContentLength(0)
                .setUniqueNo(uniqueNo)
                .setTimestamp((int)System.currentTimeMillis()/1000)
                .setProtocolType(protocolType)
        ;
 
        ProtocolPojoType protocolPojo = ProtocolPojoType.query(protocolType);
 
 
        assert protocolPojo != null;
 
 
        IMessageBody iMessageBody = null;
 
        try {
 
            iMessageBody = protocolPojo.clazz.newInstance();
        } catch (ReflectiveOperationException reflectiveOperationException) {
 
 
            //log.error("MessageBodyHandler ReflectiveOperationException", reflectiveOperationException);
 
            //log.error("java反射创建实例失败:{}", protocolPojo.clazz.getName());
 
            return null;
        }
 
 
 
        ackPackage.getBody().setMessageBody(iMessageBody);
 
 
 
        return ackPackage;
    }
 
 
 
}