|
| 1 | +/* |
| 2 | + * Copyright (c) 2019 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * |
| 9 | + * @file |
| 10 | + * @defgroup bt_mesh_dtt_cli Generic Default Transition Time Client API |
| 11 | + * @{ |
| 12 | + * @brief API for the Generic Default Transition Time (DTT) Client. |
| 13 | + */ |
| 14 | + |
| 15 | +#ifndef BT_MESH_GEN_DTT_CLI_H__ |
| 16 | +#define BT_MESH_GEN_DTT_CLI_H__ |
| 17 | + |
| 18 | +#include <bluetooth/mesh/gen_dtt.h> |
| 19 | +#include <bluetooth/mesh/model_types.h> |
| 20 | + |
| 21 | +#ifdef __cplusplus |
| 22 | +extern "C" { |
| 23 | +#endif |
| 24 | + |
| 25 | +struct bt_mesh_dtt_cli; |
| 26 | + |
| 27 | +/** @def BT_MESH_DTT_CLI_INIT |
| 28 | + * |
| 29 | + * @brief Initialization parameters for the @ref bt_mesh_dtt_cli. |
| 30 | + * |
| 31 | + * @param[in] _status_handler Optional status message handler. |
| 32 | + * @sa bt_mesh_dtt_cli::status_handler |
| 33 | + */ |
| 34 | +#define BT_MESH_DTT_CLI_INIT(_status_handler) \ |
| 35 | + { \ |
| 36 | + .pub = { .msg = NET_BUF_SIMPLE(BT_MESH_MODEL_BUF_LEN( \ |
| 37 | + BT_MESH_DTT_OP_SET, \ |
| 38 | + BT_MESH_DTT_MSG_LEN_SET)) }, \ |
| 39 | + .status_handler = _status_handler, \ |
| 40 | + } |
| 41 | + |
| 42 | +/** @def BT_MESH_MODEL_DTT_CLI |
| 43 | + * |
| 44 | + * @brief Generic DTT Client model composition data entry. |
| 45 | + * |
| 46 | + * @param[in] _cli Pointer to a @ref bt_mesh_dtt_cli instance. |
| 47 | + */ |
| 48 | +#define BT_MESH_MODEL_DTT_CLI(_cli) \ |
| 49 | + BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI, \ |
| 50 | + _bt_mesh_dtt_cli_op, &(_cli)->pub, \ |
| 51 | + BT_MESH_MODEL_USER_DATA(struct bt_mesh_dtt_cli, \ |
| 52 | + _cli), \ |
| 53 | + &_bt_mesh_dtt_cli_cb) |
| 54 | + |
| 55 | +/** |
| 56 | + * Generic DTT client structure. |
| 57 | + * |
| 58 | + * Should be initialized using the @ref BT_MESH_DTT_CLI_INIT macro. |
| 59 | + */ |
| 60 | +struct bt_mesh_dtt_cli { |
| 61 | + /** @brief Default Transition Time status message handler. |
| 62 | + * |
| 63 | + * @param[in] cli Client that received the message. |
| 64 | + * @param[in] ctx Message context. |
| 65 | + * @param[in] transition_time Transition time presented in the message. |
| 66 | + */ |
| 67 | + void (*const status_handler)(struct bt_mesh_dtt_cli *cli, |
| 68 | + struct bt_mesh_msg_ctx *ctx, |
| 69 | + s32_t transition_time); |
| 70 | + |
| 71 | + /** Response context for tracking acknowledged messages. */ |
| 72 | + struct bt_mesh_model_ack_ctx ack_ctx; |
| 73 | + /** Model publish parameters. */ |
| 74 | + struct bt_mesh_model_pub pub; |
| 75 | + /** Composition data model entry pointer. */ |
| 76 | + struct bt_mesh_model *model; |
| 77 | +}; |
| 78 | + |
| 79 | +/** @brief Get the Default Transition Time of the server. |
| 80 | + * |
| 81 | + * This call is blocking if the @p rsp_transition_time buffer is non-NULL. |
| 82 | + * Otherwise, this function will not request a response from the server, and |
| 83 | + * return immediately. |
| 84 | + * |
| 85 | + * @param[in] cli Client making the request. |
| 86 | + * @param[in] ctx Message context to use for sending, or NULL to publish with |
| 87 | + * the configured parameters. |
| 88 | + * @param[out] rsp_transition_time Pointer to a response buffer. Cannot be |
| 89 | + * NULL. Note that the response is a signed value, that can be K_FOREVER if the |
| 90 | + * current state is unknown or too large to represent. |
| 91 | + * |
| 92 | + * @retval 0 Successfully retrieved the status of the bound srv. |
| 93 | + * @retval -EALREADY A blocking operation is already in progress in this model. |
| 94 | + * @retval -EAGAIN The request timed out. |
| 95 | + */ |
| 96 | +int bt_mesh_dtt_get(struct bt_mesh_dtt_cli *cli, struct bt_mesh_msg_ctx *ctx, |
| 97 | + s32_t *rsp_transition_time); |
| 98 | + |
| 99 | +/** @brief Set the Default Transition Time of the server. |
| 100 | + * |
| 101 | + * This call is blocking if the @p rsp_transition_time buffer is non-NULL. |
| 102 | + * Otherwise, this function will not request a response from the server, and |
| 103 | + * return immediately. |
| 104 | + * |
| 105 | + * @param[in] cli Client model to send on. |
| 106 | + * @param[in] ctx Message context to use for sending, or NULL to publish with |
| 107 | + * the configured parameters. |
| 108 | + * @param[in] transition_time Transition time to set (in milliseconds). Must be |
| 109 | + * less than @ref BT_MESH_MODEL_TRANSITION_TIME_MAX_MS. |
| 110 | + * @param[out] rsp_transition_time Response buffer, or NULL to send an |
| 111 | + * unacknowledged message. Note that the response is a signed value, that can |
| 112 | + * be K_FOREVER if the current state is unknown or too large to represent. |
| 113 | + * |
| 114 | + * @retval 0 Successfully sent the message. If the message is acknowledged, |
| 115 | + * the response buffer has been set according to the srv's response. |
| 116 | + * @retval -EINVAL The given transition time is invalid. |
| 117 | + * @retval -EALREADY A blocking operation is already in progress in this model. |
| 118 | + * @retval -EAGAIN The request timed out. |
| 119 | + */ |
| 120 | +int bt_mesh_dtt_set(struct bt_mesh_dtt_cli *cli, struct bt_mesh_msg_ctx *ctx, |
| 121 | + u32_t transition_time, s32_t *rsp_transition_time); |
| 122 | + |
| 123 | +/** @cond INTERNAL_HIDDEN */ |
| 124 | +extern const struct bt_mesh_model_op _bt_mesh_dtt_cli_op[]; |
| 125 | +extern const struct bt_mesh_model_cb _bt_mesh_dtt_cli_cb; |
| 126 | +/** @endcond */ |
| 127 | + |
| 128 | +#ifdef __cplusplus |
| 129 | +} |
| 130 | +#endif |
| 131 | + |
| 132 | +#endif /* BT_MESH_GEN_DTT_CLI_H__ */ |
| 133 | + |
| 134 | +/** @} */ |
0 commit comments