forked from arduino-libraries/ArduinoBLE
-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
This is likely in the main branch but I will enter it here to see if it can be incorporated here. Let me know if I have to work with whoever manages main Arduino BLE
Problem. Noticed that the Notify and Indicate were always seen as Disabled in my Win App. I dug into the ArduinoBLE code and found the following bug
BLELocalCharacteristic constructor (line 32 in BLELocalCharacteristic.cpp)
- The Notify and Indicate are checked to determine if a Client Characteristic Config Descriptor is to be created
- But the actual value for the Descriptor are never initialized
Existing constructor body
BLELocalCharacteristic::BLELocalCharacteristic(const char* uuid, uint16_t permissions, int valueSize, bool fixedLength) :
BLELocalAttribute(uuid),
_properties((uint8_t)(permissions&0x000FF)),
_valueSize(min(valueSize, 512)),
_valueLength(0),
_fixedLength(fixedLength),
_handle(0x0000),
_broadcast(false),
_written(false),
_cccdValue(0x0000),
_permissions((uint8_t)((permissions&0xFF00)>>8))
{
memset(_eventHandlers, 0x00, sizeof(_eventHandlers));
if (permissions & (BLENotify | BLEIndicate)) {
BLELocalDescriptor* cccd = new BLELocalDescriptor("2902", (uint8_t*)&_cccdValue, sizeof(_cccdValue));
_descriptors.add(cccd);
}
_value = (uint8_t*)malloc(valueSize);
}
My change to set the proper bits for the Notify and Indicate
BLELocalCharacteristic::BLELocalCharacteristic(const char* uuid, uint16_t permissions, int valueSize, bool fixedLength) :
BLELocalAttribute(uuid),
_properties((uint8_t)(permissions&0x000FF)),
_valueSize(min(valueSize, 512)),
_valueLength(0),
_fixedLength(fixedLength),
_handle(0x0000),
_broadcast(false),
_written(false),
_cccdValue(0x0000),
_permissions((uint8_t)((permissions&0xFF00)>>8))
{
memset(_eventHandlers, 0x00, sizeof(_eventHandlers));
if (permissions & (BLENotify | BLEIndicate)) {
// *** Start of change
// Set the bits for the Client Characteristic Config descriptor so Notify and Indicate are visible
if (permissions & BLENotify) {
_cccdValue = _cccdValue ^ 0x0001;
}
if (permissions & BLEIndicate) {
_cccdValue = _cccdValue ^ 0x0002;
}
// *** End of change
BLELocalDescriptor* cccd = new BLELocalDescriptor("2902", (uint8_t*)&_cccdValue, sizeof(_cccdValue));
_descriptors.add(cccd);
}
_value = (uint8_t*)malloc(valueSize);
}
Metadata
Metadata
Assignees
Labels
No labels