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.
Dependents: Hello_BLE F446RE-BLE
Fork of X_NUCLEO_IDB0XA1 by
BlueNRGGattServer.h@77:332b416123b4, 2015-06-23 (annotated)
- Committer:
 - Andrea Palmieri 
 - Date:
 - Tue Jun 23 17:44:59 2015 +0200
 - Revision:
 - 77:332b416123b4
 - Parent:
 - 70:d20d30f59b1c
 - Child:
 - 88:579bd62b25ce
 
Update BLE_API and mbed Libs
- BLE_API Revision 713 corresponding to github Release 0.4.0 (commit d80fec885c)
- mbed Revision 101
Signed-off-by: Andrea Palmieri <andrea.palmieri@st.com>
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 1 | /* mbed Microcontroller Library | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 2 | * Copyright (c) 2006-2013 ARM Limited | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 3 | * | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 5 | * you may not use this file except in compliance with the License. | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 6 | * You may obtain a copy of the License at | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 7 | * | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 8 | * http://www.apache.org/licenses/LICENSE-2.0 | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 9 | * | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 10 | * Unless required by applicable law or agreed to in writing, software | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 11 | * distributed under the License is distributed on an "AS IS" BASIS, | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 13 | * See the License for the specific language governing permissions and | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 14 | * limitations under the License. | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 15 | */ | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 16 | /** | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 17 | ****************************************************************************** | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 18 | * @file BlueNRGGattServer.cpp | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 19 | * @author STMicroelectronics | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 20 | * @brief Header file for BLE_API GattServer Class | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 21 | ****************************************************************************** | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 22 | * @copy | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 23 | * | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 24 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 25 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 26 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 27 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 28 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 29 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 30 | * | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 31 | * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 32 | */ | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 33 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 34 | // ANDREA: Changed some types (e.g., tHalUint8 --> uint8_t) | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 35 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 36 | #ifndef __BLUENRG_GATT_SERVER_H__ | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 37 | #define __BLUENRG_GATT_SERVER_H__ | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 38 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 39 | #include "mbed.h" | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 40 | #include "blecommon.h" | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 41 | #include "btle.h" | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 42 | #include "GattService.h" | 
| Andrea Palmieri  | 
77:332b416123b4 | 43 | #include "ble/GattServer.h" | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 44 | #include <vector> | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 45 | #include <map> | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 46 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 47 | #define BLE_TOTAL_CHARACTERISTICS 10 | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 48 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 49 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 50 | using namespace std; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 51 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 52 | class BlueNRGGattServer : public GattServer | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 53 | { | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 54 | public: | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 55 | static BlueNRGGattServer &getInstance() { | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 56 | static BlueNRGGattServer m_instance; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 57 | return m_instance; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 58 | } | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 59 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 60 | /* Functions that must be implemented from GattServer */ | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 61 | // <<<ANDREA>>> | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 62 | virtual ble_error_t addService(GattService &); | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 63 | virtual ble_error_t readValue(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP); | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 64 | virtual ble_error_t readValue(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP); | 
| Andrea Palmieri  | 
77:332b416123b4 | 65 | virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false); | 
| Andrea Palmieri  | 
77:332b416123b4 | 66 | virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false); | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 67 | virtual ble_error_t initializeGATTDatabase(void); | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 68 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 69 | virtual bool isOnDataReadAvailable() const { | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 70 | return true; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 71 | } | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 72 | // <<<ANDREA>>> | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 73 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 74 | /* BlueNRG Functions */ | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 75 | void eventCallback(void); | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 76 | //void hwCallback(void *pckt); | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 77 | ble_error_t Read_Request_CB(uint16_t handle); | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 78 | GattCharacteristic* getCharacteristicFromHandle(uint16_t charHandle); | 
| Andrea Palmieri  | 
77:332b416123b4 | 79 | void HCIDataWrittenEvent(const GattWriteCallbackParams *params); | 
| Andrea Palmieri  | 
77:332b416123b4 | 80 | void HCIDataReadEvent(const GattReadCallbackParams *params); | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 81 | void HCIEvent(GattServerEvents::gattEvent_e type, uint16_t charHandle); | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 82 | void HCIDataSentEvent(unsigned count); | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 83 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 84 | private: | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 85 | static const int MAX_SERVICE_COUNT = 10; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 86 | uint8_t serviceCount; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 87 | uint8_t characteristicCount; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 88 | uint16_t servHandle, charHandle; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 89 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 90 | std::map<uint16_t, uint16_t> bleCharHanldeMap; // 1st argument is characteristic, 2nd argument is service | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 91 | GattCharacteristic *p_characteristics[BLE_TOTAL_CHARACTERISTICS]; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 92 | uint16_t bleCharacteristicHandles[BLE_TOTAL_CHARACTERISTICS]; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 93 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 94 | BlueNRGGattServer() { | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 95 | serviceCount = 0; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 96 | characteristicCount = 0; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 97 | }; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 98 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 99 | BlueNRGGattServer(BlueNRGGattServer const &); | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 100 | void operator=(BlueNRGGattServer const &); | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 101 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 102 | static const int CHAR_DESC_TYPE_16_BIT=0x01; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 103 | static const int CHAR_DESC_TYPE_128_BIT=0x02; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 104 | static const int CHAR_DESC_SECURITY_PERMISSION=0x00; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 105 | static const int CHAR_DESC_ACCESS_PERMISSION=0x03; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 106 | static const int CHAR_ATTRIBUTE_LEN_IS_FIXED=0x00; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 107 | }; | 
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 108 | |
| Silvio Lucio Oliva  | 
70:d20d30f59b1c | 109 | #endif | 
