wechat.h
Go to the documentation of this file.
1 /**
2 *****************************************************************************************
3 *
4 * @file wechat.h
5 *
6 * @brief WeChat 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 * @defgroup BLE_SDK_WECHAT Wechat (WECHAT)
45 * @{
46 * @brief Definitions and prototypes for the WeChat interface.
47 *
48 * @details The WeChat Service contains two modules: WeChat Airsync Protocol and WeChat
49 * Pedometer Protocol.
50 *
51 * WeChat Airsync Protocol opens the data link between the device and the vendor server,
52 * which supports sending data from the device to the vendor's server, as well as the vendor's
53 * data to the device. The protocol also opens the data link between the device and the WeChat server.
54 * The data format between the device and the WeChat server is stipulated by WeChat, such as login,
55 * new message notification, etc.
56 *
57 * WeChat Pedometer Protocol is based on GATT protocol, which requires less hardware
58 * capability of the device, and the manufacturer does not need a back-end server (that is,
59 * only need to develop the device) to dock with WeChat. It allows pedometers to connect to WeChat
60 * and transmit steps, kilometers, calories, moving targets, etc.
61 */
62
63 #ifndef __WECHART_H__
64 #define __WECHART_H__
65
66 #include "gr_includes.h"
67 #include "custom_config.h"
68 #include <stdint.h>
69 #include <stdbool.h>
70
71 /**
72 * @defgroup WECHAT_MACRO Defines
73 * @{
74 */
75 #define WECHAT_CONNECTION_MAX 10 /**< Maximum number of WeChat connections. */
76 #define WECHAT_DATA_LEN 20 /**< Maximum length of WeChat Data. */
77 #define WECHAT_PEDO_TARGET_VAL_LEN 0x04 /**< Maximum length of WeChat pedometer target value. */
78 #define WECHAT_PEDO_STEP_COUNT_MAX 0xFFFFFF /**< Maximum value of WeChat pedometer step count. */
79
80 /**
81 * @defgroup WECHAT_UUID WECHAT Service and Characteristic UUID
82 * @{
83 * @brief WeChat Service, Airsync and Pedometer Characteristic UUID.
84 */
85 #define WECHAT_SERVICE_UUID 0XFEE7 /**< WeChat Service UUID. */
86 #define WECHAT_WRITE_CHAR_UUID 0XFEC7 /**< WeChat Airsync Write Characteristic UUID. */
87 #define WECHAT_INDICATE_CHAR_UUID 0XFEC8 /**< WeChat Airsync Indication Characteristic UUID. */
88 #define WECHAT_READ_CHAR_UUID 0XFEC9 /**< WeChat Airsync Read Characteristic UUID. */
89 #define WECHAT_PEDOMETER_MEASUREMENT 0XFEA1 /**< WeChat Current Pedometer Measurement Characteristic UUID. */
90 #define WECHAT_TARGET 0XFEA2 /**< WeChat Pedometer Target Characteristic UUID. */
91 /** @} */
92
93 /**
94 * @defgroup WECHAT_PEDO_FLAG WECHAT pedeometer measurement flag
95 * @{
96 * @brief WeChat pedeometer measurement flag bits.
97 */
98 #define WECHAT_PEDO_FLAG_STEP_COUNT_BIT 0X01 /**< WeChat pedometer measurement step count flag bit. */
99 #define WECHAT_PEDO_FLAG_STEP_DISTENCE_BIT 0X02 /**< WeChat pedometer measurement step distance flag bit. */
100 #define WECHAT_PEDO_FLAG_STEP_CALORIE_BIT 0X04 /**< WeChat pedometer measurement step calorie flag bit. */
101 #define WECHAT_PEDO_FLAG_ALL_SUP_BIT 0X07 /**< WeChat pedometer measurement all flag bit. */
102 /** @} */
103 /** @} */
104
105 /**
106 * @defgroup WECHAT_ENUM Enumerations
107 * @{
108 */
109 /**@brief WeChat Service event type.*/
110 typedef enum
111 {
112 WECHAT_EVT_INVALID, /**< WeChat invalid event. */
113 WECHAT_EVT_AIRSYNC_IND_ENABLE, /**< WeChat Airsync indication has been enabled. */
114 WECHAT_EVT_AIRSYNC_IND_DISABLE, /**< WeChat Airsync indication has been disabled. */
115 WECHAT_EVT_PEDO_MEAS_NTF_ENABLE, /**< WeChat Pedometer measurement notification has been enabled. */
116 WECHAT_EVT_PEDO_MEAS_NTF_DISABLE, /**< WeChat Pedometer measurement notification has been disabled. */
117 WECHAT_EVT_PEDO_TARGET_IND_ENABLE, /**< WeChat Pedometer target indicaiton has been enabled. */
118 WECHAT_EVT_PEDO_TARGET_IND_DISABLE, /**< WeChat Pedometer target indicaiton has been disabled. */
119 WECHAT_EVT_PEDO_TARGET_UPDATE, /**< WeChat Pedometer target has been updated. */
120 WECHAT_EVT_AIRSYNC_DATA_RECIEVE, /**< Recieved Airsync data. */
121 } wechat_evt_type_t;
122 /** @} */
123
124 /**
125 * @defgroup WECHAT_STRUCT Structures
126 * @{
127 */
128 /**@brief WeChat current pedometer measurement variable. */
129 typedef struct
130 {
131 uint8_t flag; /**< Flag for WeChat current pedometer measurement. */
132 uint8_t step_count[3]; /**< Step counts of pedometer measurement. */
133 uint8_t step_dist[3]; /**< Step distance of pedometer measurement. */
134 uint8_t step_calorie[3]; /**< Step Calorie of pedometer measurement. */
135 } wechat_pedo_meas_t;
136
137 /**@brief WeChat pedometer target variable. */
138 typedef struct
139 {
140 uint8_t flag; /**< Flag for WeChat pedometer target. */
141 uint8_t step_count[3]; /**< Target of step pedometer counts. */
142 } wechat_pedo_target_t;
143
144 /**@brief WeChat service data. */
145 typedef struct
146 {
147 const uint8_t *p_data; /**< Pointer to data. */
148 uint16_t length; /**< Length of data. */
149 uint16_t offset; /**< Offset of data. */
150 } wechat_data_t;
151
152 /**@brief WeChat Service event.*/
153 typedef struct
154 {
155 uint8_t conn_idx; /**< The index of connection. */
156 wechat_evt_type_t evt_type; /**< Event type. */
157 union
158 {
159 wechat_pedo_target_t pedo_target; /**< Pedometer target set value. */
160 wechat_data_t data; /**< Data of Airsync. */
161 } param; /**< Parameter of WeChat airsync event. */
162 } wechat_evt_t;
163 /** @} */
164
165 /**
166 * @defgroup WECHAT_TYPEDEF Typedefs
167 * @{
168 */
169 /**@brief WeChat Service event handler type.*/
170 typedef void (*wechat_evt_handler_t)(wechat_evt_t *p_evt);
171 /** @} */
172
173 /**
174 * @defgroup WECHAT_STRUCT Structures
175 * @{
176 */
177 /**@brief WeChat Service Init variable. */
178 typedef struct
179 {
180 wechat_evt_handler_t evt_handler; /**< WeChat Service event handler. */
181 uint32_t step_count_target; /**< WeChat pedometer step count target value. */
182 uint8_t *p_dev_mac; /**< Pointer to WeChat device MAC address. */
183 } wechat_init_t;
184 /** @} */
185
186 /**
187 * @defgroup WECHAT_FUNCTION Functions
188 * @{
189 */
190 /**
191 *****************************************************************************************
192 * @brief Initialize a WeChat Service instance and add in the DB.
193 *
194 * @param[in] p_wechat_init: Pointer to WeChat init value.
195 *
196 * @return Result of service initialization.
197 *****************************************************************************************
198 */
199 sdk_err_t wechat_service_init(wechat_init_t *p_wechat_init);
200
201 /**
202 *****************************************************************************************
203 * @brief WeChat Service Airsync indicate data.
204 *
205 * @param[in] conn_idx: The index of connection.
206 * @param[in] p_data: Pointer to data.
207 * @param[in] length: Length of data.
208 *
209 * @return Result of indicaition.
210 *****************************************************************************************
211 */
212 sdk_err_t wechat_airsync_data_indicate(uint8_t conn_idx, uint8_t *p_data, uint16_t length);
213
214 /**
215 *****************************************************************************************
216 * @brief Send WeChat pedometer measurement information.
217 *
218 * @param[in] conn_idx: The index of connection.
219 * @param[in] p_pedo_meas: Pointer to pedometer measurement.
220 *
221 * @return Result of send.
222 *****************************************************************************************
223 */
224 sdk_err_t wechat_pedo_measurement_send(uint8_t conn_idx, wechat_pedo_meas_t *p_pedo_meas);
225
226 /**
227 *****************************************************************************************
228 * @brief Send WeChat pedometer target value.
229 *
230 * @param[in] conn_idx: Connection index.
231 *
232 * @return Result of send.
233 *****************************************************************************************
234 */
235 sdk_err_t wechat_pedo_target_send(uint8_t conn_idx);
236 /** @} */
237 #endif
238 /** @} */
239 /** @} */
WECHAT_EVT_INVALID
@ WECHAT_EVT_INVALID
WeChat invalid event.
Definition: wechat.h:112
wechat_evt_handler_t
void(* wechat_evt_handler_t)(wechat_evt_t *p_evt)
WeChat Service event handler type.
Definition: wechat.h:170
wechat_pedo_measurement_send
sdk_err_t wechat_pedo_measurement_send(uint8_t conn_idx, wechat_pedo_meas_t *p_pedo_meas)
Send WeChat pedometer measurement information.
WECHAT_EVT_PEDO_MEAS_NTF_ENABLE
@ WECHAT_EVT_PEDO_MEAS_NTF_ENABLE
WeChat Pedometer measurement notification has been enabled.
Definition: wechat.h:115
wechat_init_t::p_dev_mac
uint8_t * p_dev_mac
Pointer to WeChat device MAC address.
Definition: wechat.h:182
wechat_pedo_target_send
sdk_err_t wechat_pedo_target_send(uint8_t conn_idx)
Send WeChat pedometer target value.
wechat_init_t::step_count_target
uint32_t step_count_target
WeChat pedometer step count target value.
Definition: wechat.h:181
WECHAT_EVT_PEDO_MEAS_NTF_DISABLE
@ WECHAT_EVT_PEDO_MEAS_NTF_DISABLE
WeChat Pedometer measurement notification has been disabled.
Definition: wechat.h:116
wechat_evt_t::pedo_target
wechat_pedo_target_t pedo_target
Pedometer target set value.
Definition: wechat.h:159
wechat_evt_t::data
wechat_data_t data
Data of Airsync.
Definition: wechat.h:160
gr_includes.h
Include Files API.
wechat_evt_t
WeChat Service event.
Definition: wechat.h:154
WECHAT_EVT_AIRSYNC_IND_DISABLE
@ WECHAT_EVT_AIRSYNC_IND_DISABLE
WeChat Airsync indication has been disabled.
Definition: wechat.h:114
wechat_data_t::p_data
const uint8_t * p_data
Pointer to data.
Definition: wechat.h:147
wechat_data_t::length
uint16_t length
Length of data.
Definition: wechat.h:148
WECHAT_EVT_PEDO_TARGET_IND_ENABLE
@ WECHAT_EVT_PEDO_TARGET_IND_ENABLE
WeChat Pedometer target indicaiton has been enabled.
Definition: wechat.h:117
wechat_pedo_target_t
WeChat pedometer target variable.
Definition: wechat.h:139
wechat_evt_type_t
wechat_evt_type_t
WeChat Service event type.
Definition: wechat.h:111
wechat_init_t
WeChat Service Init variable.
Definition: wechat.h:179
WECHAT_EVT_PEDO_TARGET_IND_DISABLE
@ WECHAT_EVT_PEDO_TARGET_IND_DISABLE
WeChat Pedometer target indicaiton has been disabled.
Definition: wechat.h:118
wechat_pedo_meas_t::flag
uint8_t flag
Flag for WeChat current pedometer measurement.
Definition: wechat.h:131
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:273
WECHAT_EVT_AIRSYNC_IND_ENABLE
@ WECHAT_EVT_AIRSYNC_IND_ENABLE
WeChat Airsync indication has been enabled.
Definition: wechat.h:113
wechat_service_init
sdk_err_t wechat_service_init(wechat_init_t *p_wechat_init)
Initialize a WeChat Service instance and add in the DB.
wechat_data_t
WeChat service data.
Definition: wechat.h:146
wechat_airsync_data_indicate
sdk_err_t wechat_airsync_data_indicate(uint8_t conn_idx, uint8_t *p_data, uint16_t length)
WeChat Service Airsync indicate data.
wechat_evt_t::evt_type
wechat_evt_type_t evt_type
Event type.
Definition: wechat.h:156
wechat_pedo_target_t::flag
uint8_t flag
Flag for WeChat pedometer target.
Definition: wechat.h:140
wechat_pedo_meas_t
WeChat current pedometer measurement variable.
Definition: wechat.h:130
wechat_init_t::evt_handler
wechat_evt_handler_t evt_handler
WeChat Service event handler.
Definition: wechat.h:180
WECHAT_EVT_AIRSYNC_DATA_RECIEVE
@ WECHAT_EVT_AIRSYNC_DATA_RECIEVE
Recieved Airsync data.
Definition: wechat.h:120
wechat_evt_t::conn_idx
uint8_t conn_idx
The index of connection.
Definition: wechat.h:155
WECHAT_EVT_PEDO_TARGET_UPDATE
@ WECHAT_EVT_PEDO_TARGET_UPDATE
WeChat Pedometer target has been updated.
Definition: wechat.h:119
wechat_data_t::offset
uint16_t offset
Offset of data.
Definition: wechat.h:149