Fixed advertising interval checks

This commit is contained in:
ktownsend 2013-12-18 11:52:37 +00:00
parent 80f18dad9e
commit 66da5fce1b
4 changed files with 50 additions and 11 deletions

View file

@ -60,9 +60,18 @@ ble_error_t GapAdvertisingData::addData(DataType advDataType, uint8_t * payload,
/* value is exclusive or not (flags, etc.) */
/* Make sure we don't exceed the 31 byte payload limit */
if (_payloadLen + len >= GAP_ADVERTISING_DATA_MAX_PAYLOAD)
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;

View file

@ -35,8 +35,10 @@
connection modes
@param[in] interval
Advertising interval between 0x20 and 0x4000 (32 and 16384)
in 0.625ms intervals (20ms to 10.24s).
Advertising interval between 0x0020 and 0x4000 in 0.625ms
units (20ms to 10.24s). If using non-connectable mode
(\ref ADV_NON_CONNECTABLE_UNDIRECTED) this min value is
0x00A0 (100ms).
@para
Increasing this value will allow central devices to detect
@ -45,7 +47,10 @@
@note This field must be set to 0 if connectionMode is equal
to \ref ADV_CONNECTABLE_DIRECTED
@note 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.
@ -69,6 +74,18 @@ GapAdvertisingParams::GapAdvertisingParams(AdvertisingType advType, uint16_t int
/* 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 */

View file

@ -3,9 +3,10 @@
#include "blecommon.h"
#define GAP_ADV_PARAMS_INTERVAL_MIN (0x0020)
#define GAP_ADV_PARAMS_INTERVAL_MAX (0x4000)
#define GAP_ADV_PARAMS_TIMEOUT_MAX (0x3FFF)
#define GAP_ADV_PARAMS_INTERVAL_MIN (0x0020)
#define GAP_ADV_PARAMS_INTERVAL_MIN_NONCON (0x00A0)
#define GAP_ADV_PARAMS_INTERVAL_MAX (0x1000)
#define GAP_ADV_PARAMS_TIMEOUT_MAX (0x3FFF)
class GapAdvertisingParams
{
@ -21,7 +22,7 @@ class GapAdvertisingParams
};
GapAdvertisingParams(AdvertisingType advType = GapAdvertisingParams::ADV_CONNECTABLE_UNDIRECTED,
uint16_t interval = GAP_ADV_PARAMS_INTERVAL_MIN,
uint16_t interval = GAP_ADV_PARAMS_INTERVAL_MIN_NONCON,
uint16_t timeout = 0);
virtual ~GapAdvertisingParams(void);

View file

@ -1,6 +1,7 @@
#include "nrf51822.h"
#include "mbed.h"
/* Enables debug output over USB CDC at 9600 bps */
#define NRF51822_DEBUG_MODE (1)
/**************************************************************************/
@ -170,30 +171,38 @@ ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisi
/* 1.) Send advertising params, Command IDs = 0x000C, 0x000D, 0x000E */
/* A.) Command ID = 0x000C, Advertising Interval, uint16_t */
printf("10 0C 00 02 %02X %02X\r\n", (uint8_t)(params.getInterval() & 0xFF),
(uint8_t)(params.getInterval() >> 8));
uart.printf("10 0C 00 02 %02X %02X\r\n", (uint8_t)(params.getInterval() & 0xFF),
(uint8_t)(params.getInterval() >> 8));
/* ToDo: Check response */
wait(0.5);
/* B.) Command ID = 0x000D, Advertising Timeout, uint16_t */
printf("10 0D 00 02 %02X %02X\r\n", (uint8_t)(params.getTimeout() & 0xFF),
(uint8_t)(params.getTimeout() >> 8));
uart.printf("10 0D 00 02 %02X %02X\r\n", (uint8_t)(params.getTimeout() & 0xFF),
(uint8_t)(params.getTimeout() >> 8));
/* ToDo: Check response */
wait(0.5);
/* C.) Command ID = 0x000E, Advertising Type, uint8_t */
printf("10 0E 00 01 %02X\r\n", (uint8_t)(params.getAdvertisingType()));
uart.printf("10 0E 00 01 %02X\r\n", (uint8_t)(params.getAdvertisingType()));
/* ToDo: Check response */
wait(0.5);
/* 2.) Send advertising data, Command ID = 0x000A */
len = advData.getPayloadLen();
buffer = advData.getPayload();
uart.printf("10 0A 00 %02X ", len);
buffer = advData.getPayload();
printf("10 0A 00 %02X", len);
uart.printf("10 0A 00 %02X", len);
for (uint16_t i = 0; i < len; i++)
{
printf(" %02X", buffer[i]);
uart.printf(" %02X", buffer[i]);
}
printf("\r\n");
uart.printf("\r\n");
/* ToDo: Check response */
@ -204,11 +213,14 @@ ble_error_t nRF51822::setAdvertising(GapAdvertisingParams & params, GapAdvertisi
{
len = advData.getPayloadLen();
buffer = advData.getPayload();
uart.printf("10 0B 00 %02X ", len);
printf("10 0B 00 %02X", len);
uart.printf("10 0B 00 %02X", len);
for (uint16_t i = 0; i < len; i++)
{
printf(" %02X", buffer[i]);
uart.printf(" %02X", buffer[i]);
}
printf("\r\n");
uart.printf("\r\n");
/* ToDo: Check response */