• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  *****************************************************************************************
3  *
4  * @file pcs.h
5  *
6  * @brief Power Consumption 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_PCS Power Consumption Service (PCS)
46  * @{
47  * @brief Definitions and prototypes for the PCS interface.
48  *
49  * @details The Power Consumption Service is a customized GATT-based service with TX and Setting
50  *          characteristics. The application uses the service to notify data to peer and receive
51  *          some BLE parameters such as advertising interval, connect interval, PHY and so on,
52  *          which can simulate different application scenes for power consumption test.
53  *
54  *          After \ref pcs_init_t  variable is initialized , the application must call \ref pcs_service_init()
55  *          to add the ower Consumption Service and TX, Setting characteristics to the BLE Stack database.
56  */
57 
58 #ifndef __PCS_H__
59 #define __PCS_H__
60 
61 #include "gr55xx_sys.h"
62 #include "custom_config.h"
63 
64 /**
65  * @defgroup PCS_MACRO Defines
66  * @{
67  */
68 #define PCS_CONNECTION_MAX  (10 < CFG_MAX_CONNECTIONS ? \
69                             10 : CFG_MAX_CONNECTIONS)  /**< Maximum number of Power Consumption Service connections. */
70 #define PCS_MAX_DATA_LEN    244    /**< Maximum length of application data packet which is transmitted via PCS. */
71 #define PCS_SERVICE_UUID    0x1B, 0xD7, 0x90, 0xEC, 0xE8, 0xB9, 0x75, 0x80, 0x0A, 0x46, 0x44, 0xD3, 0x01, 0x05, \
72                             0xED, 0xA6   /**< The UUID of Power Consumption Service for setting advertising data. */
73 
74 #define PCS_SET_PARAM_SUCCESS   0x00               /**< PCS parameters set successfully. */
75 #define PCS_SET_PARAM_FAIL      0x81               /**< PCS parameters set unsuccessfully. */
76 
77 #define PCS_SET_ADV_DATA_3B     0x03               /**< Set 3 byte advertising data. */
78 #define PCS_SET_ADV_DATA_10B    0x0a               /**< Set 10 byte advertising data. */
79 #define PCS_SET_ADV_DATA_17B    0x11               /**< Set 17 byte advertising data. */
80 #define PCS_SET_ADV_DATA_24B    0x18               /**< Set 24 byte advertising data. */
81 #define PCS_SET_ADV_DATA_31B    0x1f               /**< Set 31 byte advertising data. */
82 /** @} */
83 
84 /**
85  * @defgroup PCS_ENUM Enumerations
86  * @{
87  */
88 /**@brief PCS Service event types. */
89 typedef enum {
90     PCS_EVT_INVALID,                    /**< Invalid PCS event. */
91     PCS_EVT_TX_ENABLE,                  /**< TX notify has been enabled. */
92     PCS_EVT_TX_DISABLE,                 /**< TX notify has been disabled. */
93     PCS_EVT_SETTING_ENABLE,             /**< Setting notify has been enabled. */
94     PCS_EVT_SETTING_DISABLE,            /**< Setting notify has been disabled. */
95     PCS_EVT_TX_DATA_SENT,               /**< Data has been notitied completely. */
96     PCS_EVT_PARAM_SET,                  /**< BLE parameters set. */
97     PCS_EVT_DISCONNECTED,               /**< Disconnected. */
98 } pcs_evt_type_t;
99 
100 /**@brief PCS Service settings types. */
101 typedef enum {
102     PCS_SETTING_TYPE_ADV_INTERVAL,       /**< BLE Advertising Interval parameter. */
103     PCS_SETTING_TYPE_CONN_PARAM,         /**< BLE Connection parameter. */
104     PCS_SETTING_TYPE_PHY,                /**< Radio Phy mode, 1M, 2M, Encoded. */
105     PCS_SETTING_TYPE_ADV_DATA,           /**< BLE advertising data. */
106     PCS_SETTING_TYPE_TX_POWER,           /**< Tx Power. */
107 } pcs_setting_type_t;
108 /** @} */
109 
110 /**
111  * @defgroup PCS_STRUCT Structures
112  * @{
113  */
114 /**@brief PCS Service event. */
115 typedef struct {
116     uint8_t         conn_idx;           /**< The index of the connection. */
117     pcs_evt_type_t  evt_type;           /**< The PCS event type. */
118     uint8_t        *p_data;             /**< Pointer to data. */
119     uint16_t        length;             /**< Length of data. */
120 } pcs_evt_t;
121 /** @} */
122 
123 /**
124  * @defgroup pPCS_TYPEDEF Typedefs
125  * @{
126  */
127 /**@brief PCS Service event handler type. */
128 typedef void (*pcs_evt_handler_t)(pcs_evt_t *p_evt);
129 /** @} */
130 
131 /**
132  * @addtogroup PCS_STRUCT Structures
133  * @{
134  */
135 /**@brief PCS Service init stucture.
136  * This contains all option and data needed for initialization of the service. */
137 typedef struct {
138     pcs_evt_handler_t evt_handler;    /**< PCS Service event handler. */
139 } pcs_init_t;
140 /** @} */
141 
142 /**
143  * @defgroup PCS_FUNCTION Functions
144  * @{
145  */
146 /**
147  *****************************************************************************************
148  * @brief Initialize a PCS Service instance and add in the database.
149  *
150  * @param[in] p_pcs_init: Pointer to PCS Service initialization variables.
151  *
152  * @return Result of service initialization.
153  *****************************************************************************************
154  */
155 sdk_err_t pcs_service_init(pcs_init_t *p_pcs_init);
156 
157 /**
158  *****************************************************************************************
159  * @brief Send data to peer device.
160  *
161  * @param[in] conn_idx: Index of the connection.
162  * @param[in] p_data:   Pointer to sent data.
163  * @param[in] length:   Length of sent data.
164  *
165  * @return Result of sending data.
166  *****************************************************************************************
167  */
168 sdk_err_t pcs_tx_data_send(uint8_t conn_idx, uint8_t *p_data, uint16_t length);
169 
170 /**
171  *****************************************************************************************
172  * @brief Reply parameters set result.
173  *
174  * @param[in] conn_idx: Index of the connection.
175  * @param[in] p_data:   Pointer to sent data.
176  * @param[in] length:   Length of sent data.
177  *
178  * @return Result of sending data.
179  *****************************************************************************************
180  */
181 sdk_err_t pcs_setting_reply(uint8_t conn_idx, uint8_t *p_data, uint16_t length);
182 /** @} */
183 
184 #endif
185 /** @} */
186 /** @} */
187