List of usage examples for java.nio ByteBuffer putShort
public abstract ByteBuffer putShort(short value);
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); buf.putShort(ENDPOINT_PING);/*from w ww . j a v a 2 s . c om*/ 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); buf.putShort(ENDPOINT_APPLOGS);//from w ww .jav a 2s .c om 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); buf.putShort(ENDPOINT_EXTENSIBLENOTIFS); buf.order(ByteOrder.LITTLE_ENDIAN); buf.put(NOTIFICATIONACTION_RESPONSE); buf.putInt(id);//from w w w .ja v a 2s. com 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); 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);// w w w . j av a 2 s .co m 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); buf.putShort(ENDPOINT_APPFETCH);//from w ww . ja v a 2 s .c o m 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 w w. jav a 2 s .c o 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;//from w w w . j a v a 2 s . c om } 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); buf.putShort(ENDPOINT_APPMANAGER);//from w w w . ja v a 2 s . c om 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); buf.putShort(ENDPOINT_PUTBYTES);/*from w w w.ja v a2s . c o m*/ 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); buf.putShort(endpoint);/*from ww w. j a v a 2 s . c o m*/ buf.put(command); return buf.array(); }