/** * 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 nRF51GattServer::addService(GattService & service) { /* ToDo: Make sure we don't overflow the array, etc. */ /* ToDo: Make sure this service UUID doesn't already exist (?) */ /* ToDo: Basic validation */ /* Add the service to the nRF51 */ ble_uuid_t uuid; if (service.primaryServiceID.type == UUID::UUID_TYPE_SHORT) { /* 16-bit BLE UUID */ uuid.type = BLE_UUID_TYPE_BLE; } else { /* 128-bit Custom UUID */ uuid.type = custom_add_uuid_base( service.primaryServiceID.base ); } uuid.uuid = service.primaryServiceID.value; ASSERT( ERROR_NONE == sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &uuid, &service.handle), BLE_ERROR_PARAM_OUT_OF_RANGE ); /* Add characteristics to the service */ for (uint8_t i = 0; i < service.characteristicCount; i++) { GattCharacteristic * p_char = service.characteristics[i]; uuid.uuid = p_char->uuid; ASSERT ( ERROR_NONE == custom_add_in_characteristic(service.handle, &uuid, p_char->properties, NULL, p_char->lenMin, p_char->lenMax, &nrfCharacteristicHandles[characteristicCount]), BLE_ERROR_PARAM_OUT_OF_RANGE ); /* Update the characteristic handle */ p_char->handle = characteristicCount; p_characteristics[characteristicCount++] = p_char; } serviceCount++; return BLE_ERROR_NONE; }