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 "gr55xx_sys.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 < CFG_MAX_CONNECTIONS ?\
76  10 : CFG_MAX_CONNECTIONS) /**< Maximum number of WeChat connections. */
77 #define WECHAT_DATA_LEN 20 /**< Maximum length of WeChat Data. */
78 #define WECHAT_PEDO_TARGET_VAL_LEN 0x04 /**< Maximum length of WeChat pedometer target value. */
79 #define WECHAT_PEDO_STEP_COUNT_MAX 0xFFFFFF /**< Maximum value of WeChat pedometer step count. */
80 
81 /**
82  * @defgroup WECHAT_UUID WECHAT Service and Characteristic UUID
83  * @{
84  * @brief WeChat Service, Airsync and Pedometer Characteristic UUID.
85  */
86 #define WECHAT_SERVICE_UUID 0XFEE7 /**< WeChat Service UUID. */
87 #define WECHAT_WRITE_CHAR_UUID 0XFEC7 /**< WeChat Airsync Write Characteristic UUID. */
88 #define WECHAT_INDICATE_CHAR_UUID 0XFEC8 /**< WeChat Airsync Indication Characteristic UUID. */
89 #define WECHAT_READ_CHAR_UUID 0XFEC9 /**< WeChat Airsync Read Characteristic UUID. */
90 #define WECHAT_PEDOMETER_MEASUREMENT 0XFEA1 /**< WeChat Current Pedometer Measurement Characteristic UUID. */
91 #define WECHAT_TARGET 0XFEA2 /**< WeChat Pedometer Target Characteristic UUID. */
92 /** @} */
93 
94 /**
95  * @defgroup WECHAT_PEDO_FLAG WECHAT pedeometer measurement flag
96  * @{
97  * @brief WeChat pedeometer measurement flag bits.
98  */
99 #define WECHAT_PEDO_FLAG_STEP_COUNT_BIT 0X01 /**< WeChat pedometer measurement step count flag bit. */
100 #define WECHAT_PEDO_FLAG_STEP_DISTENCE_BIT 0X02 /**< WeChat pedometer measurement step distance flag bit. */
101 #define WECHAT_PEDO_FLAG_STEP_CALORIE_BIT 0X04 /**< WeChat pedometer measurement step calorie flag bit. */
102 #define WECHAT_PEDO_FLAG_ALL_SUP_BIT 0X07 /**< WeChat pedometer measurement all flag bit. */
103 /** @} */
104 /** @} */
105 
106 /**
107  * @defgroup WECHAT_ENUM Enumerations
108  * @{
109  */
110 /**@brief WeChat Service event type.*/
111 typedef enum
112 {
113  WECHAT_EVT_INVALID, /**< WeChat invalid event. */
114  WECHAT_EVT_AIRSYNC_IND_ENABLE, /**< WeChat Airsync indication has been enabled. */
115  WECHAT_EVT_AIRSYNC_IND_DISABLE, /**< WeChat Airsync indication has been disabled. */
116  WECHAT_EVT_PEDO_MEAS_NTF_ENABLE, /**< WeChat Pedometer measurement notification has been enabled. */
117  WECHAT_EVT_PEDO_MEAS_NTF_DISABLE, /**< WeChat Pedometer measurement notification has been disabled. */
118  WECHAT_EVT_PEDO_TARGET_IND_ENABLE, /**< WeChat Pedometer target indicaiton has been enabled. */
119  WECHAT_EVT_PEDO_TARGET_IND_DISABLE, /**< WeChat Pedometer target indicaiton has been disabled. */
120  WECHAT_EVT_PEDO_TARGET_UPDATE, /**< WeChat Pedometer target has been updated. */
121  WECHAT_EVT_AIRSYNC_DATA_RECIEVE, /**< Recieved Airsync data. */
123 /** @} */
124 
125 /**
126  * @defgroup WECHAT_STRUCT Structures
127  * @{
128  */
129 /**@brief WeChat current pedometer measurement variable. */
130 typedef struct
131 {
132  uint8_t flag; /**< Flag for WeChat current pedometer measurement. */
133  uint8_t step_count[3]; /**< Step counts of pedometer measurement. */
134  uint8_t step_dist[3]; /**< Step distance of pedometer measurement. */
135  uint8_t step_calorie[3]; /**< Step Calorie of pedometer measurement. */
137 
138 /**@brief WeChat pedometer target variable. */
139 typedef struct
140 {
141  uint8_t flag; /**< Flag for WeChat pedometer target. */
142  uint8_t step_count[3]; /**< Target of step pedometer counts. */
144 
145 /**@brief WeChat service data. */
146 typedef struct
147 {
148  const uint8_t *p_data; /**< Pointer to data. */
149  uint16_t length; /**< Length of data. */
150  uint16_t offset; /**< Offset of data. */
151 } wechat_data_t;
152 
153 /**@brief WeChat Service event.*/
154 typedef struct
155 {
156  uint8_t conn_idx; /**< The index of connection. */
157  wechat_evt_type_t evt_type; /**< Event type. */
158  union
159  {
160  wechat_pedo_target_t pedo_target; /**< Pedometer target set value. */
161  wechat_data_t data; /**< Data of Airsync. */
162  } param; /**< Parameter of WeChat airsync event. */
163 } wechat_evt_t;
164 /** @} */
165 
166 /**
167  * @defgroup WECHAT_TYPEDEF Typedefs
168  * @{
169  */
170 /**@brief WeChat Service event handler type.*/
171 typedef void (*wechat_evt_handler_t)(wechat_evt_t *p_evt);
172 /** @} */
173 
174 /**
175  * @defgroup WECHAT_STRUCT Structures
176  * @{
177  */
178 /**@brief WeChat Service Init variable. */
179 typedef struct
180 {
181  wechat_evt_handler_t evt_handler; /**< WeChat Service event handler. */
182  uint32_t step_count_target; /**< WeChat pedometer step count target value. */
183  uint8_t *p_dev_mac; /**< Pointer to WeChat device MAC address. */
184 } wechat_init_t;
185 /** @} */
186 
187 /**
188  * @defgroup WECHAT_FUNCTION Functions
189  * @{
190  */
191 /**
192  *****************************************************************************************
193  * @brief Initialize a WeChat Service instance and add in the DB.
194  *
195  * @param[in] p_wechat_init: Pointer to WeChat init value.
196  *
197  * @return Result of service initialization.
198  *****************************************************************************************
199  */
201 
202 /**
203  *****************************************************************************************
204  * @brief WeChat Service Airsync indicate data.
205  *
206  * @param[in] conn_idx: The index of connection.
207  * @param[in] p_data: Pointer to data.
208  * @param[in] length: Length of data.
209  *
210  * @return Result of indicaition.
211  *****************************************************************************************
212  */
213 sdk_err_t wechat_airsync_data_indicate(uint8_t conn_idx, uint8_t *p_data, uint16_t length);
214 
215 /**
216  *****************************************************************************************
217  * @brief Send WeChat pedometer measurement information.
218  *
219  * @param[in] conn_idx: The index of connection.
220  * @param[in] p_pedo_meas: Pointer to pedometer measurement.
221  *
222  * @return Result of send.
223  *****************************************************************************************
224  */
226 
227 /**
228  *****************************************************************************************
229  * @brief Send WeChat pedometer target value.
230  *
231  * @param[in] conn_idx: Connection index.
232  *
233  * @return Result of send.
234  *****************************************************************************************
235  */
237 /** @} */
238 #endif
239 /** @} */
240 /** @} */
WECHAT_EVT_INVALID
@ WECHAT_EVT_INVALID
WeChat invalid event.
Definition: wechat.h:113
wechat_evt_handler_t
void(* wechat_evt_handler_t)(wechat_evt_t *p_evt)
WeChat Service event handler type.
Definition: wechat.h:171
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:116
wechat_init_t::p_dev_mac
uint8_t * p_dev_mac
Pointer to WeChat device MAC address.
Definition: wechat.h:183
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:182
WECHAT_EVT_PEDO_MEAS_NTF_DISABLE
@ WECHAT_EVT_PEDO_MEAS_NTF_DISABLE
WeChat Pedometer measurement notification has been disabled.
Definition: wechat.h:117
wechat_evt_t::pedo_target
wechat_pedo_target_t pedo_target
Pedometer target set value.
Definition: wechat.h:160
wechat_evt_t::data
wechat_data_t data
Data of Airsync.
Definition: wechat.h:161
wechat_evt_t
WeChat Service event.
Definition: wechat.h:155
WECHAT_EVT_AIRSYNC_IND_DISABLE
@ WECHAT_EVT_AIRSYNC_IND_DISABLE
WeChat Airsync indication has been disabled.
Definition: wechat.h:115
gr55xx_sys.h
GR55XX System API.
wechat_data_t::p_data
const uint8_t * p_data
Pointer to data.
Definition: wechat.h:148
wechat_data_t::length
uint16_t length
Length of data.
Definition: wechat.h:149
WECHAT_EVT_PEDO_TARGET_IND_ENABLE
@ WECHAT_EVT_PEDO_TARGET_IND_ENABLE
WeChat Pedometer target indicaiton has been enabled.
Definition: wechat.h:118
wechat_pedo_target_t
WeChat pedometer target variable.
Definition: wechat.h:140
wechat_evt_type_t
wechat_evt_type_t
WeChat Service event type.
Definition: wechat.h:112
wechat_init_t
WeChat Service Init variable.
Definition: wechat.h:180
WECHAT_EVT_PEDO_TARGET_IND_DISABLE
@ WECHAT_EVT_PEDO_TARGET_IND_DISABLE
WeChat Pedometer target indicaiton has been disabled.
Definition: wechat.h:119
wechat_pedo_meas_t::flag
uint8_t flag
Flag for WeChat current pedometer measurement.
Definition: wechat.h:132
sdk_err_t
uint16_t sdk_err_t
SDK API result type.
Definition: ble_error.h:243
WECHAT_EVT_AIRSYNC_IND_ENABLE
@ WECHAT_EVT_AIRSYNC_IND_ENABLE
WeChat Airsync indication has been enabled.
Definition: wechat.h:114
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:147
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:157
wechat_pedo_target_t::flag
uint8_t flag
Flag for WeChat pedometer target.
Definition: wechat.h:141
wechat_pedo_meas_t
WeChat current pedometer measurement variable.
Definition: wechat.h:131
wechat_init_t::evt_handler
wechat_evt_handler_t evt_handler
WeChat Service event handler.
Definition: wechat.h:181
WECHAT_EVT_AIRSYNC_DATA_RECIEVE
@ WECHAT_EVT_AIRSYNC_DATA_RECIEVE
Recieved Airsync data.
Definition: wechat.h:121
wechat_evt_t::conn_idx
uint8_t conn_idx
The index of connection.
Definition: wechat.h:156
WECHAT_EVT_PEDO_TARGET_UPDATE
@ WECHAT_EVT_PEDO_TARGET_UPDATE
WeChat Pedometer target has been updated.
Definition: wechat.h:120
wechat_data_t::offset
uint16_t offset
Offset of data.
Definition: wechat.h:150