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.
Fork of BLE_API by
Revision 119:18684018b83e, committed 2014-09-26
- Comitter:
- Rohit Grover
- Date:
- Fri Sep 26 14:28:59 2014 +0100
- Parent:
- 118:620d28e7a1ba
- Child:
- 120:467527c1b943
- Commit message:
- Add the packet characteristic to the DFU Service.
This helps mimic the layout of the actual DFU service in the
dfu-bootloader. Without this, some FOTA clients might get confused as
service definitions change after handing control over to the
bootloader.
Changed in this revision
| services/DFUService.cpp | Show annotated file Show diff for this revision Revisions of this file |
| services/DFUService.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/services/DFUService.cpp Mon Sep 22 10:59:09 2014 +0100
+++ b/services/DFUService.cpp Fri Sep 26 14:28:59 2014 +0100
@@ -22,6 +22,7 @@
};
const uint16_t DFUServiceShortUUID = 0x1530;
const uint16_t DFUServiceControlCharacteristicShortUUID = 0x1531;
+const uint16_t DFUServicePacketCharacteristicShortUUID = 0x1532;
const uint8_t DFUServiceUUID[] = {
0x00, 0x00, (uint8_t)(DFUServiceShortUUID >> 8), (uint8_t)(DFUServiceShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE,
@@ -31,5 +32,9 @@
0x00, 0x00, (uint8_t)(DFUServiceControlCharacteristicShortUUID >> 8), (uint8_t)(DFUServiceControlCharacteristicShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE,
0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23,
};
+const uint8_t DFUServicePacketCharacteristicUUID[] = {
+ 0x00, 0x00, (uint8_t)(DFUServicePacketCharacteristicShortUUID >> 8), (uint8_t)(DFUServicePacketCharacteristicShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE,
+ 0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23,
+};
DFUService::ResetPrepare_t DFUService::handoverCallback = NULL;
--- 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__*/
