Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: microbit-dal microbit-dal microbit-ble-open microbit-dal ... more
Fork of BLE_API by
Diff: services/DFUService.h
- Revision:
- 119:18684018b83e
- Parent:
- 118:620d28e7a1ba
- Child:
- 120:467527c1b943
--- a/services/DFUService.h Mon Sep 22 10:59:09 2014 +0100
+++ b/services/DFUService.h Fri Sep 26 14:28:59 2014 +0100
@@ -28,13 +28,14 @@
extern const uint8_t DFUServiceUUID[];
extern const uint8_t DFUServiceControlCharacteristicUUID[];
+extern const uint8_t DFUServicePacketCharacteristicUUID[];
class DFUService {
public:
/**
* Signature for the handover callback. The application may provide such a
* callback when setting up the DFU service, in which case it will be
- * invoked before handing control over to the Bootloader.
+ * invoked before handing control over to the bootloader.
*/
typedef void (*ResetPrepare_t)(void);
@@ -43,13 +44,15 @@
ble(_ble),
controlBytes(),
controlPoint(DFUServiceControlCharacteristicUUID, controlBytes, SIZEOF_CONTROL_BYTES, SIZEOF_CONTROL_BYTES,
- GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {
+ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
+ packet(DFUServicePacketCharacteristicUUID, packetBytes, SIZEOF_PACKET_BYTES, SIZEOF_PACKET_BYTES,
+ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE) {
static bool serviceAdded = false; /* We should only ever need to add the DFU service once. */
if (serviceAdded) {
return;
}
- GattCharacteristic *dfuChars[] = {&controlPoint};
+ GattCharacteristic *dfuChars[] = {&controlPoint, &packet};
GattService dfuService(DFUServiceUUID, dfuChars, sizeof(dfuChars) / sizeof(GattCharacteristic *));
ble.addService(dfuService);
@@ -70,6 +73,7 @@
*/
virtual void onDataWritten(const GattCharacteristicWriteCBParams *params) {
if (params->charHandle == controlPoint.getValueAttribute().getHandle()) {
+ /* At present, writing anything will do the trick--this needs to be improved. */
if (handoverCallback) {
handoverCallback();
}
@@ -80,13 +84,26 @@
private:
static const unsigned SIZEOF_CONTROL_BYTES = 2;
+ static const unsigned SIZEOF_PACKET_BYTES = 20;
static ResetPrepare_t handoverCallback; /**< application specific handover callback. */
private:
BLEDevice &ble;
uint8_t controlBytes[SIZEOF_CONTROL_BYTES];
+ uint8_t packetBytes[SIZEOF_PACKET_BYTES];
+
+ /**< Writing to the control characteristic triggers the handover to dfu-
+ * bootloader. At present, writing anything will do the trick--this needs
+ * to be improved. */
GattCharacteristic controlPoint;
+
+ /**< The packet characteristic in this service doesn't do anything meaningful, but
+ * is only a placeholder to mimic the corresponding characteristic in the
+ * actual DFU service implemented by the bootloader. Without this, some
+ * FOTA clients might get confused as service definitions change after
+ * handing control over to the bootloader. */
+ GattCharacteristic packet;
};
#endif /* #ifndef __BLE_DFU_SERVICE_H__*/
