- 调用 sd_ble_gap_addr_get API获取MAC地址
ble_gap_addr_t addr; sd_ble_gap_addr_get(&addr);
/**@brief Get local Bluetooth identity address.
*
* @note This will always return the identity address irrespective of the privacy settings,
* i.e. the address type will always be either @ref BLE_GAP_ADDR_TYPE_PUBLIC or @ref BLE_GAP_ADDR_TYPE_RANDOM_STATIC.
*
* @param[out] p_addr Pointer to address structure to be filled in.
*
* @retval ::NRF_SUCCESS Address successfully retrieved.
* @retval ::NRF_ERROR_INVALID_ADDR Invalid or NULL pointer supplied.
*/
SVCALL(SD_BLE_GAP_ADDR_GET, uint32_t, sd_ble_gap_addr_get(ble_gap_addr_t *p_addr));
- MAC地址加1
addr.addr[0]++;
- 调用 sd_ble_gap_addr_set API设置MAC地址
sd_ble_gap_addr_set(&addr);
/**@brief Set the local Bluetooth identity address.
*
* The local Bluetooth identity address is the address that identifies this device to other peers.
* The address type must be either @ref BLE_GAP_ADDR_TYPE_PUBLIC or @ref BLE_GAP_ADDR_TYPE_RANDOM_STATIC.
*
* @note The identity address cannot be changed while advertising, scanning or creating a connection.
*
* @note This address will be distributed to the peer during bonding.
* If the address changes, the address stored in the peer device will not be valid and the ability to
* reconnect using the old address will be lost.
*
* @note By default the SoftDevice will set an address of type @ref BLE_GAP_ADDR_TYPE_RANDOM_STATIC upon being
* enabled. The address is a random number populated during the IC manufacturing process and remains unchanged
* for the lifetime of each IC.
*
* @mscs
* @mmsc{@ref BLE_GAP_ADV_MSC}
* @endmscs
*
* @param[in] p_addr Pointer to address structure.
*
* @retval ::NRF_SUCCESS Address successfully set.
* @retval ::NRF_ERROR_INVALID_ADDR Invalid pointer supplied.
* @retval ::BLE_ERROR_GAP_INVALID_BLE_ADDR Invalid address.
* @retval ::NRF_ERROR_BUSY The stack is busy, process pending events and retry.
* @retval ::NRF_ERROR_INVALID_STATE The identity address cannot be changed while advertising,
* scanning or creating a connection.
*/
SVCALL(SD_BLE_GAP_ADDR_SET, uint32_t, sd_ble_gap_addr_set(ble_gap_addr_t const *p_addr));