1 /*
2  * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /** @file
8  *  @brief Bluetooth Mesh Sensor Client Model APIs.
9  */
10 
11 #ifndef _SENSOR_CLIENT_H_
12 #define _SENSOR_CLIENT_H_
13 
14 #include "client_common.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /* Sensor Client Model Callback */
21 extern const struct bt_mesh_model_cb bt_mesh_sensor_client_cb;
22 
23 /* Sensor Client Model Context */
24 extern const struct bt_mesh_model_op bt_mesh_sensor_cli_op[];
25 
26 /** @def BLE_MESH_MODEL_SENSOR_CLI
27  *
28  *  Define a new sensor client model. Note that this API needs to
29  *  be repeated for each element which the application wants to
30  *  have a sensor client model on.
31  *  @param cli_pub  Pointer to a unique struct bt_mesh_model_pub.
32  *  @param cli_data Pointer to a unique struct bt_mesh_sensor_cli.
33  *
34  *  @return New sensor client model instance.
35  */
36 #define BLE_MESH_MODEL_SENSOR_CLI(cli_pub, cli_data)    \
37         BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_SENSOR_CLI,    \
38             bt_mesh_sensor_cli_op, cli_pub, cli_data, &bt_mesh_sensor_client_cb)
39 
40 typedef bt_mesh_client_user_data_t      bt_mesh_sensor_client_t;
41 typedef bt_mesh_client_internal_data_t  sensor_internal_data_t;
42 
43 struct bt_mesh_sensor_descriptor_status {
44     struct net_buf_simple *descriptor; /* Sequence of 8-octet sensor descriptors (optional) */
45 };
46 
47 struct bt_mesh_sensor_cadence_status {
48     uint16_t property_id;              /* Property for the sensor                       */
49     struct net_buf_simple *sensor_cadence_value; /* Value of sensor cadence state */
50 };
51 
52 struct bt_mesh_sensor_settings_status {
53     uint16_t sensor_property_id;              /* Property ID identifying a sensor                        */
54     struct net_buf_simple *sensor_setting_property_ids; /* A sequence of N sensor setting property IDs (optional) */
55 };
56 
57 struct bt_mesh_sensor_setting_status {
58     bool     op_en;                      /* Indicate whether optional parameters included       */
59     uint16_t sensor_property_id;         /* Property ID identifying a sensor                    */
60     uint16_t sensor_setting_property_id; /* Setting ID identifying a setting within a sensor    */
61     uint8_t  sensor_setting_access;      /* Read/Write access rights for the setting (optional) */
62     struct net_buf_simple *sensor_setting_raw; /* Raw value for the setting */
63 };
64 
65 struct bt_mesh_sensor_status {
66     struct net_buf_simple *marshalled_sensor_data; /* Value of sensor data state (optional) */
67 };
68 
69 struct bt_mesh_sensor_column_status {
70     uint16_t property_id;             /* Property identifying a sensor and the Y axis  */
71     struct net_buf_simple *sensor_column_value; /* Left values of sensor column status */
72 };
73 
74 struct bt_mesh_sensor_series_status {
75     uint16_t property_id;             /* Property identifying a sensor and the Y axis  */
76     struct net_buf_simple *sensor_series_value; /* Left values of sensor series status */
77 };
78 
79 struct bt_mesh_sensor_descriptor_get {
80     bool     op_en;       /* Indicate whether optional parameters included */
81     uint16_t property_id; /* Property ID for the sensor (optional)         */
82 };
83 
84 struct bt_mesh_sensor_cadence_get {
85     uint16_t property_id; /* Property ID for the sensor */
86 };
87 
88 struct bt_mesh_sensor_cadence_set {
89     uint16_t property_id;                     /* Property ID for the sensor                                */
90     uint8_t  fast_cadence_period_divisor : 7, /* Divisor for the publish period                            */
91              status_trigger_type : 1;         /* The unit and format of the Status Trigger Delta fields    */
92     struct net_buf_simple *status_trigger_delta_down; /* Delta down value that triggers a status message */
93     struct net_buf_simple *status_trigger_delta_up; /* Delta up value that triggers a status message */
94     uint8_t  status_min_interval;             /* Minimum interval between two consecutive Status messages  */
95     struct net_buf_simple *fast_cadence_low;  /* Low value for the fast cadence range */
96     struct net_buf_simple *fast_cadence_high; /* Fast value for the fast cadence range */
97 };
98 
99 struct bt_mesh_sensor_settings_get {
100     uint16_t sensor_property_id; /* Property ID for the sensor */
101 };
102 
103 struct bt_mesh_sensor_setting_get {
104     uint16_t sensor_property_id;         /* Property ID identifying a sensor                 */
105     uint16_t sensor_setting_property_id; /* Setting ID identifying a setting within a sensor */
106 };
107 
108 struct bt_mesh_sensor_setting_set {
109     uint16_t sensor_property_id;         /* Property ID identifying a sensor                 */
110     uint16_t sensor_setting_property_id; /* Setting ID identifying a setting within a sensor */
111     struct net_buf_simple *sensor_setting_raw; /* Raw value for the setting */
112 };
113 
114 struct bt_mesh_sensor_get {
115     bool     op_en;       /* Indicate whether optional parameters included */
116     uint16_t property_id; /* Property ID for the sensor (optional)         */
117 };
118 
119 struct bt_mesh_sensor_column_get {
120     uint16_t property_id;     /* Property identifying a sensor                */
121     struct net_buf_simple *raw_value_x; /* Raw value identifying a column */
122 };
123 
124 struct bt_mesh_sensor_series_get {
125     bool     op_en;            /* Indicate whether optional parameters included         */
126     uint16_t property_id;      /* Property identifying a sensor                         */
127     struct net_buf_simple *raw_value_x1; /* Raw value identifying a starting column (optional) */
128     struct net_buf_simple *raw_value_x2; /* Raw value identifying a ending column (C.1) */
129 };
130 
131 /**
132  * @brief This function is called to get sensor states.
133  *
134  * @param[in]  common: Message common information structure
135  * @param[in]  get:    Pointer of sensor get message value
136  *
137  * @return Zero-success, other-fail
138  */
139 int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, void *get);
140 
141 /**
142  * @brief This function is called to set sensor states.
143  *
144  * @param[in]  common: Message common information structure
145  * @param[in]  set:    Pointer of sensor set message value
146  *
147  * @return Zero-success, other-fail
148  */
149 int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, void *set);
150 
151 #ifdef __cplusplus
152 }
153 #endif
154 
155 #endif /* _SENSOR_CLIENT_H_ */
156