High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Files at this revision

API Documentation at this revision

Comitter:
ktownsend
Date:
Wed Dec 18 06:22:35 2013 +0000
Parent:
12:2c6b1059ed36
Child:
14:6ea5d1012a64
Commit message:
Better debugging output

Changed in this revision

hw/nrf51822.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/hw/nrf51822.cpp	Wed Dec 18 04:55:56 2013 +0000
+++ b/hw/nrf51822.cpp	Wed Dec 18 06:22:35 2013 +0000
@@ -92,14 +92,15 @@
     uint8_t *buffer;
     
     #if NRF51822_DEBUG_MODE
-    printf("Configuring Advertising ... ");
+    printf("%-40s", "Configuring Advertising");
     #endif
     
     /* Make sure we support the advertising type */
     if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED)
     {
         #if NRF51822_DEBUG_MODE
-        printf("ADV_CONNECTABLE_DIRECTED not supported (BLE_ERROR = 0x%04X)\r\n", (uint16_t)BLE_ERROR_NOT_IMPLEMENTED);
+        printf("[BLE_ERROR = 0x%04X]\r\n", (uint16_t)BLE_ERROR_NOT_IMPLEMENTED);
+        printf("--> ADV_CONNECTABLE_DIRECTED not supported\r\n");
         #endif
         return BLE_ERROR_NOT_IMPLEMENTED;
     }
@@ -109,7 +110,8 @@
         (params.getInterval() > GAP_ADV_PARAMS_INTERVAL_MAX))
     {
         #if NRF51822_DEBUG_MODE
-        printf("Advertising interval out of range (BLE_ERROR = 0x%04X)\r\n", (uint16_t)BLE_ERROR_PARAM_OUT_OF_RANGE);
+        printf("[BLE_ERROR = 0x%04X]\r\n", (uint16_t)BLE_ERROR_PARAM_OUT_OF_RANGE);
+        printf("--> Advertising interval out of range\r\n");
         #endif
         return BLE_ERROR_PARAM_OUT_OF_RANGE;
     }
@@ -119,7 +121,8 @@
         (params.getTimeout() != 0))
     {
         #if NRF51822_DEBUG_MODE
-        printf("Timeout must be 0 with ADV_CONNECTABLE_DIRECTED (BLE_ERROR = 0x%04X)\r\n", (uint16_t)BLE_ERROR_PARAM_OUT_OF_RANGE);
+        printf("[BLE_ERROR = 0x%04X]\r\n", (uint16_t)BLE_ERROR_PARAM_OUT_OF_RANGE);
+        printf("--> Timeout must be 0 with ADV_CONNECTABLE_DIRECTED\r\n");
         #endif
         /* Timeout must be 0 with this type, although we'll never get here */
         /* since this isn't implemented yet anyway */
@@ -131,7 +134,8 @@
         (params.getTimeout() > GAP_ADV_PARAMS_TIMEOUT_MAX))
     {
         #if NRF51822_DEBUG_MODE
-        printf("Timeout out of range (BLE_ERROR = 0x%04X)\r\n", (uint16_t)BLE_ERROR_PARAM_OUT_OF_RANGE);
+        printf("[BLE_ERROR = 0x%04X]\r\n", (uint16_t)BLE_ERROR_PARAM_OUT_OF_RANGE);
+        printf("--> Timeout out of range\r\n");
         #endif
         return BLE_ERROR_PARAM_OUT_OF_RANGE;
     }
@@ -140,7 +144,8 @@
     if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD)
     {
         #if NRF51822_DEBUG_MODE
-        printf("Advertising payload > 31 bytes (BLE_ERROR = 0x%04X)\r\n", (uint16_t)BLE_ERROR_BUFFER_OVERFLOW);
+        printf("[BLE_ERROR = 0x%04X]\r\n", (uint16_t)BLE_ERROR_BUFFER_OVERFLOW);
+        printf("--> Advertising payload > 31 bytes\r\n");
         #endif
         return BLE_ERROR_BUFFER_OVERFLOW;
     }
@@ -151,7 +156,8 @@
         if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD)
         {
             #if NRF51822_DEBUG_MODE
-            printf("Scan response payload > 31 bytes (BLE_ERROR = 0x%04X)\r\n", (uint16_t)BLE_ERROR_BUFFER_OVERFLOW);
+            printf("[BLE_ERROR = 0x%04X]\r\n", (uint16_t)BLE_ERROR_BUFFER_OVERFLOW);
+            printf("--> Scan response payload > 31 bytes\r\n");
             #endif
             return BLE_ERROR_BUFFER_OVERFLOW;
         }
@@ -187,7 +193,7 @@
     for (uint16_t i = 0; i < len; i++)
     {
         uart.printf(" %02X", buffer[i]);
-    }    
+    }
     uart.printf("\r\n");
     
     /* ToDo: Check response */
@@ -210,7 +216,7 @@
     }
     
     #if NRF51822_DEBUG_MODE
-    printf("OK!\r\n");
+    printf("[OK]\r\n");
     #endif
     return BLE_ERROR_NONE;
 }
@@ -234,7 +240,7 @@
 ble_error_t nRF51822::addService(GattService & service)
 {
     #if NRF51822_DEBUG_MODE
-    printf("Adding a service ... ");
+    printf("%-40s", "Adding a service");
     #endif
     
     /* ToDo: Make sure we don't overflow the array, etc. */
@@ -296,7 +302,7 @@
     serviceCount++;
     
     #if NRF51822_DEBUG_MODE
-    printf("OK!\r\n");
+    printf("[OK]\r\n");
     #endif
     return BLE_ERROR_NONE;
 }
@@ -331,13 +337,13 @@
 ble_error_t nRF51822::readCharacteristic(GattService &service, GattCharacteristic &characteristic, uint8_t buffer[], uint16_t len)
 {
     #if NRF51822_DEBUG_MODE
-    printf("Reading characteristic (handle = %d) ... ", characteristic.handle);
+    printf("Reading characteristic (handle = %d)    ", characteristic.handle);
     #endif
 
     /* ToDo */
     
     #if NRF51822_DEBUG_MODE
-    printf("OK!\r\n");
+    printf("[OK]\r\n");
     #endif
     return BLE_ERROR_NONE;
 }
@@ -372,7 +378,7 @@
 ble_error_t nRF51822::writeCharacteristic(GattService &service, GattCharacteristic &characteristic, uint8_t buffer[], uint16_t len)
 {
     #if NRF51822_DEBUG_MODE
-    printf("Writing characteristic (handle = %d) ... ", characteristic.handle);
+    printf("Writing characteristic (handle = %d)    ", characteristic.handle);
     #endif
         
     /* Command ID = 0x0006, Payload = Service ID, Characteristic ID, Value */
@@ -387,7 +393,7 @@
     wait(0.1);
     
     #if NRF51822_DEBUG_MODE
-    printf("OK!\r\n");
+    printf("[OK]\r\n");
     #endif
     return BLE_ERROR_NONE;
 }
@@ -414,7 +420,7 @@
 ble_error_t nRF51822::start(void)
 {
     #if NRF51822_DEBUG_MODE
-    printf("Initialising the radio ... ");
+    printf("%-40s", "Starting the radio");
     #endif
     
     /* Command ID = 0x0003, No payload */
@@ -424,7 +430,7 @@
     wait(0.5);
 
     #if NRF51822_DEBUG_MODE
-    printf("OK!\r\n");
+    printf("[OK]\r\n");
     #endif
     return BLE_ERROR_NONE;
 }
@@ -448,7 +454,7 @@
 ble_error_t nRF51822::stop(void)
 {
     #if NRF51822_DEBUG_MODE
-    printf("Stopping the radio ... ");
+    printf("%-40s", "Stopping the radio");
     #endif
     
     /* Command ID = 0x0004, No payload */
@@ -458,7 +464,7 @@
     wait(0.1);
 
     #if NRF51822_DEBUG_MODE
-    printf("OK!\r\n");
+    printf("[OK]\r\n");
     #endif
     return BLE_ERROR_NONE;
 }
@@ -483,7 +489,7 @@
 ble_error_t nRF51822::reset(void)
 {
     #if NRF51822_DEBUG_MODE
-    printf("Resetting the radio ... ");
+    printf("%-40s", "Resetting the radio");
     #endif
     
     /* Command ID = 0x0005, No payload */
@@ -496,7 +502,7 @@
     wait(1);
     
     #if NRF51822_DEBUG_MODE
-    printf("OK!\r\n");
+    printf("[OK]\r\n");
     #endif
     return BLE_ERROR_NONE;
 }