lns.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file lns.h
5 *
6 * @brief Log Notification Service 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 * @addtogroup BLE_SRV BLE Services
39 * @{
40 * @brief Definitions and prototypes for the BLE Service interface.
41 */
42
43 /**
44 * @defgroup BLE_SDK_LNS Log Notification Service (LNS)
45 * @{
46 * @brief Log Notification Service module.
47 *
48 * @details The Log Notification Service shall expose the Log Info characteristic and the Log Control Point characteristic.
49 *
50 * The application must call \ref lns_service_init() to add Log Notification Service and Log Info
51 * and Log Control Point characteristics to the BLE Stack database.
52 */
53
54 #ifndef __LNS_H__
55 #define __LNS_H__
56
57 #include "gr55xx_sys.h"
58 #include "custom_config.h"
59 #include "fault_trace.h"
60 #include <stdint.h>
61 #include <stdbool.h>
62
63 /**
64 * @defgroup LNS_MACRO Defines
65 * @{
66 */
67 #define LNS_CONNECTION_MAX (10 < CFG_MAX_CONNECTIONS ?\
68 10 : CFG_MAX_CONNECTIONS) /**< Maximum number of Log Notification Service connections. */
69 #define LNS_SERVICE_UUID 0x1B, 0xD7, 0x90, 0xEC, 0xE8, 0xB9, 0x75, 0x80,\
70 0x0A, 0x46, 0x44, 0xD3, 0x01, 0x08, 0xED, 0xA6 /**< The UUID of Log Notification Service for setting advertising data. */
71 #define LNS_LOG_INFO_VAL_LEN 244 /**< Length of Log Information value. */
72 #define LNS_LOG_CTRL_PT_VAL_LEN 1 /**< Length of Log Control Point value. */
73 /** @} */
74
75 /**
76 * @defgroup LNS_ENUM Enumerations
77 * @{
78 */
79 /**@brief Log Notification Service Control Point. */
80 typedef enum
81 {
82 LNS_CTRL_PT_TRACE_STATUS_GET = 0x01, /**< Get trace info status. */
83 LNS_CTRL_PT_TRACE_INFO_DUMP, /**< Dump saved trace info. */
84 LNS_CTRL_PT_TRACE_INFO_CLEAR, /**< Clear trace information. */
85 } lns_ctrl_pt_t;
86
87 /**@brief Log Notification Service event type. */
88 typedef enum
89 {
90 LNS_EVT_INVALID, /**< Invalid lns event type. */
91 LNS_EVT_LOG_INFO_NTF_ENABLE, /**< Trace Information notification is enabled. */
92 LNS_EVT_LOG_INFO_NTF_DISABLE, /**< Trace Information notification is disabled. */
93 LNS_EVT_CTRL_PT_IND_ENABLE, /**< Log Control Point indiaction is enabled. */
94 LNS_EVT_CTRL_PT_IND_DISABLE, /**< Log Control Point indiaction is disabled. */
95 LNS_EVT_TRACE_STATUS_GET, /**< Get log status. */
96 LNS_EVT_TRACE_INFO_DUMP, /**< Get trace information. */
97 LNS_EVT_TRACE_INFO_CLEAR, /**< Clear trace information. */
98 } lns_evt_type_t;
99 /** @} */
100
101 /**
102 * @defgroup LNS_STRUCT Structures
103 * @{
104 */
105 /**@brief Log Notification Service event. */
106 typedef struct
107 {
108 uint8_t conn_idx; /**< The index of the connection. */
109 lns_evt_type_t evt_type; /**< The lns event type. */
110 } lns_evt_t;
111
112 /**@brief Log Information data. */
113 typedef struct
114 {
115 uint8_t *p_data; /**< Pointer to data. */
116 uint32_t length; /**< Length of data. */
117 uint32_t offset; /**< Offset of data. */
118 } lns_log_data_t;
119 /** @} */
120
121 /**
122 * @defgroup LNS_TYPEDEF Typedefs
123 * @{
124 */
125 /**@brief Log Notification Service event handler type.*/
126 typedef void (*lns_evt_handler_t)(lns_evt_t *p_evt);
127 /** @} */
128
129 /**
130 * @defgroup LNS_FUNCTION Functions
131 * @{
132 */
133 /**
134 *****************************************************************************************
135 * @brief Initialize a Log Notification Service instance and add in the DB.
136 *
137 * @param[in] evt_handler: Log Notification Service event handler.
138 *
139 * @return Result of service initialization.
140 *****************************************************************************************
141 */
142 sdk_err_t lns_service_init(lns_evt_handler_t evt_handler);
143
144 /**
145 *****************************************************************************************
146 * @brief Update lns gatt payload length (MTU - 3).
147 *
148 * @param[in] conn_idx: Connnection index.
149 * @param[in] payload_len: Length of payload.
150 *
151 * @return Result of operation.
152 *****************************************************************************************
153 */
154 sdk_err_t lns_pay_load_update(uint8_t conn_idx, const uint16_t payload_len);
155
156 /**
157 *****************************************************************************************
158 * @brief Notify saved log information if it`s cccd is enabled.
159 *
160 * @param[in] conn_idx: Connnection index.
161 *
162 * @return Result of operation.
163 *****************************************************************************************
164 */
165 sdk_err_t lns_log_info_send(uint8_t conn_idx);
166
167 /**
168 *****************************************************************************************
169 * @brief Send saved log status.
170 *
171 * @param[in] conn_idx: Connnection index.
172 * @param[in] log_num: NUmber of log.
173 *
174 * @return Result of operation.
175 *****************************************************************************************
176 */
177 sdk_err_t lns_log_status_send(uint8_t conn_idx, const uint8_t log_num);
178 /** @} */
179
180 #endif
181 /** @} */
182 /** @} */
183
LNS_CTRL_PT_TRACE_INFO_DUMP
@ LNS_CTRL_PT_TRACE_INFO_DUMP
Dump saved trace info.
Definition: lns.h:83
lns_evt_type_t
lns_evt_type_t
Log Notification Service event type.
Definition: lns.h:89
lns_log_info_send
sdk_err_t lns_log_info_send(uint8_t conn_idx)
Notify saved log information if it`s cccd is enabled.
LNS_EVT_TRACE_INFO_CLEAR
@ LNS_EVT_TRACE_INFO_CLEAR
Clear trace information.
Definition: lns.h:97
lns_log_data_t::offset
uint32_t offset
Offset of data.
Definition: lns.h:117
lns_evt_t
Log Notification Service event.
Definition: lns.h:107
LNS_EVT_CTRL_PT_IND_ENABLE
@ LNS_EVT_CTRL_PT_IND_ENABLE
Log Control Point indiaction is enabled.
Definition: lns.h:93
LNS_EVT_CTRL_PT_IND_DISABLE
@ LNS_EVT_CTRL_PT_IND_DISABLE
Log Control Point indiaction is disabled.
Definition: lns.h:94
gr55xx_sys.h
GR55XX System API.
lns_service_init
sdk_err_t lns_service_init(lns_evt_handler_t evt_handler)
Initialize a Log Notification Service instance and add in the DB.
LNS_EVT_INVALID
@ LNS_EVT_INVALID
Invalid lns event type.
Definition: lns.h:90
lns_log_data_t::length
uint32_t length
Length of data.
Definition: lns.h:116
lns_evt_t::evt_type
lns_evt_type_t evt_type
The lns event type.
Definition: lns.h:109
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:243
LNS_CTRL_PT_TRACE_INFO_CLEAR
@ LNS_CTRL_PT_TRACE_INFO_CLEAR
Clear trace information.
Definition: lns.h:84
LNS_CTRL_PT_TRACE_STATUS_GET
@ LNS_CTRL_PT_TRACE_STATUS_GET
Get trace info status.
Definition: lns.h:82
lns_log_data_t::p_data
uint8_t * p_data
Pointer to data.
Definition: lns.h:115
lns_pay_load_update
sdk_err_t lns_pay_load_update(uint8_t conn_idx, const uint16_t payload_len)
Update lns gatt payload length (MTU - 3).
lns_log_data_t
Log Information data.
Definition: lns.h:114
LNS_EVT_TRACE_INFO_DUMP
@ LNS_EVT_TRACE_INFO_DUMP
Get trace information.
Definition: lns.h:96
LNS_EVT_LOG_INFO_NTF_DISABLE
@ LNS_EVT_LOG_INFO_NTF_DISABLE
Trace Information notification is disabled.
Definition: lns.h:92
lns_log_status_send
sdk_err_t lns_log_status_send(uint8_t conn_idx, const uint8_t log_num)
Send saved log status.
LNS_EVT_LOG_INFO_NTF_ENABLE
@ LNS_EVT_LOG_INFO_NTF_ENABLE
Trace Information notification is enabled.
Definition: lns.h:91
lns_evt_t::conn_idx
uint8_t conn_idx
The index of the connection.
Definition: lns.h:108
lns_evt_handler_t
void(* lns_evt_handler_t)(lns_evt_t *p_evt)
Log Notification Service event handler type.
Definition: lns.h:126
LNS_EVT_TRACE_STATUS_GET
@ LNS_EVT_TRACE_STATUS_GET
Get log status.
Definition: lns.h:95
lns_ctrl_pt_t
lns_ctrl_pt_t
Log Notification Service Control Point.
Definition: lns.h:81