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:
Thu Jan 09 11:03:10 2014 +0000
Parent:
26:755b897a47b1
Child:
28:f6022fb90701
Commit message:
Matching file names and apache headers

Changed in this revision

GapAdvertisingData.cpp Show annotated file Show diff for this revision Revisions of this file
GapAdvertisingData.h Show annotated file Show diff for this revision Revisions of this file
GapAdvertisingParams.cpp Show annotated file Show diff for this revision Revisions of this file
GapAdvertisingParams.h Show annotated file Show diff for this revision Revisions of this file
GattCharacteristic.cpp Show annotated file Show diff for this revision Revisions of this file
GattCharacteristic.h Show annotated file Show diff for this revision Revisions of this file
GattService.cpp Show annotated file Show diff for this revision Revisions of this file
GattService.h Show annotated file Show diff for this revision Revisions of this file
UUID.cpp Show annotated file Show diff for this revision Revisions of this file
UUID.h Show annotated file Show diff for this revision Revisions of this file
blecommon.h Show annotated file Show diff for this revision Revisions of this file
hw/BLERadio.h Show annotated file Show diff for this revision Revisions of this file
hw/bleradio.h Show diff for this revision Revisions of this file
hw/nRF51822.cpp Show annotated file Show diff for this revision Revisions of this file
hw/nRF51822.h Show annotated file Show diff for this revision Revisions of this file
hw/nrf51822.cpp Show diff for this revision Revisions of this file
hw/nrf51822.h Show diff for this revision Revisions of this file
uuid.cpp Show diff for this revision Revisions of this file
uuid.h Show diff for this revision Revisions of this file
--- a/GapAdvertisingData.cpp	Thu Jan 09 10:44:47 2014 +0000
+++ b/GapAdvertisingData.cpp	Thu Jan 09 11:03:10 2014 +0000
@@ -1,3 +1,19 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+  
 #include <stdio.h>
 #include <string.h>
 
--- a/GapAdvertisingData.h	Thu Jan 09 10:44:47 2014 +0000
+++ b/GapAdvertisingData.h	Thu Jan 09 11:03:10 2014 +0000
@@ -1,3 +1,19 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+  
 #ifndef __GAP_ADVERTISING_DATA_H__
 #define __GAP_ADVERTISING_DATA_H__
 
--- a/GapAdvertisingParams.cpp	Thu Jan 09 10:44:47 2014 +0000
+++ b/GapAdvertisingParams.cpp	Thu Jan 09 11:03:10 2014 +0000
@@ -1,3 +1,19 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+  
 #include <stdio.h>
 #include <string.h>
 
--- a/GapAdvertisingParams.h	Thu Jan 09 10:44:47 2014 +0000
+++ b/GapAdvertisingParams.h	Thu Jan 09 11:03:10 2014 +0000
@@ -1,3 +1,19 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+  
 #ifndef __GAP_ADVERTISING_PARAMS_H__
 #define __GAP_ADVERTISING_PARAMS_H__
 
--- a/GattCharacteristic.cpp	Thu Jan 09 10:44:47 2014 +0000
+++ b/GattCharacteristic.cpp	Thu Jan 09 11:03:10 2014 +0000
@@ -1,3 +1,19 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+  
 #include <stdio.h>
 #include <string.h>
 
--- a/GattCharacteristic.h	Thu Jan 09 10:44:47 2014 +0000
+++ b/GattCharacteristic.h	Thu Jan 09 11:03:10 2014 +0000
@@ -1,8 +1,25 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+  
+
 #ifndef __GATT_CHARACTERISTIC_H__
 #define __GATT_CHARACTERISTIC_H__
 
 #include "blecommon.h"
-#include "uuid.h"
+#include "UUID.h"
 
 class GattCharacteristic
 {
--- a/GattService.cpp	Thu Jan 09 10:44:47 2014 +0000
+++ b/GattService.cpp	Thu Jan 09 11:03:10 2014 +0000
@@ -1,3 +1,20 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+  
+
 #include <stdio.h>
 #include <string.h>
 
--- a/GattService.h	Thu Jan 09 10:44:47 2014 +0000
+++ b/GattService.h	Thu Jan 09 11:03:10 2014 +0000
@@ -1,8 +1,25 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+*/
+  
+
 #ifndef __GATT_SERVICE_H__
 #define __GATT_SERVICE_H__
 
 #include "blecommon.h"
-#include "uuid.h"
+#include "UUID.h"
 #include "GattCharacteristic.h"
 
 #define BLE_SERVICE_MAX_CHARACTERISTICS (5)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UUID.cpp	Thu Jan 09 11:03:10 2014 +0000
@@ -0,0 +1,194 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+  
+
+#include <stdio.h>
+#include <string.h>
+
+#include "UUID.h"
+
+/**************************************************************************/
+/*!
+    @brief  Creates an empty 128-bit UUID
+            
+    @note   This UUID must be assigned a valid value via the 'update'
+            function before it can be safely used!
+*/
+/**************************************************************************/
+UUID::UUID(void)
+{
+    memset(base, 0, 16);
+    value = 0;
+    type  = UUID_TYPE_SHORT;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Creates a new 128-bit UUID
+            
+    @note   The UUID is a unique 128-bit (16 byte) ID used to identify
+            different service or characteristics on the BLE device.
+            
+    @note   When creating a UUID, the constructor will check if all bytes
+            except bytes 2/3 are equal to 0.  If only bytes 2/3 have a
+            value, the UUID will be treated as a short/BLE UUID, and the
+            .type field will be set to UUID::UUID_TYPE_SHORT.  If any
+            of the bytes outside byte 2/3 have a non-zero value, the UUID
+            will be considered a 128-bit ID, and .type will be assigned 
+            as UUID::UUID_TYPE_LONG. 
+
+    @param[in]  uuid_base
+                The 128-bit (16-byte) UUID value.  For 128-bit values,
+                assign all 16 bytes.  For 16-bit values, assign the
+                16-bits to byte 2 and 3, and leave the rest of the bytes
+                as 0.
+
+    @section EXAMPLE
+
+    @code
+
+    // Create a short UUID (0x180F)
+    uint8_t shortID[16] = { 0, 0, 0x0F, 0x18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+    UUID ble_uuid = UUID(shortID);
+    // ble_uuid.type  = UUID_TYPE_SHORT
+    // ble_uuid.value = 0x180F
+    
+    // Creeate a long UUID
+    uint8_t longID[16] = { 0x00, 0x11, 0x22, 0x33,
+                           0x44, 0x55, 0x66, 0x77, 
+                           0x88, 0x99, 0xAA, 0xBB, 
+                           0xCC, 0xDD, 0xEE, 0xFF };
+    UUID custom_uuid = UUID(longID);
+    // custom_uuid.type  = UUID_TYPE_LONG
+    // custom_uuid.value = 0x3322
+    // custom_uuid.base  = 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF
+   
+    @endcode
+*/
+/**************************************************************************/
+UUID::UUID(uint8_t const uuid_base[16])
+{
+    memcpy(base, uuid_base, 16);
+    value = (uint16_t)((uuid_base[3] << 8) | (uuid_base[2]));
+
+    /* Check if this is a short of a long UUID */
+    if (uuid_base[0]  + uuid_base[1]  +
+        uuid_base[4]  + uuid_base[5]  + uuid_base[6]  + uuid_base[7] +
+        uuid_base[8]  + uuid_base[9]  + uuid_base[10] + uuid_base[11] +
+        uuid_base[12] + uuid_base[13] + uuid_base[14] + uuid_base[15] == 0)
+    {
+        type = UUID_TYPE_SHORT; 
+    }
+    else
+    {
+        type = UUID_TYPE_LONG;
+    }
+}
+
+/**************************************************************************/
+/*!
+    @brief  Creates a short (16-bit) UUID
+
+    @param[in]  ble_uuid
+                The 16-bit BLE UUID value.
+*/
+/**************************************************************************/
+UUID::UUID(uint16_t const ble_uuid)
+{
+    memset(base, 0, 16);
+    memcpy(base+2, (uint8_t *)&ble_uuid, 2);
+    value = ble_uuid;
+    type = UUID_TYPE_SHORT;
+}
+
+/**************************************************************************/
+/*!
+    @brief  UUID destructor
+*/
+/**************************************************************************/
+UUID::~UUID(void)
+{
+}
+
+/**************************************************************************/
+/*!
+    @brief  Updates the value of the UUID
+    
+    @args[in]   uuid_base
+                The 128-bit value to use when updating the UUID.  For
+                16-bit IDs, insert the ID in bytes 2/3 in LSB format.
+                
+    @returns    BLE_ERROR_NONE (0) if everything executed correctly, or an
+                error code if there was a problem
+    @retval     BLE_ERROR_NONE
+                Everything executed correctly
+
+    @section EXAMPLE
+
+    @code
+   
+    @endcode    
+*/
+/**************************************************************************/
+ble_error_t UUID::update(uint8_t const uuid_base[16])
+{
+    memcpy(base, uuid_base, 16);
+    value = (uint16_t)((uuid_base[3] << 8) | (uuid_base[2]));
+
+    /* Check if this is a short of a long UUID */
+    if (uuid_base[0]  + uuid_base[1]  +
+        uuid_base[4]  + uuid_base[5]  + uuid_base[6]  + uuid_base[7] +
+        uuid_base[8]  + uuid_base[9]  + uuid_base[10] + uuid_base[11] +
+        uuid_base[12] + uuid_base[13] + uuid_base[14] + uuid_base[15] == 0)
+    {
+        type = UUID_TYPE_SHORT; 
+    }
+    else
+    {
+        type = UUID_TYPE_LONG;
+    }
+    
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Updates the value of the UUID
+    
+    @args[in]   ble_uuid
+                The 16-bit value to use when updating the UUID.
+                
+    @returns    BLE_ERROR_NONE (0) if everything executed correctly, or an
+                error code if there was a problem
+    @retval     BLE_ERROR_NONE
+                Everything executed correctly
+
+    @section EXAMPLE
+
+    @code
+   
+    @endcode    
+*/
+/**************************************************************************/
+ble_error_t UUID::update(uint16_t const ble_uuid)
+{
+    memset(base, 0, 16);
+    memcpy(base+2, (uint8_t *)&ble_uuid, 2);
+    value = ble_uuid;
+    type = UUID_TYPE_SHORT;
+    
+    return BLE_ERROR_NONE;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/UUID.h	Thu Jan 09 11:03:10 2014 +0000
@@ -0,0 +1,47 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+  
+
+#ifndef __UUID_H__
+#define __UUID_H__
+
+#include "blecommon.h"
+
+class UUID
+{
+private:
+    
+public:
+    enum
+    {
+        UUID_TYPE_SHORT = 0,    // Short BLE UUID
+        UUID_TYPE_LONG  = 1     // Full 128-bit UUID
+    };
+    
+    UUID(void);
+    UUID(uint8_t const[16]);
+    UUID(uint16_t const);
+    virtual ~UUID(void);
+    
+    uint8_t   type;        // UUID_TYPE_SHORT or UUID_TYPE_LONG
+    uint8_t   base[16];    // in case of custom
+    uint16_t  value;       // 16 bit uuid (byte 2-3 using with base)
+    
+    ble_error_t update(uint8_t const[16]);
+    ble_error_t update(uint16_t const);
+};
+
+#endif
--- a/blecommon.h	Thu Jan 09 10:44:47 2014 +0000
+++ b/blecommon.h	Thu Jan 09 11:03:10 2014 +0000
@@ -1,3 +1,19 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+  
 #ifndef __BLE_COMMON_H__
 #define __BLE_COMMON_H__
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hw/BLERadio.h	Thu Jan 09 11:03:10 2014 +0000
@@ -0,0 +1,78 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+  
+#ifndef __BLE_RADIO_H__
+#define __BLE_RADIO_H__
+
+#include "blecommon.h"
+#include "GattService.h"
+#include "GapAdvertisingData.h"
+#include "GapAdvertisingParams.h"
+
+/**************************************************************************/
+/*!
+    \brief
+    The base class used to abstract away BLE capable radio transceivers
+    or SOCs, to enable this BLE API to work with any radio transparently.
+*/
+/**************************************************************************/
+class BLERadio
+{
+    protected:
+        FunctionPointer _callback_event;
+        
+    public:
+        /******************************************************************/
+        /*!
+            \brief
+            Identifies events generated by the radio HW when an event
+            callback occurs
+        */
+        /******************************************************************/
+        typedef enum radio_event_e
+        {
+            RADIO_EVENT_CONNECT     = 0x01, /**< A BLE connection was established by the radio */
+            RADIO_EVENT_DISCONNECT  = 0x02, /**< The BLE device was disconnected */
+            RADIO_EVENT_WRITE       = 0x03, /**< A BLE write request occured */
+            RADIO_EVENT_RADIOERROR  = 0x80  /**< A low level error occured on the radio */
+        } radioEvent_t;
+        
+        uint8_t serviceCount;
+        uint8_t characteristicCount;
+
+        /* ToDo: Force constructor with event handler callback */
+
+        /* These functions must be defined in the sub-class */
+        virtual ble_error_t setAdvertising(GapAdvertisingParams &, GapAdvertisingData &, GapAdvertisingData &) = 0;
+        virtual ble_error_t addService(GattService &) = 0;
+        virtual ble_error_t readCharacteristic(uint8_t, uint8_t[], uint16_t) = 0;
+        virtual ble_error_t writeCharacteristic(uint8_t, uint8_t[], uint16_t) = 0;
+        virtual ble_error_t start(void) = 0;
+        virtual ble_error_t stop(void) = 0;
+        virtual ble_error_t reset(void) = 0;
+
+        /* BLE event callback (connect, disconnect, etc.) */
+        void attach(void (*function)(void)) { 
+            _callback_event.attach( function ); 
+        }
+ 
+        template<typename T>
+        void attach(T *object, void (T::*member)(void)) { 
+            _callback_event.attach( object, member );
+        }
+};
+
+#endif
--- a/hw/bleradio.h	Thu Jan 09 10:44:47 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,62 +0,0 @@
-#ifndef __BLE_RADIO_H__
-#define __BLE_RADIO_H__
-
-#include "blecommon.h"
-#include "GattService.h"
-#include "GapAdvertisingData.h"
-#include "GapAdvertisingParams.h"
-
-/**************************************************************************/
-/*!
-    \brief
-    The base class used to abstract away BLE capable radio transceivers
-    or SOCs, to enable this BLE API to work with any radio transparently.
-*/
-/**************************************************************************/
-class BLERadio
-{
-    protected:
-        FunctionPointer _callback_event;
-        
-    public:
-        /******************************************************************/
-        /*!
-            \brief
-            Identifies events generated by the radio HW when an event
-            callback occurs
-        */
-        /******************************************************************/
-        typedef enum radio_event_e
-        {
-            RADIO_EVENT_CONNECT     = 0x01, /**< A BLE connection was established by the radio */
-            RADIO_EVENT_DISCONNECT  = 0x02, /**< The BLE device was disconnected */
-            RADIO_EVENT_WRITE       = 0x03, /**< A BLE write request occured */
-            RADIO_EVENT_RADIOERROR  = 0x80  /**< A low level error occured on the radio */
-        } radioEvent_t;
-        
-        uint8_t serviceCount;
-        uint8_t characteristicCount;
-
-        /* ToDo: Force constructor with event handler callback */
-
-        /* These functions must be defined in the sub-class */
-        virtual ble_error_t setAdvertising(GapAdvertisingParams &, GapAdvertisingData &, GapAdvertisingData &) = 0;
-        virtual ble_error_t addService(GattService &) = 0;
-        virtual ble_error_t readCharacteristic(uint8_t, uint8_t[], uint16_t) = 0;
-        virtual ble_error_t writeCharacteristic(uint8_t, uint8_t[], uint16_t) = 0;
-        virtual ble_error_t start(void) = 0;
-        virtual ble_error_t stop(void) = 0;
-        virtual ble_error_t reset(void) = 0;
-
-        /* BLE event callback (connect, disconnect, etc.) */
-        void attach(void (*function)(void)) { 
-            _callback_event.attach( function ); 
-        }
- 
-        template<typename T>
-        void attach(T *object, void (T::*member)(void)) { 
-            _callback_event.attach( object, member );
-        }
-};
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hw/nRF51822.cpp	Thu Jan 09 11:03:10 2014 +0000
@@ -0,0 +1,466 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+  
+#include "nRF51822.h"
+#include "mbed.h"
+
+/**************************************************************************/
+/*!
+    @brief  UART callback function
+*/
+/**************************************************************************/
+void nRF51822::uartCallback(void)
+{
+    /* ToDo: Check responses and set a flag for success/error/etc. */
+    
+    /* Read serial to clear the RX interrupt */
+    uart.getc();
+}
+
+/**************************************************************************/
+/*!
+    @brief  Constructor
+*/
+/**************************************************************************/
+nRF51822::nRF51822() : uart(p9, p10)
+{
+    /* Setup the nRF UART interface */
+    uart.baud(9600);
+
+    /* Echo data on the debug CDC port */
+    uart.attach(this, &nRF51822::uartCallback);
+    
+    /* Add flow control for UART (required by the nRF51822) */
+    uart.set_flow_control(RawSerial::RTSCTS, p30, p29);
+
+    /* Reset the service and characteristic counters */
+    serviceCount = 0;
+    characteristicCount = 0;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Destructor
+*/
+/**************************************************************************/
+nRF51822::~nRF51822(void)
+{
+}
+
+/**************************************************************************/
+/*!
+    @brief  Sets the advertising parameters and payload for the device
+
+    @param[in]  params
+                Basic advertising details, including the advertising
+                delay, timeout and how the device should be advertised
+    @params[in] advData
+                The primary advertising data payload
+    @params[in] scanResponse
+                The optional Scan Response payload if the advertising
+                type is set to \ref GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED
+                in \ref GapAdveritinngParams
+            
+    @returns    \ref ble_error_t
+    
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+
+    @retval     BLE_ERROR_BUFFER_OVERFLOW
+                The proposed action would cause a buffer overflow.  All
+                advertising payloads must be <= 31 bytes, for example.
+                
+    @retval     BLE_ERROR_NOT_IMPLEMENTED
+                A feature was requested that is not yet supported in the
+                nRF51 firmware or hardware.
+
+    @retval     BLE_ERROR_PARAM_OUT_OF_RANGE
+                One of the proposed values is outside the valid range.
+
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisingData & advData, GapAdvertisingData & scanResponse)
+{
+    uint8_t len = 0;
+    uint8_t *buffer;
+    
+    /* Make sure we support the advertising type */
+    if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED)
+    {
+        /* ToDo: This requires a propery security implementation, etc. */
+        return BLE_ERROR_NOT_IMPLEMENTED;
+    }
+    
+    /* Check interval range */
+    if (params.getAdvertisingType() == GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED)
+    {
+        /* Min delay is slightly longer for unconnectable devices */
+        if ((params.getInterval() < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) ||
+            (params.getInterval() > GAP_ADV_PARAMS_INTERVAL_MAX))
+        {
+            return BLE_ERROR_PARAM_OUT_OF_RANGE;
+        }
+    }
+    else
+    {
+        if ((params.getInterval() < GAP_ADV_PARAMS_INTERVAL_MIN) ||
+            (params.getInterval() > GAP_ADV_PARAMS_INTERVAL_MAX))
+        {
+            return BLE_ERROR_PARAM_OUT_OF_RANGE;
+        }
+    }
+    
+    /* Check timeout is zero for Connectable Directed */
+    if ((params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) &&
+        (params.getTimeout() != 0))
+    {
+        /* Timeout must be 0 with this type, although we'll never get here */
+        /* since this isn't implemented yet anyway */
+        return BLE_ERROR_PARAM_OUT_OF_RANGE;
+    }
+    
+    /* Check timeout for other advertising types */
+    if ((params.getAdvertisingType() != GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) &&
+        (params.getTimeout() > GAP_ADV_PARAMS_TIMEOUT_MAX))
+    {
+        return BLE_ERROR_PARAM_OUT_OF_RANGE;
+    }
+
+    /* Make sure we don't exceed the advertising payload length */
+    if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD)
+    {
+        return BLE_ERROR_BUFFER_OVERFLOW;
+    }
+    
+    /* Check the scan response payload limits */
+    if ((params.getAdvertisingType() == GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED))
+    {
+        /* Check if we're within the upper limit */
+        if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD)
+        {
+            return BLE_ERROR_BUFFER_OVERFLOW;
+        }
+        /* Make sure we have a payload! */
+        if (advData.getPayloadLen() == 0)
+        {
+            return BLE_ERROR_PARAM_OUT_OF_RANGE;
+        }
+    }
+    
+    /* ToDo: Perform some checks on the payload, for example the Scan Response can't */
+    /* contains a flags AD type, etc. */
+
+    /* ToDo: Refactor these actions into separate private functions */
+
+    /* 1.) Send advertising params, Command IDs = 0x000C, 0x000D, 0x000E */
+    /* A.) Command ID = 0x000C, Advertising Interval, uint16_t */
+    uart.printf("10 0C 00 02 %02X %02X\r\n", (uint8_t)(params.getInterval() & 0xFF),
+                                             (uint8_t)(params.getInterval() >> 8));
+    /* ToDo: Check response */
+    wait(0.5);
+    
+    /* B.) Command ID = 0x000D, Advertising Timeout, uint16_t */
+    uart.printf("10 0D 00 02 %02X %02X\r\n", (uint8_t)(params.getTimeout() & 0xFF),
+                                             (uint8_t)(params.getTimeout() >> 8));
+    /* ToDo: Check response */
+    wait(0.5);
+    
+    /* C.) Command ID = 0x000E, Advertising Type, uint8_t */
+    uart.printf("10 0E 00 01 %02X\r\n", (uint8_t)(params.getAdvertisingType()));
+    /* ToDo: Check response */
+    wait(0.5);    
+
+    /* 2.) Send advertising data, Command ID = 0x000A */
+    len = advData.getPayloadLen();
+    buffer = advData.getPayload();
+    uart.printf("10 0A 00 %02X", len);
+    for (uint16_t i = 0; i < len; i++)
+    {
+        uart.printf(" %02X", buffer[i]);
+    }
+    uart.printf("\r\n");
+    
+    /* ToDo: Check response */
+    wait(0.1);
+
+    /* 3.) Send scan response data, Command ID = 0x000B */
+    if ((params.getAdvertisingType() == GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED))
+    {
+        len = scanResponse.getPayloadLen();
+        buffer = scanResponse.getPayload();
+        uart.printf("10 0B 00 %02X", len);
+        for (uint16_t i = 0; i < len; i++)
+        {
+            uart.printf(" %02X", buffer[i]);
+        }
+        uart.printf("\r\n");
+
+        /* ToDo: Check response */
+        wait(0.1);
+    }
+    
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Adds a new service to the GATT table on the peripheral
+            
+    @returns    ble_error_t
+    
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+                
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF51822::addService(GattService & service)
+{
+    /* ToDo: Make sure we don't overflow the array, etc. */
+    /* ToDo: Make sure this service UUID doesn't already exist (?) */
+    /* ToDo: Basic validation */
+    
+    /* Add the service to the nRF51 */
+    if (service.primaryServiceID.type == UUID::UUID_TYPE_SHORT)
+    {
+        /* 16-bit BLE UUID */
+        uart.printf("10 01 00 04 01 02 %02X %02X\r\n",
+                    service.primaryServiceID.value & 0xFF,
+                    service.primaryServiceID.value >> 8);
+    }
+    else
+    {
+        /* 128-bit Custom UUID */
+        uart.printf("10 01 00 12 01 10 %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\r\n",
+            service.primaryServiceID.base[0], 
+            service.primaryServiceID.base[1], 
+            service.primaryServiceID.base[2], 
+            service.primaryServiceID.base[3], 
+            service.primaryServiceID.base[4], 
+            service.primaryServiceID.base[5], 
+            service.primaryServiceID.base[6], 
+            service.primaryServiceID.base[7], 
+            service.primaryServiceID.base[8], 
+            service.primaryServiceID.base[9], 
+            service.primaryServiceID.base[10], 
+            service.primaryServiceID.base[11], 
+            service.primaryServiceID.base[12], 
+            service.primaryServiceID.base[13], 
+            service.primaryServiceID.base[14], 
+            service.primaryServiceID.base[15]);
+    }
+    
+    /* ToDo: Check response */
+    wait(0.1);
+    
+    /* Add characteristics to the service */
+    for (uint8_t i = 0; i < service.characteristicCount; i++)
+    {
+        /* Command ID = 0x0002 */
+        uart.printf("10 02 00 0F 01 02 %02X %02X 04 02 %02X %02X 05 02 %02X %02X 03 01 %02X\r\n",
+                    service.characteristics[i].uuid & 0xFF, 
+                    service.characteristics[i].uuid >> 8,
+                    service.characteristics[i].lenMin & 0xFF,
+                    service.characteristics[i].lenMin >> 8,
+                    service.characteristics[i].lenMax & 0xFF,
+                    service.characteristics[i].lenMax >> 8,
+                    service.characteristics[i].properties);
+                    
+        /* ToDo: Check response */
+        wait(0.1);
+        
+        /* Update the characteristic handle */
+        service.characteristics[i].handle = characteristicCount;
+        characteristicCount++;
+    }
+
+    /* Update the service handle */
+    service.handle = serviceCount;
+    serviceCount++;
+    
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Reads the value of a characteristic, based on the service
+            and characteristic index fields
+
+    @param[in]  charHandle
+                The handle of the GattCharacteristic to read from
+    @param[in]  buffer
+                Buffer to hold the the characteristic's value
+                (raw byte array in LSB format)
+    @param[in]  len
+                The number of bytes read into the buffer
+            
+    @returns    ble_error_t
+    
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+                
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF51822::readCharacteristic(uint8_t charHandle, uint8_t buffer[], uint16_t len)
+{
+    /* ToDo */
+    
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Updates the value of a characteristic, based on the service
+            and characteristic index fields
+
+    @param[in]  charHandle
+                The handle of the GattCharacteristic to write to
+    @param[in]  buffer
+                Data to use when updating the characteristic's value
+                (raw byte array in LSB format)
+    @param[in]  len
+                The number of bytes in buffer
+            
+    @returns    ble_error_t
+    
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+                
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF51822::writeCharacteristic(uint8_t charHandle, uint8_t buffer[], uint16_t len)
+{
+    /* Command ID = 0x0006, Payload = Characteristic ID, Value */
+    uart.printf("10 06 00 %02X %02X", len + 1, charHandle);
+    for (uint16_t i = 0; i<len; i++)
+    {
+        uart.printf(" %02X", buffer[i]);
+    }
+    uart.printf("\r\n");
+
+    /* ToDo: Check response */
+    wait(0.1);
+    
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Starts the BLE HW, initialising any services that were
+            added before this function was called.
+            
+    @note   All services must be added before calling this function!
+            
+    @returns    ble_error_t
+    
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+                
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF51822::start(void)
+{
+    /* Command ID = 0x0003, No payload */
+    uart.printf("10 03 00 00\r\n");
+
+    /* ToDo: Check response */
+    wait(0.5);
+
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Stops the BLE HW and disconnects from any devices
+            
+    @returns    ble_error_t
+    
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+                
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF51822::stop(void)
+{
+    /* Command ID = 0x0004, No payload */
+    uart.printf("10 04 00 00\r\n");
+
+    /* ToDo: Check response */
+    wait(0.1);
+
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
+    @brief  Resets the BLE HW, removing any existing services and
+            characteristics
+            
+    @returns    ble_error_t
+    
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+                
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+ble_error_t nRF51822::reset(void)
+{
+    /* Command ID = 0x0005, No payload */
+    uart.printf("10 05 00 00\r\n");
+
+    /* Reset the service and characteristic counters */
+    serviceCount = 0;
+    characteristicCount = 0;
+
+    /* Wait for the radio to come back up */    
+    wait(1);
+    
+    return BLE_ERROR_NONE;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hw/nRF51822.h	Thu Jan 09 11:03:10 2014 +0000
@@ -0,0 +1,54 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+  
+#ifndef __NRF51822_H__
+#define __NRF51822_H__
+
+#include "mbed.h"
+#include "blecommon.h"
+#include "BLERadio.h"
+#include "GattService.h"
+
+/**************************************************************************/
+/*!
+    \brief
+    Driver for the nRF51822 in connectivity mode using custom serialization
+    firmware.
+*/
+/**************************************************************************/
+class nRF51822 : public BLERadio
+{
+    public:
+        nRF51822();
+        virtual ~nRF51822(void);
+
+        /* Functions that mus be implemented from BLERadio */
+        virtual ble_error_t setAdvertising(GapAdvertisingParams &, GapAdvertisingData &, GapAdvertisingData &);
+        virtual ble_error_t addService(GattService &);
+        virtual ble_error_t readCharacteristic(uint8_t, uint8_t[], uint16_t);
+        virtual ble_error_t writeCharacteristic(uint8_t, uint8_t[], uint16_t);
+        virtual ble_error_t start(void);
+        virtual ble_error_t stop(void);
+        virtual ble_error_t reset(void);
+        
+    private:
+        RawSerial uart;
+
+        /* nRF51 Functions */
+        void uartCallback(void);
+};
+
+#endif
--- a/hw/nrf51822.cpp	Thu Jan 09 10:44:47 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,450 +0,0 @@
-#include "nrf51822.h"
-#include "mbed.h"
-
-/**************************************************************************/
-/*!
-    @brief  UART callback function
-*/
-/**************************************************************************/
-void nRF51822::uartCallback(void)
-{
-    /* ToDo: Check responses and set a flag for success/error/etc. */
-    
-    /* Read serial to clear the RX interrupt */
-    uart.getc();
-}
-
-/**************************************************************************/
-/*!
-    @brief  Constructor
-*/
-/**************************************************************************/
-nRF51822::nRF51822() : uart(p9, p10)
-{
-    /* Setup the nRF UART interface */
-    uart.baud(9600);
-
-    /* Echo data on the debug CDC port */
-    uart.attach(this, &nRF51822::uartCallback);
-    
-    /* Add flow control for UART (required by the nRF51822) */
-    uart.set_flow_control(RawSerial::RTSCTS, p30, p29);
-
-    /* Reset the service and characteristic counters */
-    serviceCount = 0;
-    characteristicCount = 0;
-}
-
-/**************************************************************************/
-/*!
-    @brief  Destructor
-*/
-/**************************************************************************/
-nRF51822::~nRF51822(void)
-{
-}
-
-/**************************************************************************/
-/*!
-    @brief  Sets the advertising parameters and payload for the device
-
-    @param[in]  params
-                Basic advertising details, including the advertising
-                delay, timeout and how the device should be advertised
-    @params[in] advData
-                The primary advertising data payload
-    @params[in] scanResponse
-                The optional Scan Response payload if the advertising
-                type is set to \ref GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED
-                in \ref GapAdveritinngParams
-            
-    @returns    \ref ble_error_t
-    
-    @retval     BLE_ERROR_NONE
-                Everything executed properly
-
-    @retval     BLE_ERROR_BUFFER_OVERFLOW
-                The proposed action would cause a buffer overflow.  All
-                advertising payloads must be <= 31 bytes, for example.
-                
-    @retval     BLE_ERROR_NOT_IMPLEMENTED
-                A feature was requested that is not yet supported in the
-                nRF51 firmware or hardware.
-
-    @retval     BLE_ERROR_PARAM_OUT_OF_RANGE
-                One of the proposed values is outside the valid range.
-
-    @section EXAMPLE
-
-    @code
-
-    @endcode
-*/
-/**************************************************************************/
-ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisingData & advData, GapAdvertisingData & scanResponse)
-{
-    uint8_t len = 0;
-    uint8_t *buffer;
-    
-    /* Make sure we support the advertising type */
-    if (params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED)
-    {
-        /* ToDo: This requires a propery security implementation, etc. */
-        return BLE_ERROR_NOT_IMPLEMENTED;
-    }
-    
-    /* Check interval range */
-    if (params.getAdvertisingType() == GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED)
-    {
-        /* Min delay is slightly longer for unconnectable devices */
-        if ((params.getInterval() < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) ||
-            (params.getInterval() > GAP_ADV_PARAMS_INTERVAL_MAX))
-        {
-            return BLE_ERROR_PARAM_OUT_OF_RANGE;
-        }
-    }
-    else
-    {
-        if ((params.getInterval() < GAP_ADV_PARAMS_INTERVAL_MIN) ||
-            (params.getInterval() > GAP_ADV_PARAMS_INTERVAL_MAX))
-        {
-            return BLE_ERROR_PARAM_OUT_OF_RANGE;
-        }
-    }
-    
-    /* Check timeout is zero for Connectable Directed */
-    if ((params.getAdvertisingType() == GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) &&
-        (params.getTimeout() != 0))
-    {
-        /* Timeout must be 0 with this type, although we'll never get here */
-        /* since this isn't implemented yet anyway */
-        return BLE_ERROR_PARAM_OUT_OF_RANGE;
-    }
-    
-    /* Check timeout for other advertising types */
-    if ((params.getAdvertisingType() != GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED) &&
-        (params.getTimeout() > GAP_ADV_PARAMS_TIMEOUT_MAX))
-    {
-        return BLE_ERROR_PARAM_OUT_OF_RANGE;
-    }
-
-    /* Make sure we don't exceed the advertising payload length */
-    if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD)
-    {
-        return BLE_ERROR_BUFFER_OVERFLOW;
-    }
-    
-    /* Check the scan response payload limits */
-    if ((params.getAdvertisingType() == GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED))
-    {
-        /* Check if we're within the upper limit */
-        if (advData.getPayloadLen() > GAP_ADVERTISING_DATA_MAX_PAYLOAD)
-        {
-            return BLE_ERROR_BUFFER_OVERFLOW;
-        }
-        /* Make sure we have a payload! */
-        if (advData.getPayloadLen() == 0)
-        {
-            return BLE_ERROR_PARAM_OUT_OF_RANGE;
-        }
-    }
-    
-    /* ToDo: Perform some checks on the payload, for example the Scan Response can't */
-    /* contains a flags AD type, etc. */
-
-    /* ToDo: Refactor these actions into separate private functions */
-
-    /* 1.) Send advertising params, Command IDs = 0x000C, 0x000D, 0x000E */
-    /* A.) Command ID = 0x000C, Advertising Interval, uint16_t */
-    uart.printf("10 0C 00 02 %02X %02X\r\n", (uint8_t)(params.getInterval() & 0xFF),
-                                             (uint8_t)(params.getInterval() >> 8));
-    /* ToDo: Check response */
-    wait(0.5);
-    
-    /* B.) Command ID = 0x000D, Advertising Timeout, uint16_t */
-    uart.printf("10 0D 00 02 %02X %02X\r\n", (uint8_t)(params.getTimeout() & 0xFF),
-                                             (uint8_t)(params.getTimeout() >> 8));
-    /* ToDo: Check response */
-    wait(0.5);
-    
-    /* C.) Command ID = 0x000E, Advertising Type, uint8_t */
-    uart.printf("10 0E 00 01 %02X\r\n", (uint8_t)(params.getAdvertisingType()));
-    /* ToDo: Check response */
-    wait(0.5);    
-
-    /* 2.) Send advertising data, Command ID = 0x000A */
-    len = advData.getPayloadLen();
-    buffer = advData.getPayload();
-    uart.printf("10 0A 00 %02X", len);
-    for (uint16_t i = 0; i < len; i++)
-    {
-        uart.printf(" %02X", buffer[i]);
-    }
-    uart.printf("\r\n");
-    
-    /* ToDo: Check response */
-    wait(0.1);
-
-    /* 3.) Send scan response data, Command ID = 0x000B */
-    if ((params.getAdvertisingType() == GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED))
-    {
-        len = scanResponse.getPayloadLen();
-        buffer = scanResponse.getPayload();
-        uart.printf("10 0B 00 %02X", len);
-        for (uint16_t i = 0; i < len; i++)
-        {
-            uart.printf(" %02X", buffer[i]);
-        }
-        uart.printf("\r\n");
-
-        /* ToDo: Check response */
-        wait(0.1);
-    }
-    
-    return BLE_ERROR_NONE;
-}
-
-/**************************************************************************/
-/*!
-    @brief  Adds a new service to the GATT table on the peripheral
-            
-    @returns    ble_error_t
-    
-    @retval     BLE_ERROR_NONE
-                Everything executed properly
-                
-    @section EXAMPLE
-
-    @code
-
-    @endcode
-*/
-/**************************************************************************/
-ble_error_t nRF51822::addService(GattService & service)
-{
-    /* ToDo: Make sure we don't overflow the array, etc. */
-    /* ToDo: Make sure this service UUID doesn't already exist (?) */
-    /* ToDo: Basic validation */
-    
-    /* Add the service to the nRF51 */
-    if (service.primaryServiceID.type == UUID::UUID_TYPE_SHORT)
-    {
-        /* 16-bit BLE UUID */
-        uart.printf("10 01 00 04 01 02 %02X %02X\r\n",
-                    service.primaryServiceID.value & 0xFF,
-                    service.primaryServiceID.value >> 8);
-    }
-    else
-    {
-        /* 128-bit Custom UUID */
-        uart.printf("10 01 00 12 01 10 %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\r\n",
-            service.primaryServiceID.base[0], 
-            service.primaryServiceID.base[1], 
-            service.primaryServiceID.base[2], 
-            service.primaryServiceID.base[3], 
-            service.primaryServiceID.base[4], 
-            service.primaryServiceID.base[5], 
-            service.primaryServiceID.base[6], 
-            service.primaryServiceID.base[7], 
-            service.primaryServiceID.base[8], 
-            service.primaryServiceID.base[9], 
-            service.primaryServiceID.base[10], 
-            service.primaryServiceID.base[11], 
-            service.primaryServiceID.base[12], 
-            service.primaryServiceID.base[13], 
-            service.primaryServiceID.base[14], 
-            service.primaryServiceID.base[15]);
-    }
-    
-    /* ToDo: Check response */
-    wait(0.1);
-    
-    /* Add characteristics to the service */
-    for (uint8_t i = 0; i < service.characteristicCount; i++)
-    {
-        /* Command ID = 0x0002 */
-        uart.printf("10 02 00 0F 01 02 %02X %02X 04 02 %02X %02X 05 02 %02X %02X 03 01 %02X\r\n",
-                    service.characteristics[i].uuid & 0xFF, 
-                    service.characteristics[i].uuid >> 8,
-                    service.characteristics[i].lenMin & 0xFF,
-                    service.characteristics[i].lenMin >> 8,
-                    service.characteristics[i].lenMax & 0xFF,
-                    service.characteristics[i].lenMax >> 8,
-                    service.characteristics[i].properties);
-                    
-        /* ToDo: Check response */
-        wait(0.1);
-        
-        /* Update the characteristic handle */
-        service.characteristics[i].handle = characteristicCount;
-        characteristicCount++;
-    }
-
-    /* Update the service handle */
-    service.handle = serviceCount;
-    serviceCount++;
-    
-    return BLE_ERROR_NONE;
-}
-
-/**************************************************************************/
-/*!
-    @brief  Reads the value of a characteristic, based on the service
-            and characteristic index fields
-
-    @param[in]  charHandle
-                The handle of the GattCharacteristic to read from
-    @param[in]  buffer
-                Buffer to hold the the characteristic's value
-                (raw byte array in LSB format)
-    @param[in]  len
-                The number of bytes read into the buffer
-            
-    @returns    ble_error_t
-    
-    @retval     BLE_ERROR_NONE
-                Everything executed properly
-                
-    @section EXAMPLE
-
-    @code
-
-    @endcode
-*/
-/**************************************************************************/
-ble_error_t nRF51822::readCharacteristic(uint8_t charHandle, uint8_t buffer[], uint16_t len)
-{
-    /* ToDo */
-    
-    return BLE_ERROR_NONE;
-}
-
-/**************************************************************************/
-/*!
-    @brief  Updates the value of a characteristic, based on the service
-            and characteristic index fields
-
-    @param[in]  charHandle
-                The handle of the GattCharacteristic to write to
-    @param[in]  buffer
-                Data to use when updating the characteristic's value
-                (raw byte array in LSB format)
-    @param[in]  len
-                The number of bytes in buffer
-            
-    @returns    ble_error_t
-    
-    @retval     BLE_ERROR_NONE
-                Everything executed properly
-                
-    @section EXAMPLE
-
-    @code
-
-    @endcode
-*/
-/**************************************************************************/
-ble_error_t nRF51822::writeCharacteristic(uint8_t charHandle, uint8_t buffer[], uint16_t len)
-{
-    /* Command ID = 0x0006, Payload = Characteristic ID, Value */
-    uart.printf("10 06 00 %02X %02X", len + 1, charHandle);
-    for (uint16_t i = 0; i<len; i++)
-    {
-        uart.printf(" %02X", buffer[i]);
-    }
-    uart.printf("\r\n");
-
-    /* ToDo: Check response */
-    wait(0.1);
-    
-    return BLE_ERROR_NONE;
-}
-
-/**************************************************************************/
-/*!
-    @brief  Starts the BLE HW, initialising any services that were
-            added before this function was called.
-            
-    @note   All services must be added before calling this function!
-            
-    @returns    ble_error_t
-    
-    @retval     BLE_ERROR_NONE
-                Everything executed properly
-                
-    @section EXAMPLE
-
-    @code
-
-    @endcode
-*/
-/**************************************************************************/
-ble_error_t nRF51822::start(void)
-{
-    /* Command ID = 0x0003, No payload */
-    uart.printf("10 03 00 00\r\n");
-
-    /* ToDo: Check response */
-    wait(0.5);
-
-    return BLE_ERROR_NONE;
-}
-
-/**************************************************************************/
-/*!
-    @brief  Stops the BLE HW and disconnects from any devices
-            
-    @returns    ble_error_t
-    
-    @retval     BLE_ERROR_NONE
-                Everything executed properly
-                
-    @section EXAMPLE
-
-    @code
-
-    @endcode
-*/
-/**************************************************************************/
-ble_error_t nRF51822::stop(void)
-{
-    /* Command ID = 0x0004, No payload */
-    uart.printf("10 04 00 00\r\n");
-
-    /* ToDo: Check response */
-    wait(0.1);
-
-    return BLE_ERROR_NONE;
-}
-
-/**************************************************************************/
-/*!
-    @brief  Resets the BLE HW, removing any existing services and
-            characteristics
-            
-    @returns    ble_error_t
-    
-    @retval     BLE_ERROR_NONE
-                Everything executed properly
-                
-    @section EXAMPLE
-
-    @code
-
-    @endcode
-*/
-/**************************************************************************/
-ble_error_t nRF51822::reset(void)
-{
-    /* Command ID = 0x0005, No payload */
-    uart.printf("10 05 00 00\r\n");
-
-    /* Reset the service and characteristic counters */
-    serviceCount = 0;
-    characteristicCount = 0;
-
-    /* Wait for the radio to come back up */    
-    wait(1);
-    
-    return BLE_ERROR_NONE;
-}
--- a/hw/nrf51822.h	Thu Jan 09 10:44:47 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-#ifndef __NRF51822_H__
-#define __NRF51822_H__
-
-#include "mbed.h"
-#include "blecommon.h"
-#include "bleradio.h"
-#include "GattService.h"
-
-/**************************************************************************/
-/*!
-    \brief
-    Driver for the nRF51822 in connectivity mode using custom serialization
-    firmware.
-*/
-/**************************************************************************/
-class nRF51822 : public BLERadio
-{
-    public:
-        nRF51822();
-        virtual ~nRF51822(void);
-
-        /* Functions that mus be implemented from BLERadio */
-        virtual ble_error_t setAdvertising(GapAdvertisingParams &, GapAdvertisingData &, GapAdvertisingData &);
-        virtual ble_error_t addService(GattService &);
-        virtual ble_error_t readCharacteristic(uint8_t, uint8_t[], uint16_t);
-        virtual ble_error_t writeCharacteristic(uint8_t, uint8_t[], uint16_t);
-        virtual ble_error_t start(void);
-        virtual ble_error_t stop(void);
-        virtual ble_error_t reset(void);
-        
-    private:
-        RawSerial uart;
-
-        /* nRF51 Functions */
-        void uartCallback(void);
-};
-
-#endif
--- a/uuid.cpp	Thu Jan 09 10:44:47 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,177 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-
-#include "uuid.h"
-
-/**************************************************************************/
-/*!
-    @brief  Creates an empty 128-bit UUID
-            
-    @note   This UUID must be assigned a valid value via the 'update'
-            function before it can be safely used!
-*/
-/**************************************************************************/
-UUID::UUID(void)
-{
-    memset(base, 0, 16);
-    value = 0;
-    type  = UUID_TYPE_SHORT;
-}
-
-/**************************************************************************/
-/*!
-    @brief  Creates a new 128-bit UUID
-            
-    @note   The UUID is a unique 128-bit (16 byte) ID used to identify
-            different service or characteristics on the BLE device.
-            
-    @note   When creating a UUID, the constructor will check if all bytes
-            except bytes 2/3 are equal to 0.  If only bytes 2/3 have a
-            value, the UUID will be treated as a short/BLE UUID, and the
-            .type field will be set to UUID::UUID_TYPE_SHORT.  If any
-            of the bytes outside byte 2/3 have a non-zero value, the UUID
-            will be considered a 128-bit ID, and .type will be assigned 
-            as UUID::UUID_TYPE_LONG. 
-
-    @param[in]  uuid_base
-                The 128-bit (16-byte) UUID value.  For 128-bit values,
-                assign all 16 bytes.  For 16-bit values, assign the
-                16-bits to byte 2 and 3, and leave the rest of the bytes
-                as 0.
-
-    @section EXAMPLE
-
-    @code
-
-    // Create a short UUID (0x180F)
-    uint8_t shortID[16] = { 0, 0, 0x0F, 0x18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
-    UUID ble_uuid = UUID(shortID);
-    // ble_uuid.type  = UUID_TYPE_SHORT
-    // ble_uuid.value = 0x180F
-    
-    // Creeate a long UUID
-    uint8_t longID[16] = { 0x00, 0x11, 0x22, 0x33,
-                           0x44, 0x55, 0x66, 0x77, 
-                           0x88, 0x99, 0xAA, 0xBB, 
-                           0xCC, 0xDD, 0xEE, 0xFF };
-    UUID custom_uuid = UUID(longID);
-    // custom_uuid.type  = UUID_TYPE_LONG
-    // custom_uuid.value = 0x3322
-    // custom_uuid.base  = 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF
-   
-    @endcode
-*/
-/**************************************************************************/
-UUID::UUID(uint8_t const uuid_base[16])
-{
-    memcpy(base, uuid_base, 16);
-    value = (uint16_t)((uuid_base[3] << 8) | (uuid_base[2]));
-
-    /* Check if this is a short of a long UUID */
-    if (uuid_base[0]  + uuid_base[1]  +
-        uuid_base[4]  + uuid_base[5]  + uuid_base[6]  + uuid_base[7] +
-        uuid_base[8]  + uuid_base[9]  + uuid_base[10] + uuid_base[11] +
-        uuid_base[12] + uuid_base[13] + uuid_base[14] + uuid_base[15] == 0)
-    {
-        type = UUID_TYPE_SHORT; 
-    }
-    else
-    {
-        type = UUID_TYPE_LONG;
-    }
-}
-
-/**************************************************************************/
-/*!
-    @brief  Creates a short (16-bit) UUID
-
-    @param[in]  ble_uuid
-                The 16-bit BLE UUID value.
-*/
-/**************************************************************************/
-UUID::UUID(uint16_t const ble_uuid)
-{
-    memset(base, 0, 16);
-    memcpy(base+2, (uint8_t *)&ble_uuid, 2);
-    value = ble_uuid;
-    type = UUID_TYPE_SHORT;
-}
-
-/**************************************************************************/
-/*!
-    @brief  UUID destructor
-*/
-/**************************************************************************/
-UUID::~UUID(void)
-{
-}
-
-/**************************************************************************/
-/*!
-    @brief  Updates the value of the UUID
-    
-    @args[in]   uuid_base
-                The 128-bit value to use when updating the UUID.  For
-                16-bit IDs, insert the ID in bytes 2/3 in LSB format.
-                
-    @returns    BLE_ERROR_NONE (0) if everything executed correctly, or an
-                error code if there was a problem
-    @retval     BLE_ERROR_NONE
-                Everything executed correctly
-
-    @section EXAMPLE
-
-    @code
-   
-    @endcode    
-*/
-/**************************************************************************/
-ble_error_t UUID::update(uint8_t const uuid_base[16])
-{
-    memcpy(base, uuid_base, 16);
-    value = (uint16_t)((uuid_base[3] << 8) | (uuid_base[2]));
-
-    /* Check if this is a short of a long UUID */
-    if (uuid_base[0]  + uuid_base[1]  +
-        uuid_base[4]  + uuid_base[5]  + uuid_base[6]  + uuid_base[7] +
-        uuid_base[8]  + uuid_base[9]  + uuid_base[10] + uuid_base[11] +
-        uuid_base[12] + uuid_base[13] + uuid_base[14] + uuid_base[15] == 0)
-    {
-        type = UUID_TYPE_SHORT; 
-    }
-    else
-    {
-        type = UUID_TYPE_LONG;
-    }
-    
-    return BLE_ERROR_NONE;
-}
-
-/**************************************************************************/
-/*!
-    @brief  Updates the value of the UUID
-    
-    @args[in]   ble_uuid
-                The 16-bit value to use when updating the UUID.
-                
-    @returns    BLE_ERROR_NONE (0) if everything executed correctly, or an
-                error code if there was a problem
-    @retval     BLE_ERROR_NONE
-                Everything executed correctly
-
-    @section EXAMPLE
-
-    @code
-   
-    @endcode    
-*/
-/**************************************************************************/
-ble_error_t UUID::update(uint16_t const ble_uuid)
-{
-    memset(base, 0, 16);
-    memcpy(base+2, (uint8_t *)&ble_uuid, 2);
-    value = ble_uuid;
-    type = UUID_TYPE_SHORT;
-    
-    return BLE_ERROR_NONE;
-}
--- a/uuid.h	Thu Jan 09 10:44:47 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,30 +0,0 @@
-#ifndef __UUID_H__
-#define __UUID_H__
-
-#include "blecommon.h"
-
-class UUID
-{
-private:
-    
-public:
-    enum
-    {
-        UUID_TYPE_SHORT = 0,    // Short BLE UUID
-        UUID_TYPE_LONG  = 1     // Full 128-bit UUID
-    };
-    
-    UUID(void);
-    UUID(uint8_t const[16]);
-    UUID(uint16_t const);
-    virtual ~UUID(void);
-    
-    uint8_t   type;        // UUID_TYPE_SHORT or UUID_TYPE_LONG
-    uint8_t   base[16];    // in case of custom
-    uint16_t  value;       // 16 bit uuid (byte 2-3 using with base)
-    
-    ble_error_t update(uint8_t const[16]);
-    ble_error_t update(uint16_t const);
-};
-
-#endif