Fork of ble-x-nucleo-idb0xa1 with changes required by BleStarMbed

Dependents:   ble-star-mbed

Committer:
lorevee
Date:
Tue Feb 20 11:07:16 2018 +0000
Revision:
0:ac0b0725c6fa
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lorevee 0:ac0b0725c6fa 1 /* mbed Microcontroller Library
lorevee 0:ac0b0725c6fa 2 * Copyright (c) 2006-2013 ARM Limited
lorevee 0:ac0b0725c6fa 3 *
lorevee 0:ac0b0725c6fa 4 * Licensed under the Apache License, Version 2.0 (the "License");
lorevee 0:ac0b0725c6fa 5 * you may not use this file except in compliance with the License.
lorevee 0:ac0b0725c6fa 6 * You may obtain a copy of the License at
lorevee 0:ac0b0725c6fa 7 *
lorevee 0:ac0b0725c6fa 8 * http://www.apache.org/licenses/LICENSE-2.0
lorevee 0:ac0b0725c6fa 9 *
lorevee 0:ac0b0725c6fa 10 * Unless required by applicable law or agreed to in writing, software
lorevee 0:ac0b0725c6fa 11 * distributed under the License is distributed on an "AS IS" BASIS,
lorevee 0:ac0b0725c6fa 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
lorevee 0:ac0b0725c6fa 13 * See the License for the specific language governing permissions and
lorevee 0:ac0b0725c6fa 14 * limitations under the License.
lorevee 0:ac0b0725c6fa 15 */
lorevee 0:ac0b0725c6fa 16 /**
lorevee 0:ac0b0725c6fa 17 ******************************************************************************
lorevee 0:ac0b0725c6fa 18 * @file BlueNRGGattClient.cpp
lorevee 0:ac0b0725c6fa 19 * @author STMicroelectronics
lorevee 0:ac0b0725c6fa 20 * @brief Header file for BLE_API GattClient Class
lorevee 0:ac0b0725c6fa 21 ******************************************************************************
lorevee 0:ac0b0725c6fa 22 * @copy
lorevee 0:ac0b0725c6fa 23 *
lorevee 0:ac0b0725c6fa 24 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
lorevee 0:ac0b0725c6fa 25 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
lorevee 0:ac0b0725c6fa 26 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
lorevee 0:ac0b0725c6fa 27 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
lorevee 0:ac0b0725c6fa 28 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
lorevee 0:ac0b0725c6fa 29 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
lorevee 0:ac0b0725c6fa 30 *
lorevee 0:ac0b0725c6fa 31 * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
lorevee 0:ac0b0725c6fa 32 */
lorevee 0:ac0b0725c6fa 33
lorevee 0:ac0b0725c6fa 34 #ifndef __BLUENRG_GATT_CLIENT_H__
lorevee 0:ac0b0725c6fa 35 #define __BLUENRG_GATT_CLIENT_H__
lorevee 0:ac0b0725c6fa 36
lorevee 0:ac0b0725c6fa 37 #ifdef YOTTA_CFG_MBED_OS
lorevee 0:ac0b0725c6fa 38 #include "mbed-drivers/mbed.h"
lorevee 0:ac0b0725c6fa 39 #else
lorevee 0:ac0b0725c6fa 40 #include "mbed.h"
lorevee 0:ac0b0725c6fa 41 #endif
lorevee 0:ac0b0725c6fa 42 #include "ble/blecommon.h"
lorevee 0:ac0b0725c6fa 43 #include "btle.h"
lorevee 0:ac0b0725c6fa 44 #include "ble/GattClient.h"
lorevee 0:ac0b0725c6fa 45 #include "ble/DiscoveredService.h"
lorevee 0:ac0b0725c6fa 46 #include "ble/CharacteristicDescriptorDiscovery.h"
lorevee 0:ac0b0725c6fa 47 #include "BlueNRGDiscoveredCharacteristic.h"
lorevee 0:ac0b0725c6fa 48 #include "BlueNRGGattConnectionClient.h"
lorevee 0:ac0b0725c6fa 49
lorevee 0:ac0b0725c6fa 50 using namespace std;
lorevee 0:ac0b0725c6fa 51
lorevee 0:ac0b0725c6fa 52 #define MAX_ACTIVE_CONNECTIONS 7
lorevee 0:ac0b0725c6fa 53
lorevee 0:ac0b0725c6fa 54 class BlueNRGGattClient : public GattClient
lorevee 0:ac0b0725c6fa 55 {
lorevee 0:ac0b0725c6fa 56 public:
lorevee 0:ac0b0725c6fa 57 static BlueNRGGattClient &getInstance() {
lorevee 0:ac0b0725c6fa 58 static BlueNRGGattClient m_instance;
lorevee 0:ac0b0725c6fa 59 return m_instance;
lorevee 0:ac0b0725c6fa 60 }
lorevee 0:ac0b0725c6fa 61
lorevee 0:ac0b0725c6fa 62 ble_error_t createGattConnectionClient(Gap::Handle_t connectionHandle);
lorevee 0:ac0b0725c6fa 63 ble_error_t removeGattConnectionClient(Gap::Handle_t connectionHandle, uint8_t reason);
lorevee 0:ac0b0725c6fa 64
lorevee 0:ac0b0725c6fa 65 /* Functions that must be implemented from GattClient */
lorevee 0:ac0b0725c6fa 66 virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle,
lorevee 0:ac0b0725c6fa 67 ServiceDiscovery::ServiceCallback_t sc = NULL,
lorevee 0:ac0b0725c6fa 68 ServiceDiscovery::CharacteristicCallback_t cc = NULL,
lorevee 0:ac0b0725c6fa 69 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
lorevee 0:ac0b0725c6fa 70 const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN));
lorevee 0:ac0b0725c6fa 71
lorevee 0:ac0b0725c6fa 72 virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle,
lorevee 0:ac0b0725c6fa 73 ServiceDiscovery::ServiceCallback_t callback,
lorevee 0:ac0b0725c6fa 74 const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN));
lorevee 0:ac0b0725c6fa 75
lorevee 0:ac0b0725c6fa 76 virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle,
lorevee 0:ac0b0725c6fa 77 ServiceDiscovery::ServiceCallback_t callback,
lorevee 0:ac0b0725c6fa 78 GattAttribute::Handle_t startHandle,
lorevee 0:ac0b0725c6fa 79 GattAttribute::Handle_t endHandle);
lorevee 0:ac0b0725c6fa 80
lorevee 0:ac0b0725c6fa 81 virtual bool isServiceDiscoveryActive(void) const;
lorevee 0:ac0b0725c6fa 82 virtual void terminateServiceDiscovery(void);
lorevee 0:ac0b0725c6fa 83 virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback);
lorevee 0:ac0b0725c6fa 84 virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const;
lorevee 0:ac0b0725c6fa 85 virtual ble_error_t write(GattClient::WriteOp_t cmd,
lorevee 0:ac0b0725c6fa 86 Gap::Handle_t connHandle,
lorevee 0:ac0b0725c6fa 87 GattAttribute::Handle_t attributeHandle,
lorevee 0:ac0b0725c6fa 88 size_t length,
lorevee 0:ac0b0725c6fa 89 const uint8_t *value) const;
lorevee 0:ac0b0725c6fa 90 virtual ble_error_t discoverCharacteristicDescriptors(
lorevee 0:ac0b0725c6fa 91 const DiscoveredCharacteristic& characteristic,
lorevee 0:ac0b0725c6fa 92 const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
lorevee 0:ac0b0725c6fa 93 const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback);
lorevee 0:ac0b0725c6fa 94
lorevee 0:ac0b0725c6fa 95 virtual ble_error_t reset(void);
lorevee 0:ac0b0725c6fa 96
lorevee 0:ac0b0725c6fa 97 void gattProcedureCompleteCB(Gap::Handle_t connectionHandle, uint8_t error_code);
lorevee 0:ac0b0725c6fa 98
lorevee 0:ac0b0725c6fa 99 void primaryServicesCB(Gap::Handle_t connectionHandle,
lorevee 0:ac0b0725c6fa 100 uint8_t event_data_length,
lorevee 0:ac0b0725c6fa 101 uint8_t attribute_data_length,
lorevee 0:ac0b0725c6fa 102 uint8_t *attribute_data_list);
lorevee 0:ac0b0725c6fa 103
lorevee 0:ac0b0725c6fa 104 void primaryServiceCB(Gap::Handle_t connectionHandle,
lorevee 0:ac0b0725c6fa 105 uint8_t event_data_length,
lorevee 0:ac0b0725c6fa 106 uint8_t *handles_info_list);
lorevee 0:ac0b0725c6fa 107
lorevee 0:ac0b0725c6fa 108 ble_error_t findServiceChars(Gap::Handle_t connectionHandle);
lorevee 0:ac0b0725c6fa 109
lorevee 0:ac0b0725c6fa 110 void serviceCharsCB(Gap::Handle_t connectionHandle,
lorevee 0:ac0b0725c6fa 111 uint8_t event_data_length,
lorevee 0:ac0b0725c6fa 112 uint8_t handle_value_pair_length,
lorevee 0:ac0b0725c6fa 113 uint8_t *handle_value_pair);
lorevee 0:ac0b0725c6fa 114
lorevee 0:ac0b0725c6fa 115 void serviceCharByUUIDCB(Gap::Handle_t connectionHandle,
lorevee 0:ac0b0725c6fa 116 uint8_t event_data_length,
lorevee 0:ac0b0725c6fa 117 uint16_t attr_handle,
lorevee 0:ac0b0725c6fa 118 uint8_t *attr_value);
lorevee 0:ac0b0725c6fa 119
lorevee 0:ac0b0725c6fa 120 void discAllCharacDescCB(Gap::Handle_t connHandle,
lorevee 0:ac0b0725c6fa 121 uint8_t event_data_length,
lorevee 0:ac0b0725c6fa 122 uint8_t format,
lorevee 0:ac0b0725c6fa 123 uint8_t *handle_uuid_pair);
lorevee 0:ac0b0725c6fa 124
lorevee 0:ac0b0725c6fa 125 void charReadCB(Gap::Handle_t connHandle,
lorevee 0:ac0b0725c6fa 126 uint8_t event_data_length,
lorevee 0:ac0b0725c6fa 127 uint8_t* attribute_value);
lorevee 0:ac0b0725c6fa 128
lorevee 0:ac0b0725c6fa 129 void charWritePrepareCB(Gap::Handle_t connHandle,
lorevee 0:ac0b0725c6fa 130 uint8_t event_data_length,
lorevee 0:ac0b0725c6fa 131 uint16_t attribute_handle,
lorevee 0:ac0b0725c6fa 132 uint16_t offset,
lorevee 0:ac0b0725c6fa 133 uint8_t *part_attr_value);
lorevee 0:ac0b0725c6fa 134
lorevee 0:ac0b0725c6fa 135 void charWriteExecCB(Gap::Handle_t connHandle,
lorevee 0:ac0b0725c6fa 136 uint8_t event_data_length);
lorevee 0:ac0b0725c6fa 137
lorevee 0:ac0b0725c6fa 138
lorevee 0:ac0b0725c6fa 139 protected:
lorevee 0:ac0b0725c6fa 140
lorevee 0:ac0b0725c6fa 141 BlueNRGGattClient(): _connectionPool() {};
lorevee 0:ac0b0725c6fa 142
lorevee 0:ac0b0725c6fa 143 ServiceDiscovery::TerminationCallback_t terminationCallback;
lorevee 0:ac0b0725c6fa 144
lorevee 0:ac0b0725c6fa 145 private:
lorevee 0:ac0b0725c6fa 146
lorevee 0:ac0b0725c6fa 147 BlueNRGGattClient(BlueNRGGattClient const &);
lorevee 0:ac0b0725c6fa 148 void operator=(BlueNRGGattClient const &);
lorevee 0:ac0b0725c6fa 149
lorevee 0:ac0b0725c6fa 150 BlueNRGGattConnectionClient *_connectionPool[MAX_ACTIVE_CONNECTIONS];
lorevee 0:ac0b0725c6fa 151 uint8_t _numConnections;
lorevee 0:ac0b0725c6fa 152
lorevee 0:ac0b0725c6fa 153 BlueNRGGattConnectionClient * getGattConnectionClient(Gap::Handle_t connectionHandle);
lorevee 0:ac0b0725c6fa 154
lorevee 0:ac0b0725c6fa 155 };
lorevee 0:ac0b0725c6fa 156
lorevee 0:ac0b0725c6fa 157 #endif /* __BLUENRG_GATT_CLIENT_H__ */