Added ability to manually set device address

pull/248/head
Kevin Townsend 2014-04-03 01:57:03 +02:00
parent 8281a04c84
commit 5e210d8ae7
3 changed files with 44 additions and 6 deletions

View File

@ -36,7 +36,15 @@ class Gap
GapEvents *m_pEventHandler;
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;
/* These functions must be defined in the sub-class */
virtual ble_error_t setAddress(addr_type_t type, uint8_t address[6]) = 0;
virtual ble_error_t setAdvertisingData(GapAdvertisingData &, GapAdvertisingData &) = 0;
virtual ble_error_t startAdvertising(GapAdvertisingParams &) = 0;
virtual ble_error_t stopAdvertising(void) = 0;

View File

@ -197,12 +197,12 @@ ble_error_t nRF51Gap::startAdvertising(GapAdvertisingParams & params)
/**************************************************************************/
ble_error_t nRF51Gap::stopAdvertising(void)
{
/* Stop Advertising */
ASSERT( ERROR_NONE == sd_ble_gap_adv_stop(), BLE_ERROR_PARAM_OUT_OF_RANGE);
/* Stop Advertising */
ASSERT( ERROR_NONE == sd_ble_gap_adv_stop(), BLE_ERROR_PARAM_OUT_OF_RANGE);
state.advertising = 0;
return BLE_ERROR_NONE;
return BLE_ERROR_NONE;
}
/**************************************************************************/
@ -224,10 +224,39 @@ ble_error_t nRF51Gap::stopAdvertising(void)
ble_error_t nRF51Gap::disconnect(void)
{
/* Disconnect if we are connected to a central device */
// ASSERT( ERROR_NONE == sd_ble_gap_disconnect(), BLE_ERROR_PARAM_OUT_OF_RANGE);
// ASSERT( ERROR_NONE == sd_ble_gap_disconnect(), BLE_ERROR_PARAM_OUT_OF_RANGE);
state.advertising = 0;
state.connected = 0;
state.connected = 0;
return BLE_ERROR_NONE;
return BLE_ERROR_NONE;
}
/**************************************************************************/
/*!
@brief Sets the BLE device address
@returns ble_error_t
@section EXAMPLE
@code
uint8_t device_address[6] = { 0xca, 0xfe, 0xf0, 0xf0, 0xf0, 0xf0 };
nrf.getGap().setAddress(Gap::ADDR_TYPE_RANDOM_STATIC, device_address);
@endcode
*/
/**************************************************************************/
ble_error_t nRF51Gap::setAddress(addr_type_t type, uint8_t address[6])
{
if ( type > ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE) return BLE_ERROR_PARAM_OUT_OF_RANGE;
ble_gap_addr_t dev_addr;
dev_addr.addr_type = type;
memcpy(dev_addr.addr, address, 6);
ASSERT_INT(ERROR_NONE, sd_ble_gap_address_set(&dev_addr), BLE_ERROR_PARAM_OUT_OF_RANGE);
return BLE_ERROR_NONE;
}

View File

@ -39,6 +39,7 @@ class nRF51Gap : public Gap
}
/* Functions that must be implemented from Gap */
virtual ble_error_t setAddress(addr_type_t type, uint8_t address[6]);
virtual ble_error_t setAdvertisingData(GapAdvertisingData &, GapAdvertisingData &);
virtual ble_error_t startAdvertising(GapAdvertisingParams &);
virtual ble_error_t stopAdvertising(void);