Simple

abstract class Simple(serviceUuid: Uuid, name: String? = null) : Profile

A class representing a simple GATT profile, based on a single GATT service.

This is intended for profiles that have a single GATT service, i.e. Battery Profile.

In rare cases, a peripheral may have multiple instances of the same service, e.g. multiple batteries reporting their level, each with a different instance of a Battery Service. Override instance method to pick a desired instance of a remote service.

Note, that the list of services contains only GATT services with specified service UUID.

See Profile for a full worked example (LedButtonProfile).

Parameters

serviceUuid

The UUID of the GATT service.

name

The name of the profile. This is for convenience, used only in logging.

Constructors

Link copied to clipboard
constructor(serviceUuid: Uuid, name: String? = null)

Properties

Link copied to clipboard
val name: String?

The name of the profile. This is for convenience, used only in logging.

Functions

Link copied to clipboard
protected open suspend fun failed(peripheral: Peripheral<*, *>, reason: RemoteServices.Failed.Reason)

Notifies the profile implementation that service discovery has failed.

Link copied to clipboard
protected abstract suspend fun CoroutineScope.initialize(peripheral: Peripheral<*, *>)

This method should initialize the profile.

Link copied to clipboard
protected open fun instance(services: List<RemoteService>): RemoteService

This method should select a single service instance from the list of identical services returned by the service discovery.

Link copied to clipboard
protected abstract fun prepare(peripheral: Peripheral<*, *>, service: RemoteService)

Validates and prepares the services to be used in initialize.

Link copied to clipboard
protected open suspend fun unsupported(peripheral: Peripheral<*, *>)

Notifies the profile implementation, that the peripheral does not support the required profile services.