Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Nucleo_BLE_BlueNRG by
BlueNRGGattServer.h@3:104f1bba39ca, 2016-01-03 (annotated)
- Committer:
- sjallouli
- Date:
- Sun Jan 03 16:05:38 2016 +0000
- Revision:
- 3:104f1bba39ca
- Parent:
- 0:a948f5f3904c
test
Who changed what in which revision?
| User | Revision | Line number | New 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" |
| sjallouli | 0:a948f5f3904c | 24 | #include "public/GattServer.h" |
| sjallouli | 0:a948f5f3904c | 25 | #include <vector> |
| sjallouli | 0:a948f5f3904c | 26 | #include <map> |
| sjallouli | 0:a948f5f3904c | 27 | |
| sjallouli | 0:a948f5f3904c | 28 | #define BLE_TOTAL_CHARACTERISTICS 10 |
| sjallouli | 0:a948f5f3904c | 29 | |
| sjallouli | 0:a948f5f3904c | 30 | |
| sjallouli | 0:a948f5f3904c | 31 | using namespace std; |
| sjallouli | 0:a948f5f3904c | 32 | |
| sjallouli | 0:a948f5f3904c | 33 | class BlueNRGGattServer : public GattServer |
| sjallouli | 0:a948f5f3904c | 34 | { |
| sjallouli | 0:a948f5f3904c | 35 | public: |
| sjallouli | 0:a948f5f3904c | 36 | static BlueNRGGattServer &getInstance() { |
| sjallouli | 0:a948f5f3904c | 37 | static BlueNRGGattServer m_instance; |
| sjallouli | 0:a948f5f3904c | 38 | return m_instance; |
| sjallouli | 0:a948f5f3904c | 39 | } |
| sjallouli | 0:a948f5f3904c | 40 | |
| sjallouli | 0:a948f5f3904c | 41 | /* Functions that must be implemented from GattServer */ |
| sjallouli | 0:a948f5f3904c | 42 | virtual ble_error_t addService(GattService &); |
| sjallouli | 0:a948f5f3904c | 43 | virtual ble_error_t readValue(uint16_t handle, uint8_t buffer[], uint16_t *const lengthP); |
| sjallouli | 0:a948f5f3904c | 44 | virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false); |
| sjallouli | 0:a948f5f3904c | 45 | |
| sjallouli | 0:a948f5f3904c | 46 | /* BlueNRG Functions */ |
| sjallouli | 0:a948f5f3904c | 47 | void eventCallback(void); |
| sjallouli | 0:a948f5f3904c | 48 | //void hwCallback(void *pckt); |
| sjallouli | 0:a948f5f3904c | 49 | ble_error_t Read_Request_CB(tHalUint16 handle); |
| sjallouli | 0:a948f5f3904c | 50 | GattCharacteristic* getCharacteristicFromHandle(tHalUint16 charHandle); |
| sjallouli | 0:a948f5f3904c | 51 | |
| sjallouli | 0:a948f5f3904c | 52 | private: |
| sjallouli | 0:a948f5f3904c | 53 | static const int MAX_SERVICE_COUNT = 10; |
| sjallouli | 0:a948f5f3904c | 54 | uint8_t serviceCount; |
| sjallouli | 0:a948f5f3904c | 55 | uint8_t characteristicCount; |
| sjallouli | 0:a948f5f3904c | 56 | tHalUint16 servHandle, charHandle; |
| sjallouli | 0:a948f5f3904c | 57 | |
| sjallouli | 0:a948f5f3904c | 58 | std::map<tHalUint16, tHalUint16> bleCharHanldeMap; // 1st argument is characteristic, 2nd argument is service |
| sjallouli | 0:a948f5f3904c | 59 | GattCharacteristic *p_characteristics[BLE_TOTAL_CHARACTERISTICS]; |
| sjallouli | 0:a948f5f3904c | 60 | tHalUint16 bleCharacteristicHandles[BLE_TOTAL_CHARACTERISTICS]; |
| sjallouli | 0:a948f5f3904c | 61 | |
| sjallouli | 0:a948f5f3904c | 62 | BlueNRGGattServer() { |
| sjallouli | 0:a948f5f3904c | 63 | serviceCount = 0; |
| sjallouli | 0:a948f5f3904c | 64 | characteristicCount = 0; |
| sjallouli | 0:a948f5f3904c | 65 | }; |
| sjallouli | 0:a948f5f3904c | 66 | |
| sjallouli | 0:a948f5f3904c | 67 | BlueNRGGattServer(BlueNRGGattServer const &); |
| sjallouli | 0:a948f5f3904c | 68 | void operator=(BlueNRGGattServer const &); |
| sjallouli | 0:a948f5f3904c | 69 | |
| sjallouli | 0:a948f5f3904c | 70 | static const int CHAR_DESC_TYPE_16_BIT=0x01; |
| sjallouli | 0:a948f5f3904c | 71 | static const int CHAR_DESC_TYPE_128_BIT=0x02; |
| sjallouli | 0:a948f5f3904c | 72 | static const int CHAR_DESC_SECURITY_PERMISSION=0x00; |
| sjallouli | 0:a948f5f3904c | 73 | static const int CHAR_DESC_ACCESS_PERMISSION=0x03; |
| sjallouli | 0:a948f5f3904c | 74 | static const int CHAR_ATTRIBUTE_LEN_IS_FIXED=0x00; |
| sjallouli | 0:a948f5f3904c | 75 | }; |
| sjallouli | 0:a948f5f3904c | 76 | |
| sjallouli | 0:a948f5f3904c | 77 | #endif |
