Merge pull request #5727 from dschuler/nrf52pf

Add presentation format descriptor support for nRF5x
pull/5862/head
Martin Kojtal 2018-01-15 15:43:21 +00:00 committed by GitHub
commit 7be79f93fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 5 deletions

View File

@ -210,6 +210,8 @@ error_t custom_add_in_characteristic(uint16_t service_handle,
bool has_variable_len,
const uint8_t *userDescriptionDescriptorValuePtr,
uint16_t userDescriptionDescriptorValueLen,
const uint8_t *presentationFormatDescriptorValuePtr,
uint16_t presentationFormatDescriptorValueLen,
bool readAuthorization,
bool writeAuthorization,
ble_gatts_char_handles_t *p_char_handle)
@ -238,6 +240,11 @@ error_t custom_add_in_characteristic(uint16_t service_handle,
char_md.char_user_desc_max_size = userDescriptionDescriptorValueLen;
char_md.char_user_desc_size = userDescriptionDescriptorValueLen;
}
if ((presentationFormatDescriptorValueLen > 0) && (presentationFormatDescriptorValuePtr != NULL)) {
ASSERT_TRUE( sizeof(ble_gatts_char_pf_t) == sizeof(GattCharacteristic::PresentationFormat_t), ERROR_INVALID_PARAM );
ASSERT_TRUE( presentationFormatDescriptorValueLen == sizeof(GattCharacteristic::PresentationFormat_t), ERROR_INVALID_PARAM );
char_md.p_char_pf = const_cast<ble_gatts_char_pf_t *>(reinterpret_cast<const ble_gatts_char_pf_t *>(presentationFormatDescriptorValuePtr));
}
/* Attribute declaration */
ble_gatts_attr_md_t attr_md = {0};

View File

@ -52,6 +52,8 @@ error_t custom_add_in_characteristic(uint16_t service_handle,
bool has_variable_len,
const uint8_t *userDescriptionDescriptorValuePtr,
uint16_t userDescriptionDescriptorValueLen,
const uint8_t *presentationFormatDescriptorValuePtr,
uint16_t presentationFormatDescriptorValueLen,
bool readAuthorization,
bool writeAuthorization,
ble_gatts_char_handles_t *p_char_handle);

View File

@ -131,6 +131,7 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
}
GattCharacteristic *p_char = service.getCharacteristic(i);
GattAttribute *p_description_descriptor = NULL;
GattAttribute *p_presentation_format_descriptor = NULL;
/* Skip any incompletely defined, read-only characteristics. */
if ((p_char->getValueAttribute().getValuePtr() == NULL) &&
@ -141,11 +142,13 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
nordicUUID = custom_convert_to_nordic_uuid(p_char->getValueAttribute().getUUID());
/* The user-description descriptor is a special case which needs to be
* handled at the time of adding the characteristic. The following block
* is meant to discover its presence. */
/* The user-description and presentation-format descriptors are special cases
* that need to be handled at the time of adding each characteristic. The
* following block is meant to discover their presence. */
const uint8_t *userDescriptionDescriptorValuePtr = NULL;
uint16_t userDescriptionDescriptorValueLen = 0;
const uint8_t *presentationFormatDescriptorValuePtr = NULL;
uint16_t presentationFormatDescriptorValueLen = 0;
for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) {
GattAttribute *p_desc = p_char->getDescriptor(j);
if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) {
@ -153,6 +156,11 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
userDescriptionDescriptorValuePtr = p_desc->getValuePtr();
userDescriptionDescriptorValueLen = p_desc->getLength();
}
if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT) {
p_presentation_format_descriptor = p_desc;
presentationFormatDescriptorValuePtr = p_desc->getValuePtr();
presentationFormatDescriptorValueLen = p_desc->getLength();
}
}
ASSERT_TRUE ( ERROR_NONE ==
@ -166,6 +174,8 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
p_char->getValueAttribute().hasVariableLength(),
userDescriptionDescriptorValuePtr,
userDescriptionDescriptorValueLen,
presentationFormatDescriptorValuePtr,
presentationFormatDescriptorValueLen,
p_char->isReadAuthorizationEnabled(),
p_char->isWriteAuthorizationEnabled(),
&nrfCharacteristicHandles[characteristicCount]),
@ -179,6 +189,10 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
nrfCharacteristicHandles[characteristicCount].user_desc_handle
);
}
if (p_presentation_format_descriptor) {
// The handle is not available from the SoftDevice
p_presentation_format_descriptor->setHandle(GattAttribute::INVALID_HANDLE);
}
characteristicCount++;
/* Add optional descriptors if any */
@ -188,8 +202,10 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
}
GattAttribute *p_desc = p_char->getDescriptor(j);
/* skip the user-description-descriptor here; this has already been handled when adding the characteristic (above). */
if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) {
/* skip the user-description or presentation-format descriptor here;
* they have already been handled when adding the characteristic (above). */
if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC
|| p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT) {
continue;
}