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 49 * the Log Control Point characteristic. 50 * 51 * After \ref lns_init_t variable is intialized, the application 52 * must call \ref lns_service_init() to add Log Notification Service and 53 * Log Info and Log Control Point characteristics to the BLE Stack database. 54 */ 55 56 #ifndef __LNS_H__ 57 #define __LNS_H__ 58 59 #include <stdint.h> 60 #include <stdbool.h> 61 #include "gr55xx_sys.h" 62 #include "custom_config.h" 63 #include "fault_trace.h" 64 65 /** 66 * @defgroup LNS_MACRO Defines 67 * @{ 68 */ 69 #define LNS_CONNECTION_MAX (10 < CFG_MAX_CONNECTIONS ? \ 70 10 : CFG_MAX_CONNECTIONS) /**< Maximum number of Log Notification \ 71 Service connections. */ 72 #define LNS_SERVICE_UUID 0x1B, 0xD7, 0x90, 0xEC, 0xE8, 0xB9, 0x75, 0x80, 0x0A, 0x46, 0x44, 0xD3, \ 73 0x01, 0x08, 0xED, 0xA6 /**< The UUID of Log Notification Service for \ 74 setting advertising data. */ 75 #define LNS_LOG_INFO_VAL_LEN 244 /**< Length of Log Information value. */ 76 #define LNS_LOG_CTRL_PT_VAL_LEN 1 /**< Length of Log Control Point value. */ 77 /** @} */ 78 79 /** 80 * @defgroup LNS_ENUM Enumerations 81 * @{ 82 */ 83 /**@brief Log Notification Service Control Point. */ 84 typedef enum { 85 LNS_CTRL_PT_TRACE_STATUS_GET = 0x01, /**< Get trace info status. */ 86 LNS_CTRL_PT_TRACE_INFO_DUMP, /**< Dump saved trace info. */ 87 LNS_CTRL_PT_TRACE_INFO_CLEAR, /**< Clear trace information. */ 88 } lns_ctrl_pt_t; 89 90 /**@brief Log Notification Service event type. */ 91 typedef enum { 92 LNS_EVT_INVALID, /**< Invalid lns event type. */ 93 LNS_EVT_LOG_INFO_NTF_ENABLE, /**< Trace Information notification is enabled. */ 94 LNS_EVT_LOG_INFO_NTF_DISABLE, /**< Trace Information notification is disabled. */ 95 LNS_EVT_CTRL_PT_IND_ENABLE, /**< Log Control Point indiaction is enabled. */ 96 LNS_EVT_CTRL_PT_IND_DISABLE, /**< Log Control Point indiaction is disabled. */ 97 LNS_EVT_TRACE_STATUS_GET, /**< Get log status. */ 98 LNS_EVT_TRACE_INFO_DUMP, /**< Get trace information. */ 99 LNS_EVT_TRACE_INFO_CLEAR, /**< Clear trace information. */ 100 } lns_evt_type_t; 101 /** @} */ 102 103 /** 104 * @defgroup LNS_STRUCT Structures 105 * @{ 106 */ 107 /**@brief Log Notification Service event. */ 108 typedef struct { 109 uint8_t conn_idx; /**< The index of the connection. */ 110 lns_evt_type_t evt_type; /**< The lns event type. */ 111 } lns_evt_t; 112 113 /**@brief Log Information data. */ 114 typedef struct { 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 184