Skip to content

Commit 7be79f9

Browse files
authored
Merge pull request #5727 from dschuler/nrf52pf
Add presentation format descriptor support for nRF5x
2 parents 280d491 + 271b09c commit 7be79f9

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/btle/custom/custom_helper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ error_t custom_add_in_characteristic(uint16_t service_handle,
210210
bool has_variable_len,
211211
const uint8_t *userDescriptionDescriptorValuePtr,
212212
uint16_t userDescriptionDescriptorValueLen,
213+
const uint8_t *presentationFormatDescriptorValuePtr,
214+
uint16_t presentationFormatDescriptorValueLen,
213215
bool readAuthorization,
214216
bool writeAuthorization,
215217
ble_gatts_char_handles_t *p_char_handle)
@@ -238,6 +240,11 @@ error_t custom_add_in_characteristic(uint16_t service_handle,
238240
char_md.char_user_desc_max_size = userDescriptionDescriptorValueLen;
239241
char_md.char_user_desc_size = userDescriptionDescriptorValueLen;
240242
}
243+
if ((presentationFormatDescriptorValueLen > 0) && (presentationFormatDescriptorValuePtr != NULL)) {
244+
ASSERT_TRUE( sizeof(ble_gatts_char_pf_t) == sizeof(GattCharacteristic::PresentationFormat_t), ERROR_INVALID_PARAM );
245+
ASSERT_TRUE( presentationFormatDescriptorValueLen == sizeof(GattCharacteristic::PresentationFormat_t), ERROR_INVALID_PARAM );
246+
char_md.p_char_pf = const_cast<ble_gatts_char_pf_t *>(reinterpret_cast<const ble_gatts_char_pf_t *>(presentationFormatDescriptorValuePtr));
247+
}
241248

242249
/* Attribute declaration */
243250
ble_gatts_attr_md_t attr_md = {0};

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/btle/custom/custom_helper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ error_t custom_add_in_characteristic(uint16_t service_handle,
5252
bool has_variable_len,
5353
const uint8_t *userDescriptionDescriptorValuePtr,
5454
uint16_t userDescriptionDescriptorValueLen,
55+
const uint8_t *presentationFormatDescriptorValuePtr,
56+
uint16_t presentationFormatDescriptorValueLen,
5557
bool readAuthorization,
5658
bool writeAuthorization,
5759
ble_gatts_char_handles_t *p_char_handle);

features/FEATURE_BLE/targets/TARGET_NORDIC/TARGET_NRF5/source/nRF5xGattServer.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
131131
}
132132
GattCharacteristic *p_char = service.getCharacteristic(i);
133133
GattAttribute *p_description_descriptor = NULL;
134+
GattAttribute *p_presentation_format_descriptor = NULL;
134135

135136
/* Skip any incompletely defined, read-only characteristics. */
136137
if ((p_char->getValueAttribute().getValuePtr() == NULL) &&
@@ -141,18 +142,25 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
141142

142143
nordicUUID = custom_convert_to_nordic_uuid(p_char->getValueAttribute().getUUID());
143144

144-
/* The user-description descriptor is a special case which needs to be
145-
* handled at the time of adding the characteristic. The following block
146-
* is meant to discover its presence. */
145+
/* The user-description and presentation-format descriptors are special cases
146+
* that need to be handled at the time of adding each characteristic. The
147+
* following block is meant to discover their presence. */
147148
const uint8_t *userDescriptionDescriptorValuePtr = NULL;
148149
uint16_t userDescriptionDescriptorValueLen = 0;
150+
const uint8_t *presentationFormatDescriptorValuePtr = NULL;
151+
uint16_t presentationFormatDescriptorValueLen = 0;
149152
for (uint8_t j = 0; j < p_char->getDescriptorCount(); j++) {
150153
GattAttribute *p_desc = p_char->getDescriptor(j);
151154
if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) {
152155
p_description_descriptor = p_desc;
153156
userDescriptionDescriptorValuePtr = p_desc->getValuePtr();
154157
userDescriptionDescriptorValueLen = p_desc->getLength();
155158
}
159+
if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT) {
160+
p_presentation_format_descriptor = p_desc;
161+
presentationFormatDescriptorValuePtr = p_desc->getValuePtr();
162+
presentationFormatDescriptorValueLen = p_desc->getLength();
163+
}
156164
}
157165

158166
ASSERT_TRUE ( ERROR_NONE ==
@@ -166,6 +174,8 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
166174
p_char->getValueAttribute().hasVariableLength(),
167175
userDescriptionDescriptorValuePtr,
168176
userDescriptionDescriptorValueLen,
177+
presentationFormatDescriptorValuePtr,
178+
presentationFormatDescriptorValueLen,
169179
p_char->isReadAuthorizationEnabled(),
170180
p_char->isWriteAuthorizationEnabled(),
171181
&nrfCharacteristicHandles[characteristicCount]),
@@ -179,6 +189,10 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
179189
nrfCharacteristicHandles[characteristicCount].user_desc_handle
180190
);
181191
}
192+
if (p_presentation_format_descriptor) {
193+
// The handle is not available from the SoftDevice
194+
p_presentation_format_descriptor->setHandle(GattAttribute::INVALID_HANDLE);
195+
}
182196
characteristicCount++;
183197

184198
/* Add optional descriptors if any */
@@ -188,8 +202,10 @@ ble_error_t nRF5xGattServer::addService(GattService &service)
188202
}
189203

190204
GattAttribute *p_desc = p_char->getDescriptor(j);
191-
/* skip the user-description-descriptor here; this has already been handled when adding the characteristic (above). */
192-
if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC) {
205+
/* skip the user-description or presentation-format descriptor here;
206+
* they have already been handled when adding the characteristic (above). */
207+
if (p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_USER_DESC
208+
|| p_desc->getUUID() == BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT) {
193209
continue;
194210
}
195211

0 commit comments

Comments
 (0)