nRF5 SDK for Mesh v5.0.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 
109 #define APP_SENSOR_SERVER_DEF(_name, _force_segmented, _mic_size, _get_cb, \
110  _settings_get_cb, _setting_set_cb, \
111  _setting_get_cb, _column_get_cb, _series_get_cb, \
112  _property_array, \
113  _cadence_timer_ids, \
114  _min_interval_timer_ids, \
115  _descriptor_struct_array, _num_descs, \
116  _p_message_buffer, _message_buffer_bytes); \
117  static uint8_t m_descriptor_buf[_num_descs * SENSOR_DESCRIPTOR_MSG_SIZE]; \
118  static app_sensor_server_t _name = \
119  { \
120  .server.settings.force_segmented = _force_segmented, \
121  .server.settings.transmic_size = _mic_size, \
122  .sensor_get_cb = _get_cb, \
123  .sensor_settings_get_cb = _settings_get_cb, \
124  .sensor_setting_set_cb = _setting_set_cb, \
125  .sensor_setting_get_cb = _setting_get_cb, \
126  .sensor_column_get_cb = _column_get_cb, \
127  .sensor_series_get_cb = _series_get_cb, \
128  .p_sensor_property_array = _property_array, \
129  .p_cadence_timer_ids = _cadence_timer_ids, \
130  .p_min_interval_timer_ids = _min_interval_timer_ids, \
131  .p_sensor_descriptor = _descriptor_struct_array, \
132  .p_descriptor_message = m_descriptor_buf, \
133  .sensor_num_desc = _num_descs, \
134  .p_message_buffer = _p_message_buffer, \
135  .message_buffer_bytes = _message_buffer_bytes \
136  };
137 
138 
142 typedef struct
143 {
144  list_node_t * p_cadence_list;
145  uint16_t marshalled_list_bytes;
147 
158 typedef void (*app_sensor_get_cb_t)(const app_sensor_server_t * p_server,
159  uint16_t property_id,
160  uint8_t * p_out,
161  uint16_t * p_out_bytes);
162 
163 
174 typedef void (*app_sensor_settings_get_cb_t)(const app_sensor_server_t * p_server,
175  uint16_t property_id,
177  uint16_t * p_out_bytes);
178 
192 typedef void (*app_sensor_setting_set_cb_t)(const app_sensor_server_t * p_server,
193  uint16_t property_id,
194  uint16_t setting_property_id,
195  const sensor_setting_set_msg_pkt_t * p_in,
196  uint16_t in_bytes,
198  uint16_t * p_out_bytes);
199 
210 typedef void (*app_sensor_setting_get_cb_t)(const app_sensor_server_t * p_server,
211  uint16_t property_id,
212  uint16_t setting_property_id,
214  uint16_t * p_out_bytes);
215 
234 typedef void (*app_sensor_column_get_cb_t)(const app_sensor_server_t * p_server,
235  const sensor_column_get_msg_pkt_t * p_in,
236  uint16_t in_bytes,
238  uint16_t * p_out_bytes);
239 
257 typedef void (*app_sensor_series_get_cb_t)(const app_sensor_server_t * p_server,
258  const sensor_series_get_msg_pkt_t * p_in,
259  uint16_t in_bytes,
261  uint16_t * p_out_bytes);
262 
263 
267 {
268  sensor_setup_server_t server;
269 
280 
292 
296 
299  app_timer_id_t const * p_cadence_timer_ids;
300 
303  app_timer_id_t const * p_min_interval_timer_ids;
304 
309  /* the number of descriptors
310  */
311  uint16_t sensor_num_desc;
312  /* the actual descriptor(s)
313  */
314  const sensor_descriptor_t * p_sensor_descriptor;
317  uint8_t * p_message_buffer;
321 
327  descriptor_status_t * p_descriptor_message;
328 };
329 
346 uint32_t app_sensor_init(app_sensor_server_t * p_server, uint16_t element_index);
347 
350 #endif /* APP_SENSOR_H__ */
Internal structure to hold state.
Definition: app_sensor.h:142
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:320
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:311
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:158
descriptor_status_t * p_descriptor_message
mid-app&#39;s packed version of the descriptor
Definition: app_sensor.h:327
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:291
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:192
Application level structure holding the Sensor server model context and sensor state representation...
Definition: app_sensor.h:266
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:299
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:210
uint8_t * p_message_buffer
Points to the message buffer.
Definition: app_sensor.h:317
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:257
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:174
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:234
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:287
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:273
app_timer_id_t const * p_min_interval_timer_ids
array of timer IDs for enforcing status min interval.
Definition: app_sensor.h:303
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:276
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:283
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:295
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:324
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:279
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...
Parameters for the Sensor Descriptor.
Message format for the Sensor Setting Status message.

Documentation feedback | Developer Zone | Subscribe | Updated