fix all line endings to be Unix style

This commit is contained in:
Rohit Grover 2014-12-16 08:18:36 +00:00
parent 270ac8d7c5
commit bec9560c70
16 changed files with 1878 additions and 1878 deletions

View file

@ -1,38 +1,38 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "BLEDevice.h"
#if defined(TARGET_OTA_ENABLED)
#include "DFUService.h"
#endif
ble_error_t
BLEDevice::init()
{
ble_error_t err = transport->init();
if (err != BLE_ERROR_NONE) {
return err;
}
/* Platforms enabled for DFU should introduce the DFU Service into
* applications automatically. */
#if defined(TARGET_OTA_ENABLED)
static DFUService dfu(*this); // defined static so that the object remains alive
#endif // TARGET_OTA_ENABLED
return BLE_ERROR_NONE;
}
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "BLEDevice.h"
#if defined(TARGET_OTA_ENABLED)
#include "DFUService.h"
#endif
ble_error_t
BLEDevice::init()
{
ble_error_t err = transport->init();
if (err != BLE_ERROR_NONE) {
return err;
}
/* Platforms enabled for DFU should introduce the DFU Service into
* applications automatically. */
#if defined(TARGET_OTA_ENABLED)
static DFUService dfu(*this); // defined static so that the object remains alive
#endif // TARGET_OTA_ENABLED
return BLE_ERROR_NONE;
}

View file

@ -1,238 +1,238 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <string.h>
#include "GapAdvertisingData.h"
/**************************************************************************/
/*!
\brief Creates a new GapAdvertisingData instance
\par EXAMPLE
\code
\endcode
*/
/**************************************************************************/
GapAdvertisingData::GapAdvertisingData(void) : _payload(), _payloadLen(0), _appearance(GENERIC_TAG) {
/* empty */
}
/**************************************************************************/
/*!
Destructor
*/
/**************************************************************************/
GapAdvertisingData::~GapAdvertisingData(void)
{
}
/**************************************************************************/
/*!
\brief Adds advertising data based on the specified AD type (see
DataType)
\args[in] advDataType The Advertising 'DataType' to add
\args[in] payload Pointer to the payload contents
\args[in] len Size of the payload in bytes
\returns ble_error_t
\retval BLE_ERROR_NONE
Everything executed properly
\retval BLE_ERROR_BUFFER_OVERFLOW
The specified data would cause the advertising buffer
to overflow
\par EXAMPLE
\code
\endcode
*/
/**************************************************************************/
ble_error_t GapAdvertisingData::addData(DataType advDataType, const uint8_t *payload, uint8_t len)
{
/* ToDo: Check if an AD type already exists and if the existing */
/* value is exclusive or not (flags, etc.) */
/* Make sure we don't exceed the 31 byte payload limit */
if (_payloadLen + len + 2 > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
return BLE_ERROR_BUFFER_OVERFLOW;
}
/* Field length */
memset(&_payload[_payloadLen], len + 1, 1);
_payloadLen++;
/* Field ID */
memset(&_payload[_payloadLen], (uint8_t)advDataType, 1);
_payloadLen++;
/* Payload */
memcpy(&_payload[_payloadLen], payload, len);
_payloadLen += len;
return BLE_ERROR_NONE;
}
/**************************************************************************/
/*!
\brief Helper function to add APPEARANCE data to the advertising
payload
\args[in] appearance The APPEARANCE value to add
\returns ble_error_t
\retval BLE_ERROR_NONE
Everything executed properly
\retval BLE_ERROR_BUFFER_OVERFLOW
The specified data would cause the advertising buffer
to overflow
\par EXAMPLE
\code
\endcode
*/
/**************************************************************************/
ble_error_t GapAdvertisingData::addAppearance(Appearance appearance)
{
_appearance = appearance;
return addData(GapAdvertisingData::APPEARANCE, (uint8_t *)&appearance, 2);
}
/**************************************************************************/
/*!
\brief Helper function to add FLAGS data to the advertising
payload
\args[in] flag The FLAGS value to add
\par LE_LIMITED_DISCOVERABLE
The peripheral is discoverable for a limited period of
time
\par LE_GENERAL_DISCOVERABLE
The peripheral is permanently discoverable
\par BREDR_NOT_SUPPORTED
This peripheral is a Bluetooth Low Energy only device
(no EDR support)
\returns ble_error_t
\retval BLE_ERROR_NONE
Everything executed properly
\retval BLE_ERROR_BUFFER_OVERFLOW
The specified data would cause the advertising buffer
to overflow
\par EXAMPLE
\code
\endcode
*/
/**************************************************************************/
ble_error_t GapAdvertisingData::addFlags(uint8_t flags)
{
return addData(GapAdvertisingData::FLAGS, &flags, 1);
}
/**************************************************************************/
/*!
\brief Helper function to add TX_POWER_LEVEL data to the
advertising payload
\args[in] flag The TX_POWER_LEVEL value to add
\returns ble_error_t
\retval BLE_ERROR_NONE
Everything executed properly
\retval BLE_ERROR_BUFFER_OVERFLOW
The specified data would cause the advertising buffer
to overflow
\par EXAMPLE
\code
\endcode
*/
/**************************************************************************/
ble_error_t GapAdvertisingData::addTxPower(int8_t txPower)
{
/* ToDo: Basic error checking to make sure txPower is in range */
return addData(GapAdvertisingData::TX_POWER_LEVEL, (uint8_t *)&txPower, 1);
}
/**************************************************************************/
/*!
\brief Clears the payload and resets the payload length counter
*/
/**************************************************************************/
void GapAdvertisingData::clear(void)
{
memset(&_payload, 0, GAP_ADVERTISING_DATA_MAX_PAYLOAD);
_payloadLen = 0;
}
/**************************************************************************/
/*!
\brief Returns a pointer to the the current payload
\returns A pointer to the payload
*/
/**************************************************************************/
const uint8_t *GapAdvertisingData::getPayload(void) const
{
return (_payloadLen > 0) ? _payload : NULL;
}
/**************************************************************************/
/*!
\brief Returns the current payload length (0..31 bytes)
\returns The payload length in bytes
*/
/**************************************************************************/
uint8_t GapAdvertisingData::getPayloadLen(void) const
{
return _payloadLen;
}
/**************************************************************************/
/*!
\brief Returns the 16-bit appearance value for this device
\returns The 16-bit appearance value
*/
/**************************************************************************/
uint16_t GapAdvertisingData::getAppearance(void) const
{
return (uint16_t)_appearance;
}
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <string.h>
#include "GapAdvertisingData.h"
/**************************************************************************/
/*!
\brief Creates a new GapAdvertisingData instance
\par EXAMPLE
\code
\endcode
*/
/**************************************************************************/
GapAdvertisingData::GapAdvertisingData(void) : _payload(), _payloadLen(0), _appearance(GENERIC_TAG) {
/* empty */
}
/**************************************************************************/
/*!
Destructor
*/
/**************************************************************************/
GapAdvertisingData::~GapAdvertisingData(void)
{
}
/**************************************************************************/
/*!
\brief Adds advertising data based on the specified AD type (see
DataType)
\args[in] advDataType The Advertising 'DataType' to add
\args[in] payload Pointer to the payload contents
\args[in] len Size of the payload in bytes
\returns ble_error_t
\retval BLE_ERROR_NONE
Everything executed properly
\retval BLE_ERROR_BUFFER_OVERFLOW
The specified data would cause the advertising buffer
to overflow
\par EXAMPLE
\code
\endcode
*/
/**************************************************************************/
ble_error_t GapAdvertisingData::addData(DataType advDataType, const uint8_t *payload, uint8_t len)
{
/* ToDo: Check if an AD type already exists and if the existing */
/* value is exclusive or not (flags, etc.) */
/* Make sure we don't exceed the 31 byte payload limit */
if (_payloadLen + len + 2 > GAP_ADVERTISING_DATA_MAX_PAYLOAD) {
return BLE_ERROR_BUFFER_OVERFLOW;
}
/* Field length */
memset(&_payload[_payloadLen], len + 1, 1);
_payloadLen++;
/* Field ID */
memset(&_payload[_payloadLen], (uint8_t)advDataType, 1);
_payloadLen++;
/* Payload */
memcpy(&_payload[_payloadLen], payload, len);
_payloadLen += len;
return BLE_ERROR_NONE;
}
/**************************************************************************/
/*!
\brief Helper function to add APPEARANCE data to the advertising
payload
\args[in] appearance The APPEARANCE value to add
\returns ble_error_t
\retval BLE_ERROR_NONE
Everything executed properly
\retval BLE_ERROR_BUFFER_OVERFLOW
The specified data would cause the advertising buffer
to overflow
\par EXAMPLE
\code
\endcode
*/
/**************************************************************************/
ble_error_t GapAdvertisingData::addAppearance(Appearance appearance)
{
_appearance = appearance;
return addData(GapAdvertisingData::APPEARANCE, (uint8_t *)&appearance, 2);
}
/**************************************************************************/
/*!
\brief Helper function to add FLAGS data to the advertising
payload
\args[in] flag The FLAGS value to add
\par LE_LIMITED_DISCOVERABLE
The peripheral is discoverable for a limited period of
time
\par LE_GENERAL_DISCOVERABLE
The peripheral is permanently discoverable
\par BREDR_NOT_SUPPORTED
This peripheral is a Bluetooth Low Energy only device
(no EDR support)
\returns ble_error_t
\retval BLE_ERROR_NONE
Everything executed properly
\retval BLE_ERROR_BUFFER_OVERFLOW
The specified data would cause the advertising buffer
to overflow
\par EXAMPLE
\code
\endcode
*/
/**************************************************************************/
ble_error_t GapAdvertisingData::addFlags(uint8_t flags)
{
return addData(GapAdvertisingData::FLAGS, &flags, 1);
}
/**************************************************************************/
/*!
\brief Helper function to add TX_POWER_LEVEL data to the
advertising payload
\args[in] flag The TX_POWER_LEVEL value to add
\returns ble_error_t
\retval BLE_ERROR_NONE
Everything executed properly
\retval BLE_ERROR_BUFFER_OVERFLOW
The specified data would cause the advertising buffer
to overflow
\par EXAMPLE
\code
\endcode
*/
/**************************************************************************/
ble_error_t GapAdvertisingData::addTxPower(int8_t txPower)
{
/* ToDo: Basic error checking to make sure txPower is in range */
return addData(GapAdvertisingData::TX_POWER_LEVEL, (uint8_t *)&txPower, 1);
}
/**************************************************************************/
/*!
\brief Clears the payload and resets the payload length counter
*/
/**************************************************************************/
void GapAdvertisingData::clear(void)
{
memset(&_payload, 0, GAP_ADVERTISING_DATA_MAX_PAYLOAD);
_payloadLen = 0;
}
/**************************************************************************/
/*!
\brief Returns a pointer to the the current payload
\returns A pointer to the payload
*/
/**************************************************************************/
const uint8_t *GapAdvertisingData::getPayload(void) const
{
return (_payloadLen > 0) ? _payload : NULL;
}
/**************************************************************************/
/*!
\brief Returns the current payload length (0..31 bytes)
\returns The payload length in bytes
*/
/**************************************************************************/
uint8_t GapAdvertisingData::getPayloadLen(void) const
{
return _payloadLen;
}
/**************************************************************************/
/*!
\brief Returns the 16-bit appearance value for this device
\returns The 16-bit appearance value
*/
/**************************************************************************/
uint16_t GapAdvertisingData::getAppearance(void) const
{
return (uint16_t)_appearance;
}

View file

@ -1,129 +1,129 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <string.h>
#include "blecommon.h"
#include "GapAdvertisingParams.h"
/**************************************************************************/
/*!
\brief
Instantiates a new GapAdvertisingParams instance
\param[in] advType
The GAP advertising mode to use for this device. Valid
values are defined in AdvertisingType:
\par ADV_NON_CONNECTABLE_UNDIRECTED
All connections to the peripheral device will be refused.
\par ADV_CONNECTABLE_DIRECTED
Only connections from a pre-defined central device will be
accepted.
\par ADV_CONNECTABLE_UNDIRECTED
Any central device can connect to this peripheral.
\par ADV_SCANNABLE_UNDIRECTED
Any central device can connect to this peripheral, and
the secondary Scan Response payload will be included or
available to central devices.
\par
See Bluetooth Core Specification 4.0 (Vol. 3), Part C,
Section 9.3 and Core Specification 4.0 (Vol. 6), Part B,
Section 2.3.1 for further information on GAP connection
modes
\param[in] interval
Advertising interval between 0x0020 and 0x4000 in 0.625ms units
(20ms to 10.24s). If using non-connectable mode
(ADV_NON_CONNECTABLE_UNDIRECTED) this min value is 0x00A0
(100ms). To reduce the likelihood of collisions, the link layer
perturbs this interval by a pseudo-random delay with a range of
0 ms to 10 ms for each advertising event.
\par
Decreasing this value will allow central devices to detect
your peripheral faster at the expense of more power being
used by the radio due to the higher data transmit rate.
\par
This field must be set to 0 if connectionMode is equal
to ADV_CONNECTABLE_DIRECTED
\par
See Bluetooth Core Specification, Vol 3., Part C,
Appendix A for suggested advertising intervals.
\param[in] timeout
Advertising timeout between 0x1 and 0x3FFF (1 and 16383)
in seconds. Enter 0 to disable the advertising timeout.
\par EXAMPLE
\code
\endcode
*/
/**************************************************************************/
GapAdvertisingParams::GapAdvertisingParams(AdvertisingType advType, uint16_t interval, uint16_t timeout)
{
_advType = advType;
_interval = interval;
_timeout = timeout;
/* Interval checks */
if (_advType == ADV_CONNECTABLE_DIRECTED) {
/* Interval must be 0 in directed connectable mode */
_interval = 0;
} else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED) {
/* Min interval is slightly larger than in other modes */
if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) {
_interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON;
}
if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
_interval = GAP_ADV_PARAMS_INTERVAL_MAX;
}
} else {
/* Stay within interval limits */
if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN) {
_interval = GAP_ADV_PARAMS_INTERVAL_MIN;
}
if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
_interval = GAP_ADV_PARAMS_INTERVAL_MAX;
}
}
/* Timeout checks */
if (timeout) {
/* Stay within timeout limits */
if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX) {
_timeout = GAP_ADV_PARAMS_TIMEOUT_MAX;
}
}
}
/**************************************************************************/
/*!
Destructor
*/
/**************************************************************************/
GapAdvertisingParams::~GapAdvertisingParams(void)
{
}
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <string.h>
#include "blecommon.h"
#include "GapAdvertisingParams.h"
/**************************************************************************/
/*!
\brief
Instantiates a new GapAdvertisingParams instance
\param[in] advType
The GAP advertising mode to use for this device. Valid
values are defined in AdvertisingType:
\par ADV_NON_CONNECTABLE_UNDIRECTED
All connections to the peripheral device will be refused.
\par ADV_CONNECTABLE_DIRECTED
Only connections from a pre-defined central device will be
accepted.
\par ADV_CONNECTABLE_UNDIRECTED
Any central device can connect to this peripheral.
\par ADV_SCANNABLE_UNDIRECTED
Any central device can connect to this peripheral, and
the secondary Scan Response payload will be included or
available to central devices.
\par
See Bluetooth Core Specification 4.0 (Vol. 3), Part C,
Section 9.3 and Core Specification 4.0 (Vol. 6), Part B,
Section 2.3.1 for further information on GAP connection
modes
\param[in] interval
Advertising interval between 0x0020 and 0x4000 in 0.625ms units
(20ms to 10.24s). If using non-connectable mode
(ADV_NON_CONNECTABLE_UNDIRECTED) this min value is 0x00A0
(100ms). To reduce the likelihood of collisions, the link layer
perturbs this interval by a pseudo-random delay with a range of
0 ms to 10 ms for each advertising event.
\par
Decreasing this value will allow central devices to detect
your peripheral faster at the expense of more power being
used by the radio due to the higher data transmit rate.
\par
This field must be set to 0 if connectionMode is equal
to ADV_CONNECTABLE_DIRECTED
\par
See Bluetooth Core Specification, Vol 3., Part C,
Appendix A for suggested advertising intervals.
\param[in] timeout
Advertising timeout between 0x1 and 0x3FFF (1 and 16383)
in seconds. Enter 0 to disable the advertising timeout.
\par EXAMPLE
\code
\endcode
*/
/**************************************************************************/
GapAdvertisingParams::GapAdvertisingParams(AdvertisingType advType, uint16_t interval, uint16_t timeout)
{
_advType = advType;
_interval = interval;
_timeout = timeout;
/* Interval checks */
if (_advType == ADV_CONNECTABLE_DIRECTED) {
/* Interval must be 0 in directed connectable mode */
_interval = 0;
} else if (_advType == ADV_NON_CONNECTABLE_UNDIRECTED) {
/* Min interval is slightly larger than in other modes */
if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN_NONCON) {
_interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON;
}
if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
_interval = GAP_ADV_PARAMS_INTERVAL_MAX;
}
} else {
/* Stay within interval limits */
if (_interval < GAP_ADV_PARAMS_INTERVAL_MIN) {
_interval = GAP_ADV_PARAMS_INTERVAL_MIN;
}
if (_interval > GAP_ADV_PARAMS_INTERVAL_MAX) {
_interval = GAP_ADV_PARAMS_INTERVAL_MAX;
}
}
/* Timeout checks */
if (timeout) {
/* Stay within timeout limits */
if (_timeout > GAP_ADV_PARAMS_TIMEOUT_MAX) {
_timeout = GAP_ADV_PARAMS_TIMEOUT_MAX;
}
}
}
/**************************************************************************/
/*!
Destructor
*/
/**************************************************************************/
GapAdvertisingParams::~GapAdvertisingParams(void)
{
}

View file

@ -1,43 +1,43 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <string.h>
#include "GattService.h"
/**************************************************************************/
/*!
@brief Creates a new GattService using the specified 128-bit UUID
@note The UUID value must be unique on the device
@param[in] uuid
The 16 byte (128-bit) UUID to use for this characteristic
@section EXAMPLE
@code
@endcode
*/
/**************************************************************************/
GattService::GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics) :
_primaryServiceID(uuid), _characteristicCount(numCharacteristics), _characteristics(characteristics), _handle(0)
{
/* empty */
}
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <string.h>
#include "GattService.h"
/**************************************************************************/
/*!
@brief Creates a new GattService using the specified 128-bit UUID
@note The UUID value must be unique on the device
@param[in] uuid
The 16 byte (128-bit) UUID to use for this characteristic
@section EXAMPLE
@code
@endcode
*/
/**************************************************************************/
GattService::GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics) :
_primaryServiceID(uuid), _characteristicCount(numCharacteristics), _characteristics(characteristics), _handle(0)
{
/* empty */
}

View file

@ -1,94 +1,94 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <string.h>
#include "UUID.h"
UUID::UUID(ShortUUIDBytes_t shortUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(shortUUID) {
/* empty */
}
/**************************************************************************/
/*!
@brief Creates a new 128-bit UUID
@note The UUID is a unique 128-bit (16 byte) ID used to identify
different service or characteristics on the BLE device.
@note When creating a UUID, the constructor will check if all bytes
except bytes 2/3 are equal to 0. If only bytes 2/3 have a
value, the UUID will be treated as a short/BLE UUID, and the
.type field will be set to UUID::UUID_TYPE_SHORT. If any
of the bytes outside byte 2/3 have a non-zero value, the UUID
will be considered a 128-bit ID, and .type will be assigned
as UUID::UUID_TYPE_LONG.
@param[in] uuid_base
The 128-bit (16-byte) UUID value. For 128-bit values,
assign all 16 bytes. For 16-bit values, assign the
16-bits to byte 2 and 3, and leave the rest of the bytes
as 0.
@section EXAMPLE
@code
// Create a short UUID (0x180F)
uint8_t shortID[16] = { 0, 0, 0x0F, 0x18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
UUID ble_uuid = UUID(shortID);
// ble_uuid.type = UUID_TYPE_SHORT
// ble_uuid.value = 0x180F
// Creeate a long UUID
uint8_t longID[16] = { 0x00, 0x11, 0x22, 0x33,
0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB,
0xCC, 0xDD, 0xEE, 0xFF };
UUID custom_uuid = UUID(longID);
// custom_uuid.type = UUID_TYPE_LONG
// custom_uuid.value = 0x3322
// custom_uuid.base = 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF
@endcode
*/
/**************************************************************************/
UUID::UUID(const LongUUIDBytes_t longUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(0)
{
memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID);
shortUUID = (uint16_t)((longUUID[2] << 8) | (longUUID[3]));
/* Check if this is a short of a long UUID */
unsigned index;
for (index = 0; index < LENGTH_OF_LONG_UUID; index++) {
if ((index == 2) || (index == 3)) {
continue; /* we should not consider bytes 2 and 3 because that's
* where the 16-bit relative UUID is placed. */
}
if (baseUUID[index] != 0) {
type = UUID_TYPE_LONG;
/* zero out the 16-bit part in the base; this will help equate long
* UUIDs when they differ only in this 16-bit relative part.*/
baseUUID[2] = 0;
baseUUID[3] = 0;
return;
}
}
}
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <string.h>
#include "UUID.h"
UUID::UUID(ShortUUIDBytes_t shortUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(shortUUID) {
/* empty */
}
/**************************************************************************/
/*!
@brief Creates a new 128-bit UUID
@note The UUID is a unique 128-bit (16 byte) ID used to identify
different service or characteristics on the BLE device.
@note When creating a UUID, the constructor will check if all bytes
except bytes 2/3 are equal to 0. If only bytes 2/3 have a
value, the UUID will be treated as a short/BLE UUID, and the
.type field will be set to UUID::UUID_TYPE_SHORT. If any
of the bytes outside byte 2/3 have a non-zero value, the UUID
will be considered a 128-bit ID, and .type will be assigned
as UUID::UUID_TYPE_LONG.
@param[in] uuid_base
The 128-bit (16-byte) UUID value. For 128-bit values,
assign all 16 bytes. For 16-bit values, assign the
16-bits to byte 2 and 3, and leave the rest of the bytes
as 0.
@section EXAMPLE
@code
// Create a short UUID (0x180F)
uint8_t shortID[16] = { 0, 0, 0x0F, 0x18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
UUID ble_uuid = UUID(shortID);
// ble_uuid.type = UUID_TYPE_SHORT
// ble_uuid.value = 0x180F
// Creeate a long UUID
uint8_t longID[16] = { 0x00, 0x11, 0x22, 0x33,
0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB,
0xCC, 0xDD, 0xEE, 0xFF };
UUID custom_uuid = UUID(longID);
// custom_uuid.type = UUID_TYPE_LONG
// custom_uuid.value = 0x3322
// custom_uuid.base = 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF
@endcode
*/
/**************************************************************************/
UUID::UUID(const LongUUIDBytes_t longUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(0)
{
memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID);
shortUUID = (uint16_t)((longUUID[2] << 8) | (longUUID[3]));
/* Check if this is a short of a long UUID */
unsigned index;
for (index = 0; index < LENGTH_OF_LONG_UUID; index++) {
if ((index == 2) || (index == 3)) {
continue; /* we should not consider bytes 2 and 3 because that's
* where the 16-bit relative UUID is placed. */
}
if (baseUUID[index] != 0) {
type = UUID_TYPE_LONG;
/* zero out the 16-bit part in the base; this will help equate long
* UUIDs when they differ only in this 16-bit relative part.*/
baseUUID[2] = 0;
baseUUID[3] = 0;
return;
}
}
}

View file

@ -1,136 +1,136 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __BLE_COMMON_H__
#define __BLE_COMMON_H__
#define NRF51
#define DEBUG_NRF_USER
#define BLE_STACK_SUPPORT_REQD
#define BOARD_PCA10001
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stddef.h>
/** @defgroup BLE_UUID_VALUES Assigned Values for BLE UUIDs
* @{ */
/* Generic UUIDs, applicable to all services */
enum {
BLE_UUID_UNKNOWN = 0x0000, /**< Reserved UUID. */
BLE_UUID_SERVICE_PRIMARY = 0x2800, /**< Primary Service. */
BLE_UUID_SERVICE_SECONDARY = 0x2801, /**< Secondary Service. */
BLE_UUID_SERVICE_INCLUDE = 0x2802, /**< Include. */
BLE_UUID_CHARACTERISTIC = 0x2803, /**< Characteristic. */
BLE_UUID_DESCRIPTOR_CHAR_EXT_PROP = 0x2900, /**< Characteristic Extended Properties Descriptor. */
BLE_UUID_DESCRIPTOR_CHAR_USER_DESC = 0x2901, /**< Characteristic User Description Descriptor. */
BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG = 0x2902, /**< Client Characteristic Configuration Descriptor. */
BLE_UUID_DESCRIPTOR_SERVER_CHAR_CONFIG = 0x2903, /**< Server Characteristic Configuration Descriptor. */
BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT = 0x2904, /**< Characteristic Presentation Format Descriptor. */
BLE_UUID_DESCRIPTOR_CHAR_AGGREGATE_FORMAT = 0x2905, /**< Characteristic Aggregate Format Descriptor. */
/* GATT specific UUIDs */
BLE_UUID_GATT = 0x1801, /**< Generic Attribute Profile. */
BLE_UUID_GATT_CHARACTERISTIC_SERVICE_CHANGED = 0x2A05, /**< Service Changed Characteristic. */
/* GAP specific UUIDs */
BLE_UUID_GAP = 0x1800, /**< Generic Access Profile. */
BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME = 0x2A00, /**< Device Name Characteristic. */
BLE_UUID_GAP_CHARACTERISTIC_APPEARANCE = 0x2A01, /**< Appearance Characteristic. */
BLE_UUID_GAP_CHARACTERISTIC_PPF = 0x2A02, /**< Peripheral Privacy Flag Characteristic. */
BLE_UUID_GAP_CHARACTERISTIC_RECONN_ADDR = 0x2A03, /**< Reconnection Address Characteristic. */
BLE_UUID_GAP_CHARACTERISTIC_PPCP = 0x2A04, /**< Peripheral Preferred Connection Parameters Characteristic. */
};
/** @} */
/** @defgroup BLE_APPEARANCES Bluetooth Appearance values
* @note Retrieved from http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
* @{ */
enum {
BLE_APPEARANCE_UNKNOWN = 0, /**< Unknown. */
BLE_APPEARANCE_GENERIC_PHONE = 64, /**< Generic Phone. */
BLE_APPEARANCE_GENERIC_COMPUTER = 128, /**< Generic Computer. */
BLE_APPEARANCE_GENERIC_WATCH = 192, /**< Generic Watch. */
BLE_APPEARANCE_WATCH_SPORTS_WATCH = 193, /**< Watch: Sports Watch. */
BLE_APPEARANCE_GENERIC_CLOCK = 256, /**< Generic Clock. */
BLE_APPEARANCE_GENERIC_DISPLAY = 320, /**< Generic Display. */
BLE_APPEARANCE_GENERIC_REMOTE_CONTROL = 384, /**< Generic Remote Control. */
BLE_APPEARANCE_GENERIC_EYE_GLASSES = 448, /**< Generic Eye-glasses. */
BLE_APPEARANCE_GENERIC_TAG = 512, /**< Generic Tag. */
BLE_APPEARANCE_GENERIC_KEYRING = 576, /**< Generic Keyring. */
BLE_APPEARANCE_GENERIC_MEDIA_PLAYER = 640, /**< Generic Media Player. */
BLE_APPEARANCE_GENERIC_BARCODE_SCANNER = 704, /**< Generic Barcode Scanner. */
BLE_APPEARANCE_GENERIC_THERMOMETER = 768, /**< Generic Thermometer. */
BLE_APPEARANCE_THERMOMETER_EAR = 769, /**< Thermometer: Ear. */
BLE_APPEARANCE_GENERIC_HEART_RATE_SENSOR = 832, /**< Generic Heart rate Sensor. */
BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT = 833, /**< Heart Rate Sensor: Heart Rate Belt. */
BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE = 896, /**< Generic Blood Pressure. */
BLE_APPEARANCE_BLOOD_PRESSURE_ARM = 897, /**< Blood Pressure: Arm. */
BLE_APPEARANCE_BLOOD_PRESSURE_WRIST = 898, /**< Blood Pressure: Wrist. */
BLE_APPEARANCE_GENERIC_HID = 960, /**< Human Interface Device (HID). */
BLE_APPEARANCE_HID_KEYBOARD = 961, /**< Keyboard (HID Subtype). */
BLE_APPEARANCE_HID_MOUSE = 962, /**< Mouse (HID Subtype). */
BLE_APPEARANCE_HID_JOYSTICK = 963, /**< Joystiq (HID Subtype). */
BLE_APPEARANCE_HID_GAMEPAD = 964, /**< Gamepad (HID Subtype). */
BLE_APPEARANCE_HID_DIGITIZERSUBTYPE = 965, /**< Digitizer Tablet (HID Subtype). */
BLE_APPEARANCE_HID_CARD_READER = 966, /**< Card Reader (HID Subtype). */
BLE_APPEARANCE_HID_DIGITAL_PEN = 967, /**< Digital Pen (HID Subtype). */
BLE_APPEARANCE_HID_BARCODE = 968, /**< Barcode Scanner (HID Subtype). */
BLE_APPEARANCE_GENERIC_GLUCOSE_METER = 1024, /**< Generic Glucose Meter. */
BLE_APPEARANCE_GENERIC_RUNNING_WALKING_SENSOR = 1088, /**< Generic Running Walking Sensor. */
BLE_APPEARANCE_RUNNING_WALKING_SENSOR_IN_SHOE = 1089, /**< Running Walking Sensor: In-Shoe. */
BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_SHOE = 1090, /**< Running Walking Sensor: On-Shoe. */
BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_HIP = 1091, /**< Running Walking Sensor: On-Hip. */
BLE_APPEARANCE_GENERIC_CYCLING = 1152, /**< Generic Cycling. */
BLE_APPEARANCE_CYCLING_CYCLING_COMPUTER = 1153, /**< Cycling: Cycling Computer. */
BLE_APPEARANCE_CYCLING_SPEED_SENSOR = 1154, /**< Cycling: Speed Sensor. */
BLE_APPEARANCE_CYCLING_CADENCE_SENSOR = 1155, /**< Cycling: Cadence Sensor. */
BLE_APPEARANCE_CYCLING_POWER_SENSOR = 1156, /**< Cycling: Power Sensor. */
BLE_APPEARANCE_CYCLING_SPEED_CADENCE_SENSOR = 1157, /**< Cycling: Speed and Cadence Sensor. */
BLE_APPEARANCE_GENERIC_PULSE_OXIMETER = 3136, /**< Generic Pulse Oximeter. */
BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP = 3137, /**< Fingertip (Pulse Oximeter subtype). */
BLE_APPEARANCE_PULSE_OXIMETER_WRIST_WORN = 3138, /**< Wrist Worn(Pulse Oximeter subtype). */
BLE_APPEARANCE_GENERIC_WEIGHT_SCALE = 3200, /**< Generic Weight Scale. */
BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS_ACT = 5184, /**< Generic Outdoor Sports Activity. */
BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_DISP = 5185, /**< Location Display Device (Outdoor Sports Activity subtype). */
BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_AND_NAV_DISP = 5186, /**< Location and Navigation Display Device (Outdoor Sports Activity subtype). */
BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_POD = 5187, /**< Location Pod (Outdoor Sports Activity subtype). */
BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_AND_NAV_POD = 5188, /**< Location and Navigation Pod (Outdoor Sports Activity subtype). */
};
/** @} */
/**************************************************************************/
/*!
\brief Error codes for the BLE API
*/
/**************************************************************************/
typedef enum ble_error_e
{
BLE_ERROR_NONE = 0, /**< No error */
BLE_ERROR_BUFFER_OVERFLOW = 1, /**< The requested action would cause a buffer overflow and has been aborted */
BLE_ERROR_NOT_IMPLEMENTED = 2, /**< Requested a feature that isn't yet implement or isn't supported by the target HW */
BLE_ERROR_PARAM_OUT_OF_RANGE = 3, /**< One of the supplied parameters is outside the valid range */
BLE_STACK_BUSY = 4, /**< The stack is busy */
} ble_error_t;
#ifdef __cplusplus
}
#endif
#endif // ifndef __BLE_COMMON_H__
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __BLE_COMMON_H__
#define __BLE_COMMON_H__
#define NRF51
#define DEBUG_NRF_USER
#define BLE_STACK_SUPPORT_REQD
#define BOARD_PCA10001
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stddef.h>
/** @defgroup BLE_UUID_VALUES Assigned Values for BLE UUIDs
* @{ */
/* Generic UUIDs, applicable to all services */
enum {
BLE_UUID_UNKNOWN = 0x0000, /**< Reserved UUID. */
BLE_UUID_SERVICE_PRIMARY = 0x2800, /**< Primary Service. */
BLE_UUID_SERVICE_SECONDARY = 0x2801, /**< Secondary Service. */
BLE_UUID_SERVICE_INCLUDE = 0x2802, /**< Include. */
BLE_UUID_CHARACTERISTIC = 0x2803, /**< Characteristic. */
BLE_UUID_DESCRIPTOR_CHAR_EXT_PROP = 0x2900, /**< Characteristic Extended Properties Descriptor. */
BLE_UUID_DESCRIPTOR_CHAR_USER_DESC = 0x2901, /**< Characteristic User Description Descriptor. */
BLE_UUID_DESCRIPTOR_CLIENT_CHAR_CONFIG = 0x2902, /**< Client Characteristic Configuration Descriptor. */
BLE_UUID_DESCRIPTOR_SERVER_CHAR_CONFIG = 0x2903, /**< Server Characteristic Configuration Descriptor. */
BLE_UUID_DESCRIPTOR_CHAR_PRESENTATION_FORMAT = 0x2904, /**< Characteristic Presentation Format Descriptor. */
BLE_UUID_DESCRIPTOR_CHAR_AGGREGATE_FORMAT = 0x2905, /**< Characteristic Aggregate Format Descriptor. */
/* GATT specific UUIDs */
BLE_UUID_GATT = 0x1801, /**< Generic Attribute Profile. */
BLE_UUID_GATT_CHARACTERISTIC_SERVICE_CHANGED = 0x2A05, /**< Service Changed Characteristic. */
/* GAP specific UUIDs */
BLE_UUID_GAP = 0x1800, /**< Generic Access Profile. */
BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME = 0x2A00, /**< Device Name Characteristic. */
BLE_UUID_GAP_CHARACTERISTIC_APPEARANCE = 0x2A01, /**< Appearance Characteristic. */
BLE_UUID_GAP_CHARACTERISTIC_PPF = 0x2A02, /**< Peripheral Privacy Flag Characteristic. */
BLE_UUID_GAP_CHARACTERISTIC_RECONN_ADDR = 0x2A03, /**< Reconnection Address Characteristic. */
BLE_UUID_GAP_CHARACTERISTIC_PPCP = 0x2A04, /**< Peripheral Preferred Connection Parameters Characteristic. */
};
/** @} */
/** @defgroup BLE_APPEARANCES Bluetooth Appearance values
* @note Retrieved from http://developer.bluetooth.org/gatt/characteristics/Pages/CharacteristicViewer.aspx?u=org.bluetooth.characteristic.gap.appearance.xml
* @{ */
enum {
BLE_APPEARANCE_UNKNOWN = 0, /**< Unknown. */
BLE_APPEARANCE_GENERIC_PHONE = 64, /**< Generic Phone. */
BLE_APPEARANCE_GENERIC_COMPUTER = 128, /**< Generic Computer. */
BLE_APPEARANCE_GENERIC_WATCH = 192, /**< Generic Watch. */
BLE_APPEARANCE_WATCH_SPORTS_WATCH = 193, /**< Watch: Sports Watch. */
BLE_APPEARANCE_GENERIC_CLOCK = 256, /**< Generic Clock. */
BLE_APPEARANCE_GENERIC_DISPLAY = 320, /**< Generic Display. */
BLE_APPEARANCE_GENERIC_REMOTE_CONTROL = 384, /**< Generic Remote Control. */
BLE_APPEARANCE_GENERIC_EYE_GLASSES = 448, /**< Generic Eye-glasses. */
BLE_APPEARANCE_GENERIC_TAG = 512, /**< Generic Tag. */
BLE_APPEARANCE_GENERIC_KEYRING = 576, /**< Generic Keyring. */
BLE_APPEARANCE_GENERIC_MEDIA_PLAYER = 640, /**< Generic Media Player. */
BLE_APPEARANCE_GENERIC_BARCODE_SCANNER = 704, /**< Generic Barcode Scanner. */
BLE_APPEARANCE_GENERIC_THERMOMETER = 768, /**< Generic Thermometer. */
BLE_APPEARANCE_THERMOMETER_EAR = 769, /**< Thermometer: Ear. */
BLE_APPEARANCE_GENERIC_HEART_RATE_SENSOR = 832, /**< Generic Heart rate Sensor. */
BLE_APPEARANCE_HEART_RATE_SENSOR_HEART_RATE_BELT = 833, /**< Heart Rate Sensor: Heart Rate Belt. */
BLE_APPEARANCE_GENERIC_BLOOD_PRESSURE = 896, /**< Generic Blood Pressure. */
BLE_APPEARANCE_BLOOD_PRESSURE_ARM = 897, /**< Blood Pressure: Arm. */
BLE_APPEARANCE_BLOOD_PRESSURE_WRIST = 898, /**< Blood Pressure: Wrist. */
BLE_APPEARANCE_GENERIC_HID = 960, /**< Human Interface Device (HID). */
BLE_APPEARANCE_HID_KEYBOARD = 961, /**< Keyboard (HID Subtype). */
BLE_APPEARANCE_HID_MOUSE = 962, /**< Mouse (HID Subtype). */
BLE_APPEARANCE_HID_JOYSTICK = 963, /**< Joystiq (HID Subtype). */
BLE_APPEARANCE_HID_GAMEPAD = 964, /**< Gamepad (HID Subtype). */
BLE_APPEARANCE_HID_DIGITIZERSUBTYPE = 965, /**< Digitizer Tablet (HID Subtype). */
BLE_APPEARANCE_HID_CARD_READER = 966, /**< Card Reader (HID Subtype). */
BLE_APPEARANCE_HID_DIGITAL_PEN = 967, /**< Digital Pen (HID Subtype). */
BLE_APPEARANCE_HID_BARCODE = 968, /**< Barcode Scanner (HID Subtype). */
BLE_APPEARANCE_GENERIC_GLUCOSE_METER = 1024, /**< Generic Glucose Meter. */
BLE_APPEARANCE_GENERIC_RUNNING_WALKING_SENSOR = 1088, /**< Generic Running Walking Sensor. */
BLE_APPEARANCE_RUNNING_WALKING_SENSOR_IN_SHOE = 1089, /**< Running Walking Sensor: In-Shoe. */
BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_SHOE = 1090, /**< Running Walking Sensor: On-Shoe. */
BLE_APPEARANCE_RUNNING_WALKING_SENSOR_ON_HIP = 1091, /**< Running Walking Sensor: On-Hip. */
BLE_APPEARANCE_GENERIC_CYCLING = 1152, /**< Generic Cycling. */
BLE_APPEARANCE_CYCLING_CYCLING_COMPUTER = 1153, /**< Cycling: Cycling Computer. */
BLE_APPEARANCE_CYCLING_SPEED_SENSOR = 1154, /**< Cycling: Speed Sensor. */
BLE_APPEARANCE_CYCLING_CADENCE_SENSOR = 1155, /**< Cycling: Cadence Sensor. */
BLE_APPEARANCE_CYCLING_POWER_SENSOR = 1156, /**< Cycling: Power Sensor. */
BLE_APPEARANCE_CYCLING_SPEED_CADENCE_SENSOR = 1157, /**< Cycling: Speed and Cadence Sensor. */
BLE_APPEARANCE_GENERIC_PULSE_OXIMETER = 3136, /**< Generic Pulse Oximeter. */
BLE_APPEARANCE_PULSE_OXIMETER_FINGERTIP = 3137, /**< Fingertip (Pulse Oximeter subtype). */
BLE_APPEARANCE_PULSE_OXIMETER_WRIST_WORN = 3138, /**< Wrist Worn(Pulse Oximeter subtype). */
BLE_APPEARANCE_GENERIC_WEIGHT_SCALE = 3200, /**< Generic Weight Scale. */
BLE_APPEARANCE_GENERIC_OUTDOOR_SPORTS_ACT = 5184, /**< Generic Outdoor Sports Activity. */
BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_DISP = 5185, /**< Location Display Device (Outdoor Sports Activity subtype). */
BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_AND_NAV_DISP = 5186, /**< Location and Navigation Display Device (Outdoor Sports Activity subtype). */
BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_POD = 5187, /**< Location Pod (Outdoor Sports Activity subtype). */
BLE_APPEARANCE_OUTDOOR_SPORTS_ACT_LOC_AND_NAV_POD = 5188, /**< Location and Navigation Pod (Outdoor Sports Activity subtype). */
};
/** @} */
/**************************************************************************/
/*!
\brief Error codes for the BLE API
*/
/**************************************************************************/
typedef enum ble_error_e
{
BLE_ERROR_NONE = 0, /**< No error */
BLE_ERROR_BUFFER_OVERFLOW = 1, /**< The requested action would cause a buffer overflow and has been aborted */
BLE_ERROR_NOT_IMPLEMENTED = 2, /**< Requested a feature that isn't yet implement or isn't supported by the target HW */
BLE_ERROR_PARAM_OUT_OF_RANGE = 3, /**< One of the supplied parameters is outside the valid range */
BLE_STACK_BUSY = 4, /**< The stack is busy */
} ble_error_t;
#ifdef __cplusplus
}
#endif
#endif // ifndef __BLE_COMMON_H__

View file

@ -228,7 +228,7 @@ public:
*
* @Note: it is possible to chain together multiple onDataSent callbacks
* (potentially from different modules of an application) to receive updates
* to characteristics.
* to characteristics.
*
* @Note: it is also possible to setup a callback into a member function of
* some object.

View file

@ -1,177 +1,177 @@
/* mbed Microcontroller Library
* Copyright (c) 2006-2013 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __GAP_H__
#define __GAP_H__
#include "GapAdvertisingData.h"
#include "GapAdvertisingParams.h"
#include "GapEvents.h"
#include "CallChain.h"
using namespace mbed;
class Gap {
public:
typedef enum addr_type_e {
ADDR_TYPE_PUBLIC = 0,
ADDR_TYPE_RANDOM_STATIC,
ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE,
ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE
} addr_type_t;
static const unsigned ADDR_LEN = 6;
typedef uint8_t address_t[ADDR_LEN];
/**
* Enumeration for disconnection reasons. The values for these reasons are
* derived from Nordic's implementation; but the reasons are meant to be
* independent of the transport. If you are returned a reason which is not
* covered by this enumeration, then please refer to the underlying
* transport library.
*/
enum DisconnectionReason_t {
REMOTE_USER_TERMINATED_CONNECTION = 0x13,
LOCAL_HOST_TERMINATED_CONNECTION = 0x16,
CONN_INTERVAL_UNACCEPTABLE = 0x3B,
};
/* Describes the current state of the device (more than one bit can be set) */
typedef struct GapState_s {
unsigned advertising : 1; /**< peripheral is currently advertising */
unsigned connected : 1; /**< peripheral is connected to a central */
} GapState_t;
typedef uint16_t Handle_t;
typedef struct {
uint16_t minConnectionInterval; /**< Minimum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
uint16_t maxConnectionInterval; /**< Maximum Connection Interval in 1.25 ms units, see @ref BLE_GAP_CP_LIMITS.*/
uint16_t slaveLatency; /**< Slave Latency in number of connection events, see @ref BLE_GAP_CP_LIMITS.*/
uint16_t connectionSupervisionTimeout; /**< Connection Supervision Timeout in 10 ms units, see @ref BLE_GAP_CP_LIMITS.*/
} ConnectionParams_t;
static const uint16_t UNIT_1_25_MS = 1250; /**< Number of microseconds in 1.25 milliseconds. */
static const uint16_t UNIT_0_625_MS = 650; /**< Number of microseconds in 0.625 milliseconds. */
static uint16_t MSEC_TO_GAP_DURATION_UNITS(uint32_t durationInMillis) {
return (durationInMillis * 1000) / UNIT_1_25_MS;
}
static uint16_t MSEC_TO_ADVERTISEMENT_DURATION_UNITS(uint32_t durationInMillis) {
return (durationInMillis * 1000) / UNIT_0_625_MS;
}
typedef void (*EventCallback_t)(void);
typedef void (*ConnectionEventCallback_t)(Handle_t, addr_type_t peerAddrType, const address_t peerAddr, const ConnectionParams_t *);
typedef void (*DisconnectionEventCallback_t)(Handle_t, DisconnectionReason_t);
friend class BLEDevice;
private:
/* These functions must be defined in the sub-class */
virtual ble_error_t setAddress(addr_type_t type, const address_t address) = 0;
virtual ble_error_t getAddress(addr_type_t *typeP, address_t address) = 0;
virtual ble_error_t setAdvertisingData(const GapAdvertisingData &, const GapAdvertisingData &) = 0;
virtual ble_error_t startAdvertising(const GapAdvertisingParams &) = 0;
virtual ble_error_t stopAdvertising(void) = 0;
virtual ble_error_t disconnect(DisconnectionReason_t reason) = 0;
virtual ble_error_t getPreferredConnectionParams(ConnectionParams_t *params) = 0;
virtual ble_error_t setPreferredConnectionParams(const ConnectionParams_t *params) = 0;
virtual ble_error_t updateConnectionParams(Handle_t handle, const ConnectionParams_t *params) = 0;
virtual ble_error_t setDeviceName(const uint8_t *deviceName) = 0;
virtual ble_error_t getDeviceName(uint8_t *deviceName, unsigned *lengthP) = 0;
virtual ble_error_t setAppearance(uint16_t appearance) = 0;
virtual ble_error_t getAppearance(uint16_t *appearanceP) = 0;
private:
/* Event callback handlers */
void setOnTimeout(EventCallback_t callback) {onTimeout = callback;}
void setOnConnection(ConnectionEventCallback_t callback) {onConnection = callback;}
/**
* Set the application callback for disconnection events.
* @param callback
* Pointer to the unique callback.
*/
void setOnDisconnection(DisconnectionEventCallback_t callback) {onDisconnection = callback;}
/**
* Append to a chain of callbacks to be invoked upon disconnection; these
* callbacks receive no context and are therefore different from the
* onDisconnection callback.
* @param callback
* function pointer to be invoked upon disconnection; receives no context.
*
* @note the disconnection CallChain should have been merged with
* onDisconnctionCallback; but this was not possible because
* FunctionPointer (which is a building block for CallChain) doesn't
* accept variadic templates.
*/
template<typename T>
void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) {disconnectionCallChain.add(tptr, mptr);}
GapState_t getState(void) const {
return state;
}
protected:
/* Default constructor. */