@Test public void testParseMessage2() { byte[] payload = new byte[]{0x0, 0x0, 0x61}; byte[] serial = new byte[]{3, 0, 0, 0, 97, 89, -125}; byte[] result = GattSerialMessage.parse(serial); assertThat(Arrays.equals(payload, result)).isTrue(); }
public static byte[] parse(byte[] payload) { int length = (payload[0] & 0xff); Buffer buffer = new Buffer(); buffer.write(payload, 2, length); int crc = computeCRC16(payload, 0, payload.length - 2); int checkCrc = (((payload[payload.length - 1] & 0xff) << 8)) + (payload[payload.length - 2] & 0xff); if (crc != checkCrc) { Log.w(TAG, "Checksum failed"); throw new IllegalStateException("Checksum mismatch"); } return buffer.readByteArray(); }
GattSerialMessage { public static byte[] parse(byte[] payload) { int length = (payload[0] & 0xff); Buffer buffer = new Buffer(); buffer.write(payload, 2, length); int crc = computeCRC16(payload, 0, payload.length - 2); int checkCrc = (((payload[payload.length - 1] & 0xff) << 8)) + (payload[payload.length - 2] & 0xff); if (crc != checkCrc) { Log.w(TAG, "Checksum failed"); throw new IllegalStateException("Checksum mismatch"); } return buffer.readByteArray(); } }
GattSerialMessage { public static byte[] parse(byte[] payload) { int length = (payload[0] & 0xff); Buffer buffer = new Buffer(); buffer.write(payload, 2, length); int crc = computeCRC16(payload, 0, payload.length - 2); int checkCrc = (((payload[payload.length - 1] & 0xff) << 8)) + (payload[payload.length - 2] & 0xff); if (crc != checkCrc) { Log.w(TAG, "Checksum failed"); throw new IllegalStateException("Checksum mismatch"); } return buffer.readByteArray(); } private  GattSerialMessage(Buffer buffer); }
GattSerialMessage { public static byte[] parse(byte[] payload) { int length = (payload[0] & 0xff); Buffer buffer = new Buffer(); buffer.write(payload, 2, length); int crc = computeCRC16(payload, 0, payload.length - 2); int checkCrc = (((payload[payload.length - 1] & 0xff) << 8)) + (payload[payload.length - 2] & 0xff); if (crc != checkCrc) { Log.w(TAG, "Checksum failed"); throw new IllegalStateException("Checksum mismatch"); } return buffer.readByteArray(); } private  GattSerialMessage(Buffer buffer); static GattSerialMessage fromPayload(byte[] payload); static byte[] parse(byte[] payload); Buffer getBuffer(); }
GattSerialMessage { public static byte[] parse(byte[] payload) { int length = (payload[0] & 0xff); Buffer buffer = new Buffer(); buffer.write(payload, 2, length); int crc = computeCRC16(payload, 0, payload.length - 2); int checkCrc = (((payload[payload.length - 1] & 0xff) << 8)) + (payload[payload.length - 2] & 0xff); if (crc != checkCrc) { Log.w(TAG, "Checksum failed"); throw new IllegalStateException("Checksum mismatch"); } return buffer.readByteArray(); } private  GattSerialMessage(Buffer buffer); static GattSerialMessage fromPayload(byte[] payload); static byte[] parse(byte[] payload); Buffer getBuffer();  }