Skip to content

Commit 6c5f2ea

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

File tree

9 files changed

+1015
-0
lines changed

9 files changed

+1015
-0
lines changed

include/bluetooth/mesh/gen_lvl.h

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
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_lvl Bluetooth Mesh Generic Level models
10+
* @{
11+
* @brief Common API for the Bluetooth Mesh Generic Level models.
12+
*/
13+
#ifndef BT_MESH_GEN_LVL_H__
14+
#define BT_MESH_GEN_LVL_H__
15+
16+
#include <bluetooth/mesh.h>
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_LVL_OP_GET BT_MESH_MODEL_OP_2(0x82, 0x05)
25+
#define BT_MESH_LVL_OP_SET BT_MESH_MODEL_OP_2(0x82, 0x06)
26+
#define BT_MESH_LVL_OP_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x07)
27+
#define BT_MESH_LVL_OP_STATUS BT_MESH_MODEL_OP_2(0x82, 0x08)
28+
#define BT_MESH_LVL_OP_DELTA_SET BT_MESH_MODEL_OP_2(0x82, 0x09)
29+
#define BT_MESH_LVL_OP_DELTA_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x0A)
30+
#define BT_MESH_LVL_OP_MOVE_SET BT_MESH_MODEL_OP_2(0x82, 0x0B)
31+
#define BT_MESH_LVL_OP_MOVE_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x0C)
32+
33+
#define BT_MESH_LVL_MSG_LEN_GET 0
34+
#define BT_MESH_LVL_MSG_MINLEN_SET 3
35+
#define BT_MESH_LVL_MSG_MAXLEN_SET 5
36+
#define BT_MESH_LVL_MSG_MINLEN_STATUS 2
37+
#define BT_MESH_LVL_MSG_MAXLEN_STATUS 5
38+
#define BT_MESH_LVL_MSG_MINLEN_DELTA_SET 5
39+
#define BT_MESH_LVL_MSG_MAXLEN_DELTA_SET 7
40+
#define BT_MESH_LVL_MSG_MINLEN_MOVE_SET 3
41+
#define BT_MESH_LVL_MSG_MAXLEN_MOVE_SET 5
42+
/** @endcond */
43+
44+
/** Generic Level minimum value. */
45+
#define BT_MESH_LVL_MIN INT16_MIN
46+
/** Generic Level maximum value. */
47+
#define BT_MESH_LVL_MAX INT16_MAX
48+
49+
/** Generic Level set message parameters. */
50+
struct bt_mesh_lvl_set {
51+
/** New level. */
52+
s16_t lvl;
53+
/** Whether this is a new action. */
54+
bool new_transaction;
55+
/**
56+
* Transition time parameters for the state change. Setting the
57+
* transition to NULL makes the server use its default transition time
58+
* parameters.
59+
*/
60+
const struct bt_mesh_model_transition *transition;
61+
};
62+
63+
/** Generic Level delta set message parameters. */
64+
struct bt_mesh_lvl_delta_set {
65+
/** Translation from original value. */
66+
s32_t delta;
67+
/**
68+
* Whether this is a new transaction. If true, the delta should be
69+
* relative to the current value. If false, the delta should be
70+
* relative to the original value in the previous delta_set command.
71+
*/
72+
bool new_transaction;
73+
/**
74+
* Transition time parameters for the state change. Setting the
75+
* transition to NULL makes the server use its default transition time
76+
* parameters.
77+
*/
78+
const struct bt_mesh_model_transition *transition;
79+
};
80+
81+
/** Generic Level move set message parameters. */
82+
struct bt_mesh_lvl_move_set {
83+
/** Translation to make for every transition step. */
84+
s16_t delta;
85+
/** Whether this is a new action. */
86+
bool new_transaction;
87+
/**
88+
* Transition parameters. @c delay indicates time until the move
89+
* should start, @c transition indicates the amount of time each
90+
* @c delta step should take. Setting the transition to NULL makes the
91+
* server use its default transition time parameters.
92+
*/
93+
const struct bt_mesh_model_transition *transition;
94+
};
95+
96+
/** Generic Level status message parameters. */
97+
struct bt_mesh_lvl_status {
98+
/** Current level value. */
99+
s16_t current;
100+
/**
101+
* Target value for the ongoing transition. If there's no ongoing
102+
* transition, @c target should match @c value.
103+
*/
104+
s16_t target;
105+
/**
106+
* Time remaining of the ongoing transition, or @ref K_FOREVER.
107+
* If there's no ongoing transition, @c remaining_time is 0.
108+
*/
109+
s32_t remaining_time;
110+
};
111+
112+
#ifdef __cplusplus
113+
}
114+
#endif
115+
116+
#endif /* BT_MESH_GEN_LVL_H__ */
117+
118+
/** @} */

include/bluetooth/mesh/gen_lvl.rst

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
.. _bt_mesh_lvl_readme:
2+
3+
Generic Level models
4+
####################
5+
6+
The Generic Level models allows remote control of integer states on a mesh
7+
device.
8+
9+
There are two Generic Level models:
10+
11+
- :ref:`bt_mesh_lvl_srv_readme`
12+
- :ref:`bt_mesh_lvl_cli_readme`
13+
14+
.. _bt_mesh_lvl_srv_readme:
15+
16+
Generic Level Server
17+
====================
18+
19+
The Generic Level Server model owns a single Generic Level state.
20+
21+
States
22+
*******
23+
24+
**Generic Level**: ``s16_t``
25+
26+
The user is expected to hold the state memory and provide access to the state
27+
through the :cpp:type:`bt_mesh_lvl_srv_handlers` handler structure.
28+
29+
Changes to the Generic Level state may include transition parameters. While
30+
transitioning to a new level state, any requests to read out the current level
31+
should report the actual current level in the transition, as well as the
32+
terminal level and remaining time in milliseconds, including delay.
33+
34+
If the transition includes a delay, the state shall remain unchanged until the
35+
delay expires.
36+
37+
Extended models
38+
****************
39+
40+
None.
41+
42+
Persistent storage
43+
*******************
44+
45+
None.
46+
47+
API documentation
48+
******************
49+
50+
| Header file: :file:`include/bluetooth/mesh/gen_lvl_srv.h`
51+
| Source file: :file:`subsys/bluetooth/mesh/gen_lvl_srv.c`
52+
53+
.. doxygengroup:: bt_mesh_lvl_srv
54+
:project: nrf
55+
:members:
56+
57+
----
58+
59+
.. _bt_mesh_lvl_cli_readme:
60+
61+
Generic Level Client
62+
====================
63+
64+
The Generic Level Client model remotely controls the state of a Generic Level
65+
Server model.
66+
67+
Extended models
68+
****************
69+
70+
None.
71+
72+
Persistent storage
73+
*******************
74+
75+
None.
76+
77+
API documentation
78+
******************
79+
80+
| Header file: :file:`include/bluetooth/mesh/gen_lvl_cli.h`
81+
| Source file: :file:`subsys/bluetooth/mesh/gen_lvl_cli.c`
82+
83+
.. doxygengroup:: bt_mesh_lvl_cli
84+
:project: nrf
85+
:members:
86+
87+
----
88+
89+
Common types
90+
=============
91+
92+
| Header file: :file:`include/bluetooth/mesh/gen_lvl.h`
93+
94+
.. doxygengroup:: bt_mesh_lvl
95+
:project: nrf
96+
:members:

0 commit comments

Comments
 (0)