|
Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
|
Data Structures | |
| struct | bt_ets_elapsed_time |
| Elapsed Time data structure as defined in GATT Specification Supplement Section 3.82. More... | |
| struct | bt_ets_cb |
| Elapsed Time Service callback structure. More... | |
Macros | |
| #define | BT_ETS_SUPPORTED_FLAGS_MASK |
| Combined supported flags mask based on configuration. | |
| #define | BT_ETS_CLOCK_CAPABILITIES_VALUE |
| Clock capabilities (Elapsed Time Service - Section 3.1.1.3). | |
Enumerations | |
| enum | bt_ets_time_resolution { BT_ETS_RESOLUTION_1_SEC = 0 , BT_ETS_RESOLUTION_100_MS = 1 , BT_ETS_RESOLUTION_1_MS = 2 , BT_ETS_RESOLUTION_100_US = 3 } |
| Time resolution values for bits 2-3 of flags field. More... | |
| enum | bt_ets_write_result { BT_ETS_WRITE_SUCCESS = 0 , BT_ETS_WRITE_TIME_SOURCE_TOO_LOW = 1 , BT_ETS_WRITE_OUT_OF_RANGE = 2 , BT_ETS_WRITE_INCORRECT_FORMAT = 3 } |
| Write result codes for write_elapsed_time callback. More... | |
Functions | |
| int | bt_ets_init (const struct bt_ets_cb *cb) |
| Initialize Elapsed Time Service. | |
| int | bt_ets_indicate (const struct bt_ets_elapsed_time *elapsed_time, uint8_t clock_status) |
| Send indication to subscribed clients. | |
| int | bt_ets_time_to_unix_ms (const struct bt_ets_elapsed_time *et_time, int64_t *unix_ms) |
| Decode ETS formatted time into milliseconds since Unix epoch. | |
| int | bt_ets_time_from_unix_ms (struct bt_ets_elapsed_time *et_time, int64_t unix_ms, uint8_t time_src, int8_t tz_dst_offset) |
| Encode Unix milliseconds into ETS formatted time. | |
Elapsed Time Service Flags | |
Elapsed Time Service flags field bits (GATT Specification Supplement Section 3.82) | |
| #define | BT_ETS_FLAG_TICK_COUNTER BIT(0) |
| Time Value reports a counter (tick counter). | |
| #define | BT_ETS_FLAG_UTC BIT(1) |
| Time is UTC. | |
| #define | BT_ETS_FLAG_RESOLUTION_MASK (BIT(2) | BIT(3)) |
| Time resolution mask (bits 2-3). | |
| #define | BT_ETS_FLAG_TZ_DST_USED BIT(4) |
| TZ/DST offset is used. | |
| #define | BT_ETS_FLAG_CURRENT_TIMELINE BIT(5) |
| Time stamp is from current timeline. | |
| #define | BT_ETS_FLAG_RESERVED_MASK (BIT(6) | BIT(7)) |
| Reserved bits (6-7). | |
Time Source Values | |
Time synchronization source values (GATT Specification Supplement Section 3.243) | |
| #define | BT_ETS_TIME_SOURCE_UNKNOWN 0 |
| Unknown time source. | |
| #define | BT_ETS_TIME_SOURCE_NTP 1 |
| Network Time Protocol. | |
| #define | BT_ETS_TIME_SOURCE_GPS 2 |
| GPS/GNSS. | |
| #define | BT_ETS_TIME_SOURCE_RADIO 3 |
| Radio Time Signal. | |
| #define | BT_ETS_TIME_SOURCE_MANUAL 4 |
| Manually set. | |
| #define | BT_ETS_TIME_SOURCE_ATOMIC 5 |
| Atomic Clock. | |
| #define | BT_ETS_TIME_SOURCE_CELLULAR 6 |
| Cellular Network. | |
| #define | BT_ETS_TIME_SOURCE_NOT_SYNCHRONIZED 7 |
| Not synchronized. | |
Clock Status Flags | |
Clock Status flags (Elapsed Time Service - Section 3.1.1.2) | |
| #define | BT_ETS_CLOCK_STATUS_NEEDS_SET BIT(0) |
| Clock needs to be set. | |
| #define | BT_ETS_CLOCK_STATUS_RFU_MASK 0xFE |
| Clock Status RFU mask (bits 1-7). | |
Clock Capabilities flags (Elapsed Time Service - Section 3.1.1.3) | |
| #define | BT_ETS_CLOCK_CAP_DST_AUTO BIT(0) |
| Clock autonomously applies DST rules. | |
| #define | BT_ETS_CLOCK_CAP_TZ_AUTO BIT(1) |
| Clock autonomously manages TZ changes. | |
| #define | BT_ETS_CLOCK_CAP_RFU_MASK 0xFC |
| Clock Capabilities RFU mask (bits 2-7). | |
| #define BT_ETS_CLOCK_CAP_DST_AUTO BIT(0) |
#include <zephyr/bluetooth/services/ets.h>
Clock autonomously applies DST rules.
| #define BT_ETS_CLOCK_CAP_RFU_MASK 0xFC |
#include <zephyr/bluetooth/services/ets.h>
Clock Capabilities RFU mask (bits 2-7).
| #define BT_ETS_CLOCK_CAP_TZ_AUTO BIT(1) |
#include <zephyr/bluetooth/services/ets.h>
Clock autonomously manages TZ changes.
| #define BT_ETS_CLOCK_CAPABILITIES_VALUE |
#include <zephyr/bluetooth/services/ets.h>
Clock capabilities (Elapsed Time Service - Section 3.1.1.3).
| #define BT_ETS_CLOCK_STATUS_NEEDS_SET BIT(0) |
| #define BT_ETS_CLOCK_STATUS_RFU_MASK 0xFE |
#include <zephyr/bluetooth/services/ets.h>
Clock Status RFU mask (bits 1-7).
| #define BT_ETS_FLAG_CURRENT_TIMELINE BIT(5) |
#include <zephyr/bluetooth/services/ets.h>
Time stamp is from current timeline.
#include <zephyr/bluetooth/services/ets.h>
Reserved bits (6-7).
#include <zephyr/bluetooth/services/ets.h>
Time resolution mask (bits 2-3).
| #define BT_ETS_FLAG_TICK_COUNTER BIT(0) |
#include <zephyr/bluetooth/services/ets.h>
Time Value reports a counter (tick counter).
If 0, Time Value reports a time of day.
| #define BT_ETS_FLAG_TZ_DST_USED BIT(4) |
#include <zephyr/bluetooth/services/ets.h>
TZ/DST offset is used.
If 0, offset not used. Has no meaning for tick counter.
| #define BT_ETS_FLAG_UTC BIT(1) |
#include <zephyr/bluetooth/services/ets.h>
Time is UTC.
If 0, time is local time. Has no meaning for tick counter.
| #define BT_ETS_SUPPORTED_FLAGS_MASK |
#include <zephyr/bluetooth/services/ets.h>
Combined supported flags mask based on configuration.
| #define BT_ETS_TIME_SOURCE_ATOMIC 5 |
#include <zephyr/bluetooth/services/ets.h>
Atomic Clock.
| #define BT_ETS_TIME_SOURCE_CELLULAR 6 |
#include <zephyr/bluetooth/services/ets.h>
Cellular Network.
| #define BT_ETS_TIME_SOURCE_GPS 2 |
#include <zephyr/bluetooth/services/ets.h>
GPS/GNSS.
| #define BT_ETS_TIME_SOURCE_MANUAL 4 |
#include <zephyr/bluetooth/services/ets.h>
Manually set.
| #define BT_ETS_TIME_SOURCE_NOT_SYNCHRONIZED 7 |
#include <zephyr/bluetooth/services/ets.h>
Not synchronized.
| #define BT_ETS_TIME_SOURCE_NTP 1 |
#include <zephyr/bluetooth/services/ets.h>
Network Time Protocol.
| #define BT_ETS_TIME_SOURCE_RADIO 3 |
#include <zephyr/bluetooth/services/ets.h>
Radio Time Signal.
| #define BT_ETS_TIME_SOURCE_UNKNOWN 0 |
#include <zephyr/bluetooth/services/ets.h>
Unknown time source.
#include <zephyr/bluetooth/services/ets.h>
Time resolution values for bits 2-3 of flags field.
| enum bt_ets_write_result |
#include <zephyr/bluetooth/services/ets.h>
Write result codes for write_elapsed_time callback.
These codes indicate the result of a time write operation and map to specific ATT error responses as defined in the ETS specification.
| int bt_ets_indicate | ( | const struct bt_ets_elapsed_time * | elapsed_time, |
| uint8_t | clock_status ) |
#include <zephyr/bluetooth/services/ets.h>
Send indication to subscribed clients.
Send indication to all subscribed clients with updated elapsed time. This should be called when the time changes other than by natural progression (e.g., manual adjustment, external time sync, DST change, timezone change).
| elapsed_time | Elapsed time to indicate. |
| clock_status | Current clock status flags (BT_ETS_CLOCK_STATUS). |
| 0 | On success. |
| -ENOTCONN | If no clients are connected or subscribed. |
| -errno | Other negative errno on failure. |
| int bt_ets_init | ( | const struct bt_ets_cb * | cb | ) |
#include <zephyr/bluetooth/services/ets.h>
Initialize Elapsed Time Service.
Must be called during initialization. This can be called before or after bt_enable, but before advertising.
| cb | Callback structure with mandatory callbacks set. |
| 0 | On success. |
| -EINVAL | If cb is NULL or mandatory callbacks are NULL. |
| int bt_ets_time_from_unix_ms | ( | struct bt_ets_elapsed_time * | et_time, |
| int64_t | unix_ms, | ||
| uint8_t | time_src, | ||
| int8_t | tz_dst_offset ) |
#include <zephyr/bluetooth/services/ets.h>
Encode Unix milliseconds into ETS formatted time.
Converts a Unix timestamp (1970-01-01 00:00:00 UTC) to ETS time format. Handles epoch conversion (Unix 1970-01-01 to ETS 2000-01-01), resolution scaling, and timezone conversion based on compile-time configuration.
The unix_ms input is always in UTC. The tz_dst_offset parameter behavior:
CONFIG_BT_ETS_SUPPORT_UTC.: Time stays as UTC, no conversion. If CONFIG_BT_ETS_SUPPORT_TZ_DST. enabled, offset is stored for client use.CONFIG_BT_ETS_SUPPORT_LOCAL_TIME. with CONFIG_BT_ETS_SUPPORT_TZ_DST.: Offset is applied to convert UTC to local time and stored in output. Formula: Local time = UTC time + TZ/DST Offset × 15 minutes BT_ETS_FLAG_TZ_DST_USED flag is set in output.et_time flags are set based on compile-time configuration:CONFIG_BT_ETS_SUPPORT_UTC. or CONFIG_BT_ETS_SUPPORT_LOCAL_TIME.CONFIG_BT_ETS_HELPER_API. is enabled. This requires either CONFIG_BT_ETS_SUPPORT_UTC. or CONFIG_BT_ETS_SUPPORT_TZ_DST. to be enabled.| et_time | Pointer to ETS time structure to fill. |
| unix_ms | Milliseconds since Unix epoch (1970-01-01 00:00:00 UTC) - always UTC. |
| time_src | Time synchronization source type. (see BT_ETS_TIME_SOURCE) |
| tz_dst_offset | TZ/DST offset from UTC in 15-minute units (signed). Used for UTC-to-local conversion if in LOCAL_TIME mode. |
| 0 | On success. |
| -EINVAL | If et_time is NULL or time is before ETS epoch (2000-01-01) after conversion. |
| -EOVERFLOW | If the time value exceeds 48-bit range after conversion. |
| int bt_ets_time_to_unix_ms | ( | const struct bt_ets_elapsed_time * | et_time, |
| int64_t * | unix_ms ) |
#include <zephyr/bluetooth/services/ets.h>
Decode ETS formatted time into milliseconds since Unix epoch.
Converts ETS time format to milliseconds with Unix epoch (1970-01-01 00:00:00 UTC). Handles epoch conversion (ETS uses 2000-01-01 vs Unix 1970-01-01), resolution scaling, and timezone conversion based on the flags field in et_time.
The output unix_ms is always in UTC. Timezone handling based on flags:
CONFIG_BT_ETS_SUPPORT_UTC.: Time is already UTC, no conversion needed. If BT_ETS_FLAG_TZ_DST_USED is set, the offset is informational only.CONFIG_BT_ETS_SUPPORT_LOCAL_TIME. with CONFIG_BT_ETS_SUPPORT_TZ_DST.: If BT_ETS_FLAG_TZ_DST_USED is set in et_time, converts local time to UTC by subtracting the offset: UTC = Local time - TZ/DST Offset × 15 minutesCONFIG_BT_ETS_HELPER_API. is enabled. This requires either CONFIG_BT_ETS_SUPPORT_UTC. or CONFIG_BT_ETS_SUPPORT_TZ_DST. to be enabled (proper UTC conversion needs either UTC mode or timezone offset information).| et_time | ETS time formatted structure to decode. |
| unix_ms | Pointer to store milliseconds since Unix epoch (1970-01-01 00:00:00 UTC). |
| 0 | On success. |
| -EINVAL | If et_time or unix_ms is NULL. |
| -EOVERFLOW | If the converted time value overflows during conversion. |