Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: BLE_HeartRate_IDB0XA1
Fork of X_NUCLEO_IDB0XA1 by
BlueNRGGattClient.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 /** 00017 ****************************************************************************** 00018 * @file BlueNRGGattClient.cpp 00019 * @author STMicroelectronics 00020 * @brief Header file for BLE_API GattClient Class 00021 ****************************************************************************** 00022 * @copy 00023 * 00024 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 00025 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 00026 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 00027 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 00028 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 00029 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 00030 * 00031 * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> 00032 */ 00033 00034 #ifndef __BLUENRG_GATT_CLIENT_H__ 00035 #define __BLUENRG_GATT_CLIENT_H__ 00036 00037 #include "mbed.h" 00038 #include "ble/blecommon.h" 00039 #include "btle.h" 00040 #include "ble/GattClient.h" 00041 #include "ble/DiscoveredService.h" 00042 #include "ble/CharacteristicDescriptorDiscovery.h" 00043 #include "BlueNRGDiscoveredCharacteristic.h" 00044 00045 using namespace std; 00046 00047 #define BLE_TOTAL_DISCOVERED_SERVICES 10 00048 #define BLE_TOTAL_DISCOVERED_CHARS 10 00049 00050 class BlueNRGGattClient : public GattClient 00051 { 00052 public: 00053 static BlueNRGGattClient &getInstance() { 00054 static BlueNRGGattClient m_instance; 00055 return m_instance; 00056 } 00057 00058 enum { 00059 GATT_IDLE, 00060 GATT_SERVICE_DISCOVERY, 00061 GATT_CHAR_DESC_DISCOVERY, 00062 //GATT_CHARS_DISCOVERY_COMPLETE, 00063 //GATT_DISCOVERY_TERMINATED, 00064 GATT_READ_CHAR, 00065 GATT_WRITE_CHAR 00066 }; 00067 00068 /* Functions that must be implemented from GattClient */ 00069 virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle, 00070 ServiceDiscovery::ServiceCallback_t sc = NULL, 00071 ServiceDiscovery::CharacteristicCallback_t cc = NULL, 00072 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN), 00073 const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)); 00074 00075 virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, 00076 ServiceDiscovery::ServiceCallback_t callback, 00077 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)); 00078 00079 virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, 00080 ServiceDiscovery::ServiceCallback_t callback, 00081 GattAttribute::Handle_t startHandle, 00082 GattAttribute::Handle_t endHandle); 00083 00084 virtual bool isServiceDiscoveryActive(void) const; 00085 virtual void terminateServiceDiscovery(void); 00086 virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) { 00087 terminationCallback = callback; 00088 } 00089 virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const; 00090 virtual ble_error_t write(GattClient::WriteOp_t cmd, 00091 Gap::Handle_t connHandle, 00092 GattAttribute::Handle_t attributeHandle, 00093 size_t length, 00094 const uint8_t *value) const; 00095 virtual ble_error_t discoverCharacteristicDescriptors( 00096 const DiscoveredCharacteristic& characteristic, 00097 const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback, 00098 const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback); 00099 00100 virtual ble_error_t reset(void); 00101 00102 void gattProcedureCompleteCB(Gap::Handle_t connectionHandle, uint8_t error_code); 00103 00104 void primaryServicesCB(Gap::Handle_t connectionHandle, 00105 uint8_t event_data_length, 00106 uint8_t attribute_data_length, 00107 uint8_t *attribute_data_list); 00108 00109 void primaryServiceCB(Gap::Handle_t connectionHandle, 00110 uint8_t event_data_length, 00111 uint8_t *handles_info_list); 00112 00113 ble_error_t findServiceChars(Gap::Handle_t connectionHandle); 00114 00115 void serviceCharsCB(Gap::Handle_t connectionHandle, 00116 uint8_t event_data_length, 00117 uint8_t handle_value_pair_length, 00118 uint8_t *handle_value_pair); 00119 00120 void serviceCharByUUIDCB(Gap::Handle_t connectionHandle, 00121 uint8_t event_data_length, 00122 uint16_t attr_handle, 00123 uint8_t *attr_value); 00124 00125 void discAllCharacDescCB(Gap::Handle_t connHandle, 00126 uint8_t event_data_length, 00127 uint8_t format, 00128 uint8_t *handle_uuid_pair); 00129 00130 void charReadCB(Gap::Handle_t connHandle, 00131 uint8_t event_data_length, 00132 uint8_t* attribute_value); 00133 00134 void charWritePrepareCB(Gap::Handle_t connHandle, 00135 uint8_t event_data_length, 00136 uint16_t attribute_handle, 00137 uint16_t offset, 00138 uint8_t *part_attr_value); 00139 00140 void charWriteExecCB(Gap::Handle_t connHandle, 00141 uint8_t event_data_length); 00142 00143 protected: 00144 00145 BlueNRGGattClient() { 00146 _currentState = GATT_IDLE; 00147 _matchingServiceUUID = BLE_UUID_UNKNOWN; 00148 _matchingCharacteristicUUIDIn = BLE_UUID_UNKNOWN; 00149 } 00150 00151 ServiceDiscovery::ServiceCallback_t serviceDiscoveryCallback; 00152 ServiceDiscovery::CharacteristicCallback_t characteristicDiscoveryCallback; 00153 ServiceDiscovery::TerminationCallback_t terminationCallback; 00154 CharacteristicDescriptorDiscovery::DiscoveryCallback_t charDescDiscoveryCallback; 00155 CharacteristicDescriptorDiscovery::TerminationCallback_t charDescTerminationCallback; 00156 00157 private: 00158 00159 BlueNRGGattClient(BlueNRGGattClient const &); 00160 void operator=(BlueNRGGattClient const &); 00161 00162 Gap::Handle_t _connectionHandle; 00163 DiscoveredService discoveredService[BLE_TOTAL_DISCOVERED_SERVICES]; 00164 BlueNRGDiscoveredCharacteristic discoveredChar[BLE_TOTAL_DISCOVERED_CHARS]; 00165 00166 GattReadCallbackParams readCBParams; 00167 GattWriteCallbackParams writeCBParams; 00168 00169 // The char for which the descriptor discovery has been launched 00170 DiscoveredCharacteristic _characteristic; 00171 00172 UUID _matchingServiceUUID; 00173 UUID _matchingCharacteristicUUIDIn; 00174 uint8_t _currentState; 00175 uint8_t _numServices, _servIndex; 00176 uint8_t _numChars; 00177 uint8_t _numCharDesc; 00178 00179 }; 00180 00181 #endif /* __BLUENRG_GATT_CLIENT_H__ */ 00182
Generated on Thu Jul 14 2022 01:08:08 by
1.7.2
