Skip to content

Gatt server and client docs #555

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion docs/reference/api/connectivity/bluetooth/GattClient.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
## GattClient

[Add description here.]
GattClient defines procedures required for interacting with a remote GattServer.

#### Discovery procedures

A GattServer hosts a fixed set of services. These services are a logical composition of characteristics that may be discovered, read, or written, and can broadcast their state to a connected client. These characteristics may also contain metainformation and named characteristic descriptors. A characteristic descriptor may indicate the unit used for a characteristic value, describe the characteristic purpose in a textual form or allow a client to register for update notifications for the characteristic value.

Prior to any interaction with a server characteristic, a GattClient discovers the layout of the services and characteristics present on the server.

The layout of the descriptors of a characteristic may also be issued as an extra discovery step.

#### Attribute manipulation

As a result of the discovery process, the client can start interacting with the characteristic discovered. Depending on the characteristic properties (acquired during discovery), a client can read or write the value of a given characteristic.

Mbed BLE abstracts read and write operations to offer a single API that can be used to read or write characteristic values. The application code does not have to handle the necessary fragmentation/reassembly process if the attribute value to be transported cannot fit in a single data packet.

#### Server Initiated events

When a server updates a characteristic value it can forward the new value to any registered clients. Clients may register for these updates on a per characteristic basis. The updates are sent via notifications (no confirmation from client) or indications (client confirms receipt). This mechanism minimises the number of transactions between a client and a server by avoiding polling.

Clients register for these updates by setting the Client Characteristic Configuration Descriptor (CCCD) value. This is an attribute and the client needs to discover its descriptor. It is present in the characteristic if its notify or indicate properties are set.

### GattClient class reference

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have an example created for this?

Expand Down
26 changes: 25 additions & 1 deletion docs/reference/api/connectivity/bluetooth/GattServer.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,30 @@
## GattServer

[Add description here.]
A GattServer is a collection of GattServices. These services contain characteristics that a peer connected to the device may read or write. These characteristics may also emit updates to subscribed clients when their values change.

#### Server Layout

Application code can add a GattService object to the server with the help of the function `addService()`. That function registers all the GattCharacteristics enclosed in the service, as well as all the characteristic descriptors (see GattAttribute) that these characteristics contain. Service registration assigns a unique handle to the various attributes that are part of the service, and this handle should be used to subsequently read or write these components.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query: Who or what should use this handle to read or write these components?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The application. Code written by the user.


There are no defined primitives that remove a single service; however, a call to the function `reset()` removes all services previously registered in the GattServer.

#### Characteristic and attributes access

Values of the characteristic and the characteristic descriptor present in the GattServer must be accessed through the handle assigned to them when the service has been registered. The GattServer class offers several flavours of `read()` and `write()` functions that retrieve or mutate an attribute value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query: Who or what must access the values of the characteristic and the characteristic descriptor present in the GattServer? Also, who or what has registered the service?

Note to self: Remove the "u" from "flavors" for U.S. spelling.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user registers a service. When this happens a handle is created. This handle must be used to read and write the attribute both by the user code (local application) and by clients (remote applications).


If a client has subscribed to a given characteristic's value update, then the application code can query by invoking the function `areUpdatesEnabled()`.

#### Events

The GattServer allows application code to register several event handlers that can be used to monitor client and server activities:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query: Who or what can use the event handlers to monitor client and server activities? You, the user?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, application code means code written by users.

- `onDataSent`: Register an event handler that is called when a characteristic value update has been sent to a client.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query: Who or what calls the event handler? You, the user? Or someone else? Also, who or what sends a characteristic value update to a client?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record I find the naming confusing too. This function lets you register a handler. You, the user, call this function and pass in a handler that we, the GattServer will call later.

The server (our code) calls the handler you registered (users code).
The server sends updates to clients.

- `onDataWriten`: Register an event handler that is called when a client has written an attribute of the server.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query: Who or what calls the event handler? Also, who or what writes an attribute of the server?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server (our code) calls the handler you registered (users code).
Clients write attributes.

- `onDataRead`: Register an event handler that is called when a client has read an attribute of the server.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query: Who or what calls the event handler? Also, who or what reads an attribute of the server?

Copy link
Member Author

@paul-szczepanek-arm paul-szczepanek-arm Jun 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Server calls the handler when a client has read an attribute.
Clients read attributes.

- `onUpdatesEnabled`: Register an event handler that is called when a client subscribes to updates for a characteristic.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query: Who or what calls the event handler?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server (our code) calls the handler you registered (users code).

- `onUpdatesDisabled`: Register an event handler that is called when a client unsubscribes from updates for a characteristic.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query: Who or what calls the event handler?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server (our code) calls the handler you registered (users code).

- `onConfimationReceived`: Register an event handler that is called when a client acknowledges a characteristic value notification.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query: Who or what calls the event handler?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The server (our code) calls the handler you registered (users code).


The term characteristic value update is used to represent Characteristic Value Notification and Characteristic Value Indication when the nature of the server initiated is not relevant.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Query: Could we say "The term "characteristic value update" represents Characteristic..."?


### GattServer class reference

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have an example created for this?

Expand Down