1 /** 2 **************************************************************************************** 3 * 4 * @file user.h 5 * 6 * @brief Header file - user defined. 7 * 8 * Copyright (C) RivieraWaves 2009-2016 9 * 10 * 11 **************************************************************************************** 12 */ 13 14 #ifndef USER_H_ 15 #define USER_H_ 16 17 18 /* 19 * INCLUDE FILES 20 **************************************************************************************** 21 */ 22 #include "rwip_config.h" 23 #if (BLE_APP_USER) 24 #include <stdint.h> 25 #include <stdbool.h> 26 //#include "htp_common.h" 27 #include "prf_types.h" 28 #include "prf_utils.h" 29 #include "prf.h" 30 #include "gap.h" 31 32 /* 33 * MACROS 34 **************************************************************************************** 35 */ 36 #define USER_IS_FEATURE_SUPPORTED(feat, bit_mask) (((feat & bit_mask) == bit_mask)) 37 38 #define USER_HANDLE(idx) (user_att_hdl_get(user_env, (idx))) 39 40 #define USER_IDX(hdl) (user_att_idx_get(user_env, (hdl))) 41 42 /* 43 * DEFINES 44 **************************************************************************************** 45 */ 46 #define USER_DATA_LEN_MAX (1024)//(64) 47 48 #define USER_READ_WRITE_ATT_NB (3) 49 #define USER_DTAA_NOTIFY_ATT_NB (3) 50 #define USER_DATA_WRITE_ATT_NB (2) 51 #define USER_DATA_INTV_ATT_NB (3) 52 53 #define USER_IND_NTF_CFG_MAX_LEN (2) 54 /// Possible states of the HTPT task 55 enum user_state 56 { 57 /// Idle state 58 USER_IDLE, 59 /// Busy state 60 USER_BUSY, 61 62 /// Number of defined states. 63 USER_STATE_MAX 64 }; 65 ///Attributes database elements 66 /// 修改服务列表 67 enum user_att_db_list 68 { 69 USER_IDX_SVC, 70 71 USER_IDX_WRITE_NOTIFY_CHAR, 72 USER_IDX_WRITE_NOTIFY_VAL, 73 USER_IDX_WRITE_NOTIFY_CFG, 74 75 #ifdef BLE_OTA_WRITE_CHAR_EN 76 USER_IDX_READ_NOTIFY_CHAR, 77 USER_IDX_READ_NOTIFY_VAL, 78 USER_IDX_WRITE_NOTIFY2_CFG, 79 #endif 80 USER_IDX_NB, 81 }; 82 /// ongoing operation information 83 struct user_op 84 { 85 /// Operation 86 uint8_t op; 87 /// Cursor on connection 88 uint8_t cursor; 89 /// Handle of the attribute to indicate/notify 90 uint16_t handle; 91 /// Task that request the operation that should receive completed message response 92 uint16_t dest_id; 93 /// Packed notification/indication data size 94 uint8_t length; 95 /// used to know on which device interval update has been requested, and to prevent 96 /// indication to be triggered on this connection index 97 uint8_t conidx; 98 /// Packed notification/indication data 99 uint8_t data[__ARRAY_EMPTY]; 100 }; 101 102 //Health Thermometer Profile Thermometer Environment Variable 103 struct user_env_tag 104 { 105 /// profile environment 106 prf_env_t prf_env; 107 /// On-going operation 108 struct user_op * operation; 109 /// Service Start Handle 110 uint16_t shdl; 111 /// Database configuration 112 uint16_t features; 113 uint8_t ntf_ind_cfg[USER_IDX_NB]; 114 ke_state_t state[1]; 115 116 // uint8_t data[ATT_VALUE_LEN_MAX/*__ARRAY_EMPTY*/]; 117 118 uint16_t receive_length; 119 uint8_t *receive_data; 120 bool receive_flag; 121 bool receive_header; 122 uint16_t receive_current_length; 123 uint16_t send_current_length; //wait to check 124 }; 125 /* 126 * GLOBAL VARIABLE DECLARATIONS 127 **************************************************************************************** 128 */ 129 130 /* 131 * FUNCTION DECLARATIONS 132 **************************************************************************************** 133 */ 134 135 /** 136 **************************************************************************************** 137 * @brief Compute the offset of the valid range descriptor. 138 * The Measurement Interval characteristic has two optional descriptors. In the database, 139 * the Client Characteristic Configuration descriptor will always be placed just after the 140 * characteristic value. Thus, this function checks if the CCC descriptor has been added. 141 * @return 0 if Measurement Interval Char. is not writable (no Valid Range descriptor) 142 * 1 if Measurement Interval Char. doesn't support indications (no CCC descriptor) 143 * 2 otherwise 144 **************************************************************************************** 145 */ 146 uint8_t user_get_valid_rge_offset(uint16_t features); 147 148 /** 149 **************************************************************************************** 150 * @brief Retrieve HTS service profile interface 151 * 152 * @return HTS service profile interface 153 **************************************************************************************** 154 */ 155 const struct prf_task_cbs* user_prf_itf_get(void); 156 //const struct prf_task_cbs* user1_prf_itf_get(void); 157 //const struct prf_task_cbs* user2_prf_itf_get(void); 158 uint16_t user_att_hdl_get(struct user_env_tag* htpt_env, uint8_t att_idx); 159 160 /** 161 **************************************************************************************** 162 * @brief Retrieve attribute index from attribute handle 163 * 164 * @param[in] htpt_env Environment variable 165 * @param[in] handle Attribute Handle 166 * 167 * @return attribute Index 168 **************************************************************************************** 169 */ 170 uint8_t user_att_idx_get(struct user_env_tag* htpt_env, uint16_t handle); 171 172 void user_exe_operation(void); 173 174 uint8_t user_update_ntf_ind_cfg(uint8_t conidx, uint8_t cfg, uint16_t valid_val,uint8_t idx,uint16_t value); 175 176 /* 177 * TASK DESCRIPTOR DECLARATIONS 178 **************************************************************************************** 179 */ 180 extern const struct ke_state_handler user_default_handler; 181 //extern const struct ke_state_handler user1_default_handler; 182 //extern const struct ke_state_handler user2_default_handler; 183 184 #endif //BLE_HT_THERMOM 185 186 /// @} HTPT 187 188 #endif // HTPT_H_ 189 190