From 712ed057e5ec4de678652ff1cac166a30ffb6165 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Mon, 1 Apr 2013 03:09:23 +0200 Subject: [PATCH] SPP is now working in Android 4.2 as well! --- README.md | 1 - SPP.cpp | 21 +++++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8a9fe556..d190c7c0 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,6 @@ The BTD library will also make it possible to use multiple services at once, the SPP stands for "Serial Port Profile" and is a Bluetooth protocol that implements a virtual comport which allows you to send data back and forth from your computer/phone to your Arduino via Bluetooth. It has been tested successfully on Windows, Mac OS X, Linux, and Android. -Unfortunately Google broke something in Android 4.2, so it's currently not working in this version of Android. More information can be found at these blog posts: diff --git a/SPP.cpp b/SPP.cpp index 8455d974..b671e3c8 100644 --- a/SPP.cpp +++ b/SPP.cpp @@ -191,13 +191,7 @@ void SPP::ACLData(uint8_t* l2capinbuf) { #endif } else if (l2capinbuf[6] == sdp_dcid[0] && l2capinbuf[7] == sdp_dcid[1]) { // SDP if (l2capinbuf[8] == SDP_SERVICE_SEARCH_ATTRIBUTE_REQUEST_PDU) { - /* - Serial.print("\r\nUUID: 0x"); - Serial.print(l2capinbuf[16],HEX); - Serial.print(" "); - Serial.print(l2capinbuf[17],HEX); - */ - if ((l2capinbuf[16] << 8 | l2capinbuf[17]) == SERIALPORT_UUID) { + if (((l2capinbuf[16] << 8 | l2capinbuf[17]) == SERIALPORT_UUID) || ((l2capinbuf[16] << 8 | l2capinbuf[17]) == 0x0000 && (l2capinbuf[18] << 8 | l2capinbuf[19]) == SERIALPORT_UUID)) { // Check if it's sending the full UUID, see: https://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm, we will just check the first four bytes if (firstMessage) { serialPortResponse1(l2capinbuf[9], l2capinbuf[10]); firstMessage = false; @@ -213,8 +207,19 @@ void SPP::ACLData(uint8_t* l2capinbuf) { l2capResponse2(l2capinbuf[9], l2capinbuf[10]); // L2CAP continuation state firstMessage = true; } - } else + } else { +#ifdef EXTRADEBUG + Notify(PSTR("\r\nLength: "), 0x80); + uint16_t length = l2capinbuf[11] << 8 | l2capinbuf[12]; + PrintHex (length, 0x80); + Notify(PSTR("\r\nData: "), 0x80); + for (uint8_t i = 0; i < length; i++) { + PrintHex (l2capinbuf[13+i], 0x80); + Notify(PSTR(" "), 0x80); + } +#endif serviceNotSupported(l2capinbuf[9], l2capinbuf[10]); // The service is not supported + } } } else if (l2capinbuf[6] == rfcomm_dcid[0] && l2capinbuf[7] == rfcomm_dcid[1]) { // RFCOMM rfcommChannel = l2capinbuf[8] & 0xF8;