mbed HRM11017を使ってkonashi.jsでナイトライダー

Dependencies:   BLE_API_Native_IRC mbed

Fork of BLE_RCBController by Junichi Katsu

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Gap.h Source File

Gap.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016   
00017 #ifndef __GAP_H__
00018 #define __GAP_H__
00019 
00020 #include "mbed.h"
00021 #include "blecommon.h"
00022 #include "GapAdvertisingData.h"
00023 #include "GapAdvertisingParams.h"
00024 #include "GapEvents.h"
00025 
00026 /**************************************************************************/
00027 /*!
00028     \brief
00029     The base class used to abstract GAP functionality to a specific radio
00030     transceiver, SOC or BLE Stack.
00031 */
00032 /**************************************************************************/
00033 class Gap
00034 {
00035     private:
00036         GapEvents *m_pEventHandler;
00037 
00038     public:
00039                 /* These functions must be defined in the sub-class */
00040                 virtual ble_error_t setAdvertisingData(GapAdvertisingData &, GapAdvertisingData &) = 0;
00041                 virtual ble_error_t startAdvertising(GapAdvertisingParams &) = 0;
00042                 virtual ble_error_t stopAdvertising(void) = 0;
00043                 virtual ble_error_t disconnect(void) = 0;
00044 
00045                 /* Describes the current state of the device (more than one bit can be set) */
00046                 typedef struct GapState_s
00047                 {
00048                         unsigned advertising : 1;   /**< The device is current advertising */
00049                         unsigned connected   : 1;   /**< The peripheral is connected to a central device */
00050                 } GapState_t;
00051 
00052                 /* Event callback handlers */
00053                 void setEventHandler(GapEvents *pEventHandler) {m_pEventHandler = pEventHandler;}
00054                 void handleEvent(GapEvents::gapEvent_e type) {
00055                         if (NULL == m_pEventHandler)
00056                                     return;
00057                         switch(type) {
00058                                     case GapEvents::GAP_EVENT_TIMEOUT:
00059                                             state.advertising = 0;
00060                                                 m_pEventHandler->onTimeout();
00061                                                 break;
00062                                     case GapEvents::GAP_EVENT_CONNECTED:
00063                                             state.connected = 1;
00064                                                 m_pEventHandler->onConnected();
00065                                                 break;
00066                                     case GapEvents::GAP_EVENT_DISCONNECTED:
00067                                             state.connected = 0;
00068                                                 m_pEventHandler->onDisconnected();
00069                                                 break;
00070                         }
00071                 }
00072                 
00073                 GapState_t state;
00074 };
00075 
00076 #endif