/** * The nRF transport has its own 3-byte representation of a UUID. If the user- * specified UUID is 128-bits wide, then the UUID base needs to be added to the * soft-device and converted to a 3-byte handle before being used further. This * function is responsible for this translation of user-specified UUIDs into * nRF's representation. * * @param[in] uuid * user-specified UUID * @return nRF * 3-byte UUID (containing a type and 16-bit UUID) representation * to be used with SVC calls. */ ble_uuid_t custom_convert_to_nordic_uuid(const UUID &uuid) { ble_uuid_t nordicUUID; nordicUUID.uuid = uuid.getShortUUID(); nordicUUID.type = BLE_UUID_TYPE_UNKNOWN; /* to be set below */ if (uuid.shortOrLong() == UUID::UUID_TYPE_SHORT) { nordicUUID.type = BLE_UUID_TYPE_BLE; } else { if (!lookupConvertedUUIDTable(uuid.getBaseUUID(), &nordicUUID.type)) { nordicUUID.type = custom_add_uuid_base(uuid.getBaseUUID()); addToConvertedUUIDTable(uuid.getBaseUUID(), nordicUUID.type); } } return nordicUUID; }
ble_error_t BlueNRGGattClient::launchServiceDiscovery(Gap::Handle_t connectionHandle, ServiceDiscovery::ServiceCallback_t sc, ServiceDiscovery::CharacteristicCallback_t cc, const UUID &matchingServiceUUID, const UUID &matchingCharacteristicUUIDIn) { PRINTF("launchServiceDiscovery\n\r"); tBleStatus ret; uint8_t uuid_type = UUID_TYPE_16; uint8_t short_uuid[2]; uint8_t *uuid = NULL; unsigned j; _connectionHandle = connectionHandle; serviceDiscoveryCallback = sc; characteristicDiscoveryCallback = cc; _matchingServiceUUID = matchingServiceUUID; _matchingCharacteristicUUIDIn = matchingCharacteristicUUIDIn; //reset services _numServices = 0; _numChars = 0; _servIndex = 0; for(j = 0; j < BLE_TOTAL_DISCOVERED_SERVICES; j++) { discoveredService[j].setup(BLE_UUID_UNKNOWN, GattAttribute::INVALID_HANDLE, GattAttribute::INVALID_HANDLE); } if(matchingServiceUUID == BLE_UUID_UNKNOWN) { // Wildcard: search for all services ret = aci_gatt_disc_all_prim_services((uint16_t)connectionHandle); } else { uint8_t type = matchingServiceUUID.shortOrLong(); //PRINTF("AddService(): Type:%d\n\r", type); if(type == UUID::UUID_TYPE_SHORT) { STORE_LE_16(short_uuid, matchingServiceUUID.getShortUUID()); PRINTF("launchServiceDiscovery short_uuid=0x"); for(j = 0; j < 2; j++) { PRINTF("%02X", short_uuid[j]); } PRINTF("\n\r"); uuid_type = UUID_TYPE_16; uuid = short_uuid; } else if(type==UUID::UUID_TYPE_LONG) { uuid_type = UUID_TYPE_128; uuid = (unsigned char*)matchingServiceUUID.getBaseUUID(); /* PRINTF("launchServiceDiscovery base_uuid=0x"); for(j = 0; j < 16; j++) { PRINTF("%02X", uuid[j]); } PRINTF("\n\r"); */ } // search for specific service by UUID ret = aci_gatt_disc_prim_service_by_uuid((uint16_t)connectionHandle, uuid_type, uuid); //ret = aci_gatt_disc_all_prim_services((uint16_t)connectionHandle); } if(ret == BLE_STATUS_SUCCESS) { _currentState = GATT_SERVICE_DISCOVERY; } PRINTF("launchServiceDiscovery ret=%d\n\r", ret); return BLE_ERROR_NONE; }