Detect writes to the DFU control characteristic and forward them separately to the DFU Service.
This commit is contained in:
parent
6d1b6e3f74
commit
4e2e9c1133
3 changed files with 26 additions and 4 deletions
|
@ -33,12 +33,12 @@ converted_uuid_table_entry_t convertedUUIDTable[UUID_TABLE_MAX_ENTRIES];
|
|||
|
||||
/**
|
||||
* lookup the cache of previously converted 128-bit UUIDs to find a type value.
|
||||
* @param uuid long UUID
|
||||
* @param uuid base 128-bit UUID
|
||||
* @param recoveredType the type field of the 3-byte nRF's uuid.
|
||||
* @return true if a match is found.
|
||||
*/
|
||||
static bool
|
||||
lookupConvertedUUIDTable(const LongUUIDBytes_t uuid, uint8_t *recoveredType)
|
||||
bool
|
||||
custom_lookupConvertedUUIDTable(const LongUUIDBytes_t uuid, uint8_t *recoveredType)
|
||||
{
|
||||
unsigned i;
|
||||
for (i = 0; i < uuidTableEntries; i++) {
|
||||
|
@ -86,7 +86,7 @@ ble_uuid_t custom_convert_to_nordic_uuid(const UUID &uuid)
|
|||
if (uuid.shortOrLong() == UUID::UUID_TYPE_SHORT) {
|
||||
nordicUUID.type = BLE_UUID_TYPE_BLE;
|
||||
} else {
|
||||
if (!lookupConvertedUUIDTable(uuid.getBaseUUID(), &nordicUUID.type)) {
|
||||
if (!custom_lookupConvertedUUIDTable(uuid.getBaseUUID(), &nordicUUID.type)) {
|
||||
nordicUUID.type = custom_add_uuid_base(uuid.getBaseUUID());
|
||||
addToConvertedUUIDTable(uuid.getBaseUUID(), nordicUUID.type);
|
||||
}
|
||||
|
|
|
@ -30,6 +30,14 @@ error_t custom_decode_uuid(uint8_t const *const p_uuid_base,
|
|||
ble_uuid_t *p_uuid);
|
||||
ble_uuid_t custom_convert_to_nordic_uuid(const UUID &uuid);
|
||||
|
||||
/**
|
||||
* lookup the cache of previously converted 128-bit UUIDs to find a type value.
|
||||
* @param uuid base 128-bit UUID
|
||||
* @param recoveredType the type field of the 3-byte nRF's uuid.
|
||||
* @return true if a match is found.
|
||||
*/
|
||||
bool custom_lookupConvertedUUIDTable(const LongUUIDBytes_t uuid, uint8_t *recoveredType);
|
||||
|
||||
error_t custom_add_in_characteristic(uint16_t service_handle,
|
||||
ble_uuid_t *p_uuid,
|
||||
uint8_t properties,
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "btle/custom/custom_helper.h"
|
||||
|
||||
#include "nRF51Gap.h"
|
||||
#include "DFUService.h"
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
|
@ -276,6 +277,19 @@ void nRF51GattServer::hwCallback(ble_evt_t *p_ble_evt)
|
|||
if (nrfCharacteristicHandles[i].value_handle == handle_value) {
|
||||
switch (eventType) {
|
||||
case GattServerEvents::GATT_EVENT_DATA_WRITTEN: {
|
||||
/* If DFUService has been employed, then filter writes to the DFU control
|
||||
* characteristic before any further callback processing. */
|
||||
uint8_t convertedDFUServiceUUIDType;
|
||||
if (custom_lookupConvertedUUIDTable(DFUServiceBaseUUID, &convertedDFUServiceUUIDType)) {
|
||||
if ((gattsEventP->params.write.context.srvc_uuid.type == convertedDFUServiceUUIDType) &&
|
||||
(gattsEventP->params.write.context.srvc_uuid.uuid == DFUServiceShortUUID) &&
|
||||
(gattsEventP->params.write.context.char_uuid.type == convertedDFUServiceUUIDType) &&
|
||||
(gattsEventP->params.write.context.char_uuid.uuid == DFUServiceControlCharacteristicShortUUID)) {
|
||||
DFUService::triggerHandoverToBooloader();
|
||||
break; /* the break here is un-necessary, we shouldn't return from the handover to the bootloader */
|
||||
}
|
||||
}
|
||||
|
||||
GattCharacteristicWriteCBParams cbParams = {
|
||||
.op = static_cast<GattCharacteristicWriteCBParams::Type>(gattsEventP->params.write.op),
|
||||
.offset = gattsEventP->params.write.offset,
|
||||
|
|
Loading…
Reference in a new issue