High level Bluetooth Low Energy API and radio abstraction layer

Dependencies:   nRF51822

Dependents:   LinkNode_LIS3DH

Fork of BLE_API by Bluetooth Low Energy

Committer:
bogdanm
Date:
Tue Apr 01 11:04:56 2014 +0100
Revision:
31:2c94f0501807
Parent:
27:4a83843f04b0
Child:
34:da2ea8cd6216
Synchronized with git revision fdcc1e387426ce216bc17175b73bcd5f4aececff

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 27:4a83843f04b0 1 /* mbed Microcontroller Library
ktownsend 27:4a83843f04b0 2 * Copyright (c) 2006-2013 ARM Limited
ktownsend 27:4a83843f04b0 3 *
ktownsend 27:4a83843f04b0 4 * Licensed under the Apache License, Version 2.0 (the "License");
ktownsend 27:4a83843f04b0 5 * you may not use this file except in compliance with the License.
ktownsend 27:4a83843f04b0 6 * You may obtain a copy of the License at
ktownsend 27:4a83843f04b0 7 *
ktownsend 27:4a83843f04b0 8 * http://www.apache.org/licenses/LICENSE-2.0
ktownsend 27:4a83843f04b0 9 *
ktownsend 27:4a83843f04b0 10 * Unless required by applicable law or agreed to in writing, software
ktownsend 27:4a83843f04b0 11 * distributed under the License is distributed on an "AS IS" BASIS,
ktownsend 27:4a83843f04b0 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ktownsend 27:4a83843f04b0 13 * See the License for the specific language governing permissions and
ktownsend 27:4a83843f04b0 14 * limitations under the License.
ktownsend 27:4a83843f04b0 15 */
ktownsend 27:4a83843f04b0 16
ktownsend 27:4a83843f04b0 17
ktownsend 2:ffc5216bd2cc 18 #include <stdio.h>
ktownsend 2:ffc5216bd2cc 19 #include <string.h>
ktownsend 2:ffc5216bd2cc 20
ktownsend 2:ffc5216bd2cc 21 #include "GattService.h"
ktownsend 2:ffc5216bd2cc 22
ktownsend 2:ffc5216bd2cc 23 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 24 /*!
ktownsend 2:ffc5216bd2cc 25 @brief Creates a new GattService using the specified 128-bit UUID
ktownsend 2:ffc5216bd2cc 26
ktownsend 2:ffc5216bd2cc 27 @note The UUID value must be unique on the device
ktownsend 2:ffc5216bd2cc 28
ktownsend 2:ffc5216bd2cc 29 @param[in] uuid
ktownsend 2:ffc5216bd2cc 30 The 16 byte (128-bit) UUID to use for this characteristic
ktownsend 2:ffc5216bd2cc 31
ktownsend 2:ffc5216bd2cc 32 @section EXAMPLE
ktownsend 2:ffc5216bd2cc 33
ktownsend 2:ffc5216bd2cc 34 @code
ktownsend 2:ffc5216bd2cc 35
ktownsend 2:ffc5216bd2cc 36 @endcode
ktownsend 2:ffc5216bd2cc 37 */
ktownsend 2:ffc5216bd2cc 38 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 39 GattService::GattService(uint8_t base_uuid[16])
ktownsend 2:ffc5216bd2cc 40 {
ktownsend 2:ffc5216bd2cc 41 primaryServiceID.update(base_uuid);
ktownsend 2:ffc5216bd2cc 42 characteristicCount = 0;
ktownsend 11:200931be5617 43 handle = 0;
ktownsend 2:ffc5216bd2cc 44 }
ktownsend 2:ffc5216bd2cc 45
ktownsend 2:ffc5216bd2cc 46 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 47 /*!
ktownsend 2:ffc5216bd2cc 48 @brief Creates a new GattService using the specified 16-bit BLE UUID
ktownsend 2:ffc5216bd2cc 49
ktownsend 2:ffc5216bd2cc 50 @param[in] ble_uuid
ktownsend 2:ffc5216bd2cc 51 The standardised 16-bit (2 byte) BLE UUID to use for this
ktownsend 2:ffc5216bd2cc 52 characteristic
ktownsend 2:ffc5216bd2cc 53
ktownsend 2:ffc5216bd2cc 54 @section EXAMPLE
ktownsend 2:ffc5216bd2cc 55
ktownsend 2:ffc5216bd2cc 56 @code
ktownsend 2:ffc5216bd2cc 57
ktownsend 2:ffc5216bd2cc 58 @endcode
ktownsend 2:ffc5216bd2cc 59 */
ktownsend 2:ffc5216bd2cc 60 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 61 GattService::GattService(uint16_t ble_uuid)
ktownsend 2:ffc5216bd2cc 62 {
ktownsend 2:ffc5216bd2cc 63 primaryServiceID.update( ble_uuid );
ktownsend 2:ffc5216bd2cc 64 characteristicCount = 0;
ktownsend 11:200931be5617 65 handle = 0;
ktownsend 2:ffc5216bd2cc 66 }
ktownsend 2:ffc5216bd2cc 67
ktownsend 2:ffc5216bd2cc 68 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 69 /*!
ktownsend 2:ffc5216bd2cc 70 @brief Destructor
ktownsend 2:ffc5216bd2cc 71 */
ktownsend 2:ffc5216bd2cc 72 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 73 GattService::~GattService(void)
ktownsend 2:ffc5216bd2cc 74 {
ktownsend 2:ffc5216bd2cc 75 }
ktownsend 2:ffc5216bd2cc 76
ktownsend 2:ffc5216bd2cc 77 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 78 /*!
ktownsend 23:f19c60478e1b 79 @brief Adds a GattCharacterisic to the service.
ktownsend 2:ffc5216bd2cc 80
ktownsend 23:f19c60478e1b 81 @note This function will not update the .handle field in the
ktownsend 23:f19c60478e1b 82 GattCharacteristic. This value is updated when the parent
ktownsend 23:f19c60478e1b 83 service is added via the radio driver.
ktownsend 2:ffc5216bd2cc 84
ktownsend 2:ffc5216bd2cc 85 @param[in] characteristic
ktownsend 2:ffc5216bd2cc 86 The GattCharacteristic object describing the characteristic
ktownsend 2:ffc5216bd2cc 87 to add to this service
ktownsend 2:ffc5216bd2cc 88
ktownsend 2:ffc5216bd2cc 89 @returns BLE_ERROR_NONE (0) if everything executed correctly, or an
ktownsend 2:ffc5216bd2cc 90 error code if there was a problem
ktownsend 2:ffc5216bd2cc 91 @retval BLE_ERROR_NONE
ktownsend 2:ffc5216bd2cc 92 Everything executed correctly
ktownsend 2:ffc5216bd2cc 93
ktownsend 2:ffc5216bd2cc 94 @section EXAMPLE
ktownsend 2:ffc5216bd2cc 95
ktownsend 2:ffc5216bd2cc 96 @code
ktownsend 2:ffc5216bd2cc 97
ktownsend 2:ffc5216bd2cc 98 @endcode
ktownsend 2:ffc5216bd2cc 99 */
ktownsend 2:ffc5216bd2cc 100 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 101 ble_error_t GattService::addCharacteristic(GattCharacteristic & characteristic)
ktownsend 2:ffc5216bd2cc 102 {
ktownsend 2:ffc5216bd2cc 103 /* ToDo: Make sure we don't overflow the array, etc. */
ktownsend 2:ffc5216bd2cc 104 /* ToDo: Make sure this characteristic UUID doesn't already exist */
ktownsend 2:ffc5216bd2cc 105 /* ToDo: Basic validation */
ktownsend 23:f19c60478e1b 106
bogdanm 31:2c94f0501807 107 characteristics[characteristicCount] = &characteristic;
ktownsend 2:ffc5216bd2cc 108 characteristicCount++;
ktownsend 2:ffc5216bd2cc 109
ktownsend 2:ffc5216bd2cc 110 return BLE_ERROR_NONE;
ktownsend 2:ffc5216bd2cc 111 }