BLE_API_Tiny_BLE
Fork of BLE_API by
GattService.cpp@69:2fd349295d2c, 2014-06-05 (annotated)
- Committer:
- Rohit Grover
- Date:
- Thu Jun 05 10:36:50 2014 +0100
- Revision:
- 69:2fd349295d2c
- Parent:
- 67:0fac4e99f29b
- Child:
- 90:f245e2d96aa0
simplified GattService constructor to take a UUID directly
This removes the duplicate constructors taking differing forms of UUID.
Who changed what in which revision?
User | Revision | Line number | New 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 | */ |
Rohit Grover |
34:da2ea8cd6216 | 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 |
Rohit Grover |
34:da2ea8cd6216 | 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 |
Rohit Grover |
34:da2ea8cd6216 | 35 | |
ktownsend | 2:ffc5216bd2cc | 36 | @endcode |
ktownsend | 2:ffc5216bd2cc | 37 | */ |
ktownsend | 2:ffc5216bd2cc | 38 | /**************************************************************************/ |
Rohit Grover |
69:2fd349295d2c | 39 | GattService::GattService(UUID uuid) : |
Rohit Grover |
69:2fd349295d2c | 40 | primaryServiceID(uuid), |
Rohit Grover |
53:a1bec483c8e3 | 41 | characteristicCount(0), |
Rohit Grover |
53:a1bec483c8e3 | 42 | characteristics(), |
Rohit Grover |
53:a1bec483c8e3 | 43 | handle(0) |
ktownsend | 2:ffc5216bd2cc | 44 | { |
Rohit Grover |
53:a1bec483c8e3 | 45 | /* empty */ |
ktownsend | 2:ffc5216bd2cc | 46 | } |
ktownsend | 2:ffc5216bd2cc | 47 | |
ktownsend | 2:ffc5216bd2cc | 48 | /**************************************************************************/ |
ktownsend | 2:ffc5216bd2cc | 49 | /*! |
ktownsend | 2:ffc5216bd2cc | 50 | @brief Destructor |
ktownsend | 2:ffc5216bd2cc | 51 | */ |
ktownsend | 2:ffc5216bd2cc | 52 | /**************************************************************************/ |
ktownsend | 2:ffc5216bd2cc | 53 | GattService::~GattService(void) |
ktownsend | 2:ffc5216bd2cc | 54 | { |
ktownsend | 2:ffc5216bd2cc | 55 | } |
ktownsend | 2:ffc5216bd2cc | 56 | |
ktownsend | 2:ffc5216bd2cc | 57 | /**************************************************************************/ |
ktownsend | 2:ffc5216bd2cc | 58 | /*! |
ktownsend | 23:f19c60478e1b | 59 | @brief Adds a GattCharacterisic to the service. |
Rohit Grover |
34:da2ea8cd6216 | 60 | |
ktownsend | 23:f19c60478e1b | 61 | @note This function will not update the .handle field in the |
ktownsend | 23:f19c60478e1b | 62 | GattCharacteristic. This value is updated when the parent |
Rohit Grover |
34:da2ea8cd6216 | 63 | service is added via the radio driver. |
ktownsend | 2:ffc5216bd2cc | 64 | |
ktownsend | 2:ffc5216bd2cc | 65 | @param[in] characteristic |
ktownsend | 2:ffc5216bd2cc | 66 | The GattCharacteristic object describing the characteristic |
ktownsend | 2:ffc5216bd2cc | 67 | to add to this service |
ktownsend | 2:ffc5216bd2cc | 68 | |
ktownsend | 2:ffc5216bd2cc | 69 | @returns BLE_ERROR_NONE (0) if everything executed correctly, or an |
ktownsend | 2:ffc5216bd2cc | 70 | error code if there was a problem |
ktownsend | 2:ffc5216bd2cc | 71 | @retval BLE_ERROR_NONE |
ktownsend | 2:ffc5216bd2cc | 72 | Everything executed correctly |
ktownsend | 2:ffc5216bd2cc | 73 | |
ktownsend | 2:ffc5216bd2cc | 74 | @section EXAMPLE |
ktownsend | 2:ffc5216bd2cc | 75 | |
ktownsend | 2:ffc5216bd2cc | 76 | @code |
Rohit Grover |
34:da2ea8cd6216 | 77 | |
ktownsend | 2:ffc5216bd2cc | 78 | @endcode |
ktownsend | 2:ffc5216bd2cc | 79 | */ |
ktownsend | 2:ffc5216bd2cc | 80 | /**************************************************************************/ |
ktownsend | 2:ffc5216bd2cc | 81 | ble_error_t GattService::addCharacteristic(GattCharacteristic & characteristic) |
ktownsend | 2:ffc5216bd2cc | 82 | { |
ktownsend | 2:ffc5216bd2cc | 83 | /* ToDo: Make sure we don't overflow the array, etc. */ |
ktownsend | 2:ffc5216bd2cc | 84 | /* ToDo: Make sure this characteristic UUID doesn't already exist */ |
ktownsend | 2:ffc5216bd2cc | 85 | /* ToDo: Basic validation */ |
ktownsend | 23:f19c60478e1b | 86 | |
bogdanm | 31:2c94f0501807 | 87 | characteristics[characteristicCount] = &characteristic; |
ktownsend | 2:ffc5216bd2cc | 88 | characteristicCount++; |
Rohit Grover |
34:da2ea8cd6216 | 89 | |
ktownsend | 2:ffc5216bd2cc | 90 | return BLE_ERROR_NONE; |
ktownsend | 2:ffc5216bd2cc | 91 | } |