sample_service.h
Go to the documentation of this file.
1 /**
2 *****************************************************************************************
3 *
4 * @file sample_service.h
5 *
6 * @brief Header file - sample_profile Server Role
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 "gr55xx_sys.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 < CFG_MAX_CONNECTIONS ?\
70 10 : CFG_MAX_CONNECTIONS) /**< Maximum number of Sample Service connections. */
71 #define SAMPLES_MAX_DATA_LEN 244 /**< Maximum length of sample charateristic value. */
72 #define SAMPLES_SERVICE_UUID 0x1B, 0xD7, 0x90, 0xEC, 0xE8, 0xB9, 0x75, 0x80,\
73 0x0A, 0x46, 0x44, 0xD3, 0x01, 0x01, 0xED, 0xA6 /**< The UUID of Sample Service for setting advertising data. */
74 /** @} */
75
76 /**
77 * @defgroup SAMPLES_ENUM Enumerations
78 * @{
79 */
80 /**@brief Sample Service event type. */
81 typedef enum
82 {
83 SAMPLES_EVT_INVALID,
84 SAMPLES_EVT_TX_NOTIFICATION_ENABLED,
85 SAMPLES_EVT_TX_NOTIFICATION_DISABLED,
86 SAMPLES_EVT_RX_RECEIVE_DATA,
87 SAMPLES_EVT_TX_NOTIFY_COMPLETE,
88 } samples_evt_type_t;
89 /** @} */
90
91 /**
92 * @defgroup SAMPLES_STRUCT Structures
93 * @{
94 */
95 /**@brief Sample Service event. */
96 typedef struct
97 {
98 samples_evt_type_t evt_type; /**< The sample service event. */
99 uint8_t conn_idx; /**< The connection index. */
100 uint8_t *p_data; /**< Pointer to event data. */
101 uint16_t length; /**< Length of event data. */
102 } samples_evt_t;
103 /** @} */
104
105 /**
106 * @addtogroup SAMPLES_TYPEDEF Typedefs
107 * @{
108 */
109 /**@brief Sample Service event handler type. */
110 typedef void (*samples_evt_handler_t)(samples_evt_t *p_evt);
111 /** @} */
112
113 /**
114 * @addtogroup SAMPLES_STRUCT Structures
115 * @{
116 */
117 /**@brief Sample Service init stucture. This contains all option and data needed for initialization of the service. */
118 typedef struct
119 {
120 samples_evt_handler_t evt_handler; /**<Service event handler. */
121 } samples_init_t;
122 /** @} */
123
124 /**
125 * @defgroup SAMPLES_FUNCTION Functions
126 * @{
127 */
128 /**
129 *****************************************************************************************
130 * @brief Initialize Sample Service instances and add in the DB.
131 *
132 * @param[in] ins_num: The number of Sample Service instances.
133 * @param[in] samples_init: The array of Sample Service initialization variables.
134 *
135 * @return Result of service initialization.
136 *****************************************************************************************
137 */
138 sdk_err_t samples_service_init(samples_init_t samples_init[], uint8_t ins_num);
139
140 /**
141 *****************************************************************************************
142 * @brief Send data to peer device
143 *
144 * @param[in] conn_idx: Connection index
145 * @param[in] ins_idx: Sample Service Instance Index
146 * @param[in] p_data: The Pointer of sent value
147 * @param[in] length: The Lenth of sent value
148 *
149 * @return Result of notify and indicate value
150 *****************************************************************************************
151 */
152 sdk_err_t samples_notify_tx_data(uint8_t conn_idx, uint8_t ins_idx, uint8_t *p_data, uint16_t length);
153 /** @} */
154
155 #endif
156 /** @} */
157 /** @} */
158
SAMPLES_EVT_TX_NOTIFY_COMPLETE
@ SAMPLES_EVT_TX_NOTIFY_COMPLETE
Definition: sample_service.h:87
SAMPLES_EVT_TX_NOTIFICATION_DISABLED
@ SAMPLES_EVT_TX_NOTIFICATION_DISABLED
Definition: sample_service.h:85
samples_init_t::evt_handler
samples_evt_handler_t evt_handler
Service event handler.
Definition: sample_service.h:120
samples_evt_handler_t
void(* samples_evt_handler_t)(samples_evt_t *p_evt)
Sample Service event handler type.
Definition: sample_service.h:110
samples_init_t
Sample Service init stucture.
Definition: sample_service.h:119
gr55xx_sys.h
GR55XX System API.
samples_evt_t
Sample Service event.
Definition: sample_service.h:97
SAMPLES_EVT_RX_RECEIVE_DATA
@ SAMPLES_EVT_RX_RECEIVE_DATA
Definition: sample_service.h:86
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:243
samples_evt_t::conn_idx
uint8_t conn_idx
The connection index.
Definition: sample_service.h:99
samples_evt_t::length
uint16_t length
Length of event data.
Definition: sample_service.h:101
SAMPLES_EVT_TX_NOTIFICATION_ENABLED
@ SAMPLES_EVT_TX_NOTIFICATION_ENABLED
Definition: sample_service.h:84
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:98
SAMPLES_EVT_INVALID
@ SAMPLES_EVT_INVALID
Definition: sample_service.h:83
samples_evt_type_t
samples_evt_type_t
Sample Service event type.
Definition: sample_service.h:82
samples_evt_t::p_data
uint8_t * p_data
Pointer to event data.
Definition: sample_service.h:100