ias_c.h
Go to the documentation of this file.
1 /**
2 *****************************************************************************************
3 *
4 * @file ias_c.h
5 *
6 * @brief Immediate Alert 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_IAS_C Immediate Alert Service Client (IAS_C)
45 * @{
46 * @brief Immediate Alert Service Client module.
47 *
48 * @details The Immediate Alert Service Client contains the APIs and types, which can be used by the
49 * application to discovery of Immediate Alert Service of peer and interact with it.
50 *
51 * The application must provide an event handler to register, then call \ref ias_client_init().
52 * After Immediate Alert Service Client discoveries peer Immediate Alert Service, application can call
53 * \ref ias_c_alert_level_set() to set alert level on peer.
54 */
55
56 #ifndef __IAS_C_H__
57 #define __IAS_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 IAS_C_MACRO Defines
67 * @{
68 */
69 #define IAS_C_CONNECTION_MAX (10 < CFG_MAX_CONNECTIONS ?\
70 10 : CFG_MAX_CONNECTIONS) /**< Maximum number of IAS Client connections. */
71 /** @} */
72
73 /**
74 * @defgroup IAS_C_ENUM Enumerations
75 * @{
76 */
77 /**@brief Immediate Alert Service Alert levels. */
78 typedef enum
79 {
80 IAS_C_ALERT_NONE, /**< No alert. */
81 IAS_C_ALERT_MILD, /**< Mild alert. */
82 IAS_C_ALERT_HIGH, /**< High alert. */
83 } ias_c_alert_level_t;
84
85 /**@brief Immediate Alert Service Client event type. */
86 typedef enum
87 {
88 IAS_C_EVT_INVALID, /**< IAS Client invalid event. */
89 IAS_C_EVT_DISCOVERY_COMPLETE, /**< IAS Client has found BAS service and its characteristics. */
90 IAS_C_EVT_DISCOVERY_FAIL, /**< IAS Client found BAS service failed because of invalid operation or no found at the peer. */
91 IAS_C_EVT_ALERT_LEVEL_SET_SUCCESS, /**< IAS Client has set Alert Level characteristic. */
92 IAS_C_EVT_ALERT_LEVEL_SET_ERR, /**< Error occured when IAS Client set Alert Level characteristic. */
93 } ias_c_evt_type_t;
94 /** @} */
95
96 /**
97 * @defgroup IAS_C_STRUCT Structures
98 * @{
99 */
100 /**@brief Handles on the connected peer device needed to interact with it. */
101 typedef struct
102 {
103 uint16_t ias_srvc_start_handle; /**< IAS Service start handle. */
104 uint16_t ias_srvc_end_handle; /**< IAS Service end handle. */
105 uint16_t ias_alert_level_handle; /**< IAS Alert Level characteristic Value handle which has been got from peer. */
106 } ias_c_handles_t;
107
108 /**@brief Immediate Alert Service Client event. */
109 typedef struct
110 {
111 uint8_t conn_idx; /**< The connection index. */
112 ias_c_evt_type_t evt_type; /**< IAS Client event type. */
113 } ias_c_evt_t;
114 /** @} */
115
116 /**
117 * @defgroup IAS_C_TYPEDEF Typedefs
118 * @{
119 */
120 /**@brief Immediate Alert Service Client event handler type. */
121 typedef void (*ias_c_evt_handler_t)(ias_c_evt_t *p_evt);
122 /** @} */
123
124 /**
125 * @defgroup IAS_C_FUNCTION Functions
126 * @{
127 */
128 /**
129 *****************************************************************************************
130 * @brief Register IAS Client event handler.
131 *
132 * @param[in] evt_handler: Immediate Alert Service Client event handler.
133 *
134 * @return Result of initialization.
135 *****************************************************************************************
136 */
137 sdk_err_t ias_client_init(ias_c_evt_handler_t evt_handler);
138
139 /**
140 *****************************************************************************************
141 * @brief Discovery Immediate Alert Service on peer.
142 *
143 * @param[in] conn_idx: Index of connection.
144 *
145 * @return Operation result.
146 *****************************************************************************************
147 */
148 sdk_err_t ias_c_disc_srvc_start(uint8_t conn_idx);
149
150 /**
151 *****************************************************************************************
152 * @brief Enable or disable peer Alert Level characteristic notify.
153 *
154 * @param[in] conn_idx: Index of connection.
155 * @param[in] alert_level: Alert level.
156 *
157 * @return Operation result.
158 *****************************************************************************************
159 */
160 sdk_err_t ias_c_alert_level_set(uint8_t conn_idx, ias_c_alert_level_t alert_level);
161
162 /** @} */
163
164 #endif
165 /** @} */
166 /** @} */
ias_c_alert_level_set
sdk_err_t ias_c_alert_level_set(uint8_t conn_idx, ias_c_alert_level_t alert_level)
Enable or disable peer Alert Level characteristic notify.
ias_c_evt_handler_t
void(* ias_c_evt_handler_t)(ias_c_evt_t *p_evt)
Immediate Alert Service Client event handler type.
Definition: ias_c.h:121
IAS_C_EVT_ALERT_LEVEL_SET_SUCCESS
@ IAS_C_EVT_ALERT_LEVEL_SET_SUCCESS
IAS Client has set Alert Level characteristic.
Definition: ias_c.h:91
gr55xx_sys.h
GR55XX System API.
ias_c_handles_t::ias_alert_level_handle
uint16_t ias_alert_level_handle
IAS Alert Level characteristic Value handle which has been got from peer.
Definition: ias_c.h:105
ias_c_evt_t
Immediate Alert Service Client event.
Definition: ias_c.h:110
ias_c_handles_t::ias_srvc_end_handle
uint16_t ias_srvc_end_handle
IAS Service end handle.
Definition: ias_c.h:104
ias_c_evt_t::evt_type
ias_c_evt_type_t evt_type
IAS Client event type.
Definition: ias_c.h:112
IAS_C_EVT_DISCOVERY_COMPLETE
@ IAS_C_EVT_DISCOVERY_COMPLETE
IAS Client has found BAS service and its characteristics.
Definition: ias_c.h:89
IAS_C_ALERT_HIGH
@ IAS_C_ALERT_HIGH
High alert.
Definition: ias_c.h:82
IAS_C_EVT_INVALID
@ IAS_C_EVT_INVALID
IAS Client invalid event.
Definition: ias_c.h:88
IAS_C_ALERT_MILD
@ IAS_C_ALERT_MILD
Mild alert.
Definition: ias_c.h:81
IAS_C_EVT_ALERT_LEVEL_SET_ERR
@ IAS_C_EVT_ALERT_LEVEL_SET_ERR
Error occured when IAS Client set Alert Level characteristic.
Definition: ias_c.h:92
ble_prf_types.h
Profile/Service Common Types.
ias_c_alert_level_t
ias_c_alert_level_t
Immediate Alert Service Alert levels.
Definition: ias_c.h:79
IAS_C_ALERT_NONE
@ IAS_C_ALERT_NONE
No alert.
Definition: ias_c.h:80
ias_c_handles_t
Handles on the connected peer device needed to interact with it.
Definition: ias_c.h:102
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:243
ias_c_disc_srvc_start
sdk_err_t ias_c_disc_srvc_start(uint8_t conn_idx)
Discovery Immediate Alert Service on peer.
ias_c_evt_type_t
ias_c_evt_type_t
Immediate Alert Service Client event type.
Definition: ias_c.h:87
ias_client_init
sdk_err_t ias_client_init(ias_c_evt_handler_t evt_handler)
Register IAS Client event handler.
IAS_C_EVT_DISCOVERY_FAIL
@ IAS_C_EVT_DISCOVERY_FAIL
IAS Client found BAS service failed because of invalid operation or no found at the peer.
Definition: ias_c.h:90
ias_c_evt_t::conn_idx
uint8_t conn_idx
The connection index.
Definition: ias_c.h:111
ias_c_handles_t::ias_srvc_start_handle
uint16_t ias_srvc_start_handle
IAS Service start handle.
Definition: ias_c.h:103