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 "gr_includes.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 /**< Maximum number of Log Notification Service connections. */
68 #define LNS_SERVICE_UUID 0x1B, 0xD7, 0x90, 0xEC, 0xE8, 0xB9, 0x75, 0x80,\
69 0x0A, 0x46, 0x44, 0xD3, 0x01, 0x08, 0xED, 0xA6 /**< The UUID of Log Notification Service for setting advertising data. */
70 #define LNS_LOG_INFO_VAL_LEN 244 /**< Length of Log Information value. */
71 #define LNS_LOG_CTRL_PT_VAL_LEN 1 /**< Length of Log Control Point value. */
72 /** @} */
73
74 /**
75 * @defgroup LNS_ENUM Enumerations
76 * @{
77 */
78 /**@brief Log Notification Service Control Point. */
79 typedef enum
80 {
81 LNS_CTRL_PT_TRACE_STATUS_GET = 0x01, /**< Get trace info status. */
82 LNS_CTRL_PT_TRACE_INFO_DUMP, /**< Dump saved trace info. */
83 LNS_CTRL_PT_TRACE_INFO_CLEAR, /**< Clear trace information. */
84 } lns_ctrl_pt_t;
85
86 /**@brief Log Notification Service event type. */
87 typedef enum
88 {
89 LNS_EVT_INVALID, /**< Invalid lns event type. */
90 LNS_EVT_LOG_INFO_NTF_ENABLE, /**< Trace Information notification is enabled. */
91 LNS_EVT_LOG_INFO_NTF_DISABLE, /**< Trace Information notification is disabled. */
92 LNS_EVT_CTRL_PT_IND_ENABLE, /**< Log Control Point indiaction is enabled. */
93 LNS_EVT_CTRL_PT_IND_DISABLE, /**< Log Control Point indiaction is disabled. */
94 LNS_EVT_TRACE_STATUS_GET, /**< Get log status. */
95 LNS_EVT_TRACE_INFO_DUMP, /**< Get trace information. */
96 LNS_EVT_TRACE_INFO_CLEAR, /**< Clear trace information. */
97 } lns_evt_type_t;
98 /** @} */
99
100 /**
101 * @defgroup LNS_STRUCT Structures
102 * @{
103 */
104 /**@brief Log Notification Service event. */
105 typedef struct
106 {
107 uint8_t conn_idx; /**< The index of the connection. */
108 lns_evt_type_t evt_type; /**< The lns event type. */
109 } lns_evt_t;
110
111 /**@brief Log Information data. */
112 typedef struct
113 {
114 uint8_t *p_data; /**< Pointer to data. */
115 uint32_t length; /**< Length of data. */
116 uint32_t offset; /**< Offset of data. */
117 } lns_log_data_t;
118 /** @} */
119
120 /**
121 * @defgroup LNS_TYPEDEF Typedefs
122 * @{
123 */
124 /**@brief Log Notification Service event handler type.*/
125 typedef void (*lns_evt_handler_t)(lns_evt_t *p_evt);
126 /** @} */
127
128 /**
129 * @defgroup LNS_FUNCTION Functions
130 * @{
131 */
132 /**
133 *****************************************************************************************
134 * @brief Initialize a Log Notification Service instance and add in the DB.
135 *
136 * @param[in] evt_handler: Log Notification Service event handler.
137 *
138 * @return Result of service initialization.
139 *****************************************************************************************
140 */
141 sdk_err_t lns_service_init(lns_evt_handler_t evt_handler);
142
143 /**
144 *****************************************************************************************
145 * @brief Update lns gatt payload length (MTU - 3).
146 *
147 * @param[in] conn_idx: Connnection index.
148 * @param[in] payload_len: Length of payload.
149 *
150 * @return Result of operation.
151 *****************************************************************************************
152 */
153 sdk_err_t lns_pay_load_update(uint8_t conn_idx, const uint16_t payload_len);
154
155 /**
156 *****************************************************************************************
157 * @brief Notify saved log information if it`s cccd is enabled.
158 *
159 * @param[in] conn_idx: Connnection index.
160 *
161 * @return Result of operation.
162 *****************************************************************************************
163 */
164 sdk_err_t lns_log_info_send(uint8_t conn_idx);
165
166 /**
167 *****************************************************************************************
168 * @brief Send saved log status.
169 *
170 * @param[in] conn_idx: Connnection index.
171 * @param[in] log_num: NUmber of log.
172 *
173 * @return Result of operation.
174 *****************************************************************************************
175 */
176 sdk_err_t lns_log_status_send(uint8_t conn_idx, const uint8_t log_num);
177 /** @} */
178
179 #endif
180 /** @} */
181 /** @} */
182
LNS_CTRL_PT_TRACE_INFO_DUMP
@ LNS_CTRL_PT_TRACE_INFO_DUMP
Dump saved trace info.
Definition: lns.h:82
lns_evt_type_t
lns_evt_type_t
Log Notification Service event type.
Definition: lns.h:88
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:96
lns_log_data_t::offset
uint32_t offset
Offset of data.
Definition: lns.h:116
lns_evt_t
Log Notification Service event.
Definition: lns.h:106
LNS_EVT_CTRL_PT_IND_ENABLE
@ LNS_EVT_CTRL_PT_IND_ENABLE
Log Control Point indiaction is enabled.
Definition: lns.h:92
LNS_EVT_CTRL_PT_IND_DISABLE
@ LNS_EVT_CTRL_PT_IND_DISABLE
Log Control Point indiaction is disabled.
Definition: lns.h:93
gr_includes.h
Include Files 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:89
lns_log_data_t::length
uint32_t length
Length of data.
Definition: lns.h:115
lns_evt_t::evt_type
lns_evt_type_t evt_type
The lns event type.
Definition: lns.h:108
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:274
LNS_CTRL_PT_TRACE_INFO_CLEAR
@ LNS_CTRL_PT_TRACE_INFO_CLEAR
Clear trace information.
Definition: lns.h:83
LNS_CTRL_PT_TRACE_STATUS_GET
@ LNS_CTRL_PT_TRACE_STATUS_GET
Get trace info status.
Definition: lns.h:81
lns_log_data_t::p_data
uint8_t * p_data
Pointer to data.
Definition: lns.h:114
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:113
LNS_EVT_TRACE_INFO_DUMP
@ LNS_EVT_TRACE_INFO_DUMP
Get trace information.
Definition: lns.h:95
LNS_EVT_LOG_INFO_NTF_DISABLE
@ LNS_EVT_LOG_INFO_NTF_DISABLE
Trace Information notification is disabled.
Definition: lns.h:91
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:90
lns_evt_t::conn_idx
uint8_t conn_idx
The index of the connection.
Definition: lns.h:107
lns_evt_handler_t
void(* lns_evt_handler_t)(lns_evt_t *p_evt)
Log Notification Service event handler type.
Definition: lns.h:125
LNS_EVT_TRACE_STATUS_GET
@ LNS_EVT_TRACE_STATUS_GET
Get log status.
Definition: lns.h:94
lns_ctrl_pt_t
lns_ctrl_pt_t
Log Notification Service Control Point.
Definition: lns.h:80