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 <stdint.h> 67 #include <stdbool.h> 68 #include "gr55xx_sys.h" 69 #include "custom_config.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 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 uint8_t flag; /**< Flag for WeChat current pedometer measurement. */ 131 uint8_t step_count[3]; /**< Step counts of pedometer measurement. */ 132 uint8_t step_dist[3]; /**< Step distance of pedometer measurement. */ 133 uint8_t step_calorie[3]; /**< Step Calorie of pedometer measurement. */ 134 } wechat_pedo_meas_t; 135 136 /**@brief WeChat pedometer target variable. */ 137 typedef struct { 138 uint8_t flag; /**< Flag for WeChat pedometer target. */ 139 uint8_t step_count[3]; /**< Target of step pedometer counts. */ 140 } wechat_pedo_target_t; 141 142 /**@brief WeChat service data. */ 143 typedef struct { 144 const uint8_t *p_data; /**< Pointer to data. */ 145 uint16_t length; /**< Length of data. */ 146 uint16_t offset; /**< Offset of data. */ 147 } wechat_data_t; 148 149 /**@brief WeChat Service event.*/ 150 typedef struct { 151 uint8_t conn_idx; /**< The index of connection. */ 152 wechat_evt_type_t evt_type; /**< Event type. */ 153 union { 154 wechat_pedo_target_t pedo_target; /**< Pedometer target set value. */ 155 wechat_data_t data; /**< Data of Airsync. */ 156 } param; /**< Parameter of WeChat airsync event. */ 157 } wechat_evt_t; 158 /** @} */ 159 160 /** 161 * @defgroup WECHAT_TYPEDEF Typedefs 162 * @{ 163 */ 164 /**@brief WeChat Service event handler type.*/ 165 typedef void (*wechat_evt_handler_t)(wechat_evt_t *p_evt); 166 /** @} */ 167 168 /** 169 * @defgroup WECHAT_STRUCT Structures 170 * @{ 171 */ 172 /**@brief WeChat Service Init variable. */ 173 typedef struct { 174 wechat_evt_handler_t evt_handler; /**< WeChat Service event handler. */ 175 uint32_t step_count_target; /**< WeChat pedometer step count target value. */ 176 uint8_t *p_dev_mac; /**< Pointer to WeChat device MAC address. */ 177 } wechat_init_t; 178 /** @} */ 179 180 /** 181 * @defgroup WECHAT_FUNCTION Functions 182 * @{ 183 */ 184 /** 185 ***************************************************************************************** 186 * @brief Initialize a WeChat Service instance and add in the DB. 187 * 188 * @param[in] p_wechat_init: Pointer to WeChat init value. 189 * 190 * @return Result of service initialization. 191 ***************************************************************************************** 192 */ 193 sdk_err_t wechat_service_init(wechat_init_t *p_wechat_init); 194 195 /** 196 ***************************************************************************************** 197 * @brief WeChat Service Airsync indicate data. 198 * 199 * @param[in] conn_idx: The index of connection. 200 * @param[in] p_data: Pointer to data. 201 * @param[in] length: Length of data. 202 * 203 * @return Result of indicaition. 204 ***************************************************************************************** 205 */ 206 sdk_err_t wechat_airsync_data_indicate(uint8_t conn_idx, uint8_t *p_data, uint16_t length); 207 208 /** 209 ***************************************************************************************** 210 * @brief Send WeChat pedometer measurement information. 211 * 212 * @param[in] conn_idx: The index of connection. 213 * @param[in] p_pedo_meas: Pointer to pedometer measurement. 214 * 215 * @return Result of send. 216 ***************************************************************************************** 217 */ 218 sdk_err_t wechat_pedo_measurement_send(uint8_t conn_idx, wechat_pedo_meas_t *p_pedo_meas); 219 220 /** 221 ***************************************************************************************** 222 * @brief Send WeChat pedometer target value. 223 * 224 * @param[in] conn_idx: Connection index. 225 * 226 * @return Result of send. 227 ***************************************************************************************** 228 */ 229 sdk_err_t wechat_pedo_target_send(uint8_t conn_idx); 230 /** @} */ 231 #endif 232 /** @} */ 233 /** @} */ 234