Skip to content

Commit 7e9c9d9

Browse files
trond-snekvikjoerchan
authored andcommitted
Bluetooth: Mesh: Generic OnOff models
Adds the Generic OnOff Client and Generic OnOff Server models. Signed-off-by: Trond Einar Snekvik <[email protected]>
1 parent ae1ce5a commit 7e9c9d9

File tree

9 files changed

+713
-0
lines changed

9 files changed

+713
-0
lines changed

include/bluetooth/mesh/gen_onoff.h

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 Generic OnOff Models
10+
* @{
11+
* @brief Common API for the Generic OnOff models.
12+
*/
13+
14+
#ifndef BT_MESH_GEN_ONOFF_H__
15+
#define BT_MESH_GEN_ONOFF_H__
16+
17+
#include <bluetooth/mesh/model_types.h>
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
/** @cond INTERNAL_HIDDEN */
24+
#define BT_MESH_ONOFF_OP_GET BT_MESH_MODEL_OP_2(0x82, 0x01)
25+
#define BT_MESH_ONOFF_OP_SET BT_MESH_MODEL_OP_2(0x82, 0x02)
26+
#define BT_MESH_ONOFF_OP_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x03)
27+
#define BT_MESH_ONOFF_OP_STATUS BT_MESH_MODEL_OP_2(0x82, 0x04)
28+
29+
#define BT_MESH_ONOFF_MSG_LEN_GET 0
30+
#define BT_MESH_ONOFF_MSG_MINLEN_SET 2
31+
#define BT_MESH_ONOFF_MSG_MAXLEN_SET 4
32+
#define BT_MESH_ONOFF_MSG_MINLEN_STATUS 1
33+
#define BT_MESH_ONOFF_MSG_MAXLEN_STATUS 3
34+
/** @endcond */
35+
36+
/** Mandatory parameters for the Generic OnOff Set message. */
37+
struct bt_mesh_onoff_set {
38+
/** State to set. */
39+
bool on_off;
40+
/** Transition parameters. */
41+
const struct bt_mesh_model_transition *transition;
42+
};
43+
44+
/** Parameters for the Generic OnOff Status message. */
45+
struct bt_mesh_onoff_status {
46+
/** The present value of the Generic OnOff state. */
47+
bool present_on_off;
48+
/** The target value of the Generic OnOff state (optional). */
49+
bool target_on_off;
50+
/** Remaining time value in milliseconds. */
51+
s32_t remaining_time;
52+
};
53+
54+
#ifdef __cplusplus
55+
}
56+
#endif
57+
58+
#endif /* BT_MESH_GEN_ONOFF_H__ */
59+
60+
/** @} */
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
.. _bt_mesh_onoff_readme:
2+
3+
Generic OnOff models
4+
####################
5+
6+
The Generic OnOff models allows remote control of boolean states on a mesh
7+
device.
8+
9+
There are two Generic OnOff models:
10+
11+
- :ref:`bt_mesh_onoff_srv_readme`
12+
- :ref:`bt_mesh_onoff_cli_readme`
13+
14+
.. _bt_mesh_onoff_srv_readme:
15+
16+
Generic OnOff Server
17+
====================
18+
19+
The Generic OnOff Server represents a single controllable On/Off value.
20+
21+
22+
States
23+
*******
24+
25+
This model has the following states:
26+
27+
**Generic OnOff:** ``boolean``
28+
29+
Generic boolean state representing an On/Off state. The user is expected
30+
to hold the state memory and provide access to the state through the
31+
:cpp:type:`bt_mesh_onoff_srv_handlers` handler structure.
32+
33+
Changes to the Generic OnOff state may include transition parameters. When
34+
transitioning to a new OnOff state, the state should be `on` during the entire
35+
transition, regardless of target state. This ensures that any bound non-binary
36+
states can have non-0 values during the transition.
37+
38+
Any requests to read out the current OnOff state while in a transition should
39+
report the current OnOff value being `on`.
40+
41+
The ``remaining_time`` parameter should be reported in milliseconds, including
42+
delay. If the transition parameters includes a delay, the state shall remain
43+
unchanged until the delay expires.
44+
45+
Extended models
46+
****************
47+
48+
None.
49+
50+
Persistent storage
51+
*******************
52+
53+
None.
54+
55+
API documentation
56+
******************
57+
58+
| Header file: :file:`include/bluetooth/mesh/gen_onoff_srv.h`
59+
| Source file: :file:`subsys/bluetooth/mesh/gen_onoff_srv.c`
60+
61+
.. doxygengroup:: bt_mesh_onoff_srv
62+
:project: nrf
63+
:members:
64+
65+
----
66+
67+
.. _bt_mesh_onoff_cli_readme:
68+
69+
Generic OnOff Client
70+
====================
71+
72+
The Generic OnOff Client model remotely controls the state of a Generic OnOff
73+
Server model.
74+
75+
Extended models
76+
****************
77+
78+
None.
79+
80+
Persistent storage
81+
*******************
82+
83+
None.
84+
85+
API documentation
86+
******************
87+
88+
| Header file: :file:`include/bluetooth/mesh/gen_onoff_cli.h`
89+
| Source file: :file:`subsys/bluetooth/mesh/gen_onoff_cli.c`
90+
91+
.. doxygengroup:: bt_mesh_onoff_cli
92+
:project: nrf
93+
:members:
94+
95+
----
96+
97+
Common types
98+
=============
99+
100+
| Header file: :file:`include/bluetooth/mesh/gen_onoff.h`
101+
102+
.. doxygengroup:: bt_mesh_onoff
103+
:project: nrf
104+
:members:
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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

Comments
 (0)