Fork of BlueNRG library to be compatible with bluetooth demo application

Dependents:   Nucleo_BLE_Demo Nucleo_BLE_Demo

Fork of Nucleo_BLE_BlueNRG by ST Americas mbed Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers BlueNRGGattServer.h Source File

BlueNRGGattServer.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 __BLUENRG_GATT_SERVER_H__
00018 #define __BLUENRG_GATT_SERVER_H__
00019 
00020 #include "mbed.h"
00021 #include "blecommon.h"
00022 #include "btle.h"
00023 #include "GattService.h"
00024 #include "public/GattServer.h"
00025 #include <vector>
00026 #include <map>
00027 
00028 #define BLE_TOTAL_CHARACTERISTICS 24
00029 
00030 
00031 using namespace std;
00032 
00033 class BlueNRGGattServer : public GattServer
00034 {
00035 public:
00036     static BlueNRGGattServer &getInstance() {
00037         static BlueNRGGattServer m_instance;
00038         return m_instance;
00039     }
00040     
00041     /* Functions that must be implemented from GattServer */
00042     virtual ble_error_t addService(GattService &);
00043     virtual ble_error_t readValue(uint16_t handle, uint8_t buffer[], uint16_t *const lengthP);
00044     virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false);
00045 
00046     /* BlueNRG Functions */
00047     void eventCallback(void);
00048     //void hwCallback(void *pckt);
00049     ble_error_t Read_Request_CB(tHalUint16 handle);
00050     GattCharacteristic* getCharacteristicFromHandle(tHalUint16 charHandle);
00051     
00052 private:
00053     static const int MAX_SERVICE_COUNT = 10;
00054     uint8_t serviceCount;
00055     uint8_t characteristicCount;
00056     tHalUint16 servHandle, charHandle;
00057 
00058     std::map<tHalUint16, tHalUint16> bleCharHanldeMap;  // 1st argument is characteristic, 2nd argument is service
00059     GattCharacteristic *p_characteristics[BLE_TOTAL_CHARACTERISTICS];
00060     tHalUint16 bleCharacteristicHandles[BLE_TOTAL_CHARACTERISTICS];
00061 
00062     BlueNRGGattServer() {
00063         serviceCount = 0;
00064         characteristicCount = 0;
00065     };
00066 
00067     BlueNRGGattServer(BlueNRGGattServer const &);
00068     void operator=(BlueNRGGattServer const &);
00069     
00070     static const int CHAR_DESC_TYPE_16_BIT=0x01; 
00071     static const int CHAR_DESC_TYPE_128_BIT=0x02;    
00072     static const int CHAR_DESC_SECURITY_PERMISSION=0x00;
00073     static const int CHAR_DESC_ACCESS_PERMISSION=0x03;  
00074     static const int CHAR_ATTRIBUTE_LEN_IS_FIXED=0x00;        
00075 };
00076 
00077 #endif