BLE_API wrapper library for STMicroelectronics' BlueNRG Bluetooth Low Energy expansion board shield

Fork of X_NUCLEO_IDB0XA1 by ST Expansion SW Team

Committer:
Wolfgang Betz
Date:
Tue Oct 06 14:25:08 2015 +0200
Revision:
130:770ce14d3d15
Child:
131:e09947216ccb
Include mbed-classic version

Derived from
- repo (on Codex): gitolite@codex.cro.st.com:x-nucleodev/X-NUCLEO-IKC01A1-MBED.git
- branch: ble_wb
- SHA1 ID: 5ccc73e35868169e42132c0d1c056f908a6d70c0

Who changed what in which revision?

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