Part 1
요약·해설
Service·attribute helper 9개, server 절차와 client discovery·read·write·subscribe를 보존했습니다.
Service · attribute
Notify · indicate
Discover · read · write
3
Part 2
접을 수 있는 영어 원문 전체
영어 원문 전체 펼치기
EB768B5EEF0E134227052630E8510B41528A9266672C0A9D77BE4E04F04BD8AE
.. _bt_gatt:
Generic Attribute Profile (GATT)
################################
GATT layer manages the service database providing APIs for service registration
and attribute declaration.
Services can be registered using :c:func:`bt_gatt_service_register` API
which takes the :c:struct:`bt_gatt_service` struct that provides the list of
attributes the service contains. The helper macro :c:macro:`BT_GATT_SERVICE()`
can be used to declare a service.
Attributes can be declared using the :c:struct:`bt_gatt_attr` struct or using
one of the helper macros:
:c:macro:`BT_GATT_PRIMARY_SERVICE`
Declares a Primary Service.
:c:macro:`BT_GATT_SECONDARY_SERVICE`
Declares a Secondary Service.
:c:macro:`BT_GATT_INCLUDE_SERVICE`
Declares a Include Service.
:c:macro:`BT_GATT_CHARACTERISTIC`
Declares a Characteristic.
:c:macro:`BT_GATT_DESCRIPTOR`
Declares a Descriptor.
:c:macro:`BT_GATT_ATTRIBUTE`
Declares an Attribute.
:c:macro:`BT_GATT_CCC`
Declares a Client Characteristic Configuration.
:c:macro:`BT_GATT_CEP`
Declares a Characteristic Extended Properties.
:c:macro:`BT_GATT_CUD`
Declares a Characteristic User Format.
Each attribute contain a ``uuid``, which describes their type, a ``read``
callback, a ``write`` callback and a set of permission. Both read and write
callbacks can be set to NULL if the attribute permission don't allow their
respective operations.
.. note::
32-bit UUIDs are not supported in GATT. All 32-bit UUIDs shall be converted
to 128-bit UUIDs when the UUID is contained in an ATT PDU.
.. note::
Attribute ``read`` and ``write`` callbacks are called directly from RX Thread
thus it is not recommended to block for long periods of time in them.
Attribute value changes can be notified using :c:func:`bt_gatt_notify` API,
alternatively there is :c:func:`bt_gatt_notify_cb` where it is possible to
pass a callback to be called when it is necessary to know the exact instant when
the data has been transmitted over the air. Indications are supported by
:c:func:`bt_gatt_indicate` API.
Client procedures can be enabled with the configuration option:
:kconfig:option:`CONFIG_BT_GATT_CLIENT`
Discover procedures can be initiated with the use of
:c:func:`bt_gatt_discover` API which takes the
:c:struct:`bt_gatt_discover_params` struct which describes the type of
discovery. The parameters also serves as a filter when setting the ``uuid``
field only attributes which matches will be discovered, in contrast setting it
to NULL allows all attributes to be discovered.
.. note::
Caching discovered attributes is not supported.
Read procedures are supported by :c:func:`bt_gatt_read` API which takes the
:c:struct:`bt_gatt_read_params` struct as parameters. In the parameters one or
more attributes can be set, though setting multiple handles requires the option:
:kconfig:option:`CONFIG_BT_GATT_READ_MULTIPLE`
Write procedures are supported by :c:func:`bt_gatt_write` API and takes
:c:struct:`bt_gatt_write_params` struct as parameters. In case the write
operation don't require a response :c:func:`bt_gatt_write_without_response`
or :c:func:`bt_gatt_write_without_response_cb` APIs can be used, with the
later working similarly to :c:func:`bt_gatt_notify_cb`.
Subscriptions to notification and indication can be initiated with use of
:c:func:`bt_gatt_subscribe` API which takes
:c:struct:`bt_gatt_subscribe_params` as parameters. Multiple subscriptions to
the same attribute are supported so there could be multiple ``notify`` callback
being triggered for the same attribute. Subscriptions can be removed with use of
:c:func:`bt_gatt_unsubscribe` API.
.. note::
When subscriptions are removed ``notify`` callback is called with the data
set to NULL.
API Reference
*************
.. doxygengroup:: bt_gatt
GATT Server
===========
.. doxygengroup:: bt_gatt_server
GATT Client
===========
.. doxygengroup:: bt_gatt_client
Part 3
한국어 전문 번역
Generic Attribute Profile
GATT layer는 service database를 관리하며 service 등록과 attribute 선언 API를 제공합니다.
Service 등록
bt_gatt_service_register는 service의 attribute 목록을 가진 bt_gatt_service를 받아 runtime에 등록합니다. BT_GATT_SERVICE() helper macro로 service를 선언할 수도 있습니다.
Attribute 선언
Attribute는 bt_gatt_attr struct를 직접 사용하거나 다음 helper macro로 선언합니다.
BT_GATT_PRIMARY_SERVICE: Primary ServiceBT_GATT_SECONDARY_SERVICE: Secondary ServiceBT_GATT_INCLUDE_SERVICE: Included ServiceBT_GATT_CHARACTERISTIC: CharacteristicBT_GATT_DESCRIPTOR: DescriptorBT_GATT_ATTRIBUTE: 일반 AttributeBT_GATT_CCC: Client Characteristic ConfigurationBT_GATT_CEP: Characteristic Extended PropertiesBT_GATT_CUD: Characteristic User Description
각 attribute는 type을 나타내는 uuid, read callback, write callback과 permission set을 가집니다. 해당 operation을 permission에서 허용하지 않으면 read 또는 write callback을 NULL로 둘 수 있습니다.
Server notification과 indication
Attribute value 변경은 bt_gatt_notify로 notification을 보냅니다. Data가 air로 전송된 정확한 시점을 알아야 하면 transmission callback을 받는 bt_gatt_notify_cb를 사용합니다. 확인 응답이 필요한 indication은 bt_gatt_indicate가 지원합니다.
GATT Client
Client procedure는 CONFIG_BT_GATT_CLIENT로 활성화합니다.
Discovery
bt_gatt_discover는 discovery type을 기술한 bt_gatt_discover_params를 받습니다. uuid field를 설정하면 일치하는 attribute만 발견하고 NULL이면 모두 발견합니다.
Read
bt_gatt_read는 bt_gatt_read_params로 하나 이상의 attribute를 읽습니다. Handle 여러 개를 한 procedure로 읽으려면 CONFIG_BT_GATT_READ_MULTIPLE이 필요합니다.
Write
bt_gatt_write는 bt_gatt_write_params로 response가 있는 write를 수행합니다. Response가 필요 없으면 bt_gatt_write_without_response를 사용하고, 전송 완료 callback이 필요하면 bt_gatt_write_without_response_cb를 사용합니다.
Notification·indication subscribe
bt_gatt_subscribe는 bt_gatt_subscribe_params로 subscription을 등록합니다. 같은 attribute에 여러 subscription을 만들 수 있어 한 notification이 여러 notify callback을 호출할 수 있습니다. 해제는 bt_gatt_unsubscribe를 사용합니다.
API Reference
bt_gatt: 공통 GATT APIbt_gatt_server: GATT Server APIbt_gatt_client: GATT Client API
Source
출처
영어 원문에는 문단, 문서 지시문, 표, 코드, 코드 심벌, 경로를 그대로 보존했습니다.