bluetooth control motor

Dependents:   BLE_LED_IDB0XA1_demo MOTOR_BLE_V2 Motor_Ble_v1 Motor_Ble_v10223 ... more

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
Vincent Coubard
Date:
Thu Sep 15 10:51:43 2016 +0100
Branch:
117ed4c55629877d7cb3d79c4bcb24e7da5bcab0
Revision:
278:a5209d8cfd61
Parent:
253:9665a6f8bbdb
Sync with 117ed4c55629877d7cb3d79c4bcb24e7da5bcab0

2016-07-26 10:10:57+01:00: Vincent Coubard
Fix include path for mbed classic.

Who changed what in which revision?

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