BLE demo for mbed Ported RunningElectronics's SBDBT firmware for BLE. It can communicate with iOS

Dependencies:   FatFileSystem mbed

Fork of BTstack by Norimasa Okamoto

Revision:
6:cf06ba884429
Parent:
1:6078e430af82
--- a/BTstack/att.c	Mon Feb 11 14:10:57 2013 +0000
+++ b/BTstack/att.c	Wed Feb 20 14:18:38 2013 +0000
@@ -38,6 +38,7 @@
 #include <string.h>
 
 #include "att.h"
+#include "debug.h"
 
 // from src/utils.
 #define READ_BT_16( buffer, pos) ( ((uint16_t) buffer[pos]) | (((uint16_t)buffer[pos+1]) << 8))
@@ -53,21 +54,21 @@
 static void hexdump2(void const *data, int size){
     int i;
     for (i=0; i<size;i++){
-        printf("%02X ", ((uint8_t *)data)[i]);
+        log_info("%02X ", ((uint8_t *)data)[i]);
     }
-    printf("\n");
+    log_info("\n");
 }
 
 static void printUUID128(const uint8_t * uuid){
     int i;
     for (i=15; i >= 0 ; i--){
-        printf("%02X", uuid[i]);
+        log_info("%02X", uuid[i]);
         switch (i){
             case 4:
             case 6:
             case 8:
             case 10:
-                printf("-");
+                log_info("-");
                 break;
             default:
                 break;
@@ -209,16 +210,16 @@
     while (att_iterator_has_next(&it)){
         att_iterator_fetch_next(&it);
         if (it.handle == 0) {
-            printf("Handle: END\n");
+            log_info("Handle: END\n");
             return;
         }
-        printf("Handle: 0x%04x, flags: 0x%04x, uuid: ", it.handle, it.flags);
+        log_info("Handle: 0x%04x, flags: 0x%04x, uuid: ", it.handle, it.flags);
         if (it.flags & ATT_PROPERTY_UUID128){
             printUUID128(it.uuid);
         } else {
-            printf("%04x", READ_BT_16(it.uuid, 0));
+            log_info("%04x", READ_BT_16(it.uuid, 0));
         }
-        printf(", value_len: %u, value: ", it.value_len);
+        log_info(", value_len: %u, value: ", it.value_len);
         hexdump2(it.value, it.value_len);
     }
 }
@@ -268,7 +269,7 @@
 static uint16_t handle_find_information_request2(uint8_t * response_buffer, uint16_t response_buffer_size,
                                            uint16_t start_handle, uint16_t end_handle){
     
-    printf("ATT_FIND_INFORMATION_REQUEST: from %04X to %04X\n", start_handle, end_handle);
+    log_info("ATT_FIND_INFORMATION_REQUEST: from %04X to %04X\n", start_handle, end_handle);
     
     uint16_t offset   = 1;
     uint16_t pair_len = 0;
@@ -283,7 +284,7 @@
         
         att_update_value_len(&it);
         
-        // printf("Handle 0x%04x\n", it.handle);
+        // log_debug("Handle 0x%04x\n", it.handle);
         
         // check if value has same len as last one
         uint16_t this_pair_len = 2 + it.value_len;
@@ -346,7 +347,7 @@
                                            uint16_t start_handle, uint16_t end_handle,
                                            uint16_t attribute_type, uint16_t attribute_len, uint8_t* attribute_value){
     
-    printf("ATT_FIND_BY_TYPE_VALUE_REQUEST: from %04X to %04X, type %04X, value: ", start_handle, end_handle, attribute_type);
+    log_info("ATT_FIND_BY_TYPE_VALUE_REQUEST: from %04X to %04X, type %04X, value: ", start_handle, end_handle, attribute_type);
     hexdump2(attribute_value, attribute_len);
     
     uint16_t offset      = 1;
@@ -365,7 +366,7 @@
         if (in_group &&
             (it.handle == 0 || att_iterator_match_uuid16(&it, GATT_PRIMARY_SERVICE_UUID) || att_iterator_match_uuid16(&it, GATT_SECONDARY_SERVICE_UUID))){
             
-            printf("End of group, handle 0x%04x\n", prev_handle);
+            log_info("End of group, handle 0x%04x\n", prev_handle);
             bt_store_16(response_buffer, offset, prev_handle);
             offset += 2;
             in_group = 0;
@@ -381,7 +382,7 @@
         
         // does current attribute match
         if (it.handle && att_iterator_match_uuid16(&it, attribute_type) && attribute_len == it.value_len && memcmp(attribute_value, it.value, it.value_len) == 0){
-            printf("Begin of group, handle 0x%04x\n", it.handle);
+            log_info("Begin of group, handle 0x%04x\n", it.handle);
             bt_store_16(response_buffer, offset, it.handle);
             offset += 2;
             in_group = 1;
@@ -410,7 +411,7 @@
                                       uint16_t start_handle, uint16_t end_handle,
                                       uint16_t attribute_type_len, uint8_t * attribute_type){
     
-    printf("ATT_READ_BY_TYPE_REQUEST: from %04X to %04X, type: ", start_handle, end_handle); 
+    log_info("ATT_READ_BY_TYPE_REQUEST: from %04X to %04X, type: ", start_handle, end_handle); 
     hexdump2(attribute_type, attribute_type_len);
     
     uint16_t offset   = 1;
@@ -482,14 +483,14 @@
 //
 static uint16_t handle_read_request2(uint8_t * response_buffer, uint16_t response_buffer_size, uint16_t handle){
     
-    printf("ATT_READ_REQUEST: handle %04x\n", handle);
+    log_info("ATT_READ_REQUEST: handle %04x\n", handle);
     
     att_iterator_t it;
     int ok = att_find_handle(&it, handle);
     if (!ok){
         return setup_error_atribute_not_found(response_buffer, ATT_READ_REQUEST, handle);
     }
-    
+
     att_update_value_len(&it);
 
     uint16_t offset   = 1;
@@ -515,7 +516,7 @@
 // MARK: ATT_READ_BLOB_REQUEST 0x0c
 //
 static uint16_t handle_read_blob_request2(uint8_t * response_buffer, uint16_t response_buffer_size, uint16_t handle, uint16_t value_offset){
-    printf("ATT_READ_BLOB_REQUEST: handle %04x, offset %u\n", handle, value_offset);
+    log_info("ATT_READ_BLOB_REQUEST: handle %04x, offset %u\n", handle, value_offset);
 
     att_iterator_t it;
     int ok = att_find_handle(&it, handle);
@@ -552,7 +553,7 @@
 // MARK: ATT_READ_MULTIPLE_REQUEST 0x0e
 //
 static uint16_t handle_read_multiple_request2(uint8_t * response_buffer, uint16_t response_buffer_size, uint16_t num_handles, uint16_t * handles){
-    printf("ATT_READ_MULTIPLE_REQUEST: num handles %u\n", num_handles);
+    log_info("ATT_READ_MULTIPLE_REQUEST: num handles %u\n", num_handles);
     
     uint16_t offset   = 1;
 
@@ -603,7 +604,7 @@
                                             uint16_t start_handle, uint16_t end_handle,
                                             uint16_t attribute_type_len, uint8_t * attribute_type){
     
-    printf("ATT_READ_BY_GROUP_TYPE_REQUEST: from %04X to %04X, buffer size %u, type: ", start_handle, end_handle, response_buffer_size);
+    log_info("ATT_READ_BY_GROUP_TYPE_REQUEST: from %04X to %04X, buffer size %u, type: ", start_handle, end_handle, response_buffer_size);
     hexdump2(attribute_type, attribute_type_len);
     
     uint16_t offset   = 1;
@@ -625,7 +626,7 @@
         if (in_group &&
             (it.handle == 0 || att_iterator_match_uuid16(&it, GATT_PRIMARY_SERVICE_UUID) || att_iterator_match_uuid16(&it, GATT_SECONDARY_SERVICE_UUID))){
             // TODO: check if handle is included in start/end range
-            // printf("End of group, handle 0x%04x, val_len: %u\n", prev_handle, pair_len - 4);
+            // log_debug("End of group, handle 0x%04x, val_len: %u\n", prev_handle, pair_len - 4);
             
             bt_store_16(response_buffer, offset, group_start_handle);
             offset += 2;
@@ -645,7 +646,7 @@
         prev_handle = it.handle;
         
         // does current attribute match
-        // printf("compare: %04x == %04x\n", *(uint16_t*) context->attribute_type, *(uint16_t*) uuid);
+        // log_debug("compare: %04x == %04x\n", *(uint16_t*) context->attribute_type, *(uint16_t*) uuid);
         if (it.handle && att_iterator_match_uuid(&it, attribute_type, attribute_type_len)) {
             
             // check if value has same len as last one
@@ -656,7 +657,7 @@
                 }
             }
             
-            // printf("Begin of group, handle 0x%04x\n", it.handle);
+            // log_debug("Begin of group, handle 0x%04x\n", it.handle);
             
             // first
             if (offset == 1) {
@@ -865,7 +866,7 @@
             handle_signed_write_command(request_buffer, request_len, response_buffer, response_buffer_size);
             break;
         default:
-            printf("Unhandled ATT Command: %02X, DATA: ", request_buffer[0]);
+            log_info("Unhandled ATT Command: %02X, DATA: ", request_buffer[0]);
             hexdump2(&request_buffer[9], request_len-9);
             break;
     }