Microbug / BLE_API

Fork of BLE_API by Bluetooth Low Energy

Revision:
27:4a83843f04b0
Parent:
23:f19c60478e1b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hw/BLERadio.h	Thu Jan 09 11:03:10 2014 +0000
@@ -0,0 +1,78 @@
+/* mbed Microcontroller Library
+ * Copyright (c) 2006-2013 ARM Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+  
+#ifndef __BLE_RADIO_H__
+#define __BLE_RADIO_H__
+
+#include "blecommon.h"
+#include "GattService.h"
+#include "GapAdvertisingData.h"
+#include "GapAdvertisingParams.h"
+
+/**************************************************************************/
+/*!
+    \brief
+    The base class used to abstract away BLE capable radio transceivers
+    or SOCs, to enable this BLE API to work with any radio transparently.
+*/
+/**************************************************************************/
+class BLERadio
+{
+    protected:
+        FunctionPointer _callback_event;
+        
+    public:
+        /******************************************************************/
+        /*!
+            \brief
+            Identifies events generated by the radio HW when an event
+            callback occurs
+        */
+        /******************************************************************/
+        typedef enum radio_event_e
+        {
+            RADIO_EVENT_CONNECT     = 0x01, /**< A BLE connection was established by the radio */
+            RADIO_EVENT_DISCONNECT  = 0x02, /**< The BLE device was disconnected */
+            RADIO_EVENT_WRITE       = 0x03, /**< A BLE write request occured */
+            RADIO_EVENT_RADIOERROR  = 0x80  /**< A low level error occured on the radio */
+        } radioEvent_t;
+        
+        uint8_t serviceCount;
+        uint8_t characteristicCount;
+
+        /* ToDo: Force constructor with event handler callback */
+
+        /* These functions must be defined in the sub-class */
+        virtual ble_error_t setAdvertising(GapAdvertisingParams &, GapAdvertisingData &, GapAdvertisingData &) = 0;
+        virtual ble_error_t addService(GattService &) = 0;
+        virtual ble_error_t readCharacteristic(uint8_t, uint8_t[], uint16_t) = 0;
+        virtual ble_error_t writeCharacteristic(uint8_t, uint8_t[], uint16_t) = 0;
+        virtual ble_error_t start(void) = 0;
+        virtual ble_error_t stop(void) = 0;
+        virtual ble_error_t reset(void) = 0;
+
+        /* BLE event callback (connect, disconnect, etc.) */
+        void attach(void (*function)(void)) { 
+            _callback_event.attach( function ); 
+        }
+ 
+        template<typename T>
+        void attach(T *object, void (T::*member)(void)) { 
+            _callback_event.attach( object, member );
+        }
+};
+
+#endif