ver:init
x-nucleo-idb0xa1/BlueNRGGattClient.h@0:88b85febcb45, 2017-06-18 (annotated)
- Committer:
- iv123
- Date:
- Sun Jun 18 16:10:28 2017 +0000
- Revision:
- 0:88b85febcb45
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iv123 | 0:88b85febcb45 | 1 | /* mbed Microcontroller Library |
iv123 | 0:88b85febcb45 | 2 | * Copyright (c) 2006-2013 ARM Limited |
iv123 | 0:88b85febcb45 | 3 | * |
iv123 | 0:88b85febcb45 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
iv123 | 0:88b85febcb45 | 5 | * you may not use this file except in compliance with the License. |
iv123 | 0:88b85febcb45 | 6 | * You may obtain a copy of the License at |
iv123 | 0:88b85febcb45 | 7 | * |
iv123 | 0:88b85febcb45 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
iv123 | 0:88b85febcb45 | 9 | * |
iv123 | 0:88b85febcb45 | 10 | * Unless required by applicable law or agreed to in writing, software |
iv123 | 0:88b85febcb45 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
iv123 | 0:88b85febcb45 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
iv123 | 0:88b85febcb45 | 13 | * See the License for the specific language governing permissions and |
iv123 | 0:88b85febcb45 | 14 | * limitations under the License. |
iv123 | 0:88b85febcb45 | 15 | */ |
iv123 | 0:88b85febcb45 | 16 | /** |
iv123 | 0:88b85febcb45 | 17 | ****************************************************************************** |
iv123 | 0:88b85febcb45 | 18 | * @file BlueNRGGattClient.cpp |
iv123 | 0:88b85febcb45 | 19 | * @author STMicroelectronics |
iv123 | 0:88b85febcb45 | 20 | * @brief Header file for BLE_API GattClient Class |
iv123 | 0:88b85febcb45 | 21 | ****************************************************************************** |
iv123 | 0:88b85febcb45 | 22 | * @copy |
iv123 | 0:88b85febcb45 | 23 | * |
iv123 | 0:88b85febcb45 | 24 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
iv123 | 0:88b85febcb45 | 25 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE |
iv123 | 0:88b85febcb45 | 26 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY |
iv123 | 0:88b85febcb45 | 27 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING |
iv123 | 0:88b85febcb45 | 28 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE |
iv123 | 0:88b85febcb45 | 29 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
iv123 | 0:88b85febcb45 | 30 | * |
iv123 | 0:88b85febcb45 | 31 | * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> |
iv123 | 0:88b85febcb45 | 32 | */ |
iv123 | 0:88b85febcb45 | 33 | |
iv123 | 0:88b85febcb45 | 34 | #ifndef __BLUENRG_GATT_CLIENT_H__ |
iv123 | 0:88b85febcb45 | 35 | #define __BLUENRG_GATT_CLIENT_H__ |
iv123 | 0:88b85febcb45 | 36 | |
iv123 | 0:88b85febcb45 | 37 | #ifdef YOTTA_CFG_MBED_OS |
iv123 | 0:88b85febcb45 | 38 | #include "mbed-drivers/mbed.h" |
iv123 | 0:88b85febcb45 | 39 | #else |
iv123 | 0:88b85febcb45 | 40 | #include "mbed.h" |
iv123 | 0:88b85febcb45 | 41 | #endif |
iv123 | 0:88b85febcb45 | 42 | #include "ble/blecommon.h" |
iv123 | 0:88b85febcb45 | 43 | #include "btle.h" |
iv123 | 0:88b85febcb45 | 44 | #include "ble/GattClient.h" |
iv123 | 0:88b85febcb45 | 45 | #include "ble/DiscoveredService.h" |
iv123 | 0:88b85febcb45 | 46 | #include "ble/CharacteristicDescriptorDiscovery.h" |
iv123 | 0:88b85febcb45 | 47 | #include "BlueNRGDiscoveredCharacteristic.h" |
iv123 | 0:88b85febcb45 | 48 | |
iv123 | 0:88b85febcb45 | 49 | using namespace std; |
iv123 | 0:88b85febcb45 | 50 | |
iv123 | 0:88b85febcb45 | 51 | #define BLE_TOTAL_DISCOVERED_SERVICES 10 |
iv123 | 0:88b85febcb45 | 52 | #define BLE_TOTAL_DISCOVERED_CHARS 10 |
iv123 | 0:88b85febcb45 | 53 | |
iv123 | 0:88b85febcb45 | 54 | class BlueNRGGattClient : public GattClient |
iv123 | 0:88b85febcb45 | 55 | { |
iv123 | 0:88b85febcb45 | 56 | public: |
iv123 | 0:88b85febcb45 | 57 | static BlueNRGGattClient &getInstance() { |
iv123 | 0:88b85febcb45 | 58 | static BlueNRGGattClient m_instance; |
iv123 | 0:88b85febcb45 | 59 | return m_instance; |
iv123 | 0:88b85febcb45 | 60 | } |
iv123 | 0:88b85febcb45 | 61 | |
iv123 | 0:88b85febcb45 | 62 | enum { |
iv123 | 0:88b85febcb45 | 63 | GATT_IDLE, |
iv123 | 0:88b85febcb45 | 64 | GATT_SERVICE_DISCOVERY, |
iv123 | 0:88b85febcb45 | 65 | GATT_CHAR_DESC_DISCOVERY, |
iv123 | 0:88b85febcb45 | 66 | //GATT_CHARS_DISCOVERY_COMPLETE, |
iv123 | 0:88b85febcb45 | 67 | //GATT_DISCOVERY_TERMINATED, |
iv123 | 0:88b85febcb45 | 68 | GATT_READ_CHAR, |
iv123 | 0:88b85febcb45 | 69 | GATT_WRITE_CHAR |
iv123 | 0:88b85febcb45 | 70 | }; |
iv123 | 0:88b85febcb45 | 71 | |
iv123 | 0:88b85febcb45 | 72 | /* Functions that must be implemented from GattClient */ |
iv123 | 0:88b85febcb45 | 73 | virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle, |
iv123 | 0:88b85febcb45 | 74 | ServiceDiscovery::ServiceCallback_t sc = NULL, |
iv123 | 0:88b85febcb45 | 75 | ServiceDiscovery::CharacteristicCallback_t cc = NULL, |
iv123 | 0:88b85febcb45 | 76 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN), |
iv123 | 0:88b85febcb45 | 77 | const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)); |
iv123 | 0:88b85febcb45 | 78 | |
iv123 | 0:88b85febcb45 | 79 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
iv123 | 0:88b85febcb45 | 80 | ServiceDiscovery::ServiceCallback_t callback, |
iv123 | 0:88b85febcb45 | 81 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)); |
iv123 | 0:88b85febcb45 | 82 | |
iv123 | 0:88b85febcb45 | 83 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
iv123 | 0:88b85febcb45 | 84 | ServiceDiscovery::ServiceCallback_t callback, |
iv123 | 0:88b85febcb45 | 85 | GattAttribute::Handle_t startHandle, |
iv123 | 0:88b85febcb45 | 86 | GattAttribute::Handle_t endHandle); |
iv123 | 0:88b85febcb45 | 87 | |
iv123 | 0:88b85febcb45 | 88 | virtual bool isServiceDiscoveryActive(void) const; |
iv123 | 0:88b85febcb45 | 89 | virtual void terminateServiceDiscovery(void); |
iv123 | 0:88b85febcb45 | 90 | virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) { |
iv123 | 0:88b85febcb45 | 91 | terminationCallback = callback; |
iv123 | 0:88b85febcb45 | 92 | } |
iv123 | 0:88b85febcb45 | 93 | virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const; |
iv123 | 0:88b85febcb45 | 94 | virtual ble_error_t write(GattClient::WriteOp_t cmd, |
iv123 | 0:88b85febcb45 | 95 | Gap::Handle_t connHandle, |
iv123 | 0:88b85febcb45 | 96 | GattAttribute::Handle_t attributeHandle, |
iv123 | 0:88b85febcb45 | 97 | size_t length, |
iv123 | 0:88b85febcb45 | 98 | const uint8_t *value) const; |
iv123 | 0:88b85febcb45 | 99 | virtual ble_error_t discoverCharacteristicDescriptors( |
iv123 | 0:88b85febcb45 | 100 | const DiscoveredCharacteristic& characteristic, |
iv123 | 0:88b85febcb45 | 101 | const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback, |
iv123 | 0:88b85febcb45 | 102 | const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback); |
iv123 | 0:88b85febcb45 | 103 | |
iv123 | 0:88b85febcb45 | 104 | virtual ble_error_t reset(void); |
iv123 | 0:88b85febcb45 | 105 | |
iv123 | 0:88b85febcb45 | 106 | void gattProcedureCompleteCB(Gap::Handle_t connectionHandle, uint8_t error_code); |
iv123 | 0:88b85febcb45 | 107 | |
iv123 | 0:88b85febcb45 | 108 | void primaryServicesCB(Gap::Handle_t connectionHandle, |
iv123 | 0:88b85febcb45 | 109 | uint8_t event_data_length, |
iv123 | 0:88b85febcb45 | 110 | uint8_t attribute_data_length, |
iv123 | 0:88b85febcb45 | 111 | uint8_t *attribute_data_list); |
iv123 | 0:88b85febcb45 | 112 | |
iv123 | 0:88b85febcb45 | 113 | void primaryServiceCB(Gap::Handle_t connectionHandle, |
iv123 | 0:88b85febcb45 | 114 | uint8_t event_data_length, |
iv123 | 0:88b85febcb45 | 115 | uint8_t *handles_info_list); |
iv123 | 0:88b85febcb45 | 116 | |
iv123 | 0:88b85febcb45 | 117 | ble_error_t findServiceChars(Gap::Handle_t connectionHandle); |
iv123 | 0:88b85febcb45 | 118 | |
iv123 | 0:88b85febcb45 | 119 | void serviceCharsCB(Gap::Handle_t connectionHandle, |
iv123 | 0:88b85febcb45 | 120 | uint8_t event_data_length, |
iv123 | 0:88b85febcb45 | 121 | uint8_t handle_value_pair_length, |
iv123 | 0:88b85febcb45 | 122 | uint8_t *handle_value_pair); |
iv123 | 0:88b85febcb45 | 123 | |
iv123 | 0:88b85febcb45 | 124 | void serviceCharByUUIDCB(Gap::Handle_t connectionHandle, |
iv123 | 0:88b85febcb45 | 125 | uint8_t event_data_length, |
iv123 | 0:88b85febcb45 | 126 | uint16_t attr_handle, |
iv123 | 0:88b85febcb45 | 127 | uint8_t *attr_value); |
iv123 | 0:88b85febcb45 | 128 | |
iv123 | 0:88b85febcb45 | 129 | void discAllCharacDescCB(Gap::Handle_t connHandle, |
iv123 | 0:88b85febcb45 | 130 | uint8_t event_data_length, |
iv123 | 0:88b85febcb45 | 131 | uint8_t format, |
iv123 | 0:88b85febcb45 | 132 | uint8_t *handle_uuid_pair); |
iv123 | 0:88b85febcb45 | 133 | |
iv123 | 0:88b85febcb45 | 134 | void charReadCB(Gap::Handle_t connHandle, |
iv123 | 0:88b85febcb45 | 135 | uint8_t event_data_length, |
iv123 | 0:88b85febcb45 | 136 | uint8_t* attribute_value); |
iv123 | 0:88b85febcb45 | 137 | |
iv123 | 0:88b85febcb45 | 138 | void charWritePrepareCB(Gap::Handle_t connHandle, |
iv123 | 0:88b85febcb45 | 139 | uint8_t event_data_length, |
iv123 | 0:88b85febcb45 | 140 | uint16_t attribute_handle, |
iv123 | 0:88b85febcb45 | 141 | uint16_t offset, |
iv123 | 0:88b85febcb45 | 142 | uint8_t *part_attr_value); |
iv123 | 0:88b85febcb45 | 143 | |
iv123 | 0:88b85febcb45 | 144 | void charWriteExecCB(Gap::Handle_t connHandle, |
iv123 | 0:88b85febcb45 | 145 | uint8_t event_data_length); |
iv123 | 0:88b85febcb45 | 146 | |
iv123 | 0:88b85febcb45 | 147 | protected: |
iv123 | 0:88b85febcb45 | 148 | |
iv123 | 0:88b85febcb45 | 149 | BlueNRGGattClient() { |
iv123 | 0:88b85febcb45 | 150 | _currentState = GATT_IDLE; |
iv123 | 0:88b85febcb45 | 151 | _matchingServiceUUID = BLE_UUID_UNKNOWN; |
iv123 | 0:88b85febcb45 | 152 | _matchingCharacteristicUUIDIn = BLE_UUID_UNKNOWN; |
iv123 | 0:88b85febcb45 | 153 | } |
iv123 | 0:88b85febcb45 | 154 | |
iv123 | 0:88b85febcb45 | 155 | ServiceDiscovery::ServiceCallback_t serviceDiscoveryCallback; |
iv123 | 0:88b85febcb45 | 156 | ServiceDiscovery::CharacteristicCallback_t characteristicDiscoveryCallback; |
iv123 | 0:88b85febcb45 | 157 | ServiceDiscovery::TerminationCallback_t terminationCallback; |
iv123 | 0:88b85febcb45 | 158 | CharacteristicDescriptorDiscovery::DiscoveryCallback_t charDescDiscoveryCallback; |
iv123 | 0:88b85febcb45 | 159 | CharacteristicDescriptorDiscovery::TerminationCallback_t charDescTerminationCallback; |
iv123 | 0:88b85febcb45 | 160 | |
iv123 | 0:88b85febcb45 | 161 | private: |
iv123 | 0:88b85febcb45 | 162 | |
iv123 | 0:88b85febcb45 | 163 | BlueNRGGattClient(BlueNRGGattClient const &); |
iv123 | 0:88b85febcb45 | 164 | void operator=(BlueNRGGattClient const &); |
iv123 | 0:88b85febcb45 | 165 | |
iv123 | 0:88b85febcb45 | 166 | Gap::Handle_t _connectionHandle; |
iv123 | 0:88b85febcb45 | 167 | DiscoveredService discoveredService[BLE_TOTAL_DISCOVERED_SERVICES]; |
iv123 | 0:88b85febcb45 | 168 | BlueNRGDiscoveredCharacteristic discoveredChar[BLE_TOTAL_DISCOVERED_CHARS]; |
iv123 | 0:88b85febcb45 | 169 | |
iv123 | 0:88b85febcb45 | 170 | GattReadCallbackParams readCBParams; |
iv123 | 0:88b85febcb45 | 171 | GattWriteCallbackParams writeCBParams; |
iv123 | 0:88b85febcb45 | 172 | |
iv123 | 0:88b85febcb45 | 173 | // The char for which the descriptor discovery has been launched |
iv123 | 0:88b85febcb45 | 174 | DiscoveredCharacteristic _characteristic; |
iv123 | 0:88b85febcb45 | 175 | |
iv123 | 0:88b85febcb45 | 176 | UUID _matchingServiceUUID; |
iv123 | 0:88b85febcb45 | 177 | UUID _matchingCharacteristicUUIDIn; |
iv123 | 0:88b85febcb45 | 178 | uint8_t _currentState; |
iv123 | 0:88b85febcb45 | 179 | uint8_t _numServices, _servIndex; |
iv123 | 0:88b85febcb45 | 180 | uint8_t _numChars; |
iv123 | 0:88b85febcb45 | 181 | uint8_t _numCharDesc; |
iv123 | 0:88b85febcb45 | 182 | |
iv123 | 0:88b85febcb45 | 183 | }; |
iv123 | 0:88b85febcb45 | 184 | |
iv123 | 0:88b85febcb45 | 185 | #endif /* __BLUENRG_GATT_CLIENT_H__ */ |