nRF5 SDK for Mesh v3.2.0
app_level.h
1 /* Copyright (c) 2010 - 2019, 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_LEVEL_H__
39 #define APP_LEVEL_H__
40 
41 #include <stdint.h>
42 
43 #include "generic_level_server.h"
44 #include "app_timer.h"
45 #include "fsm.h"
46 
104 #define APP_LEVEL_SERVER_DEF(_name, _force_segmented, _mic_size, _p_dtt, _set_cb, _get_cb) \
105  APP_TIMER_DEF(_name ## _timer); \
106  static app_level_server_t _name = \
107  { \
108  .server.settings.force_segmented = _force_segmented, \
109  .server.settings.transmic_size = _mic_size, \
110  .timer.p_timer_id = &_name ## _timer, \
111  .p_dtt_ms = _p_dtt, \
112  .level_set_cb = _set_cb, \
113  .level_get_cb = _get_cb \
114  };
115 
117 typedef enum
118 {
128 
130 typedef struct
131 {
133  int32_t required_delta;
137 
139 typedef struct
140 {
142  int16_t required_move;
146 
148 typedef struct
149 {
151  int16_t present_level;
153  int16_t target_level;
157  uint32_t delay_ms;
158 
161  union {
162  /* Parameters for Set Transition */
163  set_transition_t set;
164  /* Parameters for Move Transition */
165  move_transition_t move;
166  } params;
168 
169 /* Forward declaration */
170 typedef struct __app_level_server_t app_level_server_t;
171 
186 typedef void (*app_level_set_cb_t)(const app_level_server_t * p_server, int16_t present_level);
187 
196 typedef void (*app_level_get_cb_t)(const app_level_server_t * p_server, int16_t * p_present_level);
197 
200 {
202  generic_level_server_t server;
209 
211  const uint32_t * p_dtt_ms;
215 
217  fsm_t fsm;
218 };
219 
233 uint32_t app_level_current_value_publish(app_level_server_t * p_server);
234 
247 uint32_t app_level_init(app_level_server_t * p_server, uint8_t element_index);
248 
250 #endif /* APP_LEVEL_H__ */
indicating MOVE SET message
Definition: app_level.h:124
void(* app_level_get_cb_t)(const app_level_server_t *p_server, int16_t *p_present_level)
Application state read callback prototype.
Definition: app_level.h:196
int32_t required_delta
For storing actual required amount of level change.
Definition: app_level.h:133
int16_t required_move
Scaled representation of the Level value.
Definition: app_level.h:142
app_level_transition_type_t transition_type
Transition Type.
Definition: app_level.h:160
Application level structure holding the Level server model context and Level state representation...
Definition: app_level.h:199
uint32_t delay_ms
Time to delay the processing of received SET message.
Definition: app_level.h:157
void(* app_level_set_cb_t)(const app_level_server_t *p_server, int16_t present_level)
Application state set callback prototype.
Definition: app_level.h:186
const uint32_t * p_dtt_ms
Pointer to the default transition time value (in milliseconds) if present.
Definition: app_level.h:211
indicating SET message
Definition: app_level.h:120
Structure for model timers.
Definition: model_common.h:142
app_level_transition_type_t
Transition types.
Definition: app_level.h:117
fsm_t fsm
Internal.
Definition: app_level.h:217
uint32_t app_level_current_value_publish(app_level_server_t *p_server)
Initiates value fetch from the user application by calling a get callback, updates internal state...
Internal structure for holding Move transition related variables.
Definition: app_level.h:139
int16_t present_level
Present value of the Level state.
Definition: app_level.h:151
indicating DELTA SET message
Definition: app_level.h:122
generic_level_server_t server
Level server model interface context structure.
Definition: app_level.h:202
int16_t initial_present_level
Initial present level required for handling Set/Delta Set message.
Definition: app_level.h:135
indicating no transition
Definition: app_level.h:126
model_timer_t timer
Timer instance pointer.
Definition: app_level.h:204
int16_t initial_present_level
Initial present level required for handling Set/Delta Set message.
Definition: app_level.h:144
uint32_t app_level_init(app_level_server_t *p_server, uint8_t element_index)
Initializes the behavioral module for the Generic Level model.
uint32_t transition_time_ms
Remaining time to reach target_level.
Definition: app_level.h:155
app_level_set_cb_t level_set_cb
Callaback to be called for informing the user application to update the value.
Definition: app_level.h:206
Internal structure to hold state and timing information.
Definition: app_level.h:148
app_level_get_cb_t level_get_cb
Callback to be called for requesting current value from the user application.
Definition: app_level.h:208
Internal structure for holding Set/Delta Set transition related variables.
Definition: app_level.h:130
app_level_state_t state
Internal variable.
Definition: app_level.h:214
int16_t target_level
Target value of the Level state, as received from the model interface.
Definition: app_level.h:153

Documentation feedback | Developer Zone | Subscribe | Updated