nRF5 SDK for Mesh v4.2.0
app_sensor.h
1 /* Copyright (c) 2010 - 2020, Nordic Semiconductor ASA
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form, except as embedded into a Nordic
11  * Semiconductor ASA integrated circuit in a product or a software update for
12  * such product, must reproduce the above copyright notice, this list of
13  * conditions and the following disclaimer in the documentation and/or other
14  * materials provided with the distribution.
15  *
16  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
17  * contributors may be used to endorse or promote products derived from this
18  * software without specific prior written permission.
19  *
20  * 4. This software, with or without modification, must only be used with a
21  * Nordic Semiconductor ASA integrated circuit.
22  *
23  * 5. Any software provided in binary form under this license must not be reverse
24  * engineered, decompiled, modified and/or disassembled.
25  *
26  * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
27  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28  * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
29  * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
30  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
35  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef APP_SENSOR_H__
39 #define APP_SENSOR_H__
40 
41 #include <stdint.h>
42 
43 #include "list.h"
44 
45 #include "sensor_messages.h"
46 #include "sensor_setup_server.h"
47 #include "app_timer.h"
48 
78 typedef uint8_t pir_data_size_t;
79 
80 /* Forward declaration */
81 typedef struct __app_sensor_server_t app_sensor_server_t;
82 
83 /* internal data for mid-app */
84 typedef uint8_t descriptor_status_t;
85 
108 #define APP_SENSOR_SERVER_DEF(_name, _force_segmented, _mic_size, _get_cb, \
109  _settings_get_cb, _setting_set_cb, \
110  _setting_get_cb, _column_get_cb, _series_get_cb, \
111  _property_array, \
112  _cadence_timer_ids, \
113  _descriptor_struct_array, _num_descs, \
114  _p_message_buffer, _message_buffer_bytes); \
115  static uint8_t m_descriptor_buf[_num_descs * SENSOR_DESCRIPTOR_MSG_SIZE]; \
116  static app_sensor_server_t _name = \
117  { \
118  .server.settings.force_segmented = _force_segmented, \
119  .server.settings.transmic_size = _mic_size, \
120  .sensor_get_cb = _get_cb, \
121  .sensor_settings_get_cb = _settings_get_cb, \
122  .sensor_setting_set_cb = _setting_set_cb, \
123  .sensor_setting_get_cb = _setting_get_cb, \
124  .sensor_column_get_cb = _column_get_cb, \
125  .sensor_series_get_cb = _series_get_cb, \
126  .p_sensor_property_array = _property_array, \
127  .p_cadence_timer_ids = _cadence_timer_ids, \
128  .p_sensor_descriptor = _descriptor_struct_array, \
129  .p_descriptor_message = m_descriptor_buf, \
130  .sensor_num_desc = _num_descs, \
131  .p_message_buffer = _p_message_buffer, \
132  .message_buffer_bytes = _message_buffer_bytes \
133  };
134 
135 
139 typedef struct
140 {
141  list_node_t * p_cadence_list;
142  uint16_t marshalled_list_bytes;
144 
155 typedef void (*app_sensor_get_cb_t)(const app_sensor_server_t * p_server,
156  uint16_t property_id,
157  uint8_t * p_out,
158  uint16_t * p_out_bytes);
159 
160 
171 typedef void (*app_sensor_settings_get_cb_t)(const app_sensor_server_t * p_server,
172  uint16_t property_id,
174  uint16_t * p_out_bytes);
175 
189 typedef void (*app_sensor_setting_set_cb_t)(const app_sensor_server_t * p_server,
190  uint16_t property_id,
191  uint16_t setting_property_id,
192  const sensor_setting_set_msg_pkt_t * p_in,
193  uint16_t in_bytes,
195  uint16_t * p_out_bytes);
196 
207 typedef void (*app_sensor_setting_get_cb_t)(const app_sensor_server_t * p_server,
208  uint16_t property_id,
209  uint16_t setting_property_id,
211  uint16_t * p_out_bytes);
212 
231 typedef void (*app_sensor_column_get_cb_t)(const app_sensor_server_t * p_server,
232  const sensor_column_get_msg_pkt_t * p_in,
233  uint16_t in_bytes,
235  uint16_t * p_out_bytes);
236 
254 typedef void (*app_sensor_series_get_cb_t)(const app_sensor_server_t * p_server,
255  const sensor_series_get_msg_pkt_t * p_in,
256  uint16_t in_bytes,
258  uint16_t * p_out_bytes);
259 
260 
264 {
265  sensor_setup_server_t server;
266 
277 
289 
293 
296  app_timer_id_t const * p_cadence_timer_ids;
297 
302  /* the number of descriptors
303  */
304  uint16_t sensor_num_desc;
305  /* the actual descriptor(s)
306  */
307  const sensor_descriptor_t * p_sensor_descriptor;
310  uint8_t * p_message_buffer;
314 
320  descriptor_status_t * p_descriptor_message;
321 };
322 
339 uint32_t app_sensor_init(app_sensor_server_t * p_server, uint16_t element_index);
340 
343 #endif /* APP_SENSOR_H__ */
Internal structure to hold state.
Definition: app_sensor.h:139
Message format for the Sensor Column Status message 4.2.16 Sensor Column Status Sensor Column Status ...
uint16_t message_buffer_bytes
The number of bytes of buffer space at p_message_buffer.
Definition: app_sensor.h:313
uint16_t sensor_num_desc
Main&#39;s descriptor definition - passed in by main (main&#39;s static const) - mid app uses this to create ...
Definition: app_sensor.h:304
void(* app_sensor_get_cb_t)(const app_sensor_server_t *p_server, uint16_t property_id, uint8_t *p_out, uint16_t *p_out_bytes)
Application state read callback prototype.
Definition: app_sensor.h:155
descriptor_status_t * p_descriptor_message
mid-app&#39;s packed version of the descriptor
Definition: app_sensor.h:320
app_sensor_series_get_cb_t sensor_series_get_cb
Callback to be called for requesting a series of formatted sensor data from the user application...
Definition: app_sensor.h:288
Message format for the Sensor Series Status message 4.2.18 Sensor Series Status Sensor Series Status ...
void(* app_sensor_setting_set_cb_t)(const app_sensor_server_t *p_server, uint16_t property_id, uint16_t setting_property_id, const sensor_setting_set_msg_pkt_t *p_in, uint16_t in_bytes, sensor_setting_status_msg_pkt_t *p_out, uint16_t *p_out_bytes)
Application state set setting callback prototype.
Definition: app_sensor.h:189
Application level structure holding the Sensor server model context and sensor state representation...
Definition: app_sensor.h:263
uint32_t app_sensor_init(app_sensor_server_t *p_server, uint16_t element_index)
Initializes the behavioral module for the Sensor model.
app_timer_id_t const * p_cadence_timer_ids
array of timer IDs for supporting fast cadence.
Definition: app_sensor.h:296
void(* app_sensor_setting_get_cb_t)(const app_sensor_server_t *p_server, uint16_t property_id, uint16_t setting_property_id, sensor_setting_status_msg_pkt_t *p_out, uint16_t *p_out_bytes)
Application state read single setting callback prototype.
Definition: app_sensor.h:207
uint8_t * p_message_buffer
Points to the message buffer.
Definition: app_sensor.h:310
void(* app_sensor_series_get_cb_t)(const app_sensor_server_t *p_server, const sensor_series_get_msg_pkt_t *p_in, uint16_t in_bytes, sensor_series_status_msg_pkt_t *p_out, uint16_t *p_out_bytes)
Application state read series callback prototype.
Definition: app_sensor.h:254
void(* app_sensor_settings_get_cb_t)(const app_sensor_server_t *p_server, uint16_t property_id, sensor_settings_status_msg_pkt_t *p_out, uint16_t *p_out_bytes)
Application state read settings callback prototype.
Definition: app_sensor.h:171
void(* app_sensor_column_get_cb_t)(const app_sensor_server_t *p_server, const sensor_column_get_msg_pkt_t *p_in, uint16_t in_bytes, sensor_column_status_msg_pkt_t *p_out, uint16_t *p_out_bytes)
Application state read column callback prototype.
Definition: app_sensor.h:231
app_sensor_column_get_cb_t sensor_column_get_cb
Callback to be called for requesting a column of formatted sensor data from the user application...
Definition: app_sensor.h:284
app_sensor_get_cb_t sensor_get_cb
Callback to be called for requesting current sensor data from the user application.
Definition: app_sensor.h:270
app_sensor_settings_get_cb_t sensor_settings_get_cb
Callback to be called for requesting settings from the user application.
Definition: app_sensor.h:273
app_sensor_setting_get_cb_t sensor_setting_get_cb
Callback to be called for requesting a setting from the user application.
Definition: app_sensor.h:280
Message format for the Sensor Setting Set/Set Unacknowledged message (partial) 4.2.10 Sensor Setting Set Sensor Setting Set is an acknowledged message used to set the Sensor Setting state of an element (see Section 4.1.2).
uint16_t * p_sensor_property_array
Array of the supported property IDs.
Definition: app_sensor.h:292
Message format for the Sensor Column Get message (partial) 4.2.15 Sensor Column Get Sensor Column Get...
app_sensor_state_t state
Internal variable.
Definition: app_sensor.h:317
app_sensor_setting_set_cb_t sensor_setting_set_cb
Callback to be called for informing the user application to update the settings.
Definition: app_sensor.h:276
Message format for the Sensor Settings Status message.
Message format for the Sensor Series Get message (partial) 4.2.17 Sensor Series Get Sensor Series Get...
Sensor Descriptor - the sensor-specific sensor descriptor.
Message format for the Sensor Setting Status message.

Documentation feedback | Developer Zone | Subscribe | Updated