|
| 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_ponoff_cli Generic Power OnOff Client |
| 10 | + * @{ |
| 11 | + * @brief API for the Generic Power OnOff Client. |
| 12 | + */ |
| 13 | +#ifndef BT_MESH_GEN_PONOFF_CLI_H__ |
| 14 | +#define BT_MESH_GEN_PONOFF_CLI_H__ |
| 15 | + |
| 16 | +#include <bluetooth/mesh/gen_ponoff.h> |
| 17 | +#include <bluetooth/mesh/model_types.h> |
| 18 | + |
| 19 | +#ifdef __cplusplus |
| 20 | +extern "C" { |
| 21 | +#endif |
| 22 | + |
| 23 | +struct bt_mesh_ponoff_cli; |
| 24 | + |
| 25 | +/** @def BT_MESH_PONOFF_CLI_INIT |
| 26 | + * |
| 27 | + * @brief Initialization parameters for @ref bt_mesh_ponoff_cli. |
| 28 | + * |
| 29 | + * @param[in] _power_onoff_status_handler OnPowerUp status handler. |
| 30 | + */ |
| 31 | +#define BT_MESH_PONOFF_CLI_INIT(_power_onoff_status_handler) \ |
| 32 | + { \ |
| 33 | + .status_handler = _power_onoff_status_handler, \ |
| 34 | + .pub = { .msg = NET_BUF_SIMPLE(BT_MESH_MODEL_BUF_LEN( \ |
| 35 | + BT_MESH_PONOFF_OP_SET, \ |
| 36 | + BT_MESH_PONOFF_MSG_LEN_SET)) }, \ |
| 37 | + } |
| 38 | + |
| 39 | +/** @def BT_MESH_MODEL_PONOFF_CLI |
| 40 | + * |
| 41 | + * @brief Generic Power OnOff Client model composition data entry. |
| 42 | + * |
| 43 | + * @param[in] _cli Pointer to a @ref bt_mesh_ponoff_cli instance. |
| 44 | + */ |
| 45 | +#define BT_MESH_MODEL_PONOFF_CLI(_cli) \ |
| 46 | + BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI, \ |
| 47 | + _bt_mesh_ponoff_cli_op, &(_cli)->pub, \ |
| 48 | + BT_MESH_MODEL_USER_DATA( \ |
| 49 | + struct bt_mesh_ponoff_cli, _cli), \ |
| 50 | + &_bt_mesh_ponoff_cli_cb) |
| 51 | + |
| 52 | +/** |
| 53 | + * Generic Power OnOff client instance. |
| 54 | + * |
| 55 | + * Should be initialized with @ref BT_MESH_PONOFF_CLI_INIT. |
| 56 | + */ |
| 57 | +struct bt_mesh_ponoff_cli { |
| 58 | + /** Model entry pointer. */ |
| 59 | + struct bt_mesh_model *model; |
| 60 | + /** Publish parameters. */ |
| 61 | + struct bt_mesh_model_pub pub; |
| 62 | + /** Response context for tracking acknowledged messages. */ |
| 63 | + struct bt_mesh_model_ack_ctx ack_ctx; |
| 64 | + |
| 65 | + /** @brief OnPowerUp status message handler. |
| 66 | + * |
| 67 | + * @param[in] cli Client that received the status message. |
| 68 | + * @param[in] ctx Message context the message was received with. |
| 69 | + * @param[in] on_power_up The OnPowerUp state presented in the message. |
| 70 | + */ |
| 71 | + void (*const status_handler)(struct bt_mesh_ponoff_cli *cli, |
| 72 | + struct bt_mesh_msg_ctx *ctx, |
| 73 | + enum bt_mesh_on_power_up on_power_up); |
| 74 | +}; |
| 75 | + |
| 76 | +/** @brief Get the OnPowerUp state of a server. |
| 77 | + * |
| 78 | + * This call is blocking if the @p rsp buffer is non-NULL. Otherwise, this |
| 79 | + * function will return, and the response will be passed to the |
| 80 | + * @ref bt_mesh_ponoff_cli::status_handler callback. |
| 81 | + * |
| 82 | + * @param[in] cli Power OnOff client to send the message on. |
| 83 | + * @param[in] ctx Context of the message, or NULL to send on the configured |
| 84 | + * publish parameters. |
| 85 | + * @param[out] rsp Response buffer to put the received response in, or NULL to |
| 86 | + * process the response in the status handler callback. |
| 87 | + * |
| 88 | + * @retval 0 Successfully sent a get message. If a response buffer is |
| 89 | + * provided, it has been populated. |
| 90 | + * @retval -EALREADY A blocking request is already in progress. |
| 91 | + * @retval -EADDRNOTAVAIL A message context was not provided and publishing is |
| 92 | + * not configured. |
| 93 | + * @retval -EAGAIN The device has not been provisioned. |
| 94 | + * @retval -ETIMEDOUT The request timed out without a response. |
| 95 | + */ |
| 96 | +int bt_mesh_ponoff_cli_on_power_up_get(struct bt_mesh_ponoff_cli *cli, |
| 97 | + struct bt_mesh_msg_ctx *ctx, |
| 98 | + enum bt_mesh_on_power_up *rsp); |
| 99 | + |
| 100 | +/** @brief Set the OnPowerUp state of a server. |
| 101 | + * |
| 102 | + * @param[in] cli Power OnOff client to send the message on. |
| 103 | + * @param[in] ctx Context of the message, or NULL to send with the configured |
| 104 | + * publish parameters. |
| 105 | + * @param[in] on_power_up New OnPowerUp state of the server. |
| 106 | + * @param[out] rsp Response buffer to put the received response in, or NULL to |
| 107 | + * send an unacknowledged message. |
| 108 | + * |
| 109 | + * @retval 0 Successfully sent a set message. If a response buffer is |
| 110 | + * provided, it has been populated. |
| 111 | + * @retval -EALREADY A blocking request is already in progress. |
| 112 | + * @retval -EADDRNOTAVAIL A message context was not provided and publishing is |
| 113 | + * not configured. |
| 114 | + * @retval -EAGAIN The device has not been provisioned. |
| 115 | + * @retval -ETIMEDOUT The request timed out without a response. |
| 116 | + */ |
| 117 | +int bt_mesh_ponoff_cli_on_power_up_set(struct bt_mesh_ponoff_cli *cli, |
| 118 | + struct bt_mesh_msg_ctx *ctx, |
| 119 | + enum bt_mesh_on_power_up on_power_up, |
| 120 | + enum bt_mesh_on_power_up *rsp); |
| 121 | + |
| 122 | +/** @cond INTERNAL_HIDDEN */ |
| 123 | +extern const struct bt_mesh_model_op _bt_mesh_ponoff_cli_op[]; |
| 124 | +extern const struct bt_mesh_model_cb _bt_mesh_ponoff_cli_cb; |
| 125 | +/** @endcond */ |
| 126 | + |
| 127 | +#ifdef __cplusplus |
| 128 | +} |
| 129 | +#endif |
| 130 | + |
| 131 | +#endif /* BT_MESH_GEN_PONOFF_CLI_H__ */ |
| 132 | + |
| 133 | +/** @} */ |
0 commit comments