Compatible with Keewi v1
Fork of BLE_API by
GattService.cpp@68:dcadab8a56dd, 2014-06-05 (annotated)
- Committer:
- Rohit Grover
- Date:
- Thu Jun 05 08:52:20 2014 +0100
- Revision:
- 68:dcadab8a56dd
- Parent:
- 67:0fac4e99f29b
- Child:
- 69:2fd349295d2c
white space diffs
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 |
67:0fac4e99f29b | 39 | GattService::GattService(const LongUUID_t base_uuid) : |
Rohit Grover |
53:a1bec483c8e3 | 40 | primaryServiceID(base_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 Creates a new GattService using the specified 16-bit BLE UUID |
Rohit Grover |
34:da2ea8cd6216 | 51 | |
ktownsend | 2:ffc5216bd2cc | 52 | @param[in] ble_uuid |
ktownsend | 2:ffc5216bd2cc | 53 | The standardised 16-bit (2 byte) BLE UUID to use for this |
ktownsend | 2:ffc5216bd2cc | 54 | characteristic |
ktownsend | 2:ffc5216bd2cc | 55 | |
ktownsend | 2:ffc5216bd2cc | 56 | @section EXAMPLE |
ktownsend | 2:ffc5216bd2cc | 57 | |
ktownsend | 2:ffc5216bd2cc | 58 | @code |
Rohit Grover |
34:da2ea8cd6216 | 59 | |
ktownsend | 2:ffc5216bd2cc | 60 | @endcode |
ktownsend | 2:ffc5216bd2cc | 61 | */ |
ktownsend | 2:ffc5216bd2cc | 62 | /**************************************************************************/ |
Rohit Grover |
53:a1bec483c8e3 | 63 | GattService::GattService(uint16_t ble_uuid) : |
Rohit Grover |
53:a1bec483c8e3 | 64 | primaryServiceID(ble_uuid), |
Rohit Grover |
53:a1bec483c8e3 | 65 | characteristicCount(0), |
Rohit Grover |
53:a1bec483c8e3 | 66 | characteristics(), |
Rohit Grover |
53:a1bec483c8e3 | 67 | handle(0) |
ktownsend | 2:ffc5216bd2cc | 68 | { |
ktownsend | 2:ffc5216bd2cc | 69 | } |
ktownsend | 2:ffc5216bd2cc | 70 | |
ktownsend | 2:ffc5216bd2cc | 71 | /**************************************************************************/ |
ktownsend | 2:ffc5216bd2cc | 72 | /*! |
ktownsend | 2:ffc5216bd2cc | 73 | @brief Destructor |
ktownsend | 2:ffc5216bd2cc | 74 | */ |
ktownsend | 2:ffc5216bd2cc | 75 | /**************************************************************************/ |
ktownsend | 2:ffc5216bd2cc | 76 | GattService::~GattService(void) |
ktownsend | 2:ffc5216bd2cc | 77 | { |
ktownsend | 2:ffc5216bd2cc | 78 | } |
ktownsend | 2:ffc5216bd2cc | 79 | |
ktownsend | 2:ffc5216bd2cc | 80 | /**************************************************************************/ |
ktownsend | 2:ffc5216bd2cc | 81 | /*! |
ktownsend | 23:f19c60478e1b | 82 | @brief Adds a GattCharacterisic to the service. |
Rohit Grover |
34:da2ea8cd6216 | 83 | |
ktownsend | 23:f19c60478e1b | 84 | @note This function will not update the .handle field in the |
ktownsend | 23:f19c60478e1b | 85 | GattCharacteristic. This value is updated when the parent |
Rohit Grover |
34:da2ea8cd6216 | 86 | service is added via the radio driver. |
ktownsend | 2:ffc5216bd2cc | 87 | |
ktownsend | 2:ffc5216bd2cc | 88 | @param[in] characteristic |
ktownsend | 2:ffc5216bd2cc | 89 | The GattCharacteristic object describing the characteristic |
ktownsend | 2:ffc5216bd2cc | 90 | to add to this service |
ktownsend | 2:ffc5216bd2cc | 91 | |
ktownsend | 2:ffc5216bd2cc | 92 | @returns BLE_ERROR_NONE (0) if everything executed correctly, or an |
ktownsend | 2:ffc5216bd2cc | 93 | error code if there was a problem |
ktownsend | 2:ffc5216bd2cc | 94 | @retval BLE_ERROR_NONE |
ktownsend | 2:ffc5216bd2cc | 95 | Everything executed correctly |
ktownsend | 2:ffc5216bd2cc | 96 | |
ktownsend | 2:ffc5216bd2cc | 97 | @section EXAMPLE |
ktownsend | 2:ffc5216bd2cc | 98 | |
ktownsend | 2:ffc5216bd2cc | 99 | @code |
Rohit Grover |
34:da2ea8cd6216 | 100 | |
ktownsend | 2:ffc5216bd2cc | 101 | @endcode |
ktownsend | 2:ffc5216bd2cc | 102 | */ |
ktownsend | 2:ffc5216bd2cc | 103 | /**************************************************************************/ |
ktownsend | 2:ffc5216bd2cc | 104 | ble_error_t GattService::addCharacteristic(GattCharacteristic & characteristic) |
ktownsend | 2:ffc5216bd2cc | 105 | { |
ktownsend | 2:ffc5216bd2cc | 106 | /* ToDo: Make sure we don't overflow the array, etc. */ |
ktownsend | 2:ffc5216bd2cc | 107 | /* ToDo: Make sure this characteristic UUID doesn't already exist */ |
ktownsend | 2:ffc5216bd2cc | 108 | /* ToDo: Basic validation */ |
ktownsend | 23:f19c60478e1b | 109 | |
bogdanm | 31:2c94f0501807 | 110 | characteristics[characteristicCount] = &characteristic; |
ktownsend | 2:ffc5216bd2cc | 111 | characteristicCount++; |
Rohit Grover |
34:da2ea8cd6216 | 112 | |
ktownsend | 2:ffc5216bd2cc | 113 | return BLE_ERROR_NONE; |
ktownsend | 2:ffc5216bd2cc | 114 | } |