rename remainingCharacteristic member, now it is named

discoveredCharacteristic. Add doc to the discovery process and the
rationale behind discoveredCharacteristic member.
This commit is contained in:
Vincent Coubard 2015-12-15 09:54:25 +00:00
parent eb5ca3806d
commit 59ced0b4b1
2 changed files with 33 additions and 23 deletions

View file

@ -49,8 +49,8 @@ nRF5xServiceDiscovery::launchCharacteristicDiscovery(Gap::Handle_t connectionHan
break;
}
if(err) {
terminateCharacteristicDiscovery(err);
if (err) {
terminateCharacteristicDiscovery(err);
}
return err;
}
@ -123,31 +123,31 @@ nRF5xServiceDiscovery::setupDiscoveredCharacteristics(const ble_gattc_evt_char_d
void
nRF5xServiceDiscovery::progressCharacteristicDiscovery(void)
{
if(state != CHARACTERISTIC_DISCOVERY_ACTIVE) {
if (state != CHARACTERISTIC_DISCOVERY_ACTIVE) {
return;
}
if(remainingCharacteristic != nRF5xDiscoveredCharacteristic() && numCharacteristics > 0) {
remainingCharacteristic.setLastHandle(characteristics[0].getDeclHandle() - 1);
if ((discoveredCharacteristic != nRF5xDiscoveredCharacteristic()) && (numCharacteristics > 0)) {
discoveredCharacteristic.setLastHandle(characteristics[0].getDeclHandle() - 1);
if ((matchingCharacteristicUUID == UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) ||
((matchingCharacteristicUUID == remainingCharacteristic.getUUID()) &&
((matchingCharacteristicUUID == discoveredCharacteristic.getUUID()) &&
(matchingServiceUUID != UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)))) {
if (characteristicCallback) {
characteristicCallback(&remainingCharacteristic);
characteristicCallback(&discoveredCharacteristic);
}
}
}
for(uint8_t i = 0; i < numCharacteristics; ++i) {
if(state != CHARACTERISTIC_DISCOVERY_ACTIVE) {
for (uint8_t i = 0; i < numCharacteristics; ++i) {
if (state != CHARACTERISTIC_DISCOVERY_ACTIVE) {
return;
}
if(i == numCharacteristics - 1) {
remainingCharacteristic = characteristics[i];
if (i == (numCharacteristics - 1)) {
discoveredCharacteristic = characteristics[i];
break;
} else {
} else {
characteristics[i].setLastHandle(characteristics[i + 1].getDeclHandle() - 1);
}
@ -160,11 +160,10 @@ nRF5xServiceDiscovery::progressCharacteristicDiscovery(void)
}
}
if(state != CHARACTERISTIC_DISCOVERY_ACTIVE) {
if (state != CHARACTERISTIC_DISCOVERY_ACTIVE) {
return;
}
Gap::Handle_t startHandle = (numCharacteristics > 0) ? characteristics[numCharacteristics - 1].getValueHandle() + 1 : SRV_DISC_END_HANDLE;
Gap::Handle_t endHandle = services[serviceIndex].getEndHandle();
resetDiscoveredCharacteristics(); /* Note: resetDiscoveredCharacteristics() must come after fetching start and end Handles. */

View file

@ -94,8 +94,8 @@ public:
terminateServiceDiscovery();
}
void terminate(Gap::Handle_t connectionHandle) {
if(connHandle == connectionHandle) {
void terminate(Gap::Handle_t connectionHandle) {
if(connHandle == connectionHandle) {
terminate();
}
}
@ -116,7 +116,7 @@ private:
void removeFirstServiceNeedingUUIDDiscovery(void);
void terminateServiceDiscovery(void) {
remainingCharacteristic = nRF5xDiscoveredCharacteristic();
discoveredCharacteristic = nRF5xDiscoveredCharacteristic();
bool wasActive = isActive();
state = INACTIVE;
@ -128,20 +128,20 @@ private:
void terminateCharacteristicDiscovery(ble_error_t err) {
if (state == CHARACTERISTIC_DISCOVERY_ACTIVE) {
if(remainingCharacteristic != nRF5xDiscoveredCharacteristic()) {
if(discoveredCharacteristic != nRF5xDiscoveredCharacteristic()) {
if(err == BLE_ERROR_NONE) {
// fullfill the last characteristic
remainingCharacteristic.setLastHandle(services[serviceIndex].getEndHandle());
discoveredCharacteristic.setLastHandle(services[serviceIndex].getEndHandle());
if ((matchingCharacteristicUUID == UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) ||
((matchingCharacteristicUUID == remainingCharacteristic.getUUID()) &&
((matchingCharacteristicUUID == discoveredCharacteristic.getUUID()) &&
(matchingServiceUUID != UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)))) {
if (characteristicCallback) {
characteristicCallback(&remainingCharacteristic);
characteristicCallback(&discoveredCharacteristic);
}
}
}
remainingCharacteristic = nRF5xDiscoveredCharacteristic();
discoveredCharacteristic = nRF5xDiscoveredCharacteristic();
}
state = SERVICE_DISCOVERY_ACTIVE;
@ -322,7 +322,18 @@ private:
TerminationCallback_t onTerminationCallback;
nRF5xDiscoveredCharacteristic remainingCharacteristic;
/*
* The currently discovered characteristic. Discovery of a characteristic
* is a two phase process.
* First, declaration handle is fetched, it provide the UUID, the value handle and
* the properties of a characteristic.
* Second, the next declaration handle is fetched, with its declaration handle, it is
* possible to compute the last handle of the discovered characteristic and fill the
* missing part of the object.
* If there is no remaining characteristic to discover, the last handle of the
* discovered characteristic will be set to the last handle of its enclosing service.
*/
nRF5xDiscoveredCharacteristic discoveredCharacteristic;
};
#endif /*__NRF_SERVICE_DISCOVERY_H__*/