List of usage examples for java.nio ByteBuffer order
Endianness order
To view the source code for java.nio ByteBuffer order.
Click Source Link
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
private byte[] encodePing(byte command, int cookie) { final short LENGTH_PING = 5; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_PING); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_PING);/*from www . ja va 2 s.c o m*/ buf.putShort(ENDPOINT_PING); buf.put(command); buf.putInt(cookie); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
byte[] encodeEnableAppLogs(boolean enable) { final short LENGTH_APPLOGS = 1; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_APPLOGS); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_APPLOGS);/*from ww w. java 2 s .c o m*/ buf.putShort(ENDPOINT_APPLOGS); buf.put((byte) (enable ? 1 : 0)); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
private byte[] encodeActionResponse2x(int id, byte actionId, int iconId, String caption) { short length = (short) (18 + caption.getBytes().length); ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(length);/*from ww w . j ava 2s .co m*/ buf.putShort(ENDPOINT_EXTENSIBLENOTIFS); buf.order(ByteOrder.LITTLE_ENDIAN); buf.put(NOTIFICATIONACTION_RESPONSE); buf.putInt(id); buf.put(actionId); buf.put(NOTIFICATIONACTION_ACK); buf.put((byte) 2); //nr of attributes buf.put((byte) 6); // icon buf.putShort((short) 4); // length buf.putInt(iconId); buf.put((byte) 2); // title buf.putShort((short) caption.getBytes().length); buf.put(caption.getBytes()); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
private byte[] encodeActionResponse(UUID uuid, int iconId, String caption) { short length = (short) (29 + caption.getBytes().length); ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(length);// w ww. j a v a 2 s .c o m buf.putShort(ENDPOINT_NOTIFICATIONACTION); buf.put(NOTIFICATIONACTION_RESPONSE); buf.putLong(uuid.getMostSignificantBits()); buf.putLong(uuid.getLeastSignificantBits()); buf.order(ByteOrder.LITTLE_ENDIAN); buf.put(NOTIFICATIONACTION_ACK); buf.put((byte) 2); //nr of attributes buf.put((byte) 6); // icon buf.putShort((short) 4); // length buf.putInt(0x80000000 | iconId); buf.put((byte) 2); // title buf.putShort((short) caption.getBytes().length); buf.put(caption.getBytes()); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
byte[] encodeAppFetchAck() { final short LENGTH_APPFETCH = 2; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_APPFETCH); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_APPFETCH);/*from w w w. jav a 2s .c o m*/ buf.putShort(ENDPOINT_APPFETCH); buf.put((byte) 0x01); buf.put((byte) 0x01); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
public byte[] encodeSetMusicState(byte state, int position, int playRate, byte shuffle, byte repeat) { if (mFwMajor < 3) { return null; }/*from w ww . j av a2 s . co m*/ byte playState; switch (state) { case MusicStateSpec.STATE_PLAYING: playState = MUSICCONTROL_STATE_PLAYING; break; case MusicStateSpec.STATE_PAUSED: playState = MUSICCONTROL_STATE_PAUSED; break; default: playState = MUSICCONTROL_STATE_UNKNOWN; break; } int length = LENGTH_PREFIX + 12; // Encode Prefix ByteBuffer buf = ByteBuffer.allocate(length); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort((short) (length - LENGTH_PREFIX)); buf.putShort(ENDPOINT_MUSICCONTROL); buf.order(ByteOrder.LITTLE_ENDIAN); buf.put(MUSICCONTROL_SETPLAYSTATE); buf.put(playState); buf.putInt(position * 1000); buf.putInt(playRate); buf.put(shuffle); buf.put(repeat); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
byte[] encodeApplicationMessageAck(UUID uuid, byte id) { if (uuid == null) { uuid = currentRunningApp;//w w w . j a v a 2 s .c o m } ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + 18); // +ACK buf.order(ByteOrder.BIG_ENDIAN); buf.putShort((short) 18); buf.putShort(ENDPOINT_APPLICATIONMESSAGE); buf.put(APPLICATIONMESSAGE_ACK); buf.put(id); buf.putLong(uuid.getMostSignificantBits()); buf.putLong(uuid.getLeastSignificantBits()); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
byte[] encodeAppRefresh(int index) { final short LENGTH_REFRESHAPP = 5; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_REFRESHAPP); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_REFRESHAPP);//from w w w . java 2 s. c o m buf.putShort(ENDPOINT_APPMANAGER); buf.put(APPMANAGER_REFRESHAPP); buf.putInt(index); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
byte[] encodeUploadCancel(int token) { final short LENGTH_UPLOADCANCEL = 5; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_UPLOADCANCEL); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_UPLOADCANCEL);//from w w w .ja v a 2 s. c om buf.putShort(ENDPOINT_PUTBYTES); buf.put(PUTBYTES_ABORT); buf.putInt(token); return buf.array(); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java
private byte[] encodeSimpleMessage(short endpoint, byte command) { final short LENGTH_SIMPLEMESSAGE = 1; ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_SIMPLEMESSAGE); buf.order(ByteOrder.BIG_ENDIAN); buf.putShort(LENGTH_SIMPLEMESSAGE);/*www.j av a 2 s . com*/ buf.putShort(endpoint); buf.put(command); return buf.array(); }