|
| 1 | +/* |
| 2 | + * Copyright (c) 2019 Nordic Semiconductor ASA |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic |
| 5 | + */ |
| 6 | + |
| 7 | +/** |
| 8 | + * @file |
| 9 | + * @defgroup bt_mesh_onoff_cli Generic OnOff Client model |
| 10 | + * @{ |
| 11 | + * @brief API for the Generic OnOff Client model. |
| 12 | + */ |
| 13 | + |
| 14 | +#ifndef BT_MESH_GEN_ONOFF_CLI_H__ |
| 15 | +#define BT_MESH_GEN_ONOFF_CLI_H__ |
| 16 | + |
| 17 | +#include <bluetooth/mesh/gen_onoff.h> |
| 18 | + |
| 19 | +#ifdef __cplusplus |
| 20 | +extern "C" { |
| 21 | +#endif |
| 22 | + |
| 23 | +struct bt_mesh_onoff_cli; |
| 24 | + |
| 25 | +/** @def BT_MESH_ONOFF_CLI_INIT |
| 26 | + * |
| 27 | + * @brief Initialization parameters for a @ref bt_mesh_onoff_cli instance. |
| 28 | + * |
| 29 | + * @param[in] _status_handler Optional status message handler. |
| 30 | + */ |
| 31 | +#define BT_MESH_ONOFF_CLI_INIT(_status_handler) \ |
| 32 | + { \ |
| 33 | + .status_handler = _status_handler, \ |
| 34 | + .pub = {.msg = NET_BUF_SIMPLE(BT_MESH_MODEL_BUF_LEN( \ |
| 35 | + BT_MESH_ONOFF_OP_SET, \ |
| 36 | + BT_MESH_ONOFF_MSG_MAXLEN_SET)) } \ |
| 37 | + } |
| 38 | + |
| 39 | +/** @def BT_MESH_MODEL_ONOFF_CLI |
| 40 | + * |
| 41 | + * @brief Generic OnOff Client model composition data entry. |
| 42 | + * |
| 43 | + * @param[in] _cli Pointer to a @ref bt_mesh_onoff_cli instance. |
| 44 | + */ |
| 45 | +#define BT_MESH_MODEL_ONOFF_CLI(_cli) \ |
| 46 | + BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_GEN_ONOFF_CLI, \ |
| 47 | + _bt_mesh_onoff_cli_op, &(_cli)->pub, \ |
| 48 | + BT_MESH_MODEL_USER_DATA(struct bt_mesh_onoff_cli, \ |
| 49 | + _cli), \ |
| 50 | + &_bt_mesh_onoff_cli_cb) |
| 51 | + |
| 52 | +/** |
| 53 | + * Generic OnOff Client structure. |
| 54 | + * |
| 55 | + * Should be initialized with the @ref BT_MESH_ONOFF_CLI_INIT macro. |
| 56 | + */ |
| 57 | +struct bt_mesh_onoff_cli { |
| 58 | + /** @brief OnOff status message handler. |
| 59 | + * |
| 60 | + * @param[in] cli Client that received the status message. |
| 61 | + * @param[in] ctx Context of the incoming message. |
| 62 | + * @param[in] status OnOff Status of the Generic OnOff Server that |
| 63 | + * published the message. |
| 64 | + */ |
| 65 | + void (*const status_handler)(struct bt_mesh_onoff_cli *cli, |
| 66 | + struct bt_mesh_msg_ctx *ctx, |
| 67 | + const struct bt_mesh_onoff_status *status); |
| 68 | + /** Current Transaction ID. */ |
| 69 | + u8_t tid; |
| 70 | + /** Response context for tracking acknowledged messages. */ |
| 71 | + struct bt_mesh_model_ack_ctx ack_ctx; |
| 72 | + /** Publish parameters. */ |
| 73 | + struct bt_mesh_model_pub pub; |
| 74 | + /** Access model pointer. */ |
| 75 | + struct bt_mesh_model *model; |
| 76 | +}; |
| 77 | + |
| 78 | +/** @brief Get the status of the bound srv. |
| 79 | + * |
| 80 | + * This call is blocking if the @p rsp buffer is non-NULL. Otherwise, this |
| 81 | + * function will return, and the response will be passed to the |
| 82 | + * @ref bt_mesh_onoff_cli::status_handler callback. |
| 83 | + * |
| 84 | + * @param[in] cli Client model to send on. |
| 85 | + * @param[in] ctx Message context, or NULL to use the configured publish |
| 86 | + * parameters. |
| 87 | + * @param[out] rsp Status response buffer, or NULL to keep from blocking. |
| 88 | + * |
| 89 | + * @retval 0 Successfully sent the message and populated the @p rsp buffer. |
| 90 | + * @retval -EALREADY A blocking request is already in progress. |
| 91 | + * @retval -ENOTSUP A message context was not provided and publishing is not |
| 92 | + * supported. |
| 93 | + * @retval -EADDRNOTAVAIL A message context was not provided and publishing is |
| 94 | + * not configured. |
| 95 | + * @retval -EAGAIN The device has not been provisioned. |
| 96 | + * @retval -ETIMEDOUT The request timed out without a response. |
| 97 | + */ |
| 98 | +int bt_mesh_onoff_cli_get(struct bt_mesh_onoff_cli *cli, |
| 99 | + struct bt_mesh_msg_ctx *ctx, |
| 100 | + struct bt_mesh_onoff_status *rsp); |
| 101 | + |
| 102 | +/** @brief Set the OnOff state in the srv. |
| 103 | + * |
| 104 | + * This call is blocking if the @p rsp buffer is non-NULL. Otherwise, this |
| 105 | + * function will not request a response from the server, and return |
| 106 | + * immediately. |
| 107 | + * |
| 108 | + * @param[in] cli Client model to send on. |
| 109 | + * @param[in] ctx Message context, or NULL to use the configured publish |
| 110 | + * parameters. |
| 111 | + * @param[in] set New OnOff parameters to set. @p set::transition can either |
| 112 | + * point to a transition structure, or be left to NULL to use the default |
| 113 | + * transition parameters on the server. |
| 114 | + * @param[out] rsp Response status buffer, or NULL to send an unacknowledged |
| 115 | + * message. |
| 116 | + * |
| 117 | + * @retval 0 Successfully sent the message and populated the @p rsp buffer. |
| 118 | + * @retval -EALREADY A blocking request is already in progress. |
| 119 | + * @retval -ENOTSUP A message context was not provided and publishing is not |
| 120 | + * supported. |
| 121 | + * @retval -EADDRNOTAVAIL A message context was not provided and publishing is |
| 122 | + * not configured. |
| 123 | + * @retval -EAGAIN The device has not been provisioned. |
| 124 | + * @retval -ETIMEDOUT The request timed out without a response. |
| 125 | + */ |
| 126 | +int bt_mesh_onoff_cli_set(struct bt_mesh_onoff_cli *cli, |
| 127 | + struct bt_mesh_msg_ctx *ctx, |
| 128 | + const struct bt_mesh_onoff_set *set, |
| 129 | + struct bt_mesh_onoff_status *rsp); |
| 130 | + |
| 131 | +/** @cond INTERNAL_HIDDEN */ |
| 132 | +extern const struct bt_mesh_model_op _bt_mesh_onoff_cli_op[]; |
| 133 | +extern const struct bt_mesh_model_cb _bt_mesh_onoff_cli_cb; |
| 134 | +/** @endcond */ |
| 135 | + |
| 136 | +#ifdef __cplusplus |
| 137 | +} |
| 138 | +#endif |
| 139 | + |
| 140 | +#endif /* BT_MESH_GEN_ONOFF_CLI_H__ */ |
| 141 | + |
| 142 | +/* @} */ |
0 commit comments