BLE_API wrapper library for STMicroelectronics' BlueNRG Bluetooth Low Energy expansion board shield
Fork of X_NUCLEO_IDB0XA1 by
x-nucleo-idb0xa1/BlueNRGGap.h@183:2e517d3ddd71, 2015-11-20 (annotated)
- Committer:
- Andrea Palmieri
- Date:
- Fri Nov 20 12:14:47 2015 +0100
- Revision:
- 183:2e517d3ddd71
- Parent:
- 165:3576598c0889
- Child:
- 185:30fa96fa8ec4
Leave default device name "unknown" and other minor fixes
Signed-off-by: Andrea Palmieri <andrea.palmieri@st.com>
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wolfgang Betz |
130:770ce14d3d15 | 1 | /* mbed Microcontroller Library |
Wolfgang Betz |
130:770ce14d3d15 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Wolfgang Betz |
130:770ce14d3d15 | 3 | * |
Wolfgang Betz |
130:770ce14d3d15 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Wolfgang Betz |
130:770ce14d3d15 | 5 | * you may not use this file except in compliance with the License. |
Wolfgang Betz |
130:770ce14d3d15 | 6 | * You may obtain a copy of the License at |
Wolfgang Betz |
130:770ce14d3d15 | 7 | * |
Wolfgang Betz |
130:770ce14d3d15 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Wolfgang Betz |
130:770ce14d3d15 | 9 | * |
Wolfgang Betz |
130:770ce14d3d15 | 10 | * Unless required by applicable law or agreed to in writing, software |
Wolfgang Betz |
130:770ce14d3d15 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Wolfgang Betz |
130:770ce14d3d15 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Wolfgang Betz |
130:770ce14d3d15 | 13 | * See the License for the specific language governing permissions and |
Wolfgang Betz |
130:770ce14d3d15 | 14 | * limitations under the License. |
Wolfgang Betz |
130:770ce14d3d15 | 15 | */ |
Wolfgang Betz |
130:770ce14d3d15 | 16 | |
Wolfgang Betz |
130:770ce14d3d15 | 17 | /** |
Wolfgang Betz |
130:770ce14d3d15 | 18 | ****************************************************************************** |
Wolfgang Betz |
130:770ce14d3d15 | 19 | * @file BlueNRGGap.h |
Wolfgang Betz |
130:770ce14d3d15 | 20 | * @author STMicroelectronics |
Wolfgang Betz |
130:770ce14d3d15 | 21 | * @brief Header file for BlueNRG BLE_API Gap Class |
Wolfgang Betz |
130:770ce14d3d15 | 22 | ****************************************************************************** |
Wolfgang Betz |
130:770ce14d3d15 | 23 | * @copy |
Wolfgang Betz |
130:770ce14d3d15 | 24 | * |
Wolfgang Betz |
130:770ce14d3d15 | 25 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
Wolfgang Betz |
130:770ce14d3d15 | 26 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE |
Wolfgang Betz |
130:770ce14d3d15 | 27 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY |
Wolfgang Betz |
130:770ce14d3d15 | 28 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING |
Wolfgang Betz |
130:770ce14d3d15 | 29 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE |
Wolfgang Betz |
130:770ce14d3d15 | 30 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
Wolfgang Betz |
130:770ce14d3d15 | 31 | * |
Wolfgang Betz |
130:770ce14d3d15 | 32 | * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> |
Wolfgang Betz |
130:770ce14d3d15 | 33 | */ |
Wolfgang Betz |
130:770ce14d3d15 | 34 | |
Wolfgang Betz |
130:770ce14d3d15 | 35 | #ifndef __BLUENRG_GAP_H__ |
Wolfgang Betz |
130:770ce14d3d15 | 36 | #define __BLUENRG_GAP_H__ |
Wolfgang Betz |
130:770ce14d3d15 | 37 | |
Wolfgang Betz |
144:bdf5e8432131 | 38 | #include "mbed-drivers/mbed.h" |
Wolfgang Betz |
131:e09947216ccb | 39 | #include "ble/blecommon.h" |
Wolfgang Betz |
130:770ce14d3d15 | 40 | #include "btle.h" |
Wolfgang Betz |
131:e09947216ccb | 41 | #include "ble/GapAdvertisingParams.h" |
Wolfgang Betz |
131:e09947216ccb | 42 | #include "ble/GapAdvertisingData.h" |
Wolfgang Betz |
132:51056160fa4a | 43 | #include "ble/Gap.h" |
Wolfgang Betz |
130:770ce14d3d15 | 44 | |
Wolfgang Betz |
130:770ce14d3d15 | 45 | #define BLE_CONN_HANDLE_INVALID 0x0 |
Wolfgang Betz |
130:770ce14d3d15 | 46 | #define BDADDR_SIZE 6 |
Wolfgang Betz |
130:770ce14d3d15 | 47 | |
Wolfgang Betz |
130:770ce14d3d15 | 48 | #define BLUENRG_GAP_ADV_INTERVAL_MIN (0) |
Wolfgang Betz |
130:770ce14d3d15 | 49 | #define BLUENRG_GAP_ADV_INTERVAL_MAX (0) |
Wolfgang Betz |
130:770ce14d3d15 | 50 | #define BLE_GAP_ADV_NONCON_INTERVAL_MIN (0) |
Wolfgang Betz |
130:770ce14d3d15 | 51 | |
Wolfgang Betz |
132:51056160fa4a | 52 | // Scanning and Connection Params used by Central for creating connection |
Wolfgang Betz |
132:51056160fa4a | 53 | #define LIMITED_DISCOVERY_PROCEDURE 0x01 |
Wolfgang Betz |
132:51056160fa4a | 54 | #define GENERAL_DISCOVERY_PROCEDURE 0x02 |
Wolfgang Betz |
132:51056160fa4a | 55 | |
Wolfgang Betz |
132:51056160fa4a | 56 | #define SCAN_P (0x4000) |
Wolfgang Betz |
132:51056160fa4a | 57 | #define SCAN_L (0x4000) |
Wolfgang Betz |
132:51056160fa4a | 58 | #define SUPERV_TIMEOUT (600) |
Wolfgang Betz |
132:51056160fa4a | 59 | #define CONN_P(x) ((int)((x)/1.25f)) |
Wolfgang Betz |
132:51056160fa4a | 60 | #define CONN_L(x) ((int)((x)/0.625f)) |
Wolfgang Betz |
132:51056160fa4a | 61 | #define CONN_P1 (CONN_P(50))//(CONN_P(1000)) |
Wolfgang Betz |
132:51056160fa4a | 62 | #define CONN_P2 (CONN_P(50))//(CONN_P(1000)) |
Wolfgang Betz |
132:51056160fa4a | 63 | #define CONN_L1 (CONN_L(5)) |
Wolfgang Betz |
132:51056160fa4a | 64 | #define CONN_L2 (CONN_L(5)) |
Wolfgang Betz |
130:770ce14d3d15 | 65 | #define UUID_BUFFER_SIZE 13 //6*2(16-bit UUIDs)+1 |
Wolfgang Betz |
130:770ce14d3d15 | 66 | #define ADV_DATA_MAX_SIZE 31 |
Wolfgang Betz |
130:770ce14d3d15 | 67 | |
Wolfgang Betz |
130:770ce14d3d15 | 68 | /**************************************************************************/ |
Wolfgang Betz |
130:770ce14d3d15 | 69 | /*! |
Wolfgang Betz |
130:770ce14d3d15 | 70 | \brief |
Wolfgang Betz |
130:770ce14d3d15 | 71 | |
Wolfgang Betz |
130:770ce14d3d15 | 72 | */ |
Wolfgang Betz |
130:770ce14d3d15 | 73 | /**************************************************************************/ |
Wolfgang Betz |
130:770ce14d3d15 | 74 | class BlueNRGGap : public Gap |
Wolfgang Betz |
130:770ce14d3d15 | 75 | { |
Wolfgang Betz |
130:770ce14d3d15 | 76 | public: |
Wolfgang Betz |
130:770ce14d3d15 | 77 | static BlueNRGGap &getInstance() { |
Wolfgang Betz |
130:770ce14d3d15 | 78 | static BlueNRGGap m_instance; |
Wolfgang Betz |
130:770ce14d3d15 | 79 | return m_instance; |
Wolfgang Betz |
130:770ce14d3d15 | 80 | } |
Wolfgang Betz |
130:770ce14d3d15 | 81 | |
Wolfgang Betz |
130:770ce14d3d15 | 82 | // <<<ANDREA>>> |
Wolfgang Betz |
132:51056160fa4a | 83 | /* |
Wolfgang Betz |
130:770ce14d3d15 | 84 | enum AdvType_t { |
Wolfgang Betz |
130:770ce14d3d15 | 85 | ADV_IND = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED,//Gap::ADV_IND, |
Wolfgang Betz |
130:770ce14d3d15 | 86 | ADV_DIRECT_IND = GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED,//Gap::ADV_DIRECT_IND, |
Wolfgang Betz |
130:770ce14d3d15 | 87 | ADV_SCAN_IND = GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED,//Gap::ADV_SCAN_IND, |
Wolfgang Betz |
130:770ce14d3d15 | 88 | ADV_NONCONN_IND = GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED//Gap::ADV_NONCONN_IND |
Wolfgang Betz |
130:770ce14d3d15 | 89 | }; |
Wolfgang Betz |
132:51056160fa4a | 90 | */ |
Wolfgang Betz |
132:51056160fa4a | 91 | enum Reason_t { |
Wolfgang Betz |
132:51056160fa4a | 92 | DEVICE_FOUND, |
Wolfgang Betz |
132:51056160fa4a | 93 | DISCOVERY_COMPLETE |
Wolfgang Betz |
132:51056160fa4a | 94 | }; |
Wolfgang Betz |
130:770ce14d3d15 | 95 | |
Wolfgang Betz |
130:770ce14d3d15 | 96 | /* Functions that must be implemented from Gap */ |
Wolfgang Betz |
130:770ce14d3d15 | 97 | virtual ble_error_t setAddress(addr_type_t type, const Address_t address); |
Wolfgang Betz |
130:770ce14d3d15 | 98 | virtual ble_error_t getAddress(addr_type_t *typeP, Address_t address); |
Wolfgang Betz |
130:770ce14d3d15 | 99 | virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &); |
Wolfgang Betz |
130:770ce14d3d15 | 100 | virtual ble_error_t startAdvertising(const GapAdvertisingParams &); |
Wolfgang Betz |
130:770ce14d3d15 | 101 | virtual ble_error_t stopAdvertising(void); |
Wolfgang Betz |
130:770ce14d3d15 | 102 | virtual ble_error_t stopScan(); |
Wolfgang Betz |
130:770ce14d3d15 | 103 | virtual uint16_t getMinAdvertisingInterval(void) const; |
Wolfgang Betz |
130:770ce14d3d15 | 104 | virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const; |
Wolfgang Betz |
130:770ce14d3d15 | 105 | virtual uint16_t getMaxAdvertisingInterval(void) const; |
Wolfgang Betz |
130:770ce14d3d15 | 106 | virtual ble_error_t disconnect(DisconnectionReason_t reason); |
Wolfgang Betz |
130:770ce14d3d15 | 107 | virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason); |
Wolfgang Betz |
130:770ce14d3d15 | 108 | virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params); |
Wolfgang Betz |
130:770ce14d3d15 | 109 | virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params); |
Wolfgang Betz |
130:770ce14d3d15 | 110 | virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params); |
Wolfgang Betz |
130:770ce14d3d15 | 111 | |
Wolfgang Betz |
130:770ce14d3d15 | 112 | virtual ble_error_t setDeviceName(const uint8_t *deviceName); |
Wolfgang Betz |
130:770ce14d3d15 | 113 | virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP); |
Wolfgang Betz |
130:770ce14d3d15 | 114 | virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance); |
Wolfgang Betz |
130:770ce14d3d15 | 115 | virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP); |
Wolfgang Betz |
130:770ce14d3d15 | 116 | |
Wolfgang Betz |
130:770ce14d3d15 | 117 | virtual ble_error_t setTxPower(int8_t txPower); |
Wolfgang Betz |
130:770ce14d3d15 | 118 | virtual void getPermittedTxPowerValues(const int8_t **, size_t *); |
Wolfgang Betz |
130:770ce14d3d15 | 119 | // <<<ANDREA>>> |
Wolfgang Betz |
132:51056160fa4a | 120 | virtual ble_error_t connect(const Address_t peerAddr, |
Wolfgang Betz |
132:51056160fa4a | 121 | Gap::AddressType_t peerAddrType, |
Wolfgang Betz |
132:51056160fa4a | 122 | const ConnectionParams_t *connectionParams, |
Wolfgang Betz |
132:51056160fa4a | 123 | const GapScanningParams *scanParams); |
Wolfgang Betz |
130:770ce14d3d15 | 124 | |
Wolfgang Betz |
130:770ce14d3d15 | 125 | |
Wolfgang Betz |
132:51056160fa4a | 126 | void Discovery_CB(Reason_t reason, |
Wolfgang Betz |
132:51056160fa4a | 127 | uint8_t adv_type, |
Wolfgang Betz |
132:51056160fa4a | 128 | uint8_t *addr_type, |
Wolfgang Betz |
132:51056160fa4a | 129 | uint8_t *addr, |
Wolfgang Betz |
132:51056160fa4a | 130 | uint8_t *data_length, |
Wolfgang Betz |
132:51056160fa4a | 131 | uint8_t *data, |
Wolfgang Betz |
132:51056160fa4a | 132 | uint8_t *RSSI); |
Wolfgang Betz |
165:3576598c0889 | 133 | ble_error_t createConnection(void); |
Wolfgang Betz |
165:3576598c0889 | 134 | |
Wolfgang Betz |
130:770ce14d3d15 | 135 | void setConnectionHandle(uint16_t con_handle); |
Wolfgang Betz |
130:770ce14d3d15 | 136 | uint16_t getConnectionHandle(void); |
Wolfgang Betz |
130:770ce14d3d15 | 137 | |
Wolfgang Betz |
130:770ce14d3d15 | 138 | bool getIsSetAddress(); |
Wolfgang Betz |
130:770ce14d3d15 | 139 | |
Wolfgang Betz |
130:770ce14d3d15 | 140 | Timeout getAdvTimeout(void) const { |
Wolfgang Betz |
130:770ce14d3d15 | 141 | return advTimeout; |
Wolfgang Betz |
130:770ce14d3d15 | 142 | } |
Wolfgang Betz |
130:770ce14d3d15 | 143 | uint8_t getAdvToFlag(void) { |
Wolfgang Betz |
130:770ce14d3d15 | 144 | return AdvToFlag; |
Wolfgang Betz |
130:770ce14d3d15 | 145 | } |
Wolfgang Betz |
130:770ce14d3d15 | 146 | void setAdvToFlag(void); |
Wolfgang Betz |
130:770ce14d3d15 | 147 | |
Wolfgang Betz |
130:770ce14d3d15 | 148 | void Process(void); |
Wolfgang Betz |
130:770ce14d3d15 | 149 | |
Andrea Palmieri |
160:174387d53809 | 150 | GapScanningParams* getScanningParams(void); |
Andrea Palmieri |
160:174387d53809 | 151 | |
Wolfgang Betz |
130:770ce14d3d15 | 152 | virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams); |
Wolfgang Betz |
130:770ce14d3d15 | 153 | |
Wolfgang Betz |
130:770ce14d3d15 | 154 | private: |
Wolfgang Betz |
130:770ce14d3d15 | 155 | uint16_t m_connectionHandle; |
Wolfgang Betz |
132:51056160fa4a | 156 | AddressType_t addr_type; |
Wolfgang Betz |
132:51056160fa4a | 157 | Address_t _peerAddr; |
Wolfgang Betz |
130:770ce14d3d15 | 158 | uint8_t bdaddr[BDADDR_SIZE]; |
Wolfgang Betz |
132:51056160fa4a | 159 | bool _scanning; |
Wolfgang Betz |
132:51056160fa4a | 160 | bool _connecting; |
Wolfgang Betz |
130:770ce14d3d15 | 161 | bool isSetAddress; |
Andrea Palmieri |
145:024a552e4715 | 162 | bool btle_reinited; |
Wolfgang Betz |
130:770ce14d3d15 | 163 | uint8_t *DeviceName; |
Wolfgang Betz |
130:770ce14d3d15 | 164 | uint8_t deviceAppearance[2]; |
Wolfgang Betz |
130:770ce14d3d15 | 165 | |
Wolfgang Betz |
130:770ce14d3d15 | 166 | uint8_t *local_name; |
Wolfgang Betz |
130:770ce14d3d15 | 167 | uint8_t local_name_length; |
Wolfgang Betz |
130:770ce14d3d15 | 168 | |
Wolfgang Betz |
130:770ce14d3d15 | 169 | bool txPowerAdType; |
Wolfgang Betz |
130:770ce14d3d15 | 170 | |
Wolfgang Betz |
130:770ce14d3d15 | 171 | uint8_t servUuidlength; |
Wolfgang Betz |
130:770ce14d3d15 | 172 | uint8_t servUuidData[UUID_BUFFER_SIZE]; |
Wolfgang Betz |
130:770ce14d3d15 | 173 | |
Wolfgang Betz |
130:770ce14d3d15 | 174 | uint8_t AdvLen; |
Wolfgang Betz |
130:770ce14d3d15 | 175 | uint8_t AdvData[ADV_DATA_MAX_SIZE]; |
Wolfgang Betz |
130:770ce14d3d15 | 176 | |
Wolfgang Betz |
130:770ce14d3d15 | 177 | Timeout advTimeout; |
Wolfgang Betz |
130:770ce14d3d15 | 178 | bool AdvToFlag; |
Wolfgang Betz |
130:770ce14d3d15 | 179 | |
Wolfgang Betz |
130:770ce14d3d15 | 180 | BlueNRGGap() { |
Wolfgang Betz |
130:770ce14d3d15 | 181 | m_connectionHandle = BLE_CONN_HANDLE_INVALID; |
Wolfgang Betz |
132:51056160fa4a | 182 | addr_type = Gap::ADDR_TYPE_PUBLIC; |
Wolfgang Betz |
130:770ce14d3d15 | 183 | isSetAddress = false; |
Andrea Palmieri |
145:024a552e4715 | 184 | btle_reinited = false; |
Wolfgang Betz |
130:770ce14d3d15 | 185 | DeviceName = NULL; |
Wolfgang Betz |
130:770ce14d3d15 | 186 | } |
Wolfgang Betz |
130:770ce14d3d15 | 187 | |
Wolfgang Betz |
130:770ce14d3d15 | 188 | BlueNRGGap(BlueNRGGap const &); |
Wolfgang Betz |
130:770ce14d3d15 | 189 | void operator=(BlueNRGGap const &); |
Wolfgang Betz |
130:770ce14d3d15 | 190 | }; |
Wolfgang Betz |
130:770ce14d3d15 | 191 | |
Wolfgang Betz |
130:770ce14d3d15 | 192 | #endif // ifndef __BLUENRG_GAP_H__ |