lls_c.h
Go to the documentation of this file.
1 /**
2 *****************************************************************************************
3 *
4 * @file lls_c.h
5 *
6 * @brief Link Loss Service Client API
7 *
8 *****************************************************************************************
9 * @attention
10 #####Copyright (c) 2019 GOODIX
11 All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions are met:
15 * Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 notice, this list of conditions and the following disclaimer in the
19 documentation and/or other materials provided with the distribution.
20 * Neither the name of GOODIX nor the names of its contributors may be used
21 to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 POSSIBILITY OF SUCH DAMAGE.
35 *****************************************************************************************
36 */
37
38 /**
39 * @addtogroup BLE_SRV BLE Services
40 * @{
41 */
42
43 /**
44 * @defgroup BLE_SDK_LLS_C Link Loss Service Client (LLS_C)
45 * @{
46 * @brief Link Loss Service Client module.
47 *
48 * @details The Link Loss Service Client contains the APIs and types, which can be used by the
49 * application to discovery of Link Loss Service of peer and interact with it.
50 *
51 * The application must provide an event handler to register, then call \ref lls_client_init().
52 * After Link Loss Service Client discoveries peer Link Loss Service, application can call
53 * \ref lls_c_alert_level_set() and \ref lls_c_alert_level_read() to get Alert Level from peer.
54 */
55
56 #ifndef __LLS_C_H__
57 #define __LLS_C_H__
58
59 #include "gr55xx_sys.h"
60 #include "ble_prf_types.h"
61 #include "custom_config.h"
62 #include <stdint.h>
63 #include <stdbool.h>
64
65 /**
66 * @defgroup LLS_C_MACRO Defines
67 * @{
68 */
69 #define LLS_C_CONNECTION_MAX (10 < CFG_MAX_CONNECTIONS ?\
70 10 : CFG_MAX_CONNECTIONS) /**< Maximum number of LLS Client connections. */
71 /** @} */
72
73 /**
74 * @defgroup LLS_C_ENUM Enumerations
75 * @{
76 */
77 /**@brief Link Loss Service Client alert levels. */
78 typedef enum
79 {
80 LLS_C_ALERT_LEVEL_NO_ALERT, /**< No alert. */
81 LLS_C_ALERT_LEVEL_MILD_ALERT, /**< Mild alert. */
82 LLS_C_ALERT_LEVEL_HIGH_ALERT, /**< High alert. */
83 } lls_c_alert_level_t;
84
85 /**@brief Link Loss Service Client event type. */
86 typedef enum
87 {
88 LLS_C_EVT_INVALID, /**< LLS Client invalid event. */
89 LLS_C_EVT_DISCOVERY_COMPLETE, /**< LLS Client has found LLS service and its characteristics. */
90 LLS_C_EVT_DISCOVERY_FAIL, /**< LLS Client found LLS service failed because of invalid operation or no found at the peer. */
91 LLS_C_EVT_ALERT_LEVEL_SET_SUCCESS, /**< LLS Client has set Alert Level characteristics. */
92 LLS_C_EVT_ALERT_LEVEL_SET_ERR, /**< Error occured when LLS Client set Alert Level characteristics. */
93 LLS_C_EVT_ALERT_LEVEL_RECEIVE, /**< LLS Client has received Alert Level value. */
94 } lls_c_evt_type_t;
95 /** @} */
96
97 /**
98 * @defgroup LLS_C_STRUCT Structures
99 * @{
100 */
101 /**@brief Handles on the connected peer device needed to interact with it. */
102 typedef struct
103 {
104 uint16_t lls_srvc_start_handle; /**< LLS Service start handle. */
105 uint16_t lls_srvc_end_handle; /**< LLS Service end handle. */
106 uint16_t lls_alert_level_handle; /**< LLS Alert Level characteristic Value handle which has been got from peer. */
107 } lls_c_handles_t;
108
109 /**@brief Link Loss Service Client event. */
110 typedef struct
111 {
112 uint8_t conn_idx; /**< The connection index. */
113 lls_c_evt_type_t evt_type; /**< LLS Client event type. */
114 lls_c_alert_level_t alert_level; /**< Alert level. */
115 } lls_c_evt_t;
116 /** @} */
117
118 /**
119 * @defgroup LLS_C_TYPEDEF Typedefs
120 * @{
121 */
122 /**@brief Link Loss Service Client event handler type. */
123 typedef void (*lls_c_evt_handler_t)(lls_c_evt_t *p_evt);
124 /** @} */
125
126 /**
127 * @defgroup LLS_C_FUNCTION Functions
128 * @{
129 */
130 /**
131 *****************************************************************************************
132 * @brief Register LLS Client event handler.
133 *
134 * @param[in] evt_handler: Link Loss Service Client event handler.
135 *
136 * @return Result of initialization.
137 *****************************************************************************************
138 */
139 sdk_err_t lls_client_init(lls_c_evt_handler_t evt_handler);
140
141 /**
142 *****************************************************************************************
143 * @brief Discovery Link Loss Service on peer.
144 *
145 * @param[in] conn_idx: Index of connection.
146 *
147 * @return Operation result.
148 *****************************************************************************************
149 */
150 sdk_err_t lls_c_disc_srvc_start(uint8_t conn_idx);
151
152 /**
153 *****************************************************************************************
154 * @brief Set peer Alert Level.
155 *
156 * @param[in] conn_idx: Index of connection.
157 * @param[in] alert_level: Alert level.
158 *
159 * @return Operation result.
160 *****************************************************************************************
161 */
162 sdk_err_t lls_c_alert_level_set(uint8_t conn_idx, lls_c_alert_level_t alert_level);
163
164 /**
165 *****************************************************************************************
166 * @brief Read Alert Level characteristic value.
167 *
168 * @param[in] conn_idx: Index of connection.
169 *
170 * @return Operation result.
171 *****************************************************************************************
172 */
173 sdk_err_t lls_c_alert_level_read(uint8_t conn_idx);
174 /** @} */
175
176 #endif
177 /** @} */
178 /** @} */
lls_c_evt_type_t
lls_c_evt_type_t
Link Loss Service Client event type.
Definition: lls_c.h:87
LLS_C_EVT_ALERT_LEVEL_RECEIVE
@ LLS_C_EVT_ALERT_LEVEL_RECEIVE
LLS Client has received Alert Level value.
Definition: lls_c.h:93
lls_c_evt_t::conn_idx
uint8_t conn_idx
The connection index.
Definition: lls_c.h:112
lls_client_init
sdk_err_t lls_client_init(lls_c_evt_handler_t evt_handler)
Register LLS Client event handler.
lls_c_evt_handler_t
void(* lls_c_evt_handler_t)(lls_c_evt_t *p_evt)
Link Loss Service Client event handler type.
Definition: lls_c.h:123
LLS_C_EVT_ALERT_LEVEL_SET_ERR
@ LLS_C_EVT_ALERT_LEVEL_SET_ERR
Error occured when LLS Client set Alert Level characteristics.
Definition: lls_c.h:92
gr55xx_sys.h
GR55XX System API.
LLS_C_ALERT_LEVEL_MILD_ALERT
@ LLS_C_ALERT_LEVEL_MILD_ALERT
Mild alert.
Definition: lls_c.h:81
lls_c_alert_level_read
sdk_err_t lls_c_alert_level_read(uint8_t conn_idx)
Read Alert Level characteristic value.
LLS_C_EVT_ALERT_LEVEL_SET_SUCCESS
@ LLS_C_EVT_ALERT_LEVEL_SET_SUCCESS
LLS Client has set Alert Level characteristics.
Definition: lls_c.h:91
LLS_C_EVT_INVALID
@ LLS_C_EVT_INVALID
LLS Client invalid event.
Definition: lls_c.h:88
lls_c_disc_srvc_start
sdk_err_t lls_c_disc_srvc_start(uint8_t conn_idx)
Discovery Link Loss Service on peer.
lls_c_alert_level_t
lls_c_alert_level_t
Link Loss Service Client alert levels.
Definition: lls_c.h:79
lls_c_evt_t::alert_level
lls_c_alert_level_t alert_level
Alert level.
Definition: lls_c.h:114
lls_c_handles_t::lls_srvc_start_handle
uint16_t lls_srvc_start_handle
LLS Service start handle.
Definition: lls_c.h:104
ble_prf_types.h
Profile/Service Common Types.
LLS_C_EVT_DISCOVERY_FAIL
@ LLS_C_EVT_DISCOVERY_FAIL
LLS Client found LLS service failed because of invalid operation or no found at the peer.
Definition: lls_c.h:90
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:243
lls_c_evt_t::evt_type
lls_c_evt_type_t evt_type
LLS Client event type.
Definition: lls_c.h:113
LLS_C_ALERT_LEVEL_NO_ALERT
@ LLS_C_ALERT_LEVEL_NO_ALERT
No alert.
Definition: lls_c.h:80
LLS_C_ALERT_LEVEL_HIGH_ALERT
@ LLS_C_ALERT_LEVEL_HIGH_ALERT
High alert.
Definition: lls_c.h:82
lls_c_handles_t::lls_alert_level_handle
uint16_t lls_alert_level_handle
LLS Alert Level characteristic Value handle which has been got from peer.
Definition: lls_c.h:106
lls_c_handles_t
Handles on the connected peer device needed to interact with it.
Definition: lls_c.h:103
LLS_C_EVT_DISCOVERY_COMPLETE
@ LLS_C_EVT_DISCOVERY_COMPLETE
LLS Client has found LLS service and its characteristics.
Definition: lls_c.h:89
lls_c_alert_level_set
sdk_err_t lls_c_alert_level_set(uint8_t conn_idx, lls_c_alert_level_t alert_level)
Set peer Alert Level.
lls_c_evt_t
Link Loss Service Client event.
Definition: lls_c.h:111
lls_c_handles_t::lls_srvc_end_handle
uint16_t lls_srvc_end_handle
LLS Service end handle.
Definition: lls_c.h:105