Methods Summary |
---|
protected java.lang.String | extractAddress(int offset)Extracts Bluetooth address from the internal buffer.
byte[] addr = new byte[BluetoothUtils.BTADDR_SIZE];
System.arraycopy(buffer, offset, addr, 0, BluetoothUtils.BTADDR_SIZE);
return BluetoothUtils.getAddressString(addr);
|
protected int | extractShort(int offset)Extracts 2 octets from the internal buffer.
return ((int)buffer[offset] & 0xff) |
(((int)buffer[offset + 1] & 0xff) << 8);
|
protected java.lang.String | extractString(int offset)Extracts string (e.g. friendly name) from the internal buffer. The
string is stored in UTF-8 format and is terminated by NULL character.
int length = 0;
while (offset + length < MAX_HCI_PACKET_SIZE &&
buffer[offset + length] != 0) {
length++;
}
// IMPL_NOTE: UTF-8 encoding support for Java strings?
// return new String(buffer, offset, length, "UTF-8");
return stringUTF8(buffer, offset, length);
|
protected BluetoothEvent | retrieveEvent()Retrieves Bluetooth event from HCI event data containing in the
internal buffer.
readData(buffer);
int code = buffer[0];
int len = buffer[1];
switch (code) {
case HCI_INQUIRY_COMPLETE:
return new InquiryCompleteEvent(buffer[2] == 0);
case HCI_INQUIRY_RESULT:
int num = buffer[2];
int offset = 3;
InquiryResult[] results = new InquiryResult[num];
for (int i = 0; i < num; i++) {
String addr = extractAddress(offset);
int cod = 0;
for (int j = 0; j < 3; j++) {
cod |= ((int)buffer[offset + 9 + j] & 0xff) <<
(16 - j * 8);
}
results[i] = new InquiryResult(addr, cod);
offset += 14; // 14 is the size of the response structure
}
return new InquiryResultEvent(results);
case HCI_AUTH_COMPLETE:
return new AuthenticationCompleteEvent(extractShort(3),
buffer[2] == 0);
case HCI_NAME_COMPLETE:
return new NameResultEvent(extractAddress(3), extractString(9));
case HCI_ENCRYPT_CHANGE:
return new EncryptionChangeEvent(extractShort(3),
buffer[2] == 0, buffer[5] == 1);
default:
return null;
}
|