My fork of X_NUCLEO_IDB0XA1
Fork of X_NUCLEO_IDB0XA1 by
Embed:
(wiki syntax)
Show/hide line numbers
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 ****************************************************************************** 00018 * @file BlueNRGGattServer.cpp 00019 * @author STMicroelectronics 00020 * @brief Header file for BLE_API GattServer Class 00021 ****************************************************************************** 00022 * @copy 00023 * 00024 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 00025 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 00026 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 00027 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 00028 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 00029 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 00030 * 00031 * <h2><center>© COPYRIGHT 2013 STMicroelectronics</center></h2> 00032 */ 00033 00034 #ifndef __BLUENRG_GATT_SERVER_H__ 00035 #define __BLUENRG_GATT_SERVER_H__ 00036 00037 #ifdef YOTTA_CFG_MBED_OS 00038 #include "mbed-drivers/mbed.h" 00039 #else 00040 #include "mbed.h" 00041 #endif 00042 #include "ble/blecommon.h" 00043 #include "btle.h" 00044 #include "ble/GattService.h" 00045 #include "ble/GattServer.h" 00046 #include <vector> 00047 #include <map> 00048 00049 #define BLE_TOTAL_CHARACTERISTICS 10 00050 00051 using namespace std; 00052 00053 class BlueNRGGattServer : public GattServer 00054 { 00055 public: 00056 static BlueNRGGattServer &getInstance() { 00057 static BlueNRGGattServer m_instance; 00058 return m_instance; 00059 } 00060 00061 enum HandleEnum_t { 00062 CHAR_HANDLE = 0, 00063 CHAR_VALUE_HANDLE, 00064 CHAR_DESC_HANDLE 00065 }; 00066 00067 /* Functions that must be implemented from GattServer */ 00068 virtual ble_error_t addService(GattService &); 00069 virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP); 00070 virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP); 00071 virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false); 00072 virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t[], uint16_t, bool localOnly = false); 00073 virtual ble_error_t initializeGATTDatabase(void); 00074 00075 virtual bool isOnDataReadAvailable() const { 00076 return true; 00077 } 00078 00079 virtual ble_error_t reset(void); 00080 00081 /* BlueNRG Functions */ 00082 void eventCallback(void); 00083 //void hwCallback(void *pckt); 00084 ble_error_t Read_Request_CB(uint16_t attributeHandle); 00085 uint8_t Write_Request_CB( 00086 uint16_t connection_handle, uint16_t attr_handle, 00087 uint8_t data_length, const uint8_t* data 00088 ); 00089 GattCharacteristic* getCharacteristicFromHandle(uint16_t charHandle); 00090 void HCIDataWrittenEvent(const GattWriteCallbackParams *params); 00091 void HCIDataReadEvent(const GattReadCallbackParams *params); 00092 void HCIEvent(GattServerEvents::gattEvent_e type, uint16_t charHandle); 00093 void HCIDataSentEvent(unsigned count); 00094 00095 private: 00096 00097 // compute the number of attribute record needed by a service 00098 static uint16_t computeAttributesRecord(GattService& service); 00099 00100 00101 static const int MAX_SERVICE_COUNT = 10; 00102 uint8_t serviceCount; 00103 uint8_t characteristicCount; 00104 uint16_t servHandle, charHandle; 00105 00106 std::map<uint16_t, uint16_t> bleCharHandleMap; // 1st argument is characteristic, 2nd argument is service 00107 GattCharacteristic *p_characteristics[BLE_TOTAL_CHARACTERISTICS]; 00108 uint16_t bleCharacteristicHandles[BLE_TOTAL_CHARACTERISTICS]; 00109 00110 BlueNRGGattServer() { 00111 serviceCount = 0; 00112 characteristicCount = 0; 00113 }; 00114 00115 BlueNRGGattServer(BlueNRGGattServer const &); 00116 void operator=(BlueNRGGattServer const &); 00117 00118 static const int CHAR_DESC_TYPE_16_BIT=0x01; 00119 static const int CHAR_DESC_TYPE_128_BIT=0x02; 00120 static const int CHAR_DESC_SECURITY_PERMISSION=0x00; 00121 static const int CHAR_DESC_ACCESS_PERMISSION=0x03; 00122 static const int CHAR_ATTRIBUTE_LEN_IS_FIXED=0x00; 00123 }; 00124 00125 #endif
Generated on Wed Jul 13 2022 03:04:51 by 1.7.2