Microbug / BLE_API

Fork of BLE_API by Bluetooth Low Energy

Committer:
bogdanm
Date:
Tue Apr 01 11:04:56 2014 +0100
Revision:
31:2c94f0501807
Parent:
30:9614522cf932
Child:
33:6d51a2c69442
Synchronized with git revision fdcc1e387426ce216bc17175b73bcd5f4aececff

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