diff --git a/part7-bluetooth/bt.c b/part7-bluetooth/bt.c index b494df0..acf7547 100644 --- a/part7-bluetooth/bt.c +++ b/part7-bluetooth/bt.c @@ -80,6 +80,7 @@ enum { COMMAND_LOAD_FIRMWARE = 0x2e, HCI_COMMAND_PKT = 0x01, + HCI_ACL_PKT = 0x02, HCI_EVENT_PKT = 0x04, COMMAND_COMPLETE_CODE = 0x0e, CONNECT_COMPLETE_CODE = 0x0f, @@ -193,6 +194,31 @@ void bt_getbdaddr(unsigned char *bdaddr) { for (int c=0;c<6;c++) bdaddr[c] = bt_waitReadByte(); } +void sendACLreadreq(unsigned int handle) +{ + bt_writeByte(HCI_ACL_PKT); + + bt_writeByte(lo(handle)); + bt_writeByte(hi(handle)); + + unsigned int length = 0x0007; + bt_writeByte(lo(length)); + bt_writeByte(hi(length)); + + unsigned int data_length = 0x0003; + bt_writeByte(lo(data_length)); + bt_writeByte(hi(data_length)); + + unsigned int channel = 0x0004; + bt_writeByte(lo(channel)); + bt_writeByte(hi(channel)); + + unsigned char params[] = { 0x0a, 0x2a, 0x00 }; + + unsigned int c=0; + while (c++> 4; + + h1 = bt_waitReadByte(); + h2 = bt_waitReadByte(); + + unsigned int length = h1 | (h2 << 8); + unsigned char data[length]; + + for (int i=0;i "); uart_hex(connection_handle); uart_writeText("\n"); + uart_writeText("\n"); + + // Get the characteristic value + uart_writeText("Sending read request: "); + uart_hex(connection_handle); uart_writeText("\n"); + sendACLreadreq(connection_handle); // Into the main infinite loop uart_writeText("Waiting for input...\n"); - while (1) uart_update(); - - /* - // Get the Eddystone beacon going - uart_writeText("startActiveAdvertising()\n"); - startActiveAdvertising(); - */ + while (1) { + acl_poll(); + uart_update(); + } }