BLE_API_Tiny_BLE

Dependents:   CSSE4011_BLE_IMU

Fork of BLE_API by Bluetooth Low Energy

Committer:
ktownsend
Date:
Tue Jan 07 19:58:06 2014 +0000
Revision:
23:f19c60478e1b
Parent:
11:200931be5617
Child:
27:4a83843f04b0
Added GattService example

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ktownsend 2:ffc5216bd2cc 1 #include <stdio.h>
ktownsend 2:ffc5216bd2cc 2 #include <string.h>
ktownsend 2:ffc5216bd2cc 3
ktownsend 2:ffc5216bd2cc 4 #include "GattService.h"
ktownsend 2:ffc5216bd2cc 5
ktownsend 2:ffc5216bd2cc 6 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 7 /*!
ktownsend 2:ffc5216bd2cc 8 @brief Creates a new GattService using the specified 128-bit UUID
ktownsend 2:ffc5216bd2cc 9
ktownsend 2:ffc5216bd2cc 10 @note The UUID value must be unique on the device
ktownsend 2:ffc5216bd2cc 11
ktownsend 2:ffc5216bd2cc 12 @param[in] uuid
ktownsend 2:ffc5216bd2cc 13 The 16 byte (128-bit) UUID to use for this characteristic
ktownsend 2:ffc5216bd2cc 14
ktownsend 2:ffc5216bd2cc 15 @section EXAMPLE
ktownsend 2:ffc5216bd2cc 16
ktownsend 2:ffc5216bd2cc 17 @code
ktownsend 2:ffc5216bd2cc 18
ktownsend 2:ffc5216bd2cc 19 @endcode
ktownsend 2:ffc5216bd2cc 20 */
ktownsend 2:ffc5216bd2cc 21 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 22 GattService::GattService(uint8_t base_uuid[16])
ktownsend 2:ffc5216bd2cc 23 {
ktownsend 2:ffc5216bd2cc 24 primaryServiceID.update(base_uuid);
ktownsend 2:ffc5216bd2cc 25 characteristicCount = 0;
ktownsend 11:200931be5617 26 handle = 0;
ktownsend 2:ffc5216bd2cc 27 }
ktownsend 2:ffc5216bd2cc 28
ktownsend 2:ffc5216bd2cc 29 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 30 /*!
ktownsend 2:ffc5216bd2cc 31 @brief Creates a new GattService using the specified 16-bit BLE UUID
ktownsend 2:ffc5216bd2cc 32
ktownsend 2:ffc5216bd2cc 33 @param[in] ble_uuid
ktownsend 2:ffc5216bd2cc 34 The standardised 16-bit (2 byte) BLE UUID to use for this
ktownsend 2:ffc5216bd2cc 35 characteristic
ktownsend 2:ffc5216bd2cc 36
ktownsend 2:ffc5216bd2cc 37 @section EXAMPLE
ktownsend 2:ffc5216bd2cc 38
ktownsend 2:ffc5216bd2cc 39 @code
ktownsend 2:ffc5216bd2cc 40
ktownsend 2:ffc5216bd2cc 41 @endcode
ktownsend 2:ffc5216bd2cc 42 */
ktownsend 2:ffc5216bd2cc 43 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 44 GattService::GattService(uint16_t ble_uuid)
ktownsend 2:ffc5216bd2cc 45 {
ktownsend 2:ffc5216bd2cc 46 primaryServiceID.update( ble_uuid );
ktownsend 2:ffc5216bd2cc 47 characteristicCount = 0;
ktownsend 11:200931be5617 48 handle = 0;
ktownsend 2:ffc5216bd2cc 49 }
ktownsend 2:ffc5216bd2cc 50
ktownsend 2:ffc5216bd2cc 51 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 52 /*!
ktownsend 2:ffc5216bd2cc 53 @brief Destructor
ktownsend 2:ffc5216bd2cc 54 */
ktownsend 2:ffc5216bd2cc 55 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 56 GattService::~GattService(void)
ktownsend 2:ffc5216bd2cc 57 {
ktownsend 2:ffc5216bd2cc 58 }
ktownsend 2:ffc5216bd2cc 59
ktownsend 2:ffc5216bd2cc 60 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 61 /*!
ktownsend 23:f19c60478e1b 62 @brief Adds a GattCharacterisic to the service.
ktownsend 2:ffc5216bd2cc 63
ktownsend 23:f19c60478e1b 64 @note This function will not update the .handle field in the
ktownsend 23:f19c60478e1b 65 GattCharacteristic. This value is updated when the parent
ktownsend 23:f19c60478e1b 66 service is added via the radio driver.
ktownsend 2:ffc5216bd2cc 67
ktownsend 2:ffc5216bd2cc 68 @param[in] characteristic
ktownsend 2:ffc5216bd2cc 69 The GattCharacteristic object describing the characteristic
ktownsend 2:ffc5216bd2cc 70 to add to this service
ktownsend 2:ffc5216bd2cc 71
ktownsend 2:ffc5216bd2cc 72 @returns BLE_ERROR_NONE (0) if everything executed correctly, or an
ktownsend 2:ffc5216bd2cc 73 error code if there was a problem
ktownsend 2:ffc5216bd2cc 74 @retval BLE_ERROR_NONE
ktownsend 2:ffc5216bd2cc 75 Everything executed correctly
ktownsend 2:ffc5216bd2cc 76
ktownsend 2:ffc5216bd2cc 77 @section EXAMPLE
ktownsend 2:ffc5216bd2cc 78
ktownsend 2:ffc5216bd2cc 79 @code
ktownsend 2:ffc5216bd2cc 80
ktownsend 2:ffc5216bd2cc 81 @endcode
ktownsend 2:ffc5216bd2cc 82 */
ktownsend 2:ffc5216bd2cc 83 /**************************************************************************/
ktownsend 2:ffc5216bd2cc 84 ble_error_t GattService::addCharacteristic(GattCharacteristic & characteristic)
ktownsend 2:ffc5216bd2cc 85 {
ktownsend 2:ffc5216bd2cc 86 /* ToDo: Make sure we don't overflow the array, etc. */
ktownsend 2:ffc5216bd2cc 87 /* ToDo: Make sure this characteristic UUID doesn't already exist */
ktownsend 2:ffc5216bd2cc 88 /* ToDo: Basic validation */
ktownsend 23:f19c60478e1b 89
ktownsend 23:f19c60478e1b 90 characteristics[characteristicCount] = characteristic;
ktownsend 2:ffc5216bd2cc 91 characteristicCount++;
ktownsend 2:ffc5216bd2cc 92
ktownsend 2:ffc5216bd2cc 93 return BLE_ERROR_NONE;
ktownsend 2:ffc5216bd2cc 94 }