Previous version which works for my stm32f401 Nucleo board
Fork of X_NUCLEO_IDB0XA1 by
BlueNRGGattServer.h@55:0e4db6804c8d, 2014-10-01 (annotated)
- Committer:
- hemddabral
- Date:
- Wed Oct 01 08:49:52 2014 +0000
- Revision:
- 55:0e4db6804c8d
- Parent:
- 53:8c10d592ca49
- Child:
- 58:027c65a54097
added support for BLE_API version 116 (WIP)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mridup | 2:a2b623661316 | 1 | /* mbed Microcontroller Library |
mridup | 2:a2b623661316 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mridup | 2:a2b623661316 | 3 | * |
mridup | 2:a2b623661316 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mridup | 2:a2b623661316 | 5 | * you may not use this file except in compliance with the License. |
mridup | 2:a2b623661316 | 6 | * You may obtain a copy of the License at |
mridup | 2:a2b623661316 | 7 | * |
mridup | 2:a2b623661316 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mridup | 2:a2b623661316 | 9 | * |
mridup | 2:a2b623661316 | 10 | * Unless required by applicable law or agreed to in writing, software |
mridup | 2:a2b623661316 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mridup | 2:a2b623661316 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mridup | 2:a2b623661316 | 13 | * See the License for the specific language governing permissions and |
mridup | 2:a2b623661316 | 14 | * limitations under the License. |
mridup | 2:a2b623661316 | 15 | */ |
mridup | 2:a2b623661316 | 16 | |
mridup | 2:a2b623661316 | 17 | #ifndef __BLUENRG_GATT_SERVER_H__ |
mridup | 2:a2b623661316 | 18 | #define __BLUENRG_GATT_SERVER_H__ |
mridup | 2:a2b623661316 | 19 | |
mridup | 2:a2b623661316 | 20 | #include "mbed.h" |
mridup | 13:4c30346287e4 | 21 | #include "blecommon.h" |
mridup | 5:31dedfa19a12 | 22 | #include "btle.h" |
mridup | 2:a2b623661316 | 23 | #include "GattService.h" |
hemddabral | 33:96724af256a5 | 24 | #include "public/GattServer.h" |
hemddabral | 52:94638d2461c1 | 25 | #include <vector> |
hemddabral | 52:94638d2461c1 | 26 | #include <map> |
mridup | 2:a2b623661316 | 27 | |
mridup | 2:a2b623661316 | 28 | #define BLE_TOTAL_CHARACTERISTICS 10 |
mridup | 2:a2b623661316 | 29 | |
hemddabral | 53:8c10d592ca49 | 30 | |
hemddabral | 52:94638d2461c1 | 31 | using namespace std; |
hemddabral | 52:94638d2461c1 | 32 | |
mridup | 2:a2b623661316 | 33 | class BlueNRGGattServer : public GattServer |
mridup | 2:a2b623661316 | 34 | { |
mridup | 2:a2b623661316 | 35 | public: |
mridup | 2:a2b623661316 | 36 | static BlueNRGGattServer &getInstance() { |
mridup | 2:a2b623661316 | 37 | static BlueNRGGattServer m_instance; |
mridup | 2:a2b623661316 | 38 | return m_instance; |
mridup | 2:a2b623661316 | 39 | } |
hemddabral | 52:94638d2461c1 | 40 | |
hemddabral | 52:94638d2461c1 | 41 | /* Functions that must be implemented from GattServer */ |
mridup | 2:a2b623661316 | 42 | virtual ble_error_t addService(GattService &); |
mridup | 2:a2b623661316 | 43 | virtual ble_error_t readValue(uint16_t handle, uint8_t buffer[], uint16_t *const lengthP); |
mridup | 2:a2b623661316 | 44 | virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false); |
mridup | 2:a2b623661316 | 45 | |
mridup | 6:08cfc94b5f49 | 46 | /* BlueNRG Functions */ |
mridup | 2:a2b623661316 | 47 | void eventCallback(void); |
mridup | 6:08cfc94b5f49 | 48 | //void hwCallback(void *pckt); |
mridup | 26:047d45ea379e | 49 | ble_error_t Read_Request_CB(tHalUint16 handle); |
mridup | 27:b4c21a9e8b39 | 50 | GattCharacteristic* getCharacteristicFromHandle(tHalUint16 charHandle); |
mridup | 27:b4c21a9e8b39 | 51 | |
mridup | 2:a2b623661316 | 52 | private: |
hemddabral | 52:94638d2461c1 | 53 | static const int MAX_SERVICE_COUNT = 10; |
mridup | 2:a2b623661316 | 54 | uint8_t serviceCount; |
mridup | 2:a2b623661316 | 55 | uint8_t characteristicCount; |
hemddabral | 51:963982e7c17c | 56 | tHalUint16 servHandle, charHandle; |
hemddabral | 52:94638d2461c1 | 57 | |
hemddabral | 52:94638d2461c1 | 58 | std::map<tHalUint16, tHalUint16> bleCharHanldeMap; // 1st argument is characteristic, 2nd argument is service |
mridup | 2:a2b623661316 | 59 | GattCharacteristic *p_characteristics[BLE_TOTAL_CHARACTERISTICS]; |
mridup | 7:55ac052585db | 60 | tHalUint16 bleCharacteristicHandles[BLE_TOTAL_CHARACTERISTICS]; |
hemddabral | 55:0e4db6804c8d | 61 | |
mridup | 2:a2b623661316 | 62 | BlueNRGGattServer() { |
mridup | 2:a2b623661316 | 63 | serviceCount = 0; |
mridup | 2:a2b623661316 | 64 | characteristicCount = 0; |
mridup | 2:a2b623661316 | 65 | }; |
mridup | 2:a2b623661316 | 66 | |
mridup | 2:a2b623661316 | 67 | BlueNRGGattServer(BlueNRGGattServer const &); |
mridup | 2:a2b623661316 | 68 | void operator=(BlueNRGGattServer const &); |
hemddabral | 53:8c10d592ca49 | 69 | |
hemddabral | 53:8c10d592ca49 | 70 | static const int CHAR_DESC_TYPE_16_BIT=0x01; |
hemddabral | 53:8c10d592ca49 | 71 | static const int CHAR_DESC_TYPE_128_BIT=0x02; |
hemddabral | 53:8c10d592ca49 | 72 | static const int CHAR_DESC_SECURITY_PERMISSION=0x00; |
hemddabral | 53:8c10d592ca49 | 73 | static const int CHAR_DESC_ACCESS_PERMISSION=0x03; |
hemddabral | 53:8c10d592ca49 | 74 | static const int CHAR_ATTRIBUTE_LEN_IS_FIXED=0x00; |
mridup | 2:a2b623661316 | 75 | }; |
mridup | 2:a2b623661316 | 76 | |
mridup | 2:a2b623661316 | 77 | #endif |