nRF Connect SDK API 0.1.0
Loading...
Searching...
No Matches
sensor_srv.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
13#ifndef BT_MESH_SENSOR_SRV_H__
14#define BT_MESH_SENSOR_SRV_H__
15
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
23
35#define BT_MESH_SENSOR_SRV_INIT(_sensors, _count) \
36 { \
37 .sensor_array = _sensors, \
38 .sensor_count = \
39 MIN(CONFIG_BT_MESH_SENSOR_SRV_SENSORS_MAX, _count), \
40 }
41
51#define BT_MESH_MODEL_SENSOR_SRV(_srv, ...) \
52 BT_MESH_MODEL_METADATA_CB(BT_MESH_MODEL_ID_SENSOR_SRV, \
53 _bt_mesh_sensor_srv_op, &(_srv)->pub, \
54 BT_MESH_MODEL_USER_DATA(struct bt_mesh_sensor_srv, \
55 _srv), \
56 &_bt_mesh_sensor_srv_cb, __VA_ARGS__), \
57 BT_MESH_MODEL_CB(BT_MESH_MODEL_ID_SENSOR_SETUP_SRV, \
58 _bt_mesh_sensor_setup_srv_op, \
59 &(_srv)->setup_pub, \
60 BT_MESH_MODEL_USER_DATA(struct bt_mesh_sensor_srv, \
61 _srv), \
62 &_bt_mesh_sensor_setup_srv_cb)
63
65#define BT_MESH_SENSOR_PROP_METADATA_ID 0x0001
66
72#define BT_MESH_SENSOR_PROP_METADATA(...) \
73 BT_MESH_MODELS_METADATA_ENTRY(2 * ARRAY_SIZE(((uint16_t[]){__VA_ARGS__})), \
74 BT_MESH_SENSOR_PROP_METADATA_ID, \
75 ((uint16_t[]){__VA_ARGS__}))
76
82 sys_slist_t sensors;
84 uint16_t seq;
86 uint8_t sensor_count;
87
89 struct bt_mesh_model_pub pub;
90 /* Publication buffer */
91 struct net_buf_simple pub_buf;
92 /* Publication data */
93 uint8_t pub_data[BT_MESH_MODEL_BUF_LEN(
94 BT_MESH_SENSOR_OP_STATUS,
95 (CONFIG_BT_MESH_SENSOR_SRV_SENSORS_MAX *
96 BT_MESH_SENSOR_STATUS_MAXLEN))];
98 struct bt_mesh_model_pub setup_pub;
99 /* Publication buffer */
100 struct net_buf_simple setup_pub_buf;
101 /* Publication data */
102 uint8_t setup_pub_data[MAX(
103 BT_MESH_MODEL_BUF_LEN(
104 BT_MESH_SENSOR_OP_SETTING_STATUS,
105 BT_MESH_SENSOR_MSG_MAXLEN_SETTING_STATUS),
106 BT_MESH_MODEL_BUF_LEN(
107 BT_MESH_SENSOR_OP_CADENCE_STATUS,
108 BT_MESH_SENSOR_MSG_MAXLEN_CADENCE_STATUS))];
110 const struct bt_mesh_model *model;
111};
112
113#if !defined(CONFIG_BT_MESH_SENSOR_USE_LEGACY_SENSOR_VALUE) || defined(__DOXYGEN__)
133 struct bt_mesh_msg_ctx *ctx,
134 struct bt_mesh_sensor *sensor,
135 const struct bt_mesh_sensor_value *value);
136#else /* defined(CONFIG_BT_MESH_SENSOR_USE_LEGACY_SENSOR_VALUE) */
156 struct bt_mesh_msg_ctx *ctx,
157 struct bt_mesh_sensor *sensor,
158 const struct sensor_value *value);
159#endif /* !defined(CONFIG_BT_MESH_SENSOR_USE_LEGACY_SENSOR_VALUE) */
160
181 struct bt_mesh_sensor *sensor);
182
184extern const struct bt_mesh_model_cb _bt_mesh_sensor_srv_cb;
185extern const struct bt_mesh_model_op _bt_mesh_sensor_srv_op[];
186extern const struct bt_mesh_model_cb _bt_mesh_sensor_setup_srv_cb;
187extern const struct bt_mesh_model_op _bt_mesh_sensor_setup_srv_op[];
190#ifdef __cplusplus
191}
192#endif
193
194#endif /* BT_MESH_SENSOR_SRV_H__ */
195
int bt_mesh_sensor_srv_pub(struct bt_mesh_sensor_srv *srv, struct bt_mesh_msg_ctx *ctx, struct bt_mesh_sensor *sensor, const struct bt_mesh_sensor_value *value)
Publish a sensor value.
int bt_mesh_sensor_srv_sample(struct bt_mesh_sensor_srv *srv, struct bt_mesh_sensor *sensor)
Make the server to take a sample of the sensor, and publish if the value changed sufficiently.
struct net_buf_simple setup_pub_buf
Definition: sensor_srv.h:100
struct bt_mesh_model_pub pub
Definition: sensor_srv.h:89
uint8_t sensor_count
Definition: sensor_srv.h:86
sys_slist_t sensors
Definition: sensor_srv.h:82
const struct bt_mesh_model * model
Definition: sensor_srv.h:110
struct bt_mesh_model_pub setup_pub
Definition: sensor_srv.h:98
struct net_buf_simple pub_buf
Definition: sensor_srv.h:91
struct bt_mesh_sensor *const * sensor_array
Definition: sensor_srv.h:80
uint8_t setup_pub_data[MAX(BT_MESH_MODEL_BUF_LEN(BT_MESH_SENSOR_OP_SETTING_STATUS, BT_MESH_SENSOR_MSG_MAXLEN_SETTING_STATUS), BT_MESH_MODEL_BUF_LEN(BT_MESH_SENSOR_OP_CADENCE_STATUS, BT_MESH_SENSOR_MSG_MAXLEN_CADENCE_STATUS))]
Definition: sensor_srv.h:108
uint16_t seq
Definition: sensor_srv.h:84
uint8_t pub_data[BT_MESH_MODEL_BUF_LEN(BT_MESH_SENSOR_OP_STATUS,(CONFIG_BT_MESH_SENSOR_SRV_SENSORS_MAX *BT_MESH_SENSOR_STATUS_MAXLEN))]
Definition: sensor_srv.h:96
Definition: sensor_srv.h:78
Definition: sensor.h:176
Definition: sensor.h:565