Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
hw/Gap.h@105:f29ab9f74d7e, 2014-07-11 (annotated)
- Committer:
- Rohit Grover
- Date:
- Fri Jul 11 14:39:17 2014 +0100
- Revision:
- 105:f29ab9f74d7e
- Parent:
- 104:6ef5abef5714
add APIs for working with connectionParams
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ktownsend | 29:011e95ce78b8 | 1 | /* mbed Microcontroller Library |
| ktownsend | 29:011e95ce78b8 | 2 | * Copyright (c) 2006-2013 ARM Limited |
| ktownsend | 29:011e95ce78b8 | 3 | * |
| ktownsend | 29:011e95ce78b8 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| ktownsend | 29:011e95ce78b8 | 5 | * you may not use this file except in compliance with the License. |
| ktownsend | 29:011e95ce78b8 | 6 | * You may obtain a copy of the License at |
| ktownsend | 29:011e95ce78b8 | 7 | * |
| ktownsend | 29:011e95ce78b8 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| ktownsend | 29:011e95ce78b8 | 9 | * |
| ktownsend | 29:011e95ce78b8 | 10 | * Unless required by applicable law or agreed to in writing, software |
| ktownsend | 29:011e95ce78b8 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| ktownsend | 29:011e95ce78b8 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| ktownsend | 29:011e95ce78b8 | 13 | * See the License for the specific language governing permissions and |
| ktownsend | 29:011e95ce78b8 | 14 | * limitations under the License. |
| ktownsend | 29:011e95ce78b8 | 15 | */ |
| Rohit Grover |
34:da2ea8cd6216 | 16 | |
| ktownsend | 29:011e95ce78b8 | 17 | #ifndef __GAP_H__ |
| ktownsend | 29:011e95ce78b8 | 18 | #define __GAP_H__ |
| ktownsend | 29:011e95ce78b8 | 19 | |
| ktownsend | 29:011e95ce78b8 | 20 | #include "mbed.h" |
| ktownsend | 29:011e95ce78b8 | 21 | #include "blecommon.h" |
| ktownsend | 29:011e95ce78b8 | 22 | #include "GapAdvertisingData.h" |
| ktownsend | 29:011e95ce78b8 | 23 | #include "GapAdvertisingParams.h" |
| bogdanm | 31:2c94f0501807 | 24 | #include "GapEvents.h" |
| ktownsend | 29:011e95ce78b8 | 25 | |
| ktownsend | 29:011e95ce78b8 | 26 | /**************************************************************************/ |
| ktownsend | 29:011e95ce78b8 | 27 | /*! |
| ktownsend | 29:011e95ce78b8 | 28 | \brief |
| ktownsend | 29:011e95ce78b8 | 29 | The base class used to abstract GAP functionality to a specific radio |
| ktownsend | 29:011e95ce78b8 | 30 | transceiver, SOC or BLE Stack. |
| ktownsend | 29:011e95ce78b8 | 31 | */ |
| ktownsend | 29:011e95ce78b8 | 32 | /**************************************************************************/ |
| ktownsend | 29:011e95ce78b8 | 33 | class Gap |
| ktownsend | 29:011e95ce78b8 | 34 | { |
| Rohit Grover |
34:da2ea8cd6216 | 35 | public: |
| Rohit Grover |
34:da2ea8cd6216 | 36 | typedef enum addr_type_e { |
| Rohit Grover |
34:da2ea8cd6216 | 37 | ADDR_TYPE_PUBLIC = 0, |
| Rohit Grover |
34:da2ea8cd6216 | 38 | ADDR_TYPE_RANDOM_STATIC, |
| Rohit Grover |
34:da2ea8cd6216 | 39 | ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE, |
| Rohit Grover |
34:da2ea8cd6216 | 40 | ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE |
| Rohit Grover |
34:da2ea8cd6216 | 41 | } addr_type_t; |
| Rohit Grover |
34:da2ea8cd6216 | 42 | |
| Rohit Grover |
105:f29ab9f74d7e | 43 | /* Describes the current state of the device (more than one bit can be set) */ |
| Rohit Grover |
105:f29ab9f74d7e | 44 | typedef struct GapState_s { |
| Rohit Grover |
105:f29ab9f74d7e | 45 | unsigned advertising : 1; /**< peripheral is currently advertising */ |
| Rohit Grover |
105:f29ab9f74d7e | 46 | unsigned connected : 1; /**< peripheral is connected to a central */ |
| Rohit Grover |
105:f29ab9f74d7e | 47 | } GapState_t; |
| Rohit Grover |
105:f29ab9f74d7e | 48 | |
| Rohit Grover |
105:f29ab9f74d7e | 49 | typedef uint16_t Handle_t; |
| Rohit Grover |
105:f29ab9f74d7e | 50 | |
| Rohit Grover |
105:f29ab9f74d7e | 51 | typedef struct { |
| Rohit Grover |
105:f29ab9f74d7e | 52 | uint16_t minConnectionInterval; /**< Minimum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/ |
| Rohit Grover |
105:f29ab9f74d7e | 53 | uint16_t maxConnectionInterval; /**< Maximum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/ |
| Rohit Grover |
105:f29ab9f74d7e | 54 | uint16_t slaveLatency; /**< Slave Latency in number of connection events, see @ref BLE_GAP_CP_LIMITS.*/ |
| Rohit Grover |
105:f29ab9f74d7e | 55 | uint16_t connectionSupervisionTimeout; /**< Connection Supervision Timeout in 10 ms units, see @ref BLE_GAP_CP_LIMITS.*/ |
| Rohit Grover |
105:f29ab9f74d7e | 56 | } ConnectionParams_t; |
| Rohit Grover |
105:f29ab9f74d7e | 57 | |
| Rohit Grover |
105:f29ab9f74d7e | 58 | public: |
| Rohit Grover |
34:da2ea8cd6216 | 59 | /* These functions must be defined in the sub-class */ |
| Rohit Grover |
38:02cf26a2a4db | 60 | virtual ble_error_t setAddress(addr_type_t type, const uint8_t address[6]) = 0; |
| Rohit Grover |
75:d08bdef22500 | 61 | virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &) = 0; |
| Rohit Grover |
40:d405c9b1419d | 62 | virtual ble_error_t startAdvertising(const GapAdvertisingParams &) = 0; |
| Rohit Grover |
34:da2ea8cd6216 | 63 | virtual ble_error_t stopAdvertising(void) = 0; |
| Rohit Grover |
34:da2ea8cd6216 | 64 | virtual ble_error_t disconnect(void) = 0; |
| Rohit Grover |
105:f29ab9f74d7e | 65 | virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params) = 0; |
| Rohit Grover |
105:f29ab9f74d7e | 66 | virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params) = 0; |
| Rohit Grover |
105:f29ab9f74d7e | 67 | virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params) = 0; |
| Rohit Grover |
34:da2ea8cd6216 | 68 | |
| Rohit Grover |
104:6ef5abef5714 | 69 | typedef void (*EventCallback_t)(void); |
| Rohit Grover |
104:6ef5abef5714 | 70 | typedef void (*HandleSpecificEventCallback_t)(Handle_t); |
| Rohit Grover |
104:6ef5abef5714 | 71 | |
| Rohit Grover |
34:da2ea8cd6216 | 72 | /* Event callback handlers */ |
| Rohit Grover |
63:653378e782ea | 73 | void setOnTimeout(EventCallback_t callback) { |
| Rohit Grover |
63:653378e782ea | 74 | onTimeout = callback; |
| Rohit Grover |
63:653378e782ea | 75 | } |
| Rohit Grover |
104:6ef5abef5714 | 76 | void setOnConnection(HandleSpecificEventCallback_t callback) { |
| Rohit Grover |
63:653378e782ea | 77 | onConnection = callback; |
| Rohit Grover |
63:653378e782ea | 78 | } |
| Rohit Grover |
104:6ef5abef5714 | 79 | void setOnDisconnection(HandleSpecificEventCallback_t callback) { |
| Rohit Grover |
63:653378e782ea | 80 | onDisconnection = callback; |
| Rohit Grover |
34:da2ea8cd6216 | 81 | } |
| ktownsend | 29:011e95ce78b8 | 82 | |
| Rohit Grover |
104:6ef5abef5714 | 83 | void processHandleSpecificEvent(GapEvents::gapEvent_e type, Handle_t handle) { |
| Rohit Grover |
104:6ef5abef5714 | 84 | switch (type) { |
| Rohit Grover |
104:6ef5abef5714 | 85 | case GapEvents::GAP_EVENT_CONNECTED: |
| Rohit Grover |
104:6ef5abef5714 | 86 | state.connected = 1; |
| Rohit Grover |
104:6ef5abef5714 | 87 | if (onConnection) { |
| Rohit Grover |
104:6ef5abef5714 | 88 | onConnection(handle); |
| Rohit Grover |
104:6ef5abef5714 | 89 | } |
| Rohit Grover |
104:6ef5abef5714 | 90 | break; |
| Rohit Grover |
104:6ef5abef5714 | 91 | case GapEvents::GAP_EVENT_DISCONNECTED: |
| Rohit Grover |
104:6ef5abef5714 | 92 | state.connected = 0; |
| Rohit Grover |
104:6ef5abef5714 | 93 | if (onDisconnection) { |
| Rohit Grover |
104:6ef5abef5714 | 94 | onDisconnection(handle); |
| Rohit Grover |
104:6ef5abef5714 | 95 | } |
| Rohit Grover |
104:6ef5abef5714 | 96 | break; |
| Rohit Grover |
104:6ef5abef5714 | 97 | } |
| Rohit Grover |
104:6ef5abef5714 | 98 | } |
| Rohit Grover |
104:6ef5abef5714 | 99 | |
| Rohit Grover |
104:6ef5abef5714 | 100 | void processEvent(GapEvents::gapEvent_e type) { |
| Rohit Grover |
34:da2ea8cd6216 | 101 | switch (type) { |
| Rohit Grover |
77:1436ecf09583 | 102 | case GapEvents::GAP_EVENT_TIMEOUT: |
| Rohit Grover |
77:1436ecf09583 | 103 | state.advertising = 0; |
| Rohit Grover |
77:1436ecf09583 | 104 | if (onTimeout) { |
| Rohit Grover |
77:1436ecf09583 | 105 | onTimeout(); |
| Rohit Grover |
77:1436ecf09583 | 106 | } |
| Rohit Grover |
77:1436ecf09583 | 107 | break; |
| Rohit Grover |
34:da2ea8cd6216 | 108 | } |
| Rohit Grover |
34:da2ea8cd6216 | 109 | } |
| Rohit Grover |
34:da2ea8cd6216 | 110 | |
| Rohit Grover |
73:eeb1ac3545e9 | 111 | GapState_t getState(void) const { |
| Rohit Grover |
73:eeb1ac3545e9 | 112 | return state; |
| Rohit Grover |
73:eeb1ac3545e9 | 113 | } |
| Rohit Grover |
73:eeb1ac3545e9 | 114 | |
| Rohit Grover |
63:653378e782ea | 115 | protected: |
| Rohit Grover |
75:d08bdef22500 | 116 | Gap() : state(), onTimeout(NULL), onConnection(NULL), onDisconnection(NULL) { |
| Rohit Grover |
63:653378e782ea | 117 | /* empty */ |
| Rohit Grover |
63:653378e782ea | 118 | } |
| Rohit Grover |
63:653378e782ea | 119 | |
| Rohit Grover |
63:653378e782ea | 120 | protected: |
| Rohit Grover |
34:da2ea8cd6216 | 121 | GapState_t state; |
| Rohit Grover |
63:653378e782ea | 122 | |
| Rohit Grover |
63:653378e782ea | 123 | private: |
| Rohit Grover |
104:6ef5abef5714 | 124 | EventCallback_t onTimeout; |
| Rohit Grover |
104:6ef5abef5714 | 125 | HandleSpecificEventCallback_t onConnection; |
| Rohit Grover |
104:6ef5abef5714 | 126 | HandleSpecificEventCallback_t onDisconnection; |
| ktownsend | 29:011e95ce78b8 | 127 | }; |
| ktownsend | 29:011e95ce78b8 | 128 | |
| Rohit Grover |
34:da2ea8cd6216 | 129 | #endif // ifndef __GAP_H__ |
