nRF5 SDK for Mesh v5.0.0
app_sensor_utils.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_UTILS_H__
39 #define APP_SENSOR_UTILS_H__
40 
41 #include "list.h"
42 #include "model_common.h"
43 
44 #include "app_sensor.h"
45 #include "sensor_utils.h"
46 
47 typedef struct __sensor_cadence_t sensor_cadence_t;
48 
49 typedef bool (*sensor_in_fast_region_t)(sensor_cadence_t *);
50 typedef bool (*sensor_delta_trigger_fast_t)(sensor_cadence_t *);
51 typedef uint16_t (*cadence_value_marshall_t)(sensor_cadence_t *, uint8_t *, uint16_t);
52 
54 {
55  list_node_t list_node;
59  app_sensor_server_t * p_server;
61  uint8_t * p_trigger_delta_up;
62  uint8_t * p_fast_cadence_low;
63  uint8_t * p_fast_cadence_high;
64  uint8_t * p_previous_value;
65  uint8_t * p_current_value;
66  sensor_in_fast_region_t in_fast_region;
67  sensor_delta_trigger_fast_t delta_trigger_fast;
68  cadence_value_marshall_t value_marshall;
69  uint16_t property_id;
71  uint8_t trigger_type;
75  uint16_t marshalled_bytes;
76 };
77 
92 uint8_t * sensor_marshalled_entry_parse(uint8_t * p_data_buf,
93  uint8_t * p_format,
94  uint8_t * p_data_length,
95  uint16_t * p_property_id,
96  uint8_t ** pp_data_value);
97 
108 uint8_t sensor_percentage8_create(uint8_t value, uint8_t b_exp);
109 
118 uint8_t sensor_percentage8_parse(uint8_t value, uint8_t * p_b_exp);
119 
133 sensor_cadence_t * sensor_cadence_create(uint16_t property_id,
134  uint8_t * p_buffer,
135  uint16_t * p_bytes);
136 
154 bool sensor_cadence_set(app_sensor_server_t * p_server,
155  const sensor_cadence_set_msg_pkt_t * p_in,
156  uint16_t in_bytes,
157  sensor_cadence_status_msg_pkt_t * p_out,
158  uint16_t * p_out_bytes);
159 
160 
170 void sensor_cadence_get(app_sensor_server_t * p_server,
171  uint16_t property_id,
172  sensor_cadence_status_msg_pkt_t * p_out,
173  uint16_t * p_out_bytes);
174 
183 void sensor_cadence_to_buffer_serialize(sensor_cadence_t * p_cadence,
184  uint8_t * p_buffer,
185  uint16_t * p_bytes);
186 
203 sensor_cadence_t * sensor_cadence_to_buffer_deserialize(uint8_t * p_in_buffer,
204  uint16_t in_bytes,
205  uint8_t * p_out_buffer,
206  uint16_t * p_out_bytes);
207 
214 void sensor_initialize(app_sensor_server_t *p_server);
215 
216 
226 app_sensor_server_t * sensor_list_activate(app_sensor_server_t * p_server,
227  sensor_status_msg_pkt_t * p_out,
228  uint16_t * p_out_bytes);
229 
239 void sensor_activate(app_sensor_server_t * p_server,
240  uint16_t property_id,
241  sensor_status_msg_pkt_t * p_out,
242  uint16_t * p_out_bytes);
243 
251 uint32_t sensor_cadence_publication_abort(app_sensor_server_t * p_server);
252 
272 uint32_t sensor_status_publish(app_sensor_server_t * p_server, uint16_t property_id);
273 
274 #endif
uint16_t marshalled_bytes
The marshalled value size.
uint16_t range_value_bytes_allocated
buffer size for value arrays
cadence_value_marshall_t value_marshall
Function to marshall the data in the supplied buffer into correct format.
sensor_in_fast_region_t in_fast_region
Function returning whether the value is in the fast cadence region.
uint8_t * p_previous_value
The previous sensor value.
Message format for the Sensor Cadence Set/Set Unacknowledged message (partial) 4.2.4 Sensor Cadence Set Sensor Cadence Set is an acknowledged message used to set the Sensor Cadence state of an element (see Section 4.1.3).
uint16_t delta_value_bytes_allocated
buffer size for delta arrays
Structure for model timers.
Definition: model_common.h:198
model_timer_t timer
For providing cadence.
uint8_t fast_period_exponent
Fast cadence exponent.
uint8_t trigger_type
Fast cadence trigger type.
sensor_delta_trigger_fast_t delta_trigger_fast
Function returning whether the delta should trigger fast cadence.
uint8_t min_interval_exponent
Minimum cadence interval.
model_timer_t min_interval_timer
For enforcing status min interval.
uint8_t * p_current_value
The current sensor value.
uint8_t * p_fast_cadence_high
Value for fast cadence range.
uint8_t * p_fast_cadence_low
Value for fast cadence range.
bool min_interval_publication_pending
Has a publication been scheduled waiting for min interval to expire.
uint8_t * p_trigger_delta_down
Value triggers fast cadence.
app_sensor_server_t * p_server
Identifies the owning server.
uint16_t property_id
Sensor property ID.
uint8_t * p_trigger_delta_up
Value triggers fast cadence.

Documentation feedback | Developer Zone | Subscribe | Updated