1 package com.github.google.bumble.remotehci; 2 3 import java.util.ArrayList; 4 5 public class HciPacket { 6 public enum Type { 7 COMMAND((byte) 1), 8 ACL_DATA((byte) 2), 9 SCO_DATA((byte) 3), 10 EVENT((byte) 4), 11 ISO_DATA((byte)5); 12 13 final byte value; 14 final int lengthSize; 15 final int lengthOffset; 16 Type(byte value)17 Type(byte value) throws IllegalArgumentException { 18 switch (value) { 19 case 1: 20 case 3: 21 lengthSize = 1; 22 lengthOffset = 2; 23 break; 24 25 case 2: 26 case 5: 27 lengthSize = 2; 28 lengthOffset = 2; 29 break; 30 31 case 4: 32 lengthSize = 1; 33 lengthOffset = 1; 34 break; 35 36 default: 37 throw new IllegalArgumentException(); 38 39 } 40 this.value = value; 41 } 42 fromValue(byte value)43 static Type fromValue(byte value) { 44 for (Type type : values()) { 45 if (type.value == value) { 46 return type; 47 } 48 } 49 return null; 50 } 51 } 52 byteArrayToList(byte[] byteArray)53 public static ArrayList<Byte> byteArrayToList(byte[] byteArray) { 54 ArrayList<Byte> list = new ArrayList<>(); 55 list.ensureCapacity(byteArray.length); 56 for (byte x : byteArray) { 57 list.add(x); 58 } 59 return list; 60 } 61 listToByteArray(ArrayList<Byte> byteList)62 public static byte[] listToByteArray(ArrayList<Byte> byteList) { 63 byte[] byteArray = new byte[byteList.size()]; 64 for (int i = 0; i < byteList.size(); i++) { 65 byteArray[i] = byteList.get(i); 66 } 67 return byteArray; 68 } 69 } 70