lms.h
Go to the documentation of this file.
1 /**
2 ****************************************************************************************
3 *
4 * @file lms.h
5 *
6 * @brief Log Management 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 /**
39 * @addtogroup BLE_SRV BLE Services
40 * @{
41 * @brief Definitions and prototypes for the BLE Service interface.
42 */
43
44 /**
45 * @defgroup BLE_SDK_LMS LMS Service (LMS)
46 * @{
47 * @brief Definitions and prototypes for the LMS interface.
48 *
49 * @details The Log Management Service is a customized service with Command and Data
50 * characteristics. This module implements the log storage and sending function.
51 * After @ref lms_init_t variable is initialized, the developer shall call
52 * @ref lms_service_init() to add the LMS Service and RX, TX, Control characteristic
53 * to the BLE stack database.
54 *
55 * This module also provides \ref lms_notify_data() function to the application
56 * to send data to peer.
57 */
58
59 #ifndef _LMS_H_
60 #define _LMS_H_
61
62 /*
63 * INCLUDE FILES
64 ****************************************************************************************
65 */
66 #include "gr_includes.h"
67
68 /**
69 * @defgroup LMS_MACRO Defines
70 * @{
71 */
72 #define LMS_CONNECTION_MAX 10 /**< Maximum number of LMS Service connections. */
73 #define LMS_MAX_DATA_LEN 244 /**< Maximum length of LMS characteristic. */
74 #define LMS_SERVICE_UUID 0x1B, 0xD7, 0x90, 0xEC, 0xE8, 0xB9, 0x75, 0x80,\
75 0x0A, 0x46, 0x44, 0xD3, 0x01, 0x0B, 0xED, 0xA6 /**< The UUID of LMS Service for setting advertising data. */
76
77 #define LMS_PATTERN_VALUE 0x474f4f44 /**< The Fast OTA pattern value. */
78 /** @} */
79
80 /**
81 * @defgroup LMS_ENUM Enumerations
82 * @{
83 */
84 /**@brief LMS Service event type. */
85 typedef enum
86 {
87 LMS_EVT_INVALID,
88 LMS_EVT_CMD_NOTIFICATION_ENABLED,
89 LMS_EVT_CMD_NOTIFICATION_DISABLED,
90 LMS_EVT_CMD_RECEIVE_DATA,
91 LMS_EVT_CMD_NOTIFY_COMPLETE,
92 LMS_EVT_DATA_NOTIFICATION_ENABLED,
93 LMS_EVT_DATA_NOTIFICATION_DISABLED,
94 LMS_EVT_DATA_RECEIVE_DATA,
95 LMS_EVT_DATA_NOTIFY_COMPLETE
96 } lms_evt_type_t;
97 /** @} */
98
99 /**
100 * @defgroup LMS_STRUCT Structures
101 * @{
102 */
103 /**@brief LMS Service event. */
104 typedef struct
105 {
106 lms_evt_type_t evt_type; /**< The LMS event. */
107 uint8_t conn_idx; /**< Index of connection. */
108 uint8_t *p_data; /**< Pointer to data. */
109 uint16_t length; /**< Length of data. */
110 } lms_evt_t;
111 /** @} */
112
113 /**
114 * @defgroup LMS_TYPEDEF Typedefs
115 * @{
116 */
117 /**@brief LMS Service event handler type. */
118 typedef void (*lms_evt_handler_t)(lms_evt_t *p_evt);
119
120 /** @} */
121
122 /**
123 * @defgroup LMS_STRUCT Structures
124 * @{
125 */
126 /**@brief LMS Service initialization variable. */
127 typedef struct
128 {
129 lms_evt_handler_t evt_handler; /**< Handler to handle lms event. */
130 } lms_init_t;
131 /** @} */
132
133
134 /**
135 * @defgroup LMS_FUNCTION Functions
136 * @{
137 */
138 /**
139 *****************************************************************************************
140 * @brief Add an LMS Service instance in the DB
141 *
142 * @param[in] p_lms_init :Pointer to LMS Service environment variable
143 *
144 * @return Result of service initialization.
145 *****************************************************************************************
146 */
147 sdk_err_t lms_service_init(lms_init_t *p_lms_init);
148
149
150 /**
151 *****************************************************************************************
152 * @brief Send data to peer device
153 *
154 * @param[in] conn_idx: Connection index
155 * @param[in] p_data: The Pointer of send value
156 * @param[in] length: The Lenth of send value
157 *
158 * @return Result of notify and indicate value
159 *****************************************************************************************
160 */
161 sdk_err_t lms_notify_cmd(uint8_t conn_idx, uint8_t *p_data, uint16_t length);
162
163 /**
164 *****************************************************************************************
165 * @brief Send data to peer device
166 *
167 * @param[in] conn_idx: Connection index
168 * @param[in] p_data: The Pointer of send value
169 * @param[in] length: The Lenth of send value
170 *
171 * @return Result of notify and indicate value
172 *****************************************************************************************
173 */
174 sdk_err_t lms_notify_data(uint8_t conn_idx, uint8_t *p_data,uint16_t length);
175 /** @} */
176
177 #endif
178 /** @} */
179 /** @} */
lms_service_init
sdk_err_t lms_service_init(lms_init_t *p_lms_init)
Add an LMS Service instance in the DB.
lms_evt_t::conn_idx
uint8_t conn_idx
Index of connection.
Definition: lms.h:107
lms_evt_t::evt_type
lms_evt_type_t evt_type
The LMS event.
Definition: lms.h:106
LMS_EVT_INVALID
@ LMS_EVT_INVALID
Definition: lms.h:87
lms_init_t
LMS Service initialization variable.
Definition: lms.h:128
gr_includes.h
Include Files API.
LMS_EVT_CMD_NOTIFY_COMPLETE
@ LMS_EVT_CMD_NOTIFY_COMPLETE
Definition: lms.h:91
lms_evt_handler_t
void(* lms_evt_handler_t)(lms_evt_t *p_evt)
LMS Service event handler type.
Definition: lms.h:118
LMS_EVT_DATA_RECEIVE_DATA
@ LMS_EVT_DATA_RECEIVE_DATA
Definition: lms.h:94
lms_notify_cmd
sdk_err_t lms_notify_cmd(uint8_t conn_idx, uint8_t *p_data, uint16_t length)
Send data to peer device.
LMS_EVT_DATA_NOTIFICATION_DISABLED
@ LMS_EVT_DATA_NOTIFICATION_DISABLED
Definition: lms.h:93
lms_evt_t
LMS Service event.
Definition: lms.h:105
LMS_EVT_CMD_NOTIFICATION_ENABLED
@ LMS_EVT_CMD_NOTIFICATION_ENABLED
Definition: lms.h:88
LMS_EVT_DATA_NOTIFY_COMPLETE
@ LMS_EVT_DATA_NOTIFY_COMPLETE
Definition: lms.h:95
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:274
lms_evt_t::length
uint16_t length
Length of data.
Definition: lms.h:109
LMS_EVT_CMD_NOTIFICATION_DISABLED
@ LMS_EVT_CMD_NOTIFICATION_DISABLED
Definition: lms.h:89
lms_evt_type_t
lms_evt_type_t
LMS Service event type.
Definition: lms.h:86
LMS_EVT_DATA_NOTIFICATION_ENABLED
@ LMS_EVT_DATA_NOTIFICATION_ENABLED
Definition: lms.h:92
lms_notify_data
sdk_err_t lms_notify_data(uint8_t conn_idx, uint8_t *p_data, uint16_t length)
Send data to peer device.
LMS_EVT_CMD_RECEIVE_DATA
@ LMS_EVT_CMD_RECEIVE_DATA
Definition: lms.h:90
lms_evt_t::p_data
uint8_t * p_data
Pointer to data.
Definition: lms.h:108
lms_init_t::evt_handler
lms_evt_handler_t evt_handler
Handler to handle lms event.
Definition: lms.h:129