BLE lib

Fork of Nucleo_BLE_BlueNRG by STM32 eKairn

Committer:
fbd38
Date:
Tue Jan 20 12:11:36 2015 +0000
Revision:
3:89230b3e003b
Parent:
0:a948f5f3904c
Updated with Write

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sjallouli 0:a948f5f3904c 1 /* mbed Microcontroller Library
sjallouli 0:a948f5f3904c 2 * Copyright (c) 2006-2013 ARM Limited
sjallouli 0:a948f5f3904c 3 *
sjallouli 0:a948f5f3904c 4 * Licensed under the Apache License, Version 2.0 (the "License");
sjallouli 0:a948f5f3904c 5 * you may not use this file except in compliance with the License.
sjallouli 0:a948f5f3904c 6 * You may obtain a copy of the License at
sjallouli 0:a948f5f3904c 7 *
sjallouli 0:a948f5f3904c 8 * http://www.apache.org/licenses/LICENSE-2.0
sjallouli 0:a948f5f3904c 9 *
sjallouli 0:a948f5f3904c 10 * Unless required by applicable law or agreed to in writing, software
sjallouli 0:a948f5f3904c 11 * distributed under the License is distributed on an "AS IS" BASIS,
sjallouli 0:a948f5f3904c 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
sjallouli 0:a948f5f3904c 13 * See the License for the specific language governing permissions and
sjallouli 0:a948f5f3904c 14 * limitations under the License.
sjallouli 0:a948f5f3904c 15 */
sjallouli 0:a948f5f3904c 16
sjallouli 0:a948f5f3904c 17 #ifndef __BLUENRG_GATT_SERVER_H__
sjallouli 0:a948f5f3904c 18 #define __BLUENRG_GATT_SERVER_H__
sjallouli 0:a948f5f3904c 19
sjallouli 0:a948f5f3904c 20 #include "mbed.h"
sjallouli 0:a948f5f3904c 21 #include "blecommon.h"
sjallouli 0:a948f5f3904c 22 #include "btle.h"
sjallouli 0:a948f5f3904c 23 #include "GattService.h"
fbd38 3:89230b3e003b 24 #include "GattAttribute.h"
sjallouli 0:a948f5f3904c 25 #include "public/GattServer.h"
sjallouli 0:a948f5f3904c 26 #include <vector>
sjallouli 0:a948f5f3904c 27 #include <map>
sjallouli 0:a948f5f3904c 28
sjallouli 0:a948f5f3904c 29 #define BLE_TOTAL_CHARACTERISTICS 10
sjallouli 0:a948f5f3904c 30
sjallouli 0:a948f5f3904c 31
sjallouli 0:a948f5f3904c 32 using namespace std;
sjallouli 0:a948f5f3904c 33
sjallouli 0:a948f5f3904c 34 class BlueNRGGattServer : public GattServer
sjallouli 0:a948f5f3904c 35 {
sjallouli 0:a948f5f3904c 36 public:
sjallouli 0:a948f5f3904c 37 static BlueNRGGattServer &getInstance() {
sjallouli 0:a948f5f3904c 38 static BlueNRGGattServer m_instance;
sjallouli 0:a948f5f3904c 39 return m_instance;
sjallouli 0:a948f5f3904c 40 }
sjallouli 0:a948f5f3904c 41
sjallouli 0:a948f5f3904c 42 /* Functions that must be implemented from GattServer */
sjallouli 0:a948f5f3904c 43 virtual ble_error_t addService(GattService &);
sjallouli 0:a948f5f3904c 44 virtual ble_error_t readValue(uint16_t handle, uint8_t buffer[], uint16_t *const lengthP);
sjallouli 0:a948f5f3904c 45 virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false);
sjallouli 0:a948f5f3904c 46
sjallouli 0:a948f5f3904c 47 /* BlueNRG Functions */
sjallouli 0:a948f5f3904c 48 void eventCallback(void);
sjallouli 0:a948f5f3904c 49 //void hwCallback(void *pckt);
sjallouli 0:a948f5f3904c 50 ble_error_t Read_Request_CB(tHalUint16 handle);
sjallouli 0:a948f5f3904c 51 GattCharacteristic* getCharacteristicFromHandle(tHalUint16 charHandle);
sjallouli 0:a948f5f3904c 52
sjallouli 0:a948f5f3904c 53 private:
sjallouli 0:a948f5f3904c 54 static const int MAX_SERVICE_COUNT = 10;
sjallouli 0:a948f5f3904c 55 uint8_t serviceCount;
sjallouli 0:a948f5f3904c 56 uint8_t characteristicCount;
sjallouli 0:a948f5f3904c 57 tHalUint16 servHandle, charHandle;
sjallouli 0:a948f5f3904c 58
sjallouli 0:a948f5f3904c 59 std::map<tHalUint16, tHalUint16> bleCharHanldeMap; // 1st argument is characteristic, 2nd argument is service
sjallouli 0:a948f5f3904c 60 GattCharacteristic *p_characteristics[BLE_TOTAL_CHARACTERISTICS];
sjallouli 0:a948f5f3904c 61 tHalUint16 bleCharacteristicHandles[BLE_TOTAL_CHARACTERISTICS];
sjallouli 0:a948f5f3904c 62
sjallouli 0:a948f5f3904c 63 BlueNRGGattServer() {
sjallouli 0:a948f5f3904c 64 serviceCount = 0;
sjallouli 0:a948f5f3904c 65 characteristicCount = 0;
sjallouli 0:a948f5f3904c 66 };
sjallouli 0:a948f5f3904c 67
sjallouli 0:a948f5f3904c 68 BlueNRGGattServer(BlueNRGGattServer const &);
sjallouli 0:a948f5f3904c 69 void operator=(BlueNRGGattServer const &);
sjallouli 0:a948f5f3904c 70
sjallouli 0:a948f5f3904c 71 static const int CHAR_DESC_TYPE_16_BIT=0x01;
sjallouli 0:a948f5f3904c 72 static const int CHAR_DESC_TYPE_128_BIT=0x02;
sjallouli 0:a948f5f3904c 73 static const int CHAR_DESC_SECURITY_PERMISSION=0x00;
sjallouli 0:a948f5f3904c 74 static const int CHAR_DESC_ACCESS_PERMISSION=0x03;
sjallouli 0:a948f5f3904c 75 static const int CHAR_ATTRIBUTE_LEN_IS_FIXED=0x00;
sjallouli 0:a948f5f3904c 76 };
sjallouli 0:a948f5f3904c 77
sjallouli 0:a948f5f3904c 78 #endif