BLE Temperature Service Mobile and Ubiquitous Computing Module Birkbeck College

Dependencies:   DS1820

Committer:
gkroussos
Date:
Sun Mar 08 19:42:20 2015 +0000
Revision:
0:dd0fea342ad2
BLE Temperature Service ; Mobile and Ubiquitous Computing Module; Birkbeck College

Who changed what in which revision?

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