mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #5727 from dschuler/nrf52pf
Add presentation format descriptor support for nRF5xpull/5862/head
commit
7be79f93fe
|
@ -210,6 +210,8 @@ error_t custom_add_in_characteristic(uint16_t service_handle,
|
||||||
bool has_variable_len,
|
bool has_variable_len,
|
||||||
const uint8_t *userDescriptionDescriptorValuePtr,
|
const uint8_t *userDescriptionDescriptorValuePtr,
|
||||||
uint16_t userDescriptionDescriptorValueLen,
|
uint16_t userDescriptionDescriptorValueLen,
|
||||||
|
const uint8_t *presentationFormatDescriptorValuePtr,
|
||||||
|
uint16_t presentationFormatDescriptorValueLen,
|
||||||
bool readAuthorization,
|
bool readAuthorization,
|
||||||
bool writeAuthorization,
|
bool writeAuthorization,
|
||||||
ble_gatts_char_handles_t *p_char_handle)
|
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_max_size = userDescriptionDescriptorValueLen;
|
||||||
char_md.char_user_desc_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 */
|
/* Attribute declaration */
|
||||||
ble_gatts_attr_md_t attr_md = {0};
|
ble_gatts_attr_md_t attr_md = {0};
|
||||||
|
|
|
@ -52,6 +52,8 @@ error_t custom_add_in_characteristic(uint16_t service_handle,
|
||||||
bool has_variable_len,
|
bool has_variable_len,
|
||||||
const uint8_t *userDescriptionDescriptorValuePtr,
|
const uint8_t *userDescriptionDescriptorValuePtr,
|
||||||
uint16_t userDescriptionDescriptorValueLen,
|
uint16_t userDescriptionDescriptorValueLen,
|
||||||
|
const uint8_t *presentationFormatDescriptorValuePtr,
|
||||||
|
uint16_t presentationFormatDescriptorValueLen,
|
||||||
bool readAuthorization,
|
bool readAuthorization,
|
||||||
bool writeAuthorization,
|
bool writeAuthorization,
|
||||||
ble_gatts_char_handles_t *p_char_handle);
|
ble_gatts_char_handles_t *p_char_handle);
|
||||||
|
|
|
@ -131,6 +131,7 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
|
||||||
}
|
}
|
||||||
GattCharacteristic *p_char = service.getCharacteristic(i);
|
GattCharacteristic *p_char = service.getCharacteristic(i);
|
||||||
GattAttribute *p_description_descriptor = NULL;
|
GattAttribute *p_description_descriptor = NULL;
|
||||||
|
GattAttribute *p_presentation_format_descriptor = NULL;
|
||||||
|
|
||||||
/* Skip any incompletely defined, read-only characteristics. */
|
/* Skip any incompletely defined, read-only characteristics. */
|
||||||
if ((p_char->getValueAttribute().getValuePtr() == NULL) &&
|
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());
|
nordicUUID = custom_convert_to_nordic_uuid(p_char->getValueAttribute().getUUID());
|
||||||
|
|
||||||
/* The user-description descriptor is a special case which needs to be
|
/* The user-description and presentation-format descriptors are special cases
|
||||||
* handled at the time of adding the characteristic. The following block
|
* that need to be handled at the time of adding each characteristic. The
|
||||||
* is meant to discover its presence. */
|
* following block is meant to discover their presence. */
|
||||||
const uint8_t *userDescriptionDescriptorValuePtr = NULL;
|
const uint8_t *userDescriptionDescriptorValuePtr = NULL;
|
||||||
uint16_t userDescriptionDescriptorValueLen = 0;
|
uint16_t userDescriptionDescriptorValueLen = 0;
|
||||||
|
const uint8_t *presentationFormatDescriptorValuePtr = NULL;
|
||||||
|
uint16_t presentationFormatDescriptorValueLen = 0;
|
||||||
for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) {
|
for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) {
|
||||||
GattAttribute *p_desc = p_char->getDescriptor(j);
|
GattAttribute *p_desc = p_char->getDescriptor(j);
|
||||||
if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) {
|
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();
|
userDescriptionDescriptorValuePtr = p_desc->getValuePtr();
|
||||||
userDescriptionDescriptorValueLen = p_desc->getLength();
|
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 ==
|
ASSERT_TRUE ( ERROR_NONE ==
|
||||||
|
@ -166,6 +174,8 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
|
||||||
p_char->getValueAttribute().hasVariableLength(),
|
p_char->getValueAttribute().hasVariableLength(),
|
||||||
userDescriptionDescriptorValuePtr,
|
userDescriptionDescriptorValuePtr,
|
||||||
userDescriptionDescriptorValueLen,
|
userDescriptionDescriptorValueLen,
|
||||||
|
presentationFormatDescriptorValuePtr,
|
||||||
|
presentationFormatDescriptorValueLen,
|
||||||
p_char->isReadAuthorizationEnabled(),
|
p_char->isReadAuthorizationEnabled(),
|
||||||
p_char->isWriteAuthorizationEnabled(),
|
p_char->isWriteAuthorizationEnabled(),
|
||||||
&nrfCharacteristicHandles[characteristicCount]),
|
&nrfCharacteristicHandles[characteristicCount]),
|
||||||
|
@ -179,6 +189,10 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
|
||||||
nrfCharacteristicHandles[characteristicCount].user_desc_handle
|
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++;
|
characteristicCount++;
|
||||||
|
|
||||||
/* Add optional descriptors if any */
|
/* Add optional descriptors if any */
|
||||||
|
@ -188,8 +202,10 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
|
||||||
}
|
}
|
||||||
|
|
||||||
GattAttribute *p_desc = p_char->getDescriptor(j);
|
GattAttribute *p_desc = p_char->getDescriptor(j);
|
||||||
/* skip the user-description-descriptor here; this has already been handled when adding the characteristic (above). */
|
/* skip the user-description or presentation-format descriptor here;
|
||||||
if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) {
|
* 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue