Open
Description
hardware used:
BLE client: ESP-WROOM-32
BLE server: quarq power meter
When calling discoverAttributs the function discoverDescriptors in ATT.cpp turns into an infinite loop.
I added a breaker to prevent this. Maybe someone with more skills can solve this more nicely..
>bool ATTClass::discoverDescriptors(uint16_t connectionHandle, BLERemoteDevice* device)
> {
> //Serial.println("discoverDescriptors");
> uint16_t reqStartHandle = 0x0001;
> uint16_t reqEndHandle = 0xffff;
> uint8_t responseBuffer[_maxMtu];
>
> int serviceCount = device->serviceCount();
>
> for (int i = 0; i < serviceCount; i++) {
> BLERemoteService* service = device->service(i);
>
> uint16_t serviceEndHandle = service->endHandle();
> int characteristicCount = service->characteristicCount();
> for (int j = 0; j < characteristicCount; j++) {
> BLERemoteCharacteristic* characteristic = service->characteristic(j);
> BLERemoteCharacteristic* nextCharacteristic = (j == (characteristicCount - 1)) ? NULL : service->characteristic(j + 1);
>
> reqStartHandle = characteristic->valueHandle() + 1;
> reqEndHandle = nextCharacteristic ? nextCharacteristic->valueHandle() : serviceEndHandle;
>
> if (reqStartHandle > reqEndHandle) {
> continue;
> }
> int brkr=0;
> while (1) {
> brkr+=1;
>
> int respLength = findInfoReq(connectionHandle, reqStartHandle, reqEndHandle, responseBuffer);
>
> if (brkr==50) {
> // Serial.println("breaker");
> //Serial.println(respLength );
> //Serial.println(responseBuffer[0] );
> break;
> }
> if (respLength == 0) {
> return false;
> }
>
> if (responseBuffer[0] == ATT_OP_FIND_INFO_RESP) {
> uint16_t lengthPerDescriptor = responseBuffer[1] * 4;
> uint8_t uuidLen = 2;
>
> for (int i = 2; i < respLength; i += lengthPerDescriptor) {
> struct __attribute__ ((packed)) RawDescriptor {
> uint16_t handle;
> uint8_t uuid[16];
> } *rawDescriptor = (RawDescriptor*)&responseBuffer[i];
>
> BLERemoteDescriptor* descriptor = new BLERemoteDescriptor(rawDescriptor->uuid, uuidLen,
> connectionHandle,
> rawDescriptor->handle);
>
> if (descriptor == NULL) {
> return false;
> }
>
> characteristic->addDescriptor(descriptor);
> Serial.print("descriptor toegevoegd");
> reqStartHandle = rawDescriptor->handle + 1;
> }
> } else {
> break;
> }
> }
> }
> }
>
> return true;
> }
>
>
Metadata
Metadata
Assignees
Labels
No labels