Microbug / BLE_API

Fork of BLE_API by Bluetooth Low Energy

Committer:
mbed_official
Date:
Thu Apr 03 01:45:33 2014 +0100
Revision:
33:6d51a2c69442
Parent:
31:2c94f0501807
Child:
34:da2ea8cd6216
Synchronized with git revision 348e2de6c8b2badc1fd1fe7ae044c24c25244a11

Full URL: https://github.com/mbedmicro/mbed/commit/348e2de6c8b2badc1fd1fe7ae044c24c25244a11/

Who changed what in which revision?

UserRevisionLine numberNew 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 */
ktownsend 29:011e95ce78b8 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 {
bogdanm 31:2c94f0501807 35 private:
bogdanm 31:2c94f0501807 36 GapEvents *m_pEventHandler;
bogdanm 31:2c94f0501807 37
ktownsend 29:011e95ce78b8 38 public:
mbed_official 33:6d51a2c69442 39 typedef enum addr_type_e{
mbed_official 33:6d51a2c69442 40 ADDR_TYPE_PUBLIC = 0,
mbed_official 33:6d51a2c69442 41 ADDR_TYPE_RANDOM_STATIC,
mbed_official 33:6d51a2c69442 42 ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE,
mbed_official 33:6d51a2c69442 43 ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE
mbed_official 33:6d51a2c69442 44 } addr_type_t;
mbed_official 33:6d51a2c69442 45
bogdanm 31:2c94f0501807 46 /* These functions must be defined in the sub-class */
mbed_official 33:6d51a2c69442 47 virtual ble_error_t setAddress(addr_type_t type, uint8_t address[6]) = 0;
bogdanm 31:2c94f0501807 48 virtual ble_error_t setAdvertisingData(GapAdvertisingData &, GapAdvertisingData &) = 0;
bogdanm 31:2c94f0501807 49 virtual ble_error_t startAdvertising(GapAdvertisingParams &) = 0;
bogdanm 31:2c94f0501807 50 virtual ble_error_t stopAdvertising(void) = 0;
bogdanm 31:2c94f0501807 51 virtual ble_error_t disconnect(void) = 0;
bogdanm 31:2c94f0501807 52
bogdanm 31:2c94f0501807 53 /* Describes the current state of the device (more than one bit can be set) */
bogdanm 31:2c94f0501807 54 typedef struct GapState_s
bogdanm 31:2c94f0501807 55 {
bogdanm 31:2c94f0501807 56 unsigned advertising : 1; /**< The device is current advertising */
bogdanm 31:2c94f0501807 57 unsigned connected : 1; /**< The peripheral is connected to a central device */
bogdanm 31:2c94f0501807 58 } GapState_t;
ktownsend 29:011e95ce78b8 59
bogdanm 31:2c94f0501807 60 /* Event callback handlers */
bogdanm 31:2c94f0501807 61 void setEventHandler(GapEvents *pEventHandler) {m_pEventHandler = pEventHandler;}
bogdanm 31:2c94f0501807 62 void handleEvent(GapEvents::gapEvent_e type) {
bogdanm 31:2c94f0501807 63 if (NULL == m_pEventHandler)
bogdanm 31:2c94f0501807 64 return;
bogdanm 31:2c94f0501807 65 switch(type) {
bogdanm 31:2c94f0501807 66 case GapEvents::GAP_EVENT_TIMEOUT:
bogdanm 31:2c94f0501807 67 state.advertising = 0;
bogdanm 31:2c94f0501807 68 m_pEventHandler->onTimeout();
bogdanm 31:2c94f0501807 69 break;
bogdanm 31:2c94f0501807 70 case GapEvents::GAP_EVENT_CONNECTED:
bogdanm 31:2c94f0501807 71 state.connected = 1;
bogdanm 31:2c94f0501807 72 m_pEventHandler->onConnected();
bogdanm 31:2c94f0501807 73 break;
bogdanm 31:2c94f0501807 74 case GapEvents::GAP_EVENT_DISCONNECTED:
bogdanm 31:2c94f0501807 75 state.connected = 0;
bogdanm 31:2c94f0501807 76 m_pEventHandler->onDisconnected();
bogdanm 31:2c94f0501807 77 break;
bogdanm 31:2c94f0501807 78 }
bogdanm 31:2c94f0501807 79 }
bogdanm 31:2c94f0501807 80
bogdanm 31:2c94f0501807 81 GapState_t state;
ktownsend 29:011e95ce78b8 82 };
ktownsend 29:011e95ce78b8 83
ktownsend 29:011e95ce78b8 84 #endif