Fixes to BLE_API for mbedOS Alpha1 release. Mostly relating to doxygen fixes.

Fork of BLE_API by Bluetooth Low Energy

Committer:
Rohit Grover
Date:
Wed Jul 23 15:09:23 2014 +0100
Revision:
106:a20be740075d
Child:
116:ca826083980e
initial re-organization of BLE_API directory structure

Who changed what in which revision?

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