bluetooth control motor
Dependents: BLE_LED_IDB0XA1_demo MOTOR_BLE_V2 Motor_Ble_v1 Motor_Ble_v10223 ... more
Fork of X_NUCLEO_IDB0XA1 by
x-nucleo-idb0xa1/BlueNRGGattClient.h@132:51056160fa4a, 2015-10-07 (annotated)
- Committer:
- Wolfgang Betz
- Date:
- Wed Oct 07 08:39:04 2015 +0200
- Revision:
- 132:51056160fa4a
- Child:
- 144:bdf5e8432131
Andrea's version as of mail from 10/06/2015 05:56 PM
From: Andrea PALMIERI <andrea.palmieri@st.com>
To: Wolfgang BETZ <wolfgang.betz@st.com>, Rohit Grover <rohit.grover@arm.com>,
Antonio VILEI <antonio.vilei@st.com>, Mihail Stoyanov
<Mihail.Stoyanov@arm.com>
CC: Nicola CAPOVILLA <nicola.capovilla@st.com>, Silvio Lucio OLIVA
<silvio.oliva@st.com>, "jonathan.austin@arm.com" <jonathan.austin@arm.com>
Content-Class: urn:content-classes:message
Date: Tue, 6 Oct 2015 17:56:34 +0200
Subject: RE: Arduino Compatibility of X-NUCLEO-IDB04A1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wolfgang Betz |
132:51056160fa4a | 1 | /* mbed Microcontroller Library |
Wolfgang Betz |
132:51056160fa4a | 2 | * Copyright (c) 2006-2013 ARM Limited |
Wolfgang Betz |
132:51056160fa4a | 3 | * |
Wolfgang Betz |
132:51056160fa4a | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Wolfgang Betz |
132:51056160fa4a | 5 | * you may not use this file except in compliance with the License. |
Wolfgang Betz |
132:51056160fa4a | 6 | * You may obtain a copy of the License at |
Wolfgang Betz |
132:51056160fa4a | 7 | * |
Wolfgang Betz |
132:51056160fa4a | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Wolfgang Betz |
132:51056160fa4a | 9 | * |
Wolfgang Betz |
132:51056160fa4a | 10 | * Unless required by applicable law or agreed to in writing, software |
Wolfgang Betz |
132:51056160fa4a | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Wolfgang Betz |
132:51056160fa4a | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Wolfgang Betz |
132:51056160fa4a | 13 | * See the License for the specific language governing permissions and |
Wolfgang Betz |
132:51056160fa4a | 14 | * limitations under the License. |
Wolfgang Betz |
132:51056160fa4a | 15 | */ |
Wolfgang Betz |
132:51056160fa4a | 16 | /** |
Wolfgang Betz |
132:51056160fa4a | 17 | ****************************************************************************** |
Wolfgang Betz |
132:51056160fa4a | 18 | * @file BlueNRGGattClient.cpp |
Wolfgang Betz |
132:51056160fa4a | 19 | * @author STMicroelectronics |
Wolfgang Betz |
132:51056160fa4a | 20 | * @brief Header file for BLE_API GattClient Class |
Wolfgang Betz |
132:51056160fa4a | 21 | ****************************************************************************** |
Wolfgang Betz |
132:51056160fa4a | 22 | * @copy |
Wolfgang Betz |
132:51056160fa4a | 23 | * |
Wolfgang Betz |
132:51056160fa4a | 24 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
Wolfgang Betz |
132:51056160fa4a | 25 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE |
Wolfgang Betz |
132:51056160fa4a | 26 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY |
Wolfgang Betz |
132:51056160fa4a | 27 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING |
Wolfgang Betz |
132:51056160fa4a | 28 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE |
Wolfgang Betz |
132:51056160fa4a | 29 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
Wolfgang Betz |
132:51056160fa4a | 30 | * |
Wolfgang Betz |
132:51056160fa4a | 31 | * <h2><center>© COPYRIGHT 2015 STMicroelectronics</center></h2> |
Wolfgang Betz |
132:51056160fa4a | 32 | */ |
Wolfgang Betz |
132:51056160fa4a | 33 | |
Wolfgang Betz |
132:51056160fa4a | 34 | #ifndef __BLUENRG_GATT_CLIENT_H__ |
Wolfgang Betz |
132:51056160fa4a | 35 | #define __BLUENRG_GATT_CLIENT_H__ |
Wolfgang Betz |
132:51056160fa4a | 36 | |
Wolfgang Betz |
132:51056160fa4a | 37 | #include "mbed.h" |
Wolfgang Betz |
132:51056160fa4a | 38 | #include "ble/blecommon.h" |
Wolfgang Betz |
132:51056160fa4a | 39 | #include "btle.h" |
Wolfgang Betz |
132:51056160fa4a | 40 | #include "ble/GattClient.h" |
Wolfgang Betz |
132:51056160fa4a | 41 | #include "ble/DiscoveredService.h" |
Wolfgang Betz |
132:51056160fa4a | 42 | #include "BlueNRGDiscoveredCharacteristic.h" |
Wolfgang Betz |
132:51056160fa4a | 43 | |
Wolfgang Betz |
132:51056160fa4a | 44 | using namespace std; |
Wolfgang Betz |
132:51056160fa4a | 45 | |
Wolfgang Betz |
132:51056160fa4a | 46 | #define BLE_TOTAL_DISCOVERED_SERVICES 10 |
Wolfgang Betz |
132:51056160fa4a | 47 | #define BLE_TOTAL_DISCOVERED_CHARS 10 |
Wolfgang Betz |
132:51056160fa4a | 48 | |
Wolfgang Betz |
132:51056160fa4a | 49 | class BlueNRGGattClient : public GattClient |
Wolfgang Betz |
132:51056160fa4a | 50 | { |
Wolfgang Betz |
132:51056160fa4a | 51 | public: |
Wolfgang Betz |
132:51056160fa4a | 52 | static BlueNRGGattClient &getInstance() { |
Wolfgang Betz |
132:51056160fa4a | 53 | static BlueNRGGattClient m_instance; |
Wolfgang Betz |
132:51056160fa4a | 54 | return m_instance; |
Wolfgang Betz |
132:51056160fa4a | 55 | } |
Wolfgang Betz |
132:51056160fa4a | 56 | |
Wolfgang Betz |
132:51056160fa4a | 57 | enum { |
Wolfgang Betz |
132:51056160fa4a | 58 | GATT_IDLE, |
Wolfgang Betz |
132:51056160fa4a | 59 | GATT_SERVICE_DISCOVERY, |
Wolfgang Betz |
132:51056160fa4a | 60 | GATT_CHARS_DISCOVERY_COMPLETE, |
Wolfgang Betz |
132:51056160fa4a | 61 | GATT_DISCOVERY_TERMINATED, |
Wolfgang Betz |
132:51056160fa4a | 62 | GATT_READ_CHAR, |
Wolfgang Betz |
132:51056160fa4a | 63 | GATT_WRITE_CHAR |
Wolfgang Betz |
132:51056160fa4a | 64 | }; |
Wolfgang Betz |
132:51056160fa4a | 65 | |
Wolfgang Betz |
132:51056160fa4a | 66 | /* Functions that must be implemented from GattClient */ |
Wolfgang Betz |
132:51056160fa4a | 67 | virtual ble_error_t launchServiceDiscovery(Gap::Handle_t connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 68 | ServiceDiscovery::ServiceCallback_t sc = NULL, |
Wolfgang Betz |
132:51056160fa4a | 69 | ServiceDiscovery::CharacteristicCallback_t cc = NULL, |
Wolfgang Betz |
132:51056160fa4a | 70 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN), |
Wolfgang Betz |
132:51056160fa4a | 71 | const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)); |
Wolfgang Betz |
132:51056160fa4a | 72 | |
Wolfgang Betz |
132:51056160fa4a | 73 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 74 | ServiceDiscovery::ServiceCallback_t callback, |
Wolfgang Betz |
132:51056160fa4a | 75 | const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)); |
Wolfgang Betz |
132:51056160fa4a | 76 | |
Wolfgang Betz |
132:51056160fa4a | 77 | virtual ble_error_t discoverServices(Gap::Handle_t connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 78 | ServiceDiscovery::ServiceCallback_t callback, |
Wolfgang Betz |
132:51056160fa4a | 79 | GattAttribute::Handle_t startHandle, |
Wolfgang Betz |
132:51056160fa4a | 80 | GattAttribute::Handle_t endHandle); |
Wolfgang Betz |
132:51056160fa4a | 81 | |
Wolfgang Betz |
132:51056160fa4a | 82 | virtual bool isServiceDiscoveryActive(void) const; |
Wolfgang Betz |
132:51056160fa4a | 83 | virtual void terminateServiceDiscovery(void); |
Wolfgang Betz |
132:51056160fa4a | 84 | virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) { |
Wolfgang Betz |
132:51056160fa4a | 85 | terminationCallback = callback; |
Wolfgang Betz |
132:51056160fa4a | 86 | } |
Wolfgang Betz |
132:51056160fa4a | 87 | virtual ble_error_t read(Gap::Handle_t connHandle, GattAttribute::Handle_t attributeHandle, uint16_t offset) const; |
Wolfgang Betz |
132:51056160fa4a | 88 | virtual ble_error_t write(GattClient::WriteOp_t cmd, |
Wolfgang Betz |
132:51056160fa4a | 89 | Gap::Handle_t connHandle, |
Wolfgang Betz |
132:51056160fa4a | 90 | GattAttribute::Handle_t attributeHandle, |
Wolfgang Betz |
132:51056160fa4a | 91 | size_t length, |
Wolfgang Betz |
132:51056160fa4a | 92 | const uint8_t *value) const; |
Wolfgang Betz |
132:51056160fa4a | 93 | |
Wolfgang Betz |
132:51056160fa4a | 94 | void gattProcedureCompleteCB(Gap::Handle_t connectionHandle, uint8_t error_code); |
Wolfgang Betz |
132:51056160fa4a | 95 | |
Wolfgang Betz |
132:51056160fa4a | 96 | void primaryServicesCB(Gap::Handle_t connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 97 | uint8_t event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 98 | uint8_t attribute_data_length, |
Wolfgang Betz |
132:51056160fa4a | 99 | uint8_t *attribute_data_list); |
Wolfgang Betz |
132:51056160fa4a | 100 | |
Wolfgang Betz |
132:51056160fa4a | 101 | void primaryServiceCB(Gap::Handle_t connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 102 | uint8_t event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 103 | uint8_t *handles_info_list); |
Wolfgang Betz |
132:51056160fa4a | 104 | |
Wolfgang Betz |
132:51056160fa4a | 105 | ble_error_t findServiceChars(Gap::Handle_t connectionHandle); |
Wolfgang Betz |
132:51056160fa4a | 106 | |
Wolfgang Betz |
132:51056160fa4a | 107 | void serviceCharsCB(Gap::Handle_t connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 108 | uint8_t event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 109 | uint8_t handle_value_pair_length, |
Wolfgang Betz |
132:51056160fa4a | 110 | uint8_t *handle_value_pair); |
Wolfgang Betz |
132:51056160fa4a | 111 | |
Wolfgang Betz |
132:51056160fa4a | 112 | void serviceCharByUUIDCB(Gap::Handle_t connectionHandle, |
Wolfgang Betz |
132:51056160fa4a | 113 | uint8_t event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 114 | uint16_t attr_handle, |
Wolfgang Betz |
132:51056160fa4a | 115 | uint8_t *attr_value); |
Wolfgang Betz |
132:51056160fa4a | 116 | |
Wolfgang Betz |
132:51056160fa4a | 117 | void charReadCB(Gap::Handle_t connHandle, |
Wolfgang Betz |
132:51056160fa4a | 118 | uint8_t event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 119 | uint8_t* attribute_value); |
Wolfgang Betz |
132:51056160fa4a | 120 | |
Wolfgang Betz |
132:51056160fa4a | 121 | void charWritePrepareCB(Gap::Handle_t connHandle, |
Wolfgang Betz |
132:51056160fa4a | 122 | uint8_t event_data_length, |
Wolfgang Betz |
132:51056160fa4a | 123 | uint16_t attribute_handle, |
Wolfgang Betz |
132:51056160fa4a | 124 | uint16_t offset, |
Wolfgang Betz |
132:51056160fa4a | 125 | uint8_t *part_attr_value); |
Wolfgang Betz |
132:51056160fa4a | 126 | |
Wolfgang Betz |
132:51056160fa4a | 127 | void charWriteExecCB(Gap::Handle_t connHandle, |
Wolfgang Betz |
132:51056160fa4a | 128 | uint8_t event_data_length); |
Wolfgang Betz |
132:51056160fa4a | 129 | |
Wolfgang Betz |
132:51056160fa4a | 130 | protected: |
Wolfgang Betz |
132:51056160fa4a | 131 | |
Wolfgang Betz |
132:51056160fa4a | 132 | BlueNRGGattClient() { |
Wolfgang Betz |
132:51056160fa4a | 133 | _currentState = GATT_IDLE; |
Wolfgang Betz |
132:51056160fa4a | 134 | _matchingServiceUUID = BLE_UUID_UNKNOWN; |
Wolfgang Betz |
132:51056160fa4a | 135 | _matchingCharacteristicUUIDIn = BLE_UUID_UNKNOWN; |
Wolfgang Betz |
132:51056160fa4a | 136 | } |
Wolfgang Betz |
132:51056160fa4a | 137 | |
Wolfgang Betz |
132:51056160fa4a | 138 | ServiceDiscovery::ServiceCallback_t serviceDiscoveryCallback; |
Wolfgang Betz |
132:51056160fa4a | 139 | ServiceDiscovery::CharacteristicCallback_t characteristicDiscoveryCallback; |
Wolfgang Betz |
132:51056160fa4a | 140 | ServiceDiscovery::TerminationCallback_t terminationCallback; |
Wolfgang Betz |
132:51056160fa4a | 141 | |
Wolfgang Betz |
132:51056160fa4a | 142 | private: |
Wolfgang Betz |
132:51056160fa4a | 143 | |
Wolfgang Betz |
132:51056160fa4a | 144 | BlueNRGGattClient(BlueNRGGattClient const &); |
Wolfgang Betz |
132:51056160fa4a | 145 | void operator=(BlueNRGGattClient const &); |
Wolfgang Betz |
132:51056160fa4a | 146 | |
Wolfgang Betz |
132:51056160fa4a | 147 | Gap::Handle_t _connectionHandle; |
Wolfgang Betz |
132:51056160fa4a | 148 | DiscoveredService discoveredService[BLE_TOTAL_DISCOVERED_SERVICES]; |
Wolfgang Betz |
132:51056160fa4a | 149 | BlueNRGDiscoveredCharacteristic discoveredChar[BLE_TOTAL_DISCOVERED_CHARS]; |
Wolfgang Betz |
132:51056160fa4a | 150 | |
Wolfgang Betz |
132:51056160fa4a | 151 | GattReadCallbackParams readCBParams; |
Wolfgang Betz |
132:51056160fa4a | 152 | GattWriteCallbackParams writeCBParams; |
Wolfgang Betz |
132:51056160fa4a | 153 | |
Wolfgang Betz |
132:51056160fa4a | 154 | UUID _matchingServiceUUID; |
Wolfgang Betz |
132:51056160fa4a | 155 | UUID _matchingCharacteristicUUIDIn; |
Wolfgang Betz |
132:51056160fa4a | 156 | uint8_t _currentState; |
Wolfgang Betz |
132:51056160fa4a | 157 | uint8_t _numServices, _servIndex; |
Wolfgang Betz |
132:51056160fa4a | 158 | uint8_t _numChars; |
Wolfgang Betz |
132:51056160fa4a | 159 | |
Wolfgang Betz |
132:51056160fa4a | 160 | }; |
Wolfgang Betz |
132:51056160fa4a | 161 | |
Wolfgang Betz |
132:51056160fa4a | 162 | #endif /* __BLUENRG_GATT_CLIENT_H__ */ |