Skip to content

Commit db1290f

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

File tree

9 files changed

+653
-0
lines changed

9 files changed

+653
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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_battery Generic Battery models
10+
* @{
11+
* @brief API for the Generic Battery models.
12+
*/
13+
14+
#ifndef BT_MESH_GEN_BATTERY_H__
15+
#define BT_MESH_GEN_BATTERY_H__
16+
17+
#include <bluetooth/mesh.h>
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
/** @cond INTERNAL_HIDDEN */
24+
#define BT_MESH_BATTERY_OP_GET BT_MESH_MODEL_OP_2(0x82, 0x23)
25+
#define BT_MESH_BATTERY_OP_STATUS BT_MESH_MODEL_OP_2(0x82, 0x24)
26+
27+
#define BT_MESH_BATTERY_MSG_LEN_GET 0
28+
#define BT_MESH_BATTERY_MSG_LEN_STATUS 8
29+
/** @endcond */
30+
31+
/** Unknown battery level. */
32+
#define BT_MESH_BATTERY_LVL_UNKNOWN 0xff
33+
34+
/** Longest acceptable charge and discharge time in minutes */
35+
#define BT_MESH_BATTERY_TIME_MAX 0xfffffe
36+
/** Unknown discharge time */
37+
#define BT_MESH_BATTERY_TIME_UNKNOWN 0xffffff
38+
39+
/** Battery presence state. */
40+
enum bt_mesh_battery_presence {
41+
/** The battery is not present. */
42+
BT_MESH_BATTERY_PRESENCE_NOT_PRESENT,
43+
/** The battery is present and is removable. */
44+
BT_MESH_BATTERY_PRESENCE_PRESENT_REMOVABLE,
45+
/** The battery is present and is non-removable. */
46+
BT_MESH_BATTERY_PRESENCE_PRESENT_NOT_REMOVABLE,
47+
/** The battery presence is unknown. */
48+
BT_MESH_BATTERY_PRESENCE_UNKNOWN,
49+
};
50+
51+
/** Indicator for the charge level of the battery. */
52+
enum bt_mesh_battery_indicator {
53+
/** The battery charge is Critically Low Level. */
54+
BT_MESH_BATTERY_INDICATOR_CRITICALLY_LOW,
55+
/** The battery charge is Low Level. */
56+
BT_MESH_BATTERY_INDICATOR_LOW,
57+
/** The battery charge is Good Level. */
58+
BT_MESH_BATTERY_INDICATOR_GOOD,
59+
/** The battery charge is unknown. */
60+
BT_MESH_BATTERY_INDICATOR_UNKNOWN,
61+
};
62+
63+
/** Battery charging state. */
64+
enum bt_mesh_battery_charging {
65+
/** The battery is not chargeable. */
66+
BT_MESH_BATTERY_CHARGING_NOT_CHARGEABLE,
67+
/** The battery is chargeable and is not charging. */
68+
BT_MESH_BATTERY_CHARGING_CHARGEABLE_NOT_CHARGING,
69+
/** The battery is chareable and is charging. */
70+
BT_MESH_BATTERY_CHARGING_CHARGEABLE_CHARGING,
71+
/** The battery charging state is unknown. */
72+
BT_MESH_BATTERY_CHARGING_UNKNOWN,
73+
};
74+
75+
/** Battery service state. */
76+
enum bt_mesh_battery_service {
77+
/** Reserved for future use. */
78+
BT_MESH_BATTERY_SERVICE_INVALID,
79+
/** The battery does not require service. */
80+
BT_MESH_BATTERY_SERVICE_NOT_REQUIRED,
81+
/** The battery requires service. */
82+
BT_MESH_BATTERY_SERVICE_REQUIRED,
83+
/** The battery servicability is unknown. */
84+
BT_MESH_BATTERY_SERVICE_UNKNOWN,
85+
};
86+
87+
struct bt_mesh_battery_status {
88+
/**
89+
* Current battery level in percent, or
90+
* @ref BT_MESH_BATTERY_LVL_UNKNOWN.
91+
*/
92+
u8_t battery_lvl;
93+
/** Minutes until discharged, or @ref BT_MESH_BATTERY_TIME_UNKNOWN. */
94+
u32_t discharge_minutes;
95+
/** Minutes until discharged, or @ref BT_MESH_BATTERY_TIME_UNKNOWN. */
96+
u32_t charge_minutes;
97+
/** Presence state. */
98+
enum bt_mesh_battery_presence presence;
99+
/** Charge level indicator. */
100+
enum bt_mesh_battery_indicator indicator;
101+
/** Charging state. */
102+
enum bt_mesh_battery_charging charging;
103+
/** Service state. */
104+
enum bt_mesh_battery_service service;
105+
};
106+
107+
#ifdef __cplusplus
108+
}
109+
#endif
110+
111+
#endif /* BT_MESH_GEN_BATTERY_H__ */
112+
113+
/** @} */
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
.. _bt_mesh_battery_readme:
2+
3+
Generic Battery models
4+
######################
5+
6+
The Generic Battery models allow remote monitoring of the battery status of
7+
a mesh device.
8+
9+
There are two Generic Battery models:
10+
11+
- :ref:`bt_mesh_battery_srv_readme`
12+
- :ref:`bt_mesh_battery_cli_readme`
13+
14+
.. _bt_mesh_battery_srv_readme:
15+
16+
Generic Battery Server
17+
======================
18+
19+
The Generic Battery Server model provides information about the current battery
20+
status of the device.
21+
22+
States
23+
*******
24+
25+
**Generic Battery Status**: :cpp:type:`bt_mesh_battery_status`
26+
27+
The Generic Battery Status is a composite state, containing various information
28+
about the battery state. The battery state can only be changed locally, so a
29+
Generic Battery Client is only able to observe it.
30+
31+
The user is expected to hold the Generic Battery Status state memory and
32+
provide access to the state through the :cpp:member:`bt_mesh_battery_srv::get`
33+
handler function. All the fields in the Generic Battery Status have special
34+
*unknown* values, which are used by default.
35+
36+
Extended models
37+
****************
38+
39+
None.
40+
41+
Persistent storage
42+
*******************
43+
44+
None.
45+
46+
API documentation
47+
******************
48+
49+
| Header file: :file:`include/bluetooth/mesh/gen_battery_srv.h`
50+
| Source file: :file:`subsys/bluetooth/mesh/gen_battery_srv.c`
51+
52+
.. doxygengroup:: bt_mesh_battery_srv
53+
:project: nrf
54+
:members:
55+
56+
----
57+
58+
.. _bt_mesh_battery_cli_readme:
59+
60+
Generic Battery Client
61+
======================
62+
63+
The Generic Battery Client model can query the state of a Generic Battery
64+
Server model remotely, but does not have any ability to control the Battery
65+
state.
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_battery_cli.h`
81+
| Source file: :file:`subsys/bluetooth/mesh/gen_battery_cli.c`
82+
83+
.. doxygengroup:: bt_mesh_battery_cli
84+
:project: nrf
85+
:members:
86+
87+
----
88+
89+
Common types
90+
=============
91+
92+
| Header file: :file:`include/bluetooth/mesh/gen_battery.h`
93+
94+
.. doxygengroup:: bt_mesh_battery
95+
:project: nrf
96+
:members:
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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_battery_cli Generic Battery Client model
10+
* @{
11+
* @brief API for the Generic Battery Client model.
12+
*/
13+
14+
#ifndef BT_MESH_GEN_BATTERY_CLI_H__
15+
#define BT_MESH_GEN_BATTERY_CLI_H__
16+
17+
#include <bluetooth/mesh/gen_battery.h>
18+
#include <bluetooth/mesh/model_types.h>
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
struct bt_mesh_battery_cli;
25+
26+
/** @def BT_MESH_BATTERY_CLI_INIT
27+
*
28+
* @brief Initialization parameters for a @ref bt_mesh_battery_cli instance.
29+
*
30+
* @param[in] _status_handler Optional status message handler.
31+
*/
32+
#define BT_MESH_BATTERY_CLI_INIT(_status_handler) \
33+
{ \
34+
.status_handler = _status_handler, \
35+
.pub = {.msg = NET_BUF_SIMPLE(BT_MESH_MODEL_BUF_LEN( \
36+
BT_MESH_BATTERY_OP_GET, \
37+
BT_MESH_BATTERY_MSG_LEN_GET)) } \
38+
}
39+
40+
/** @def BT_MESH_MODEL_BATTERY_CLI
41+
*
42+
* @brief Generic Battery Client model composition data entry.
43+
*
44+
* @param[in] _cli Pointer to a @ref bt_mesh_battery_cli instance.
45+
*/
46+
#define BT_MESH_MODEL_BATTERY_CLI(_cli) \
47+
BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_GEN_BATTERY_CLI, \
48+
_bt_mesh_battery_cli_op, &(_cli)->pub, \
49+
BT_MESH_MODEL_USER_DATA(struct bt_mesh_battery_cli, \
50+
_cli), \
51+
&_bt_mesh_battery_cli_cb)
52+
53+
/**
54+
* Generic Battery Client structure.
55+
*
56+
* Should be initialized with the @ref BT_MESH_BATTERY_CLI_INIT macro.
57+
*/
58+
struct bt_mesh_battery_cli {
59+
/** @brief Battery status message handler.
60+
*
61+
* @param[in] cli Client that received the status message.
62+
* @param[in] ctx Context of the incoming message.
63+
* @param[in] status Battery Status of the Generic Battery Server that
64+
* published the message.
65+
*/
66+
void (*const status_handler)(
67+
struct bt_mesh_battery_cli *cli, struct bt_mesh_msg_ctx *ctx,
68+
const struct bt_mesh_battery_status *status);
69+
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+
/** Composition data model entry 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_battery_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_battery_cli_get(struct bt_mesh_battery_cli *cli,
99+
struct bt_mesh_msg_ctx *ctx,
100+
struct bt_mesh_battery_status *rsp);
101+
102+
/** @cond INTERNAL_HIDDEN */
103+
extern const struct bt_mesh_model_op _bt_mesh_battery_cli_op[];
104+
extern const struct bt_mesh_model_cb _bt_mesh_battery_cli_cb;
105+
/** @endcond */
106+
107+
#ifdef __cplusplus
108+
}
109+
#endif
110+
111+
#endif /* BT_MESH_GEN_BATTERY_CLI_H__ */
112+
113+
/* @} */

0 commit comments

Comments
 (0)