public static DatagramPacket buildPacket(PacketType type, ByteBuffer deviceName, ByteBuffer payload) {
        ByteBuffer content = ByteBuffer.allocate(0x1f + payload.remaining());
        content.put(getMagicHeader());
        content.put(type.protocolValue);
        content.put(deviceName);
        content.put(payload);
        return new DatagramPacket(content.array(), content.capacity());
    }
public static DatagramPacket buildPacket ( PacketType type , ByteBuffer deviceName , ByteBuffer payload ) { ByteBuffer content = ByteBuffer . allocate ( 0x1f + payload . remaining ( ) ) ; content . put ( getMagicHeader ( ) ) ; content . put ( type . protocolValue ) ; content . put ( deviceName ) ; content . put ( payload ) ; return new DatagramPacket ( content . array ( ) , content . capacity ( ) ) ; }
Build a standard-format UDP packet for sending to port 50001 or 50002 in the protocol.

@param type the type of packet to create.
@param deviceName the 0x14 (twenty) bytes of the device name to send in the packet.
@param payload the remaining bytes which come after the device name.
@return the packet to send.