Devchannel Team / X_NUCLEO_IDB0XA1

Dependents:   Hello_BLE F446RE-BLE

Fork of X_NUCLEO_IDB0XA1 by ST

Revision:
28:edeb91b415c6
Parent:
27:b4c21a9e8b39
Child:
29:1870b03aa25b
--- a/btle/src/btle.cpp	Wed Aug 20 07:55:23 2014 +0000
+++ b/btle/src/btle.cpp	Wed Aug 20 12:09:06 2014 +0000
@@ -220,20 +220,34 @@
                           
                           //Extract the GattCharacteristic from p_characteristics[] and find the properties mask
                           GattCharacteristic *p_char = BlueNRGGattServer::getInstance().getCharacteristicFromHandle(evt->attr_handle);
-                          
+                          DEBUG("getProperties 0x%x\n\r",p_char->getProperties());
                           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)
+                                   {
+                                    DEBUG("Notify ENABLED\n\r"); 
                                     BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_UPDATES_ENABLED, evt->attr_handle);
+                                   } 
                                    else
+                                   {
+                                    DEBUG("Notify DISABLED\n\r"); 
                                     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
+                          //Check is attr handle property is WRITEABLE, if yes, generate GATT_EVENT_DATA_WRITTEN Event
+                          if((p_char->getProperties() &
+                                 (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE|
+                                  GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE))) {
+                                    
+                                    BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_WRITTEN, evt->attr_handle);
+                                    //Write the actual Data to the Attr Handle? (uint8_1[])evt->att_data contains the data
+                                    if ((p_char->getValuePtr() != NULL) && (p_char->getInitialLength() > 0)) {
+                                        BlueNRGGattServer::getInstance().updateValue(p_char->getHandle(), p_char->getValuePtr(), p_char->getInitialLength(), false /* localOnly */);
+                                    }
+                          }
                           
                           //Attribute_Modified_CB(evt->attr_handle, evt->data_length, evt->att_data);                    
                         }