HW layer for the Nucleo board, it only work with old BLE_API
Dependents: Hello_BLE F446RE-BLE
Fork of X_NUCLEO_IDB0XA1 by
BlueNRGGap.h@94:2993df23d1ac, 2015-07-24 (annotated)
- Committer:
- apalmieri
- Date:
- Fri Jul 24 15:00:36 2015 +0000
- Revision:
- 94:2993df23d1ac
- Parent:
- 90:26c0c9807ab4
- Child:
- 107:5cc5ac5bfbbb
Fix issues related to application compatibility
;
; Advertising payload building
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wolfgang Betz |
90:26c0c9807ab4 | 1 | /* mbed Microcontroller Library |
Wolfgang Betz |
90:26c0c9807ab4 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Wolfgang Betz |
90:26c0c9807ab4 | 3 | * |
Wolfgang Betz |
90:26c0c9807ab4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Wolfgang Betz |
90:26c0c9807ab4 | 5 | * you may not use this file except in compliance with the License. |
Wolfgang Betz |
90:26c0c9807ab4 | 6 | * You may obtain a copy of the License at |
Wolfgang Betz |
90:26c0c9807ab4 | 7 | * |
Wolfgang Betz |
90:26c0c9807ab4 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Wolfgang Betz |
90:26c0c9807ab4 | 9 | * |
Wolfgang Betz |
90:26c0c9807ab4 | 10 | * Unless required by applicable law or agreed to in writing, software |
Wolfgang Betz |
90:26c0c9807ab4 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Wolfgang Betz |
90:26c0c9807ab4 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Wolfgang Betz |
90:26c0c9807ab4 | 13 | * See the License for the specific language governing permissions and |
Wolfgang Betz |
90:26c0c9807ab4 | 14 | * limitations under the License. |
Wolfgang Betz |
90:26c0c9807ab4 | 15 | */ |
Wolfgang Betz |
90:26c0c9807ab4 | 16 | |
Wolfgang Betz |
90:26c0c9807ab4 | 17 | /** |
Wolfgang Betz |
90:26c0c9807ab4 | 18 | ****************************************************************************** |
Wolfgang Betz |
90:26c0c9807ab4 | 19 | * @file BlueNRGGap.h |
Wolfgang Betz |
90:26c0c9807ab4 | 20 | * @author STMicroelectronics |
Wolfgang Betz |
90:26c0c9807ab4 | 21 | * @brief Header file for BlueNRG BLE_API Gap Class |
Wolfgang Betz |
90:26c0c9807ab4 | 22 | ****************************************************************************** |
Wolfgang Betz |
90:26c0c9807ab4 | 23 | * @copy |
Wolfgang Betz |
90:26c0c9807ab4 | 24 | * |
Wolfgang Betz |
90:26c0c9807ab4 | 25 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
Wolfgang Betz |
90:26c0c9807ab4 | 26 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE |
Wolfgang Betz |
90:26c0c9807ab4 | 27 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY |
Wolfgang Betz |
90:26c0c9807ab4 | 28 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING |
Wolfgang Betz |
90:26c0c9807ab4 | 29 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE |
Wolfgang Betz |
90:26c0c9807ab4 | 30 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
Wolfgang Betz |
90:26c0c9807ab4 | 31 | * |
Wolfgang Betz |
90:26c0c9807ab4 | 32 | * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> |
Wolfgang Betz |
90:26c0c9807ab4 | 33 | */ |
Wolfgang Betz |
90:26c0c9807ab4 | 34 | |
Wolfgang Betz |
90:26c0c9807ab4 | 35 | #ifndef __BLUENRG_GAP_H__ |
Wolfgang Betz |
90:26c0c9807ab4 | 36 | #define __BLUENRG_GAP_H__ |
Wolfgang Betz |
90:26c0c9807ab4 | 37 | |
Wolfgang Betz |
90:26c0c9807ab4 | 38 | #include "mbed.h" |
Wolfgang Betz |
90:26c0c9807ab4 | 39 | #include "blecommon.h" |
Wolfgang Betz |
90:26c0c9807ab4 | 40 | #include "btle.h" |
Wolfgang Betz |
90:26c0c9807ab4 | 41 | #include "GapAdvertisingParams.h" |
Wolfgang Betz |
90:26c0c9807ab4 | 42 | #include "GapAdvertisingData.h" |
Wolfgang Betz |
90:26c0c9807ab4 | 43 | #include <ble/Gap.h> |
Wolfgang Betz |
90:26c0c9807ab4 | 44 | |
Wolfgang Betz |
90:26c0c9807ab4 | 45 | #define BLE_CONN_HANDLE_INVALID 0x0 |
Wolfgang Betz |
90:26c0c9807ab4 | 46 | #define BDADDR_SIZE 6 |
Wolfgang Betz |
90:26c0c9807ab4 | 47 | |
Wolfgang Betz |
90:26c0c9807ab4 | 48 | #define BLUENRG_GAP_ADV_INTERVAL_MIN (0) |
Wolfgang Betz |
90:26c0c9807ab4 | 49 | #define BLUENRG_GAP_ADV_INTERVAL_MAX (0) |
Wolfgang Betz |
90:26c0c9807ab4 | 50 | #define BLE_GAP_ADV_NONCON_INTERVAL_MIN (0) |
Wolfgang Betz |
90:26c0c9807ab4 | 51 | |
apalmieri | 94:2993df23d1ac | 52 | #define UUID_BUFFER_SIZE 13 //6*2(16-bit UUIDs)+1 |
apalmieri | 94:2993df23d1ac | 53 | #define ADV_DATA_MAX_SIZE 31 |
Wolfgang Betz |
90:26c0c9807ab4 | 54 | |
Wolfgang Betz |
90:26c0c9807ab4 | 55 | /**************************************************************************/ |
Wolfgang Betz |
90:26c0c9807ab4 | 56 | /*! |
Wolfgang Betz |
90:26c0c9807ab4 | 57 | \brief |
Wolfgang Betz |
90:26c0c9807ab4 | 58 | |
Wolfgang Betz |
90:26c0c9807ab4 | 59 | */ |
Wolfgang Betz |
90:26c0c9807ab4 | 60 | /**************************************************************************/ |
Wolfgang Betz |
90:26c0c9807ab4 | 61 | class BlueNRGGap : public Gap |
Wolfgang Betz |
90:26c0c9807ab4 | 62 | { |
Wolfgang Betz |
90:26c0c9807ab4 | 63 | public: |
Wolfgang Betz |
90:26c0c9807ab4 | 64 | static BlueNRGGap &getInstance() { |
Wolfgang Betz |
90:26c0c9807ab4 | 65 | static BlueNRGGap m_instance; |
Wolfgang Betz |
90:26c0c9807ab4 | 66 | return m_instance; |
Wolfgang Betz |
90:26c0c9807ab4 | 67 | } |
Wolfgang Betz |
90:26c0c9807ab4 | 68 | |
Wolfgang Betz |
90:26c0c9807ab4 | 69 | // <<<ANDREA>>> |
Wolfgang Betz |
90:26c0c9807ab4 | 70 | enum AdvType_t { |
Wolfgang Betz |
90:26c0c9807ab4 | 71 | ADV_IND = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED,//Gap::ADV_IND, |
Wolfgang Betz |
90:26c0c9807ab4 | 72 | ADV_DIRECT_IND = GapAdvertisingParams::ADV_CONNECTABLE_DIRECTED,//Gap::ADV_DIRECT_IND, |
Wolfgang Betz |
90:26c0c9807ab4 | 73 | ADV_SCAN_IND = GapAdvertisingParams::ADV_SCANNABLE_UNDIRECTED,//Gap::ADV_SCAN_IND, |
Wolfgang Betz |
90:26c0c9807ab4 | 74 | ADV_NONCONN_IND = GapAdvertisingParams::ADV_NON_CONNECTABLE_UNDIRECTED//Gap::ADV_NONCONN_IND |
Wolfgang Betz |
90:26c0c9807ab4 | 75 | }; |
Wolfgang Betz |
90:26c0c9807ab4 | 76 | |
Wolfgang Betz |
90:26c0c9807ab4 | 77 | /* Functions that must be implemented from Gap */ |
Wolfgang Betz |
90:26c0c9807ab4 | 78 | virtual ble_error_t setAddress(addr_type_t type, const Address_t address); |
Wolfgang Betz |
90:26c0c9807ab4 | 79 | virtual ble_error_t getAddress(addr_type_t *typeP, Address_t address); |
Wolfgang Betz |
90:26c0c9807ab4 | 80 | virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &); |
Wolfgang Betz |
90:26c0c9807ab4 | 81 | virtual ble_error_t startAdvertising(const GapAdvertisingParams &); |
Wolfgang Betz |
90:26c0c9807ab4 | 82 | virtual ble_error_t stopAdvertising(void); |
Wolfgang Betz |
90:26c0c9807ab4 | 83 | virtual ble_error_t stopScan(); |
Wolfgang Betz |
90:26c0c9807ab4 | 84 | virtual uint16_t getMinAdvertisingInterval(void) const; |
Wolfgang Betz |
90:26c0c9807ab4 | 85 | virtual uint16_t getMinNonConnectableAdvertisingInterval(void) const; |
Wolfgang Betz |
90:26c0c9807ab4 | 86 | virtual uint16_t getMaxAdvertisingInterval(void) const; |
Wolfgang Betz |
90:26c0c9807ab4 | 87 | virtual ble_error_t disconnect(DisconnectionReason_t reason); |
Wolfgang Betz |
90:26c0c9807ab4 | 88 | virtual ble_error_t disconnect(Handle_t connectionHandle, DisconnectionReason_t reason); |
Wolfgang Betz |
90:26c0c9807ab4 | 89 | virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params); |
Wolfgang Betz |
90:26c0c9807ab4 | 90 | virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params); |
Wolfgang Betz |
90:26c0c9807ab4 | 91 | virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params); |
Wolfgang Betz |
90:26c0c9807ab4 | 92 | |
Wolfgang Betz |
90:26c0c9807ab4 | 93 | virtual ble_error_t setDeviceName(const uint8_t *deviceName); |
Wolfgang Betz |
90:26c0c9807ab4 | 94 | virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP); |
Wolfgang Betz |
90:26c0c9807ab4 | 95 | virtual ble_error_t setAppearance(GapAdvertisingData::Appearance appearance); |
Wolfgang Betz |
90:26c0c9807ab4 | 96 | virtual ble_error_t getAppearance(GapAdvertisingData::Appearance *appearanceP); |
Wolfgang Betz |
90:26c0c9807ab4 | 97 | |
Wolfgang Betz |
90:26c0c9807ab4 | 98 | virtual ble_error_t setTxPower(int8_t txPower); |
Wolfgang Betz |
90:26c0c9807ab4 | 99 | virtual void getPermittedTxPowerValues(const int8_t **, size_t *); |
Wolfgang Betz |
90:26c0c9807ab4 | 100 | // <<<ANDREA>>> |
Wolfgang Betz |
90:26c0c9807ab4 | 101 | |
Wolfgang Betz |
90:26c0c9807ab4 | 102 | |
Wolfgang Betz |
90:26c0c9807ab4 | 103 | void setConnectionHandle(uint16_t con_handle); |
Wolfgang Betz |
90:26c0c9807ab4 | 104 | uint16_t getConnectionHandle(void); |
Wolfgang Betz |
90:26c0c9807ab4 | 105 | |
Wolfgang Betz |
90:26c0c9807ab4 | 106 | //tHalUint8* getAddress(); |
Wolfgang Betz |
90:26c0c9807ab4 | 107 | bool getIsSetAddress(); |
Wolfgang Betz |
90:26c0c9807ab4 | 108 | |
Wolfgang Betz |
90:26c0c9807ab4 | 109 | protected: |
Wolfgang Betz |
90:26c0c9807ab4 | 110 | virtual ble_error_t startRadioScan(const GapScanningParams &scanningParams); |
Wolfgang Betz |
90:26c0c9807ab4 | 111 | |
Wolfgang Betz |
90:26c0c9807ab4 | 112 | private: |
Wolfgang Betz |
90:26c0c9807ab4 | 113 | uint16_t m_connectionHandle; |
Wolfgang Betz |
90:26c0c9807ab4 | 114 | uint8_t bdaddr[BDADDR_SIZE]; |
Wolfgang Betz |
90:26c0c9807ab4 | 115 | bool isSetAddress; |
apalmieri | 94:2993df23d1ac | 116 | tBleStatus ret; // FIXME: delete this |
Wolfgang Betz |
90:26c0c9807ab4 | 117 | uint8_t *DeviceName; |
Wolfgang Betz |
90:26c0c9807ab4 | 118 | uint8_t deviceAppearance[2]; |
Wolfgang Betz |
90:26c0c9807ab4 | 119 | |
apalmieri | 94:2993df23d1ac | 120 | uint8_t *local_name; |
apalmieri | 94:2993df23d1ac | 121 | uint8_t local_name_length; |
apalmieri | 94:2993df23d1ac | 122 | |
apalmieri | 94:2993df23d1ac | 123 | uint8_t servUuidlength; |
apalmieri | 94:2993df23d1ac | 124 | uint8_t servUuidData[UUID_BUFFER_SIZE]; |
apalmieri | 94:2993df23d1ac | 125 | |
apalmieri | 94:2993df23d1ac | 126 | uint8_t AdvLen; |
apalmieri | 94:2993df23d1ac | 127 | uint8_t AdvData[ADV_DATA_MAX_SIZE]; |
apalmieri | 94:2993df23d1ac | 128 | |
Wolfgang Betz |
90:26c0c9807ab4 | 129 | BlueNRGGap() { |
Wolfgang Betz |
90:26c0c9807ab4 | 130 | m_connectionHandle = BLE_CONN_HANDLE_INVALID; |
Wolfgang Betz |
90:26c0c9807ab4 | 131 | isSetAddress = false; |
Wolfgang Betz |
90:26c0c9807ab4 | 132 | DeviceName = NULL; |
Wolfgang Betz |
90:26c0c9807ab4 | 133 | } |
Wolfgang Betz |
90:26c0c9807ab4 | 134 | |
Wolfgang Betz |
90:26c0c9807ab4 | 135 | BlueNRGGap(BlueNRGGap const &); |
Wolfgang Betz |
90:26c0c9807ab4 | 136 | void operator=(BlueNRGGap const &); |
Wolfgang Betz |
90:26c0c9807ab4 | 137 | }; |
Wolfgang Betz |
90:26c0c9807ab4 | 138 | |
Wolfgang Betz |
90:26c0c9807ab4 | 139 | #endif // ifndef __BLUENRG_GAP_H__ |