sample_service.h
Go to the documentation of this file.
1 /**
2 *****************************************************************************************
3 *
4 * @file sample_service.h
5 *
6 * @brief Sample 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_SAMPLES Sample Service (SAMPLES)
46 * @{
47 * @brief Definitions and prototypes for the GUS interface.
48 *
49 * @details The Sample Service demonstrates how to add vendor service to BLE Stack database, which includes
50 * Tx and Rx base charateristic, developer can changes and adds other characteristics.
51 *
52 * After \ref samples_init_t variable is initialized, the application must call \ref samples_service_init()
53 * to add example characteristics to the BLE Stack database, and it provides \ref samples_notify_tx_data().
54 */
55
56 #ifndef _SAMPLE_PROFILE_H_
57 #define _SAMPLE_PROFILE_H_
58
59 #include "gr_includes.h"
60 #include "custom_config.h"
61 #include <stdbool.h>
62 #include <stdint.h>
63
64 /**
65 * @defgroup SAMPLES_MACRO Defines
66 * @{
67 */
68 #define SAMPLES_INSTANCE_MAX 0x01 /**< Maximum number of Sample Service instances. The value is configurable. */
69 #define SAMPLES_CONNECTION_MAX 10 /**< Maximum number of Sample Service connections. */
70 #define SAMPLES_MAX_DATA_LEN 244 /**< Maximum length of sample charateristic value. */
71 #define SAMPLES_SERVICE_UUID 0x1B, 0xD7, 0x90, 0xEC, 0xE8, 0xB9, 0x75, 0x80,\
72 0x0A, 0x46, 0x44, 0xD3, 0x01, 0x01, 0xED, 0xA6 /**< The UUID of Sample Service for setting advertising data. */
73 /** @} */
74
75 /**
76 * @defgroup SAMPLES_ENUM Enumerations
77 * @{
78 */
79 /**@brief Sample Service event type. */
80 typedef enum
81 {
82 SAMPLES_EVT_INVALID,
83 SAMPLES_EVT_TX_NOTIFICATION_ENABLED,
84 SAMPLES_EVT_TX_NOTIFICATION_DISABLED,
85 SAMPLES_EVT_RX_RECEIVE_DATA,
86 SAMPLES_EVT_TX_NOTIFY_COMPLETE,
87 } samples_evt_type_t;
88 /** @} */
89
90 /**
91 * @defgroup SAMPLES_STRUCT Structures
92 * @{
93 */
94 /**@brief Sample Service event. */
95 typedef struct
96 {
97 samples_evt_type_t evt_type; /**< The sample service event. */
98 uint8_t conn_idx; /**< The connection index. */
99 uint8_t *p_data; /**< Pointer to event data. */
100 uint16_t length; /**< Length of event data. */
101 } samples_evt_t;
102 /** @} */
103
104 /**
105 * @addtogroup SAMPLES_TYPEDEF Typedefs
106 * @{
107 */
108 /**@brief Sample Service event handler type. */
109 typedef void (*samples_evt_handler_t)(samples_evt_t *p_evt);
110 /** @} */
111
112 /**
113 * @addtogroup SAMPLES_STRUCT Structures
114 * @{
115 */
116 /**@brief Sample Service init stucture. This contains all option and data needed for initialization of the service. */
117 typedef struct
118 {
119 samples_evt_handler_t evt_handler; /**<Service event handler. */
120 } samples_init_t;
121 /** @} */
122
123 /**
124 * @defgroup SAMPLES_FUNCTION Functions
125 * @{
126 */
127 /**
128 *****************************************************************************************
129 * @brief Initialize Sample Service instances and add in the DB.
130 *
131 * @param[in] ins_num: The number of Sample Service instances.
132 * @param[in] samples_init: The array of Sample Service initialization variables.
133 *
134 * @return Result of service initialization.
135 *****************************************************************************************
136 */
137 sdk_err_t samples_service_init(samples_init_t samples_init[], uint8_t ins_num);
138
139 /**
140 *****************************************************************************************
141 * @brief Send data to peer device
142 *
143 * @param[in] conn_idx: Connection index
144 * @param[in] ins_idx: Sample Service Instance Index
145 * @param[in] p_data: The Pointer of sent value
146 * @param[in] length: The Lenth of sent value
147 *
148 * @return Result of notify and indicate value
149 *****************************************************************************************
150 */
151 sdk_err_t samples_notify_tx_data(uint8_t conn_idx, uint8_t ins_idx, uint8_t *p_data, uint16_t length);
152 /** @} */
153
154 #endif
155 /** @} */
156 /** @} */
157
SAMPLES_EVT_TX_NOTIFY_COMPLETE
@ SAMPLES_EVT_TX_NOTIFY_COMPLETE
Definition: sample_service.h:86
SAMPLES_EVT_TX_NOTIFICATION_DISABLED
@ SAMPLES_EVT_TX_NOTIFICATION_DISABLED
Definition: sample_service.h:84
samples_init_t::evt_handler
samples_evt_handler_t evt_handler
Service event handler.
Definition: sample_service.h:119
samples_evt_handler_t
void(* samples_evt_handler_t)(samples_evt_t *p_evt)
Sample Service event handler type.
Definition: sample_service.h:109
samples_init_t
Sample Service init stucture.
Definition: sample_service.h:118
gr_includes.h
Include Files API.
samples_evt_t
Sample Service event.
Definition: sample_service.h:96
SAMPLES_EVT_RX_RECEIVE_DATA
@ SAMPLES_EVT_RX_RECEIVE_DATA
Definition: sample_service.h:85
samples_notify_tx_data
sdk_err_t samples_notify_tx_data(uint8_t conn_idx, uint8_t ins_idx, uint8_t *p_data, uint16_t length)
Send data to peer device.
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:274
samples_evt_t::conn_idx
uint8_t conn_idx
The connection index.
Definition: sample_service.h:98
samples_evt_t::length
uint16_t length
Length of event data.
Definition: sample_service.h:100
SAMPLES_EVT_TX_NOTIFICATION_ENABLED
@ SAMPLES_EVT_TX_NOTIFICATION_ENABLED
Definition: sample_service.h:83
samples_service_init
sdk_err_t samples_service_init(samples_init_t samples_init[], uint8_t ins_num)
Initialize Sample Service instances and add in the DB.
samples_evt_t::evt_type
samples_evt_type_t evt_type
The sample service event.
Definition: sample_service.h:97
SAMPLES_EVT_INVALID
@ SAMPLES_EVT_INVALID
Definition: sample_service.h:82
samples_evt_type_t
samples_evt_type_t
Sample Service event type.
Definition: sample_service.h:81
samples_evt_t::p_data
uint8_t * p_data
Pointer to event data.
Definition: sample_service.h:99