Previous version which works for my stm32f401 Nucleo board

Fork of X_NUCLEO_IDB0XA1 by ST

Committer:
apalmieri
Date:
Mon Jul 27 11:10:19 2015 +0000
Revision:
97:a89d28ad6092
Parent:
90:26c0c9807ab4
Child:
98:731050bb5362
Fix bug on searching Char by handle

Who changed what in which revision?

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