BLE API as used in the blog entry.

Dependents:   BLE_iBeacon_Exercise

Fork of BLE_API_Native by Kevin Townsend

Committer:
donalm
Date:
Sun Feb 23 12:51:12 2014 +0000
Revision:
18:f776bb9efb7a
Parent:
17:d5600677d532
Removed hw layer.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 17:d5600677d532 1 /* mbed Microcontroller Library
ktownsend 17:d5600677d532 2 * Copyright (c) 2006-2013 ARM Limited
ktownsend 17:d5600677d532 3 *
ktownsend 17:d5600677d532 4 * Licensed under the Apache License, Version 2.0 (the "License");
ktownsend 17:d5600677d532 5 * you may not use this file except in compliance with the License.
ktownsend 17:d5600677d532 6 * You may obtain a copy of the License at
ktownsend 17:d5600677d532 7 *
ktownsend 17:d5600677d532 8 * http://www.apache.org/licenses/LICENSE-2.0
ktownsend 17:d5600677d532 9 *
ktownsend 17:d5600677d532 10 * Unless required by applicable law or agreed to in writing, software
ktownsend 17:d5600677d532 11 * distributed under the License is distributed on an "AS IS" BASIS,
ktownsend 17:d5600677d532 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ktownsend 17:d5600677d532 13 * See the License for the specific language governing permissions and
ktownsend 17:d5600677d532 14 * limitations under the License.
ktownsend 17:d5600677d532 15 */
ktownsend 17:d5600677d532 16
ktownsend 17:d5600677d532 17 #ifndef __GAP_H__
ktownsend 17:d5600677d532 18 #define __GAP_H__
ktownsend 17:d5600677d532 19
ktownsend 17:d5600677d532 20 #include "mbed.h"
ktownsend 17:d5600677d532 21 #include "blecommon.h"
ktownsend 17:d5600677d532 22 #include "GapAdvertisingData.h"
ktownsend 17:d5600677d532 23 #include "GapAdvertisingParams.h"
ktownsend 17:d5600677d532 24 #include "GapEvents.h"
ktownsend 17:d5600677d532 25
ktownsend 17:d5600677d532 26 /**************************************************************************/
ktownsend 17:d5600677d532 27 /*!
ktownsend 17:d5600677d532 28 \brief
ktownsend 17:d5600677d532 29 The base class used to abstract GAP functionality to a specific radio
ktownsend 17:d5600677d532 30 transceiver, SOC or BLE Stack.
ktownsend 17:d5600677d532 31 */
ktownsend 17:d5600677d532 32 /**************************************************************************/
ktownsend 17:d5600677d532 33 class Gap
ktownsend 17:d5600677d532 34 {
ktownsend 17:d5600677d532 35 private:
ktownsend 17:d5600677d532 36 GapEvents *m_pEventHandler;
ktownsend 17:d5600677d532 37
ktownsend 17:d5600677d532 38 public:
ktownsend 17:d5600677d532 39 /* These functions must be defined in the sub-class */
ktownsend 17:d5600677d532 40 virtual ble_error_t setAdvertisingData(GapAdvertisingData &, GapAdvertisingData &) = 0;
ktownsend 17:d5600677d532 41 virtual ble_error_t startAdvertising(GapAdvertisingParams &) = 0;
ktownsend 17:d5600677d532 42 virtual ble_error_t stopAdvertising(void) = 0;
ktownsend 17:d5600677d532 43 virtual ble_error_t disconnect(void) = 0;
ktownsend 17:d5600677d532 44
ktownsend 17:d5600677d532 45 /* Describes the current state of the device (more than one bit can be set) */
ktownsend 17:d5600677d532 46 typedef struct GapState_s
ktownsend 17:d5600677d532 47 {
ktownsend 17:d5600677d532 48 unsigned advertising : 1; /**< The device is current advertising */
ktownsend 17:d5600677d532 49 unsigned connected : 1; /**< The peripheral is connected to a central device */
ktownsend 17:d5600677d532 50 } GapState_t;
ktownsend 17:d5600677d532 51
ktownsend 17:d5600677d532 52 /* Event callback handlers */
ktownsend 17:d5600677d532 53 void setEventHandler(GapEvents *pEventHandler) {m_pEventHandler = pEventHandler;}
ktownsend 17:d5600677d532 54 void handleEvent(GapEvents::gapEvent_e type) {
ktownsend 17:d5600677d532 55 if (NULL == m_pEventHandler)
ktownsend 17:d5600677d532 56 return;
ktownsend 17:d5600677d532 57 switch(type) {
ktownsend 17:d5600677d532 58 case GapEvents::GAP_EVENT_TIMEOUT:
ktownsend 17:d5600677d532 59 state.advertising = 0;
ktownsend 17:d5600677d532 60 m_pEventHandler->onTimeout();
ktownsend 17:d5600677d532 61 break;
ktownsend 17:d5600677d532 62 case GapEvents::GAP_EVENT_CONNECTED:
ktownsend 17:d5600677d532 63 state.connected = 1;
ktownsend 17:d5600677d532 64 m_pEventHandler->onConnected();
ktownsend 17:d5600677d532 65 break;
ktownsend 17:d5600677d532 66 case GapEvents::GAP_EVENT_DISCONNECTED:
ktownsend 17:d5600677d532 67 state.connected = 0;
ktownsend 17:d5600677d532 68 m_pEventHandler->onDisconnected();
ktownsend 17:d5600677d532 69 break;
ktownsend 17:d5600677d532 70 }
ktownsend 17:d5600677d532 71 }
ktownsend 17:d5600677d532 72
ktownsend 17:d5600677d532 73 GapState_t state;
ktownsend 17:d5600677d532 74 };
ktownsend 17:d5600677d532 75
ktownsend 17:d5600677d532 76 #endif