Example usage for java.nio ByteOrder BIG_ENDIAN

List of usage examples for java.nio ByteOrder BIG_ENDIAN

Introduction

In this page you can find the example usage for java.nio ByteOrder BIG_ENDIAN.

Prototype

ByteOrder BIG_ENDIAN

To view the source code for java.nio ByteOrder BIG_ENDIAN.

Click Source Link

Document

This constant represents big endian.

Usage

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 www.j av a2  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

@Override
public byte[] encodeSetMusicInfo(String artist, String album, String track, int duration, int trackCount,
        int trackNr) {
    String[] parts = { artist, album, track };
    if (duration == 0 || mFwMajor < 3) {
        return encodeMessage(ENDPOINT_MUSICCONTROL, MUSICCONTROL_SETMUSICINFO, 0, parts);
    } else {/* w ww  .  j  ava2  s.c o m*/
        // Calculate length first
        int length = LENGTH_PREFIX + 9;
        if (parts != null) {
            for (String s : parts) {
                if (s == null || s.equals("")) {
                    length++; // encode null or empty strings as 0x00 later
                    continue;
                }
                length += (1 + s.getBytes().length);
            }
        }

        // Encode Prefix
        ByteBuffer buf = ByteBuffer.allocate(length);
        buf.order(ByteOrder.BIG_ENDIAN);
        buf.putShort((short) (length - LENGTH_PREFIX));
        buf.putShort(ENDPOINT_MUSICCONTROL);
        buf.put(MUSICCONTROL_SETMUSICINFO);

        // Encode Pascal-Style Strings
        for (String s : parts) {
            if (s == null || s.equals("")) {
                buf.put((byte) 0x00);
                continue;
            }

            int partlength = s.getBytes().length;
            if (partlength > 255)
                partlength = 255;
            buf.put((byte) partlength);
            buf.put(s.getBytes(), 0, partlength);
        }

        buf.order(ByteOrder.LITTLE_ENDIAN);
        buf.putInt(duration * 1000);
        buf.putShort((short) (trackCount & 0xffff));
        buf.putShort((short) (trackNr & 0xffff));

        return buf.array();
    }
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

@Override
public byte[] encodeAppStart(UUID uuid, boolean start) {
    if (mFwMajor >= 3) {
        final short LENGTH_APPRUNSTATE = 17;
        ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_APPRUNSTATE);
        buf.order(ByteOrder.BIG_ENDIAN);
        buf.putShort(LENGTH_APPRUNSTATE);
        buf.putShort(ENDPOINT_APPRUNSTATE);
        buf.put(start ? APPRUNSTATE_START : APPRUNSTATE_STOP);
        buf.putLong(uuid.getMostSignificantBits());
        buf.putLong(uuid.getLeastSignificantBits());
        return buf.array();
    } else {//from  w w w  .j  a v  a  2  s.  c om
        ArrayList<Pair<Integer, Object>> pairs = new ArrayList<>();
        int param = start ? 1 : 0;
        pairs.add(new Pair<>(1, (Object) param));
        return encodeApplicationMessagePush(ENDPOINT_LAUNCHER, uuid, pairs);
    }
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

@Override
public byte[] encodeAppDelete(UUID uuid) {
    if (mFwMajor >= 3) {
        if (UUID_PEBBLE_HEALTH.equals(uuid)) {
            return encodeActivateHealth(false);
        }//from   ww  w .  j a  va  2 s.  c  om
        if (UUID_WORKOUT.equals(uuid)) {
            return encodeActivateHRM(false);
        }
        if (UUID_WEATHER.equals(uuid)) { //TODO: probably it wasn't present in firmware 3
            return encodeActivateWeather(false);
        }
        return encodeBlobdb(uuid, BLOBDB_DELETE, BLOBDB_APP, null);
    } else {
        final short LENGTH_REMOVEAPP_2X = 17;
        ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_REMOVEAPP_2X);
        buf.order(ByteOrder.BIG_ENDIAN);
        buf.putShort(LENGTH_REMOVEAPP_2X);
        buf.putShort(ENDPOINT_APPMANAGER);
        buf.put(APPMANAGER_REMOVEAPP);
        buf.putLong(uuid.getMostSignificantBits());
        buf.putLong(uuid.getLeastSignificantBits());
        return buf.array();
    }
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

private byte[] encodePhoneVersion2x(byte os) {
    final short LENGTH_PHONEVERSION = 17;
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_PHONEVERSION);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort(LENGTH_PHONEVERSION);/*  w  w w.  jav  a 2s.  c  o  m*/
    buf.putShort(ENDPOINT_PHONEVERSION);
    buf.put((byte) 0x01);
    buf.putInt(-1); //0xffffffff

    if (os == PHONEVERSION_REMOTE_OS_ANDROID) {
        buf.putInt(PHONEVERSION_SESSION_CAPS_GAMMARAY);
    } else {
        buf.putInt(0);
    }
    buf.putInt(PHONEVERSION_REMOTE_CAPS_SMS | PHONEVERSION_REMOTE_CAPS_TELEPHONY | os);

    buf.put(PHONEVERSION_APPVERSION_MAGIC);
    buf.put(PHONEVERSION_APPVERSION_MAJOR);
    buf.put(PHONEVERSION_APPVERSION_MINOR);
    buf.put(PHONEVERSION_APPVERSION_PATCH);

    return buf.array();
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

private byte[] encodePhoneVersion3x(byte os) {
    final short LENGTH_PHONEVERSION3X = 25;
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_PHONEVERSION3X);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort(LENGTH_PHONEVERSION3X);
    buf.putShort(ENDPOINT_PHONEVERSION);
    buf.put((byte) 0x01);
    buf.putInt(-1); //0xffffffff
    buf.putInt(0);/*w w  w  . j a  va2 s  .  c o m*/

    buf.putInt(os);

    buf.put(PHONEVERSION_APPVERSION_MAGIC);
    buf.put((byte) 4); // major
    buf.put((byte) 1); // minor
    buf.put((byte) 1); // patch
    buf.order(ByteOrder.LITTLE_ENDIAN);
    buf.putLong(0x00000000000029af); //flags

    return buf.array();
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

@Override
public byte[] encodeAppReorder(UUID[] uuids) {
    int length = 2 + uuids.length * LENGTH_UUID;
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort((short) length);
    buf.putShort(ENDPOINT_APPREORDER);//from  w w  w. j  av a2s.  co  m
    buf.put((byte) 0x01);
    buf.put((byte) uuids.length);
    for (UUID uuid : uuids) {
        buf.putLong(uuid.getMostSignificantBits());
        buf.putLong(uuid.getLeastSignificantBits());
    }

    return buf.array();
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

byte[] encodeUploadStart(byte type, int app_id, int size, String filename) {
    short length;
    if (mFwMajor >= 3 && (type != PUTBYTES_TYPE_FILE)) {
        length = (short) 10;
        type |= 0b10000000;//  www  .  jav  a  2s .  co  m
    } else {
        length = (short) 7;
    }

    if (type == PUTBYTES_TYPE_FILE && filename != null) {
        length += filename.getBytes().length + 1;
    }

    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + length);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort(length);
    buf.putShort(ENDPOINT_PUTBYTES);
    buf.put(PUTBYTES_INIT);
    buf.putInt(size);
    buf.put(type);

    if (mFwMajor >= 3 && (type != PUTBYTES_TYPE_FILE)) {
        buf.putInt(app_id);
    } else {
        // slot
        buf.put((byte) app_id);
    }

    if (type == PUTBYTES_TYPE_FILE && filename != null) {
        buf.put(filename.getBytes());
        buf.put((byte) 0);
    }

    return buf.array();
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

byte[] encodeUploadChunk(int token, byte[] buffer, int size) {
    final short LENGTH_UPLOADCHUNK = 9;
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_UPLOADCHUNK + size);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort((short) (LENGTH_UPLOADCHUNK + size));
    buf.putShort(ENDPOINT_PUTBYTES);//from   w  ww. j a  v a 2 s . c  o  m
    buf.put(PUTBYTES_SEND);
    buf.putInt(token);
    buf.putInt(size);
    buf.put(buffer, 0, size);
    return buf.array();
}

From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.pebble.PebbleProtocol.java

byte[] encodeUploadCommit(int token, int crc) {
    final short LENGTH_UPLOADCOMMIT = 9;
    ByteBuffer buf = ByteBuffer.allocate(LENGTH_PREFIX + LENGTH_UPLOADCOMMIT);
    buf.order(ByteOrder.BIG_ENDIAN);
    buf.putShort(LENGTH_UPLOADCOMMIT);//from  ww  w. j a  va  2s.  c  om
    buf.putShort(ENDPOINT_PUTBYTES);
    buf.put(PUTBYTES_COMMIT);
    buf.putInt(token);
    buf.putInt(crc);
    return buf.array();
}