BLE test
Fork of X_NUCLEO_IDB0XA1 by
Diff: source/BlueNRGGattServer.cpp
- Revision:
- 132:51056160fa4a
- Parent:
- 130:770ce14d3d15
- Child:
- 142:adf1567d3900
--- a/source/BlueNRGGattServer.cpp Tue Oct 06 15:19:19 2015 +0200 +++ b/source/BlueNRGGattServer.cpp Wed Oct 07 08:39:04 2015 +0200 @@ -43,6 +43,7 @@ #include "mbed.h" #include "BlueNRGGap.h" #include "Utils.h" +#include "debug.h" /**************************************************************************/ /*! @@ -82,7 +83,7 @@ uint8_t maxAttrRecords = 0; type = (service.getUUID()).shortOrLong(); - DEBUG("AddService(): Type:%d\n\r", type); + PRINTF("AddService(): Type:%d\n\r", type); /* Add the service to the BlueNRG */ short_uuid = (service.getUUID()).getShortUUID(); @@ -105,7 +106,7 @@ PRIMARY_SERVICE, maxAttrRecords/*7*/, &servHandle); - DEBUG("aci_gatt_add_serv UUID_TYPE_LONG ret=%d\n\r", ret); + PRINTF("aci_gatt_add_serv UUID_TYPE_LONG ret=%d\n\r", ret); } else if(type==UUID::UUID_TYPE_LONG) { ret = aci_gatt_add_serv(UUID_TYPE_128, @@ -113,12 +114,12 @@ PRIMARY_SERVICE, maxAttrRecords/*7*/, &servHandle); - DEBUG("aci_gatt_add_serv UUID_TYPE_LONG ret=%d\n\r", ret); + PRINTF("aci_gatt_add_serv UUID_TYPE_LONG ret=%d\n\r", ret); } service.setHandle(servHandle); //serviceHandleVector.push_back(servHandle); - DEBUG("added servHandle handle =%u\n\r", servHandle); + PRINTF("added servHandle handle =%u\n\r", servHandle); uint16_t bleCharacteristic; //iterate to include all characteristics @@ -136,7 +137,7 @@ base_char_uuid[8],base_char_uuid[7],base_char_uuid[6],base_char_uuid[5],base_char_uuid[4],int_8_uuid[1],int_8_uuid[0],base_char_uuid[1],base_char_uuid[0]); } - DEBUG("Char Properties 0x%x\n\r", p_char->getProperties()); + PRINTF("Char Properties 0x%x\n\r", p_char->getProperties()); /* * Gatt_Evt_Mask -> HardCoded (0) * Encryption_Key_Size -> Hardcoded (16) @@ -147,13 +148,13 @@ if((p_char->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE| GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE))) { - DEBUG("Setting up Gatt GATT_NOTIFY_ATTRIBUTE_WRITE Mask\n\r"); + PRINTF("Setting up Gatt GATT_NOTIFY_ATTRIBUTE_WRITE Mask\n\r"); Gatt_Evt_Mask = Gatt_Evt_Mask | GATT_NOTIFY_ATTRIBUTE_WRITE; } if((p_char->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_READ| GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY| GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE))) { - DEBUG("Setting up Gatt GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP Mask\n\r"); + PRINTF("Setting up Gatt GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP Mask\n\r"); Gatt_Evt_Mask = Gatt_Evt_Mask | GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP; } //This will support also GATT_SERVER_ATTR_READ_WRITE since it will be covered by previous if() check. @@ -169,7 +170,7 @@ 1 /*isVariable*/, &bleCharacteristic); - DEBUG("aci_gatt_add_char UUID_TYPE_16 props=%d MaxLength=%d ret=%d\n\r", p_char->getProperties(), p_char->getValueAttribute().getMaxLength(), ret); + PRINTF("aci_gatt_add_char UUID_TYPE_16 props=%d MaxLength=%d ret=%d\n\r", p_char->getProperties(), p_char->getValueAttribute().getMaxLength(), ret); } else if(type==UUID::UUID_TYPE_LONG) { ret = aci_gatt_add_char(service.getHandle(), @@ -183,7 +184,7 @@ 1 /*isVariable*/, &bleCharacteristic); - DEBUG("aci_gatt_add_char UUID_TYPE_128 props=%d MaxLength=%d ret=%d\n\r", p_char->getProperties(), p_char->getValueAttribute().getMaxLength(), ret); + PRINTF("aci_gatt_add_char UUID_TYPE_128 props=%d MaxLength=%d ret=%d\n\r", p_char->getProperties(), p_char->getValueAttribute().getMaxLength(), ret); } /* Update the characteristic handle */ @@ -193,7 +194,7 @@ p_characteristics[characteristicCount++] = p_char; p_char->getValueAttribute().setHandle(bleCharacteristic); //Set the characteristic count as the corresponding char handle - DEBUG("added bleCharacteristic handle =%u\n\r", bleCharacteristic); + PRINTF("added bleCharacteristic handle =%u\n\r", bleCharacteristic); if ((p_char->getValueAttribute().getValuePtr() != NULL) && (p_char->getValueAttribute().getInitialLength() > 0)) { write(p_char->getValueAttribute().getHandle(), p_char->getValueAttribute().getValuePtr(), p_char->getValueAttribute().getInitialLength(), false /* localOnly */); @@ -201,7 +202,7 @@ // add descriptors now uint16_t descHandle = 0; - DEBUG("p_char->getDescriptorCount()=%d\n\r", p_char->getDescriptorCount()); + PRINTF("p_char->getDescriptorCount()=%d\n\r", p_char->getDescriptorCount()); for(uint8_t descIndex=0; descIndex<p_char->getDescriptorCount(); descIndex++) { GattAttribute *descriptor = p_char->getDescriptor(descIndex); @@ -211,9 +212,9 @@ CHAR_DESC_TYPE_16_BIT, uuidArray, descriptor->getMaxLength(), descriptor->getInitialLength(), descriptor->getValuePtr(), CHAR_DESC_SECURITY_PERMISSION, CHAR_DESC_ACCESS_PERMISSION, GATT_NOTIFY_ATTRIBUTE_WRITE, MIN_ENCRY_KEY_SIZE, CHAR_ATTRIBUTE_LEN_IS_FIXED, &descHandle); - DEBUG("Adding Descriptor descriptor handle=%d ret=%d\n\r", descHandle, ret); + PRINTF("Adding Descriptor descriptor handle=%d ret=%d\n\r", descHandle, ret); if(ret==(tBleStatus)0) { - DEBUG("Descriptor added successfully, descriptor handle=%d\n\r", descHandle); + PRINTF("Descriptor added successfully, descriptor handle=%d\n\r", descHandle); descriptor->setHandle(descHandle); } } @@ -255,7 +256,7 @@ /**************************************************************************/ ble_error_t BlueNRGGattServer::readValue(uint16_t charHandle, uint8_t buffer[], uint16_t *const lengthP) { - DEBUG("ReadValue() Not Supported\n\r"); + PRINTF("ReadValue() Not Supported\n\r"); return BLE_ERROR_NONE; } @@ -300,16 +301,16 @@ tBleStatus ret; //uint8_t buff[2]; - DEBUG("updating bleCharacteristic charHandle =%u, corresponding serviceHanle= %u len=%d\n\r", charHandle, bleCharHanldeMap.find(charHandle)->second, len); + PRINTF("updating bleCharacteristic charHandle =%u, corresponding serviceHanle= %u len=%d\n\r", charHandle, bleCharHanldeMap.find(charHandle)->second, len); /* for(int i=0; i<len; i++) { - DEBUG("buffer[%d]=%d\n\r", i, buffer[i]); + PRINTF("buffer[%d]=%d\n\r", i, buffer[i]); } */ ret = aci_gatt_update_char_value(bleCharHanldeMap.find(charHandle)->second, charHandle, 0, len, buffer); if (ret != BLE_STATUS_SUCCESS){ - DEBUG("Error while updating characteristic (ret=0x%x).\n\r", ret) ; + PRINTF("Error while updating characteristic (ret=0x%x).\n\r", ret) ; return BLE_ERROR_PARAM_OUT_OF_RANGE ; //Not correct Error Value //FIXME: Define Error values equivalent to BlueNRG Error Codes. } @@ -319,7 +320,7 @@ GattCharacteristic *p_char = BlueNRGGattServer::getInstance().getCharacteristicFromHandle(charHandle); if(p_char->getProperties() & (GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_INDICATE)) { - DEBUG("Generate event after updating\n\r"); + PRINTF("Generate event after updating\n\r"); BlueNRGGattServer::getInstance().handleEvent(GattServerEvents::GATT_EVENT_DATA_SENT, charHandle); } @@ -353,12 +354,12 @@ GattReadCallbackParams readParams; readParams.handle = handle; - //DEBUG("readParams.charHandle = %d\n\r", readParams.charHandle); + //PRINTF("readParams.charHandle = %d\n\r", readParams.charHandle); HCIDataReadEvent(&readParams); //EXIT: if(gapConnectionHandle != 0){ - //DEBUG("Calling aci_gatt_allow_read\n\r"); + //PRINTF("Calling aci_gatt_allow_read\n\r"); aci_gatt_allow_read(gapConnectionHandle); } @@ -390,17 +391,17 @@ int i; uint16_t handle, handle_1; - DEBUG("BlueNRGGattServer::getCharacteristicFromHandle()>>Attribute Handle received %d\n\r",attrHandle); + PRINTF("BlueNRGGattServer::getCharacteristicFromHandle()>>Attribute Handle received %d\n\r",attrHandle); for(i=0; i<characteristicCount; i++) { handle = p_characteristics[i]->getValueAttribute().getHandle(); - DEBUG("handle(%d)=%d\n\r", i, handle); + PRINTF("handle(%d)=%d\n\r", i, handle); if(i==characteristicCount-1)//Last Characteristic check { if(attrHandle>=handle) { p_char = p_characteristics[i]; - DEBUG("Found Characteristic Properties 0x%x (handle=%d)\n\r",p_char->getProperties(), handle); + PRINTF("Found Characteristic Properties 0x%x (handle=%d)\n\r",p_char->getProperties(), handle); break; } } @@ -410,7 +411,7 @@ if(attrHandle>=handle && attrHandle<handle_1) { p_char = p_characteristics[i]; - DEBUG("Found Characteristic Properties 0x%x (handle=%d handle_1=%d)\n\r",p_char->getProperties(), handle, handle_1); + PRINTF("Found Characteristic Properties 0x%x (handle=%d handle_1=%d)\n\r",p_char->getProperties(), handle, handle_1); break; } else continue; } @@ -424,7 +425,7 @@ } void BlueNRGGattServer::HCIDataReadEvent(const GattReadCallbackParams *params) { - DEBUG("Called HCIDataReadEvent\n\r"); + PRINTF("Called HCIDataReadEvent\n\r"); this->handleDataReadEvent(params); }