fast_otas.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file fast_otas.h
5  *
6  * @brief Fast Over The Air 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_FAST_OTA FAST_OTA Service (FAST_OTAS)
46  * @{
47  * @brief Definitions and prototypes for the FAST_OTAS interface.
48  *
49  * @details The Fast OTA Service is a customized service with Tx, Rx and Flow Control
50  * characteristics. After @ref fast_otas_init_t variable is initialized, the
51  * developer shall call @ref fast_otas_service_init() to add the FAST_OTA
52  * Service and RX, TX, Control characteristic to the BLE stack database.
53  *
54  * This module also provides \ref fast_otas_notify_cmd_data() function to the
55  * application to send data to peer.
56  */
57 
58 #ifndef _FAST_OTAS_H_
59 #define _FAST_OTAS_H_
60 
61 /*
62  * INCLUDE FILES
63  ****************************************************************************************
64  */
65 #include "gr_includes.h"
66 #include "custom_config.h"
67 
68 /**
69  * @defgroup FAST_OTAS_MACRO Defines
70  * @{
71  */
72 #define FAST_OTAS_CONNECTION_MAX (10 < CFG_MAX_CONNECTIONS ?\
73  10 : CFG_MAX_CONNECTIONS) /**< Maximum number of FAST_OTA Service connections. */
74 #define FAST_OTAS_MAX_DATA_LEN 244 /**< Maximum length of FAST_OTAS characteristic. */
75 #define BLE_UUID_FAST_OTA_SERVICE 0x1B, 0xD7, 0x90, 0xEC, 0xE8, 0xB9, 0x75, 0x80,\
76  0x0A, 0x46, 0x44, 0xD3, 0x01, 0x07, 0xED, 0xA6 /**< The UUID of FAST_OTA Service for setting advertising data. */
77 
78 #define FAST_OTA_PATTERN_VALUE 0x474f4f44 /**< The Fast OTA pattern value. */
79 /** @} */
80 
81 /**
82  * @defgroup FAST_OTA_ENUM Enumerations
83  * @{
84  */
85 /**@brief FAST_OTA Service event type. */
86 typedef enum
87 {
95 /** @} */
96 
97 /**
98  * @defgroup FAST_OTAS_STRUCT Structures
99  * @{
100  */
101 /**@brief FAST_OTA Service event. */
102 typedef struct
103 {
104  fast_otas_evt_type_t evt_type; /**< The FAST_OTAS event. */
105  uint8_t conn_idx; /**< Index of connection. */
106  uint8_t *p_data; /**< Pointer to data. */
107  uint16_t length; /**< Length of data. */
109 /** @} */
110 
111 /**
112  * @defgroup FAST_OTAS_TYPEDEF Typedefs
113  * @{
114  */
115 /**@brief FAST_OTA Service event handler type. */
116 typedef void (*fast_otas_evt_handler_t)(fast_otas_evt_t *p_evt);
117 
118 /** @} */
119 
120 /**
121  * @defgroup FAST_OTAS_STRUCT Structures
122  * @{
123  */
124 /**@brief FAST_OTA Service initialization variable. */
125 typedef struct
126 {
127  fast_otas_evt_handler_t evt_handler; /**< Handler to handle otas event. */
129 /** @} */
130 
131 
132 /**
133  * @defgroup FAST_OTAS_FUNCTION Functions
134  * @{
135  */
136 /**
137  *****************************************************************************************
138  * @brief Add an FAST_OTA Service instance in the DB
139  *
140  * @param[in] p_otas_init :Pointer to FAST_OTA Service environment variable
141  *
142  * @return Result of service initialization.
143  *****************************************************************************************
144  */
146 
147 
148 /**
149  *****************************************************************************************
150  * @brief Send data to peer device
151  *
152  * @param[in] conn_idx: Connection index
153  * @param[in] p_data: The Pointer of send value
154  * @param[in] length: The Lenth of send value
155  *
156  * @return Result of notify and indicate value
157  *****************************************************************************************
158  */
159 sdk_err_t fast_otas_notify_cmd_data(uint8_t conn_idx, uint8_t *p_data,uint16_t length);
160 /** @} */
161 
162 #endif
163 /** @} */
164 /** @} */
fast_otas_evt_t
FAST_OTA Service event.
Definition: fast_otas.h:103
FAST_OTAS_EVT_CMD_NOTIFY_COMPLETE
@ FAST_OTAS_EVT_CMD_NOTIFY_COMPLETE
Definition: fast_otas.h:92
fast_otas_service_init
sdk_err_t fast_otas_service_init(fast_otas_init_t *p_otas_init)
Add an FAST_OTA Service instance in the DB.
fast_otas_evt_type_t
fast_otas_evt_type_t
FAST_OTA Service event type.
Definition: fast_otas.h:87
FAST_OTAS_EVT_INVALID
@ FAST_OTAS_EVT_INVALID
Definition: fast_otas.h:88
fast_otas_notify_cmd_data
sdk_err_t fast_otas_notify_cmd_data(uint8_t conn_idx, uint8_t *p_data, uint16_t length)
Send data to peer device.
fast_otas_evt_t::conn_idx
uint8_t conn_idx
Definition: fast_otas.h:105
gr_includes.h
Include Files API.
fast_otas_init_t
FAST_OTA Service initialization variable.
Definition: fast_otas.h:126
FAST_OTAS_EVT_CMD_NOTIFICATION_DISABLED
@ FAST_OTAS_EVT_CMD_NOTIFICATION_DISABLED
Definition: fast_otas.h:90
fast_otas_evt_handler_t
void(* fast_otas_evt_handler_t)(fast_otas_evt_t *p_evt)
FAST_OTA Service event handler type.
Definition: fast_otas.h:116
FAST_OTAS_EVT_CMD_NOTIFICATION_ENABLED
@ FAST_OTAS_EVT_CMD_NOTIFICATION_ENABLED
Definition: fast_otas.h:89
fast_otas_init_t::evt_handler
fast_otas_evt_handler_t evt_handler
Definition: fast_otas.h:127
FAST_OTAS_EVT_DATA_RECEIVE_DATA
@ FAST_OTAS_EVT_DATA_RECEIVE_DATA
Definition: fast_otas.h:93
fast_otas_evt_t::p_data
uint8_t * p_data
Definition: fast_otas.h:106
fast_otas_evt_t::evt_type
fast_otas_evt_type_t evt_type
Definition: fast_otas.h:104
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:273
FAST_OTAS_EVT_CMD_RECEIVE_DATA
@ FAST_OTAS_EVT_CMD_RECEIVE_DATA
Definition: fast_otas.h:91
fast_otas_evt_t::length
uint16_t length
Definition: fast_otas.h:107