A library for easier setup and prototyping of IoT devices (pucks), by collecting everything that is common for all pucks in one place.

Dependencies:   BLE_API nRF51822

Fork of Puck by Nordic Pucks

Files at this revision

API Documentation at this revision

Comitter:
aleksanb
Date:
Mon Feb 23 15:25:22 2015 +0000
Parent:
13:93d3574e9e36
Commit message:
Update Puck library to newest versions of BLE_API.h, mbed.h.

Changed in this revision

BLE_API.lib Show annotated file Show diff for this revision Revisions of this file
Puck.h Show annotated file Show diff for this revision Revisions of this file
nRF51822.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 93d3574e9e36 -r 9eda2d99fc1d BLE_API.lib
--- a/BLE_API.lib	Mon Aug 11 09:42:01 2014 +0000
+++ b/BLE_API.lib	Mon Feb 23 15:25:22 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#189ff241dae1
+http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#1956023d42fb
diff -r 93d3574e9e36 -r 9eda2d99fc1d Puck.h
--- a/Puck.h	Mon Aug 11 09:42:01 2014 +0000
+++ b/Puck.h	Mon Feb 23 15:25:22 2015 +0000
@@ -19,8 +19,9 @@
 #define __PUCK_HPP__
  
 #include "BLEDevice.h"
+#include "mbed.h"
+#include "Log.h"
 #include <vector>
-#include "Log.h"
 
 enum PuckState {
     CONNECTING,
@@ -82,18 +83,21 @@
     return _puckSingletonInstance;
 }
 
-void onDisconnection(Gap::Handle_t handle) {
+void onDisconnection(Gap::Handle_t handle, Gap::DisconnectionReason_t disconnectReason) {
     LOG_INFO("Disconnected.\n");
     Puck::getPuck().setState(DISCONNECTED);
 }
 
-void onConnection(Gap::Handle_t handle) {
+void onConnection(Gap::Handle_t handle,
+        Gap::addr_type_t peerAddrType,
+        const Gap::address_t peerAddr,
+        const Gap::ConnectionParams_t * connectionParams) {
     LOG_INFO("Connected.\n");
     Puck::getPuck().setState(CONNECTED);
 }
 
-void onDataWrittenCallback(uint16_t handle) {
-    Puck::getPuck().onDataWritten(handle);
+void onDataWrittenCallback(const GattCharacteristicWriteCBParams *context) {
+    Puck::getPuck().onDataWritten(context->charHandle);
 }
 
 bool isEqualUUID(const UUID* uuidA, const UUID uuidB) {
@@ -120,7 +124,7 @@
 }
 
 void Puck::disconnect() {
-    ble.disconnect();    
+    ble.disconnect(Gap::LOCAL_HOST_TERMINATED_CONNECTION);    
 }
 
 int Puck::countFreeMemory() {
@@ -271,17 +275,17 @@
     LOG_DEBUG("Added characteristic.\n");
 }
 
-
 void Puck::updateCharacteristicValue(const UUID uuid, uint8_t* value, int length) {
     GattCharacteristic* characteristic = NULL;
-    for( int i = 0; i < characteristics.size(); i++) {
-        if(isEqualUUID(&characteristics[i]->getUUID(), uuid)) {
+    for(int i = 0; i < characteristics.size(); i++) {
+        GattAttribute &gattAttribute = characteristics[i]->getValueAttribute();
+        if(isEqualUUID(&gattAttribute.getUUID(), uuid)) {
             characteristic = characteristics[i];
-            break;    
-        }    
+            break;
+        }
     }
     if(characteristic != NULL) {
-        ble.updateCharacteristicValue(characteristic->getHandle(), value, length);
+        ble.updateCharacteristicValue(characteristic->getValueHandle(), value, length);
         LOG_VERBOSE("Updated characteristic value.\n");
     } else {
         LOG_WARN("Tried to update an unkown characteristic!\n");    
@@ -289,10 +293,12 @@
 }
 
 bool Puck::drive() {
+    if(state == DISCONNECTED) {
+        startAdvertising();
+    }
+
     ble.waitForEvent();
-    if(state == DISCONNECTED) {
-        startAdvertising();    
-    }
+
     while(pendingCallbackStack.size() > 0) {
         pendingCallbackStack.back()(pendingCallbackParameterStack.back());
         pendingCallbackStack.pop_back();
@@ -327,9 +333,9 @@
 uint8_t* Puck::getCharacteristicValue(const UUID uuid) {
     LOG_VERBOSE("Reading characteristic value for UUID %x\n", uuid);
     for(int i = 0; i < characteristics.size(); i++) {
-        GattCharacteristic* characteristic = characteristics[i];
-        if(isEqualUUID(&characteristic->getUUID(), uuid)) {
-            return characteristic->getValuePtr();
+        GattAttribute &gattAttribute = characteristics[i]->getValueAttribute();
+        if(isEqualUUID(&gattAttribute.getUUID(), uuid)) {
+            return gattAttribute.getValuePtr();
         }
     }
     LOG_WARN("Tried to read an unknown characteristic!");
@@ -340,15 +346,17 @@
 void Puck::onDataWritten(uint16_t handle) {
     for (int i = 0; i < characteristics.size(); i++) {
         GattCharacteristic* characteristic = characteristics[i];
-        if (characteristic->getHandle() == handle) {
-            uint16_t maxLength = characteristic->getMaxLength();
-            ble.readCharacteristicValue(handle, characteristic->getValuePtr(), &maxLength);
+        
+        if (characteristic->getValueHandle() == handle) {
+            GattAttribute &gattAttribute = characteristic->getValueAttribute();
+
             for(int j = 0; j < writeCallbacks.size(); j++) {    
                 CharacteristicWriteCallbacks* characteristicWriteCallbacks = writeCallbacks[j];
-                if(isEqualUUID(characteristicWriteCallbacks->uuid, characteristic->getUUID())) {
+
+                if(isEqualUUID(characteristicWriteCallbacks->uuid, gattAttribute.getUUID())) {
                     for(int k = 0; k < characteristicWriteCallbacks->callbacks->size(); k++) {
                         pendingCallbackStack.push_back(characteristicWriteCallbacks->callbacks->at(k));
-                        pendingCallbackParameterStack.push_back(characteristic->getValuePtr());
+                        pendingCallbackParameterStack.push_back(gattAttribute.getValuePtr());
                     }
                     return;
                 }
@@ -358,5 +366,4 @@
 }
 
 
-
  #endif // __PUCK_HPP__
\ No newline at end of file
diff -r 93d3574e9e36 -r 9eda2d99fc1d nRF51822.lib
--- a/nRF51822.lib	Mon Aug 11 09:42:01 2014 +0000
+++ b/nRF51822.lib	Mon Feb 23 15:25:22 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#1e5c300cec7f
+http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#0e7a9efee6d7