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; } }