@@ -28,13 +28,14 @@ extern const uint16_t DFUServiceControlCharacteristicShortUUID;
28
28
29
29
extern const uint8_t DFUServiceUUID[];
30
30
extern const uint8_t DFUServiceControlCharacteristicUUID[];
31
+ extern const uint8_t DFUServicePacketCharacteristicUUID[];
31
32
32
33
class DFUService {
33
34
public:
34
35
/* *
35
36
* Signature for the handover callback. The application may provide such a
36
37
* callback when setting up the DFU service, in which case it will be
37
- * invoked before handing control over to the Bootloader .
38
+ * invoked before handing control over to the bootloader .
38
39
*/
39
40
typedef void (*ResetPrepare_t)(void );
40
41
@@ -43,13 +44,15 @@ class DFUService {
43
44
ble (_ble),
44
45
controlBytes (),
45
46
controlPoint (DFUServiceControlCharacteristicUUID, controlBytes, SIZEOF_CONTROL_BYTES, SIZEOF_CONTROL_BYTES,
46
- GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY) {
47
+ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY),
48
+ packet (DFUServicePacketCharacteristicUUID, packetBytes, SIZEOF_PACKET_BYTES, SIZEOF_PACKET_BYTES,
49
+ GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE) {
47
50
static bool serviceAdded = false ; /* We should only ever need to add the DFU service once. */
48
51
if (serviceAdded) {
49
52
return ;
50
53
}
51
54
52
- GattCharacteristic *dfuChars[] = {&controlPoint};
55
+ GattCharacteristic *dfuChars[] = {&controlPoint, &packet };
53
56
GattService dfuService (DFUServiceUUID, dfuChars, sizeof (dfuChars) / sizeof (GattCharacteristic *));
54
57
55
58
ble.addService (dfuService);
@@ -70,6 +73,7 @@ class DFUService {
70
73
*/
71
74
virtual void onDataWritten (const GattCharacteristicWriteCBParams *params) {
72
75
if (params->charHandle == controlPoint.getValueAttribute ().getHandle ()) {
76
+ /* At present, writing anything will do the trick--this needs to be improved. */
73
77
if (handoverCallback) {
74
78
handoverCallback ();
75
79
}
@@ -80,13 +84,26 @@ class DFUService {
80
84
81
85
private:
82
86
static const unsigned SIZEOF_CONTROL_BYTES = 2 ;
87
+ static const unsigned SIZEOF_PACKET_BYTES = 20 ;
83
88
84
89
static ResetPrepare_t handoverCallback; /* *< application specific handover callback. */
85
90
86
91
private:
87
92
BLEDevice &ble;
88
93
uint8_t controlBytes[SIZEOF_CONTROL_BYTES];
94
+ uint8_t packetBytes[SIZEOF_PACKET_BYTES];
95
+
96
+ /* *< Writing to the control characteristic triggers the handover to dfu-
97
+ * bootloader. At present, writing anything will do the trick--this needs
98
+ * to be improved. */
89
99
GattCharacteristic controlPoint;
100
+
101
+ /* *< The packet characteristic in this service doesn't do anything meaningful, but
102
+ * is only a placeholder to mimic the corresponding characteristic in the
103
+ * actual DFU service implemented by the bootloader. Without this, some
104
+ * FOTA clients might get confused as service definitions change after
105
+ * handing control over to the bootloader. */
106
+ GattCharacteristic packet;
90
107
};
91
108
92
109
#endif /* #ifndef __BLE_DFU_SERVICE_H__*/
0 commit comments