From abd6048bab99a878c8a60ea127895be3c516b108 Mon Sep 17 00:00:00 2001 From: Kristian Lauszus Date: Tue, 31 Jul 2012 19:07:23 +0200 Subject: [PATCH] Now works with Galaxy S running Gingerbread Thanks to Sebastian for feedback --- RFCOMM.cpp | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/RFCOMM.cpp b/RFCOMM.cpp index 1f88ca7d..fa6b4c1a 100644 --- a/RFCOMM.cpp +++ b/RFCOMM.cpp @@ -844,13 +844,13 @@ void RFCOMM::ACL_event_task() #endif sendRfcommCredit(rfcommChannelPermanent,rfcommDirection,0,RFCOMM_UIH,0x10,0xFF); // 255 credit creditSent = true; + timer = millis(); + waitForLastCommand = true; } } else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[10] == 0x01) { // UIH Command with credit #ifdef DEBUG - Notify(PSTR("\r\nReceived UIH Command with credit")); -#endif - timer = millis(); - waitForLastCommand = true; + Notify(PSTR("\r\nReceived UIH Command with credit")); +#endif } else if(rfcommChannelType == RFCOMM_UIH && l2capinbuf[11] == BT_RFCOMM_RPN_CMD) { // UIH Remote Port Negotiation Command #ifdef DEBUG Notify(PSTR("\r\nReceived UIH Remote Port Negotiation Command")); @@ -1030,11 +1030,7 @@ void RFCOMM::readReport() { if(rfcommAvailable + length > 256) return; // Return if the buffer would be full - uint8_t offset; - if(l2capinbuf[4] == length+4) - offset = 0; - else - offset = 1; // There must be credit + uint8_t offset = l2capinbuf[4]-length-4; // See if there is credit for(uint8_t i = 0; i < length; i++) rfcommDataBuffer[rfcommAvailable+i] = l2capinbuf[11+i+offset]; @@ -1042,19 +1038,17 @@ void RFCOMM::readReport() { #ifdef EXTRADEBUG Notify(PSTR("\r\nRFCOMM Data Available: ")); Serial.print(rfcommAvailable); + if (offset) { + Notify(PSTR(" - Credit: 0x")); + Serial.print(l2capinbuf[11],HEX); + } #endif } void RFCOMM::printReport() { //Uncomment "#define PRINTREPORT" to print the report send to the Arduino if(rfcommChannelType != RFCOMM_UIH || rfcommChannel != rfcommChannelPermanent) return; - uint8_t length = l2capinbuf[10] >> 1; // Get length - - uint8_t offset; - if(l2capinbuf[4] == length+4) - offset = 0; - else - offset = 1; // There must be credit - + uint8_t length = l2capinbuf[10] >> 1; // Get length + uint8_t offset = l2capinbuf[4]-length-4; // See if there is credit for(uint8_t i = 0; i < length; i++) Serial.write(l2capinbuf[i+11+offset]); }