Devchannel Team / X_NUCLEO_IDB0XA1

Dependents:   Hello_BLE F446RE-BLE

Fork of X_NUCLEO_IDB0XA1 by ST

Files at this revision

API Documentation at this revision

Comitter:
mridup
Date:
Wed Aug 20 07:55:23 2014 +0000
Parent:
26:047d45ea379e
Child:
28:edeb91b415c6
Commit message:
Gatt Notify/Indicate Event Enabled/Disabled support

Changed in this revision

BlueNRGGattServer.cpp Show annotated file Show diff for this revision Revisions of this file
BlueNRGGattServer.h Show annotated file Show diff for this revision Revisions of this file
btle/src/btle.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/BlueNRGGattServer.cpp	Tue Aug 19 08:43:19 2014 +0000
+++ b/BlueNRGGattServer.cpp	Wed Aug 20 07:55:23 2014 +0000
@@ -144,7 +144,7 @@
 /**************************************************************************/
 ble_error_t BlueNRGGattServer::readValue(uint16_t charHandle, uint8_t buffer[], uint16_t *const lengthP)
 {
-    DEBUG("ReadValue()\n\r");
+    DEBUG("ReadValue() Not Supported\n\r");
     return BLE_ERROR_NONE;
 }
 
@@ -189,6 +189,8 @@
     
   ret = aci_gatt_update_char_value(hrmServHandle, bleCharacteristicHandles[charHandle], 0, len, buffer);
 
+  //TODO?: Generate Data Sent Event Here? (GattServerEvents::GATT_EVENT_DATA_SENT)
+  
   if (ret != BLE_STATUS_SUCCESS){
       DEBUG("Error while updating characteristic.\n\r") ;
       return BLE_ERROR_PARAM_OUT_OF_RANGE ; //Not correct Error Value 
@@ -202,12 +204,7 @@
     @brief  Reads a value according to the handle provided
 
     @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
+                The handle of the GattCharacteristic to read from
 
     @returns    ble_error_t
 
@@ -233,11 +230,47 @@
     data = 450 + ((uint64_t)rand()*100)/RAND_MAX;
     STORE_LE_16(buff,data);
     
-    ret = aci_gatt_update_char_value(hrmServHandle, handle, 0, sizeof(buff), buff);
-    
+    //ret = aci_gatt_update_char_value(hrmServHandle, handle, 0, sizeof(buff), buff);
+    //ret = aci_gatt_read_charac_val(gapConnectionHandle, handle);
     
     //EXIT:
     if(gapConnectionHandle != 0)
     aci_gatt_allow_read(gapConnectionHandle);
 }
 
+/**************************************************************************/
+/*!
+    @brief  Returns the GattCharacteristic according to the handle provided
+
+    @param[in]  charHandle
+                The handle of the GattCharacteristic
+
+    @returns    ble_error_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+
+    @section EXAMPLE
+
+    @code
+
+    @endcode
+*/
+/**************************************************************************/
+GattCharacteristic* BlueNRGGattServer::getCharacteristicFromHandle(tHalUint16 charHandle)
+{
+    GattCharacteristic *p_char;
+    int i;
+    uint16_t handle;
+    
+    for(i=0; i<characteristicCount; i++)
+    {
+        handle = p_characteristics[i]->getHandle();
+        if(charHandle==bleCharacteristicHandles[handle])
+        {
+            p_char = p_characteristics[i];
+            break;
+        }
+    }
+    return p_char;
+}
--- a/BlueNRGGattServer.h	Tue Aug 19 08:43:19 2014 +0000
+++ b/BlueNRGGattServer.h	Wed Aug 20 07:55:23 2014 +0000
@@ -42,7 +42,8 @@
     void eventCallback(void);
     //void hwCallback(void *pckt);
     ble_error_t Read_Request_CB(tHalUint16 handle);
-
+    GattCharacteristic* getCharacteristicFromHandle(tHalUint16 charHandle);
+    
 private:
 
     uint8_t serviceCount;
@@ -51,7 +52,8 @@
     
     GattCharacteristic *p_characteristics[BLE_TOTAL_CHARACTERISTICS];
     tHalUint16 bleCharacteristicHandles[BLE_TOTAL_CHARACTERISTICS];
-
+    
+    
     BlueNRGGattServer() {
         serviceCount = 0;
         characteristicCount = 0;
--- a/btle/src/btle.cpp	Tue Aug 19 08:43:19 2014 +0000
+++ b/btle/src/btle.cpp	Wed Aug 20 07:55:23 2014 +0000
@@ -203,7 +203,7 @@
     
                     case EVT_BLUE_GATT_READ_PERMIT_REQ:
                         {
-                            DEBUG("EVT_BLUE_GATT_READ_PERMIT_REQ\n\r");
+                            DEBUG("EVT_BLUE_GATT_READ_PERMIT_REQ_OK\n\r");
                             evt_gatt_read_permit_req *pr = (evt_gatt_read_permit_req*)blue_evt->data;                    
                             BlueNRGGattServer::getInstance().Read_Request_CB(pr->attr_handle);                                                
                         }
@@ -215,9 +215,25 @@
                              extract callback data and pass to suitable handler function */
                           evt_gatt_attr_modified *evt = (evt_gatt_attr_modified*)blue_evt->data;
                           DEBUG("EVT_BLUE_GATT_ATTRIBUTE_MODIFIED\n\r");                          
-                          DEBUG("CharHandle 0x%x, Data: 0x%x\n\r",evt->attr_handle, evt->att_data);
+                          DEBUG("CharHandle 0x%x, length: 0x%x, Data: 0x%x\n\r",evt->attr_handle, evt->data_length, (uint16_t)evt->att_data[0]);
+                          
+                          
+                          //Extract the GattCharacteristic from p_characteristics[] and find the properties mask
+                          GattCharacteristic *p_char = BlueNRGGattServer::getInstance().getCharacteristicFromHandle(evt->attr_handle);
                           
+                          if((p_char->getProperties() &  (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY
+                                  | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE))) {
+                                  
+                                   //Now Check if data written in Enable or Disable
+                                   if((uint16_t)evt->att_data[0]==1)
+                                    BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_UPDATES_ENABLED, evt->attr_handle);
+                                   else
+                                    BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_UPDATES_DISABLED, evt->attr_handle);
+                                }
+                          
+                          //TODO: Check is attr handle property is WRITEABLE, if yes, generate GATT_EVENT_DATA_WRITTEN Event
                           BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_WRITTEN, evt->attr_handle);
+                          //TODO: Write the actual Data to the Attr Handle? (uint8_1[])evt->att_data contains the data
                           
                           //Attribute_Modified_CB(evt->attr_handle, evt->data_length, evt->att_data);                    
                         }
@@ -225,11 +241,17 @@
                         
                     //Any cases for Data Sent Notifications?
                     case EVT_BLUE_GATT_NOTIFICATION:
+                    //This is only relevant for Client Side Event
                     DEBUG("EVT_BLUE_GATT_NOTIFICATION");
                     break;
                     case EVT_BLUE_GATT_INDICATION:
+                    //This is only relevant for Client Side Event
                     DEBUG("EVT_BLUE_GATT_INDICATION");
-                    break;                                        
+                    break;   
+                    
+                    case EVT_BLUE_GATT_PROCEDURE_COMPLETE:
+                    DEBUG("EVT_BLUE_GATT_PROCEDURE_COMPLETE");
+                    break;                                     
             }
         }
         break;