Microbug / BLE_API

Fork of BLE_API by Bluetooth Low Energy

Committer:
sam_grove
Date:
Thu Jan 09 16:41:15 2014 +0000
Revision:
28:f6022fb90701
Parent:
27:4a83843f04b0
Updated constructor to take parameters

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 27:4a83843f04b0 1 /* mbed Microcontroller Library
ktownsend 27:4a83843f04b0 2 * Copyright (c) 2006-2013 ARM Limited
ktownsend 27:4a83843f04b0 3 *
ktownsend 27:4a83843f04b0 4 * Licensed under the Apache License, Version 2.0 (the "License");
ktownsend 27:4a83843f04b0 5 * you may not use this file except in compliance with the License.
ktownsend 27:4a83843f04b0 6 * You may obtain a copy of the License at
ktownsend 27:4a83843f04b0 7 *
ktownsend 27:4a83843f04b0 8 * http://www.apache.org/licenses/LICENSE-2.0
ktownsend 27:4a83843f04b0 9 *
ktownsend 27:4a83843f04b0 10 * Unless required by applicable law or agreed to in writing, software
ktownsend 27:4a83843f04b0 11 * distributed under the License is distributed on an "AS IS" BASIS,
ktownsend 27:4a83843f04b0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ktownsend 27:4a83843f04b0 13 * See the License for the specific language governing permissions and
ktownsend 27:4a83843f04b0 14 * limitations under the License.
ktownsend 27:4a83843f04b0 15 */
ktownsend 27:4a83843f04b0 16
ktownsend 0:ace2e8d3ce79 17 #ifndef __BLE_RADIO_H__
ktownsend 0:ace2e8d3ce79 18 #define __BLE_RADIO_H__
ktownsend 0:ace2e8d3ce79 19
ktownsend 0:ace2e8d3ce79 20 #include "blecommon.h"
ktownsend 2:ffc5216bd2cc 21 #include "GattService.h"
ktownsend 2:ffc5216bd2cc 22 #include "GapAdvertisingData.h"
ktownsend 2:ffc5216bd2cc 23 #include "GapAdvertisingParams.h"
ktownsend 0:ace2e8d3ce79 24
ktownsend 19:a6f33421746c 25 /**************************************************************************/
ktownsend 19:a6f33421746c 26 /*!
ktownsend 19:a6f33421746c 27 \brief
ktownsend 19:a6f33421746c 28 The base class used to abstract away BLE capable radio transceivers
ktownsend 19:a6f33421746c 29 or SOCs, to enable this BLE API to work with any radio transparently.
ktownsend 19:a6f33421746c 30 */
ktownsend 19:a6f33421746c 31 /**************************************************************************/
ktownsend 0:ace2e8d3ce79 32 class BLERadio
ktownsend 0:ace2e8d3ce79 33 {
ktownsend 2:ffc5216bd2cc 34 protected:
ktownsend 2:ffc5216bd2cc 35 FunctionPointer _callback_event;
ktownsend 2:ffc5216bd2cc 36
ktownsend 0:ace2e8d3ce79 37 public:
ktownsend 19:a6f33421746c 38 /******************************************************************/
ktownsend 19:a6f33421746c 39 /*!
ktownsend 19:a6f33421746c 40 \brief
ktownsend 19:a6f33421746c 41 Identifies events generated by the radio HW when an event
ktownsend 19:a6f33421746c 42 callback occurs
ktownsend 19:a6f33421746c 43 */
ktownsend 19:a6f33421746c 44 /******************************************************************/
ktownsend 0:ace2e8d3ce79 45 typedef enum radio_event_e
ktownsend 0:ace2e8d3ce79 46 {
ktownsend 19:a6f33421746c 47 RADIO_EVENT_CONNECT = 0x01, /**< A BLE connection was established by the radio */
ktownsend 19:a6f33421746c 48 RADIO_EVENT_DISCONNECT = 0x02, /**< The BLE device was disconnected */
ktownsend 19:a6f33421746c 49 RADIO_EVENT_WRITE = 0x03, /**< A BLE write request occured */
ktownsend 19:a6f33421746c 50 RADIO_EVENT_RADIOERROR = 0x80 /**< A low level error occured on the radio */
ktownsend 0:ace2e8d3ce79 51 } radioEvent_t;
ktownsend 0:ace2e8d3ce79 52
ktownsend 0:ace2e8d3ce79 53 uint8_t serviceCount;
ktownsend 23:f19c60478e1b 54 uint8_t characteristicCount;
ktownsend 23:f19c60478e1b 55
ktownsend 0:ace2e8d3ce79 56 /* ToDo: Force constructor with event handler callback */
ktownsend 0:ace2e8d3ce79 57
ktownsend 0:ace2e8d3ce79 58 /* These functions must be defined in the sub-class */
ktownsend 7:5e1f0d7f7c7d 59 virtual ble_error_t setAdvertising(GapAdvertisingParams &, GapAdvertisingData &, GapAdvertisingData &) = 0;
ktownsend 2:ffc5216bd2cc 60 virtual ble_error_t addService(GattService &) = 0;
ktownsend 23:f19c60478e1b 61 virtual ble_error_t readCharacteristic(uint8_t, uint8_t[], uint16_t) = 0;
ktownsend 23:f19c60478e1b 62 virtual ble_error_t writeCharacteristic(uint8_t, uint8_t[], uint16_t) = 0;
ktownsend 0:ace2e8d3ce79 63 virtual ble_error_t start(void) = 0;
ktownsend 0:ace2e8d3ce79 64 virtual ble_error_t stop(void) = 0;
ktownsend 0:ace2e8d3ce79 65 virtual ble_error_t reset(void) = 0;
ktownsend 2:ffc5216bd2cc 66
ktownsend 2:ffc5216bd2cc 67 /* BLE event callback (connect, disconnect, etc.) */
ktownsend 2:ffc5216bd2cc 68 void attach(void (*function)(void)) {
ktownsend 2:ffc5216bd2cc 69 _callback_event.attach( function );
ktownsend 2:ffc5216bd2cc 70 }
ktownsend 2:ffc5216bd2cc 71
ktownsend 2:ffc5216bd2cc 72 template<typename T>
ktownsend 2:ffc5216bd2cc 73 void attach(T *object, void (T::*member)(void)) {
ktownsend 2:ffc5216bd2cc 74 _callback_event.attach( object, member );
ktownsend 2:ffc5216bd2cc 75 }
ktownsend 0:ace2e8d3ce79 76 };
ktownsend 0:ace2e8d3ce79 77
ktownsend 0:ace2e8d3ce79 78 #endif