BLE shield
Fork of X_NUCLEO_IDB0XA1 by
Embed:
(wiki syntax)
Show/hide line numbers
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 "BlueNRGDiscoveredCharacteristic.h" 00043 00044 using namespace std; 00045 00046 #define BLE_TOTAL_DISCOVERED_SERVICES 10 00047 #define BLE_TOTAL_DISCOVERED_CHARS 10 00048 00049 class BlueNRGGattClient : public GattClient 00050 { 00051 public: 00052 static BlueNRGGattClient &getInstance() { 00053 static BlueNRGGattClient m_instance; 00054 return m_instance; 00055 } 00056 00057 enum { 00058 GATT_IDLE, 00059 GATT_SERVICE_DISCOVERY, 00060 GATT_CHARS_DISCOVERY_COMPLETE, 00061 GATT_DISCOVERY_TERMINATED, 00062 GATT_READ_CHAR, 00063 GATT_WRITE_CHAR 00064 }; 00065 00066 /* Functions that must be implemented from GattClient */ 00067 virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle, 00068 ServiceDiscovery::ServiceCallback_t sc = NULL, 00069 ServiceDiscovery::CharacteristicCallback_t cc = NULL, 00070 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN), 00071 const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)); 00072 00073 virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, 00074 ServiceDiscovery::ServiceCallback_t callback, 00075 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)); 00076 00077 virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, 00078 ServiceDiscovery::ServiceCallback_t callback, 00079 GattAttribute::Handle_t startHandle, 00080 GattAttribute::Handle_t endHandle); 00081 00082 virtual bool isServiceDiscoveryActive(void) const; 00083 virtual void terminateServiceDiscovery(void); 00084 virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) { 00085 terminationCallback = callback; 00086 } 00087 virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const; 00088 virtual ble_error_t write(GattClient::WriteOp_t cmd, 00089 Gap::Handle_t connHandle, 00090 GattAttribute::Handle_t attributeHandle, 00091 size_t length, 00092 const uint8_t *value) const; 00093 00094 void gattProcedureCompleteCB(Gap::Handle_t connectionHandle, uint8_t error_code); 00095 00096 void primaryServicesCB(Gap::Handle_t connectionHandle, 00097 uint8_t event_data_length, 00098 uint8_t attribute_data_length, 00099 uint8_t *attribute_data_list); 00100 00101 void primaryServiceCB(Gap::Handle_t connectionHandle, 00102 uint8_t event_data_length, 00103 uint8_t *handles_info_list); 00104 00105 ble_error_t findServiceChars(Gap::Handle_t connectionHandle); 00106 00107 void serviceCharsCB(Gap::Handle_t connectionHandle, 00108 uint8_t event_data_length, 00109 uint8_t handle_value_pair_length, 00110 uint8_t *handle_value_pair); 00111 00112 void serviceCharByUUIDCB(Gap::Handle_t connectionHandle, 00113 uint8_t event_data_length, 00114 uint16_t attr_handle, 00115 uint8_t *attr_value); 00116 00117 void charReadCB(Gap::Handle_t connHandle, 00118 uint8_t event_data_length, 00119 uint8_t* attribute_value); 00120 00121 void charWritePrepareCB(Gap::Handle_t connHandle, 00122 uint8_t event_data_length, 00123 uint16_t attribute_handle, 00124 uint16_t offset, 00125 uint8_t *part_attr_value); 00126 00127 void charWriteExecCB(Gap::Handle_t connHandle, 00128 uint8_t event_data_length); 00129 00130 protected: 00131 00132 BlueNRGGattClient() { 00133 _currentState = GATT_IDLE; 00134 _matchingServiceUUID = BLE_UUID_UNKNOWN; 00135 _matchingCharacteristicUUIDIn = BLE_UUID_UNKNOWN; 00136 } 00137 00138 ServiceDiscovery::ServiceCallback_t serviceDiscoveryCallback; 00139 ServiceDiscovery::CharacteristicCallback_t characteristicDiscoveryCallback; 00140 ServiceDiscovery::TerminationCallback_t terminationCallback; 00141 00142 private: 00143 00144 BlueNRGGattClient(BlueNRGGattClient const &); 00145 void operator=(BlueNRGGattClient const &); 00146 00147 Gap::Handle_t _connectionHandle; 00148 DiscoveredService discoveredService[BLE_TOTAL_DISCOVERED_SERVICES]; 00149 BlueNRGDiscoveredCharacteristic discoveredChar[BLE_TOTAL_DISCOVERED_CHARS]; 00150 00151 GattReadCallbackParams readCBParams; 00152 GattWriteCallbackParams writeCBParams; 00153 00154 UUID _matchingServiceUUID; 00155 UUID _matchingCharacteristicUUIDIn; 00156 uint8_t _currentState; 00157 uint8_t _numServices, _servIndex; 00158 uint8_t _numChars; 00159 00160 }; 00161 00162 #endif /* __BLUENRG_GATT_CLIENT_H__ */
Generated on Tue Jul 12 2022 19:27:28 by 1.7.2