Skip to content

Commit

Permalink
Update address types to align with the latest Mbed OS API changes
Browse files Browse the repository at this point in the history
In ARMmbed/mbed-os#12730 we have removed
legacy address-related types (BLEProtocol:: namespace) in favour
of new once in ble:: namespace. This commit updates examples
so they continue to work the latest Mbed OS.
  • Loading branch information
LDong-Arm authored and paul-szczepanek-arm committed Sep 10, 2020
1 parent a866f9f commit e76a53a
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 75 deletions.
8 changes: 4 additions & 4 deletions BLE_BatteryLevel/source/pretty_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
}

/** print device address to the terminal */
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_address(const ble::address_t &addr)
{
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Expand All @@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_mac_address()
{
/* Print out device MAC address to the console*/
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t address;
BLE::Instance().gap().getAddress(&addr_type, address);
ble::own_address_type_t addr_type;
ble::address_t address;
BLE::Instance().gap().getAddress(addr_type, address);
printf("DEVICE MAC ADDRESS: ");
print_address(address);
}
Expand Down
8 changes: 4 additions & 4 deletions BLE_Beacon/source/pretty_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
}

/** print device address to the terminal */
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_address(const ble::address_t &addr)
{
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Expand All @@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_mac_address()
{
/* Print out device MAC address to the console*/
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t address;
BLE::Instance().gap().getAddress(&addr_type, address);
ble::own_address_type_t addr_type;
ble::address_t address;
BLE::Instance().gap().getAddress(addr_type, address);
printf("DEVICE MAC ADDRESS: ");
print_address(address);
}
Expand Down
8 changes: 4 additions & 4 deletions BLE_Button/source/pretty_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
}

/** print device address to the terminal */
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_address(const ble::address_t &addr)
{
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Expand All @@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_mac_address()
{
/* Print out device MAC address to the console*/
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t address;
BLE::Instance().gap().getAddress(&addr_type, address);
ble::own_address_type_t addr_type;
ble::address_t address;
BLE::Instance().gap().getAddress(addr_type, address);
printf("DEVICE MAC ADDRESS: ");
print_address(address);
}
Expand Down
8 changes: 4 additions & 4 deletions BLE_GAP/source/pretty_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
}

/** print device address to the terminal */
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_address(const ble::address_t &addr)
{
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Expand All @@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_mac_address()
{
/* Print out device MAC address to the console*/
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t address;
BLE::Instance().gap().getAddress(&addr_type, address);
ble::own_address_type_t addr_type;
ble::address_t address;
BLE::Instance().gap().getAddress(addr_type, address);
printf("DEVICE MAC ADDRESS: ");
print_address(address);
}
Expand Down
8 changes: 4 additions & 4 deletions BLE_GAPButton/source/pretty_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
}

/** print device address to the terminal */
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_address(const ble::address_t &addr)
{
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Expand All @@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_mac_address()
{
/* Print out device MAC address to the console*/
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t address;
BLE::Instance().gap().getAddress(&addr_type, address);
ble::own_address_type_t addr_type;
ble::address_t address;
BLE::Instance().gap().getAddress(addr_type, address);
printf("DEVICE MAC ADDRESS: ");
print_address(address);
}
Expand Down
10 changes: 5 additions & 5 deletions BLE_GattClient/source/pretty_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ inline void print_error(ble_error_t error, const char* msg)
}

/** print device address to the terminal */
inline void print_address(const uint8_t *addr)
inline void print_address(const ble::address_t addr)
{
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Expand All @@ -80,16 +80,16 @@ inline void print_address(const uint8_t *addr)
inline void print_mac_address()
{
/* Print out device MAC address to the console*/
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t address;
BLE::Instance().gap().getAddress(&addr_type, address);
ble::own_address_type_t addr_type;
ble::address_t address;
BLE::Instance().gap().getAddress(addr_type, address);
printf("DEVICE MAC ADDRESS: ");
print_address(address);

if (!seeded) {
seeded = true;
/* use the address as a seed */
uint8_t* random_data = address;
uint8_t* random_data = address.data();
srand(*((unsigned int*)random_data));
}
}
Expand Down
10 changes: 5 additions & 5 deletions BLE_GattServer/source/pretty_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ inline void print_error(ble_error_t error, const char* msg)
}

/** print device address to the terminal */
inline void print_address(const uint8_t *addr)
inline void print_address(const ble::address_t &addr)
{
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Expand All @@ -80,16 +80,16 @@ inline void print_address(const uint8_t *addr)
inline void print_mac_address()
{
/* Print out device MAC address to the console*/
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t address;
BLE::Instance().gap().getAddress(&addr_type, address);
ble::own_address_type_t addr_type;
ble::address_t address;
BLE::Instance().gap().getAddress(addr_type, address);
printf("DEVICE MAC ADDRESS: ");
print_address(address);

if (!seeded) {
seeded = true;
/* use the address as a seed */
uint8_t* random_data = address;
uint8_t* random_data = address.data();
srand(*((unsigned int*)random_data));
}
}
Expand Down
8 changes: 4 additions & 4 deletions BLE_HeartRate/source/pretty_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
}

/** print device address to the terminal */
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_address(const ble::address_t &addr)
{
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Expand All @@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_mac_address()
{
/* Print out device MAC address to the console*/
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t address;
BLE::Instance().gap().getAddress(&addr_type, address);
ble::own_address_type_t addr_type;
ble::address_t address;
BLE::Instance().gap().getAddress(addr_type, address);
printf("DEVICE MAC ADDRESS: ");
print_address(address);
}
Expand Down
8 changes: 4 additions & 4 deletions BLE_LED/source/pretty_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
}

/** print device address to the terminal */
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_address(const ble::address_t &addr)
{
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Expand All @@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
inline void print_mac_address()
{
/* Print out device MAC address to the console*/
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t address;
BLE::Instance().gap().getAddress(&addr_type, address);
ble::own_address_type_t addr_type;
ble::address_t address;
BLE::Instance().gap().getAddress(addr_type, address);
printf("DEVICE MAC ADDRESS: ");
print_address(address);
}
Expand Down
8 changes: 4 additions & 4 deletions BLE_LEDBlinker/source/pretty_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
}

/** print device address to the terminal */
void print_address(const uint8_t *addr)
void print_address(const ble::address_t &addr)
{
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Expand All @@ -74,9 +74,9 @@ void print_address(const uint8_t *addr)
inline void print_mac_address()
{
/* Print out device MAC address to the console*/
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t address;
BLE::Instance().gap().getAddress(&addr_type, address);
ble::own_address_type_t addr_type;
ble::address_t address;
BLE::Instance().gap().getAddress(addr_type, address);
printf("DEVICE MAC ADDRESS: ");
print_address(address);
}
Expand Down
10 changes: 5 additions & 5 deletions BLE_PeriodicAdvertising/source/pretty_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ inline void print_error(ble_error_t error, const char* msg)
}

/** print device address to the terminal */
inline void print_address(const uint8_t *addr)
inline void print_address(const ble::address_t &addr)
{
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Expand All @@ -77,16 +77,16 @@ inline void print_address(const uint8_t *addr)
inline void print_mac_address()
{
/* Print out device MAC address to the console*/
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t address;
BLE::Instance().gap().getAddress(&addr_type, address);
ble::own_address_type_t addr_type;
ble::address_t address;
BLE::Instance().gap().getAddress(addr_type, address);
printf("DEVICE MAC ADDRESS: ");
print_address(address);

if (!seeded) {
seeded = true;
/* use the address as a seed */
uint8_t* random_data = address;
uint8_t* random_data = address.data();
srand(*((unsigned int*)random_data));
}
}
Expand Down
8 changes: 4 additions & 4 deletions BLE_Privacy/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,16 @@ class PrivacyDevice : private mbed::NonCopyable<PrivacyDevice>,
void print_local_address()
{
/* show what address we are using now */
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t addr;
_ble.gap().getAddress(&addr_type, addr);
ble::own_address_type_t addr_type;
ble::address_t addr;
_ble.gap().getAddress(addr_type, addr);
printf("Device address: ");
print_address(addr);

if (!_seeded) {
_seeded = true;
/* use the address as a seed */
uint8_t* random_data = addr;
uint8_t* random_data = addr.data();
srand(*((unsigned int*)random_data));
}
}
Expand Down
8 changes: 4 additions & 4 deletions BLE_Privacy/source/pretty_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
}

/** print device address to the terminal */
void print_address(const uint8_t *addr)
void print_address(const ble::address_t &addr)
{
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
Expand All @@ -74,9 +74,9 @@ void print_address(const uint8_t *addr)
inline void print_mac_address()
{
/* Print out device MAC address to the console*/
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t address;
BLE::Instance().gap().getAddress(&addr_type, address);
ble::own_address_type_t addr_type;
ble::address_t address;
BLE::Instance().gap().getAddress(addr_type, address);
printf("DEVICE MAC ADDRESS: ");
print_address(address);
}
Expand Down
21 changes: 9 additions & 12 deletions BLE_SM/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const static disconnect_call_t disconnect_call = &Gap::disconnect;
/* for demonstration purposes we will store the peer device address
* of the device that connects to us in the first demonstration
* so we can use its address to reconnect to it later */
static BLEProtocol::AddressBytes_t peer_address;
static ble::address_t peer_address;

/** Base class for both peripheral and central. The same class that provides
* the logic for the application also implements the SecurityManagerEventHandler
Expand All @@ -61,7 +61,7 @@ class SMDevice : private mbed::NonCopyable<SMDevice>,
public ble::Gap::EventHandler
{
public:
SMDevice(BLE &ble, events::EventQueue &event_queue, BLEProtocol::AddressBytes_t &peer_address) :
SMDevice(BLE &ble, events::EventQueue &event_queue, ble::address_t &peer_address) :
_led1(LED1, 0),
_ble(ble),
_event_queue(event_queue),
Expand Down Expand Up @@ -180,10 +180,7 @@ class SMDevice : private mbed::NonCopyable<SMDevice>,
_ble.gap().setEventHandler(this);

/* print device address */
BLEProtocol::AddressType_t addr_type;
BLEProtocol::AddressBytes_t addr;
_ble.gap().getAddress(&addr_type, addr);
print_address(addr);
print_mac_address();

/* start test in 500 ms */
_event_queue.call_in(500, this, &SMDevice::start);
Expand Down Expand Up @@ -278,7 +275,7 @@ class SMDevice : private mbed::NonCopyable<SMDevice>,
protected:
BLE &_ble;
events::EventQueue &_event_queue;
BLEProtocol::AddressBytes_t &_peer_address;
ble::address_t &_peer_address;
ble::connection_handle_t _handle;
bool _is_connecting;
};
Expand All @@ -287,7 +284,7 @@ class SMDevice : private mbed::NonCopyable<SMDevice>,
* a change in link security. */
class SMDevicePeripheral : public SMDevice {
public:
SMDevicePeripheral(BLE &ble, events::EventQueue &event_queue, BLEProtocol::AddressBytes_t &peer_address)
SMDevicePeripheral(BLE &ble, events::EventQueue &event_queue, ble::address_t &peer_address)
: SMDevice(ble, event_queue, peer_address) { }

virtual void start()
Expand Down Expand Up @@ -352,7 +349,7 @@ class SMDevicePeripheral : public SMDevice {

/* remember the device that connects to us now so we can connect to it
* during the next demonstration */
memcpy(_peer_address, event.getPeerAddress().data(), sizeof(_peer_address));
_peer_address = event.getPeerAddress();

printf("Connected to peer: ");
print_address(event.getPeerAddress().data());
Expand All @@ -379,7 +376,7 @@ class SMDevicePeripheral : public SMDevice {
/** A central device will scan, connect to a peer and request pairing. */
class SMDeviceCentral : public SMDevice {
public:
SMDeviceCentral(BLE &ble, events::EventQueue &event_queue, BLEProtocol::AddressBytes_t &peer_address)
SMDeviceCentral(BLE &ble, events::EventQueue &event_queue, ble::address_t &peer_address)
: SMDevice(ble, event_queue, peer_address) { }

virtual void start()
Expand All @@ -403,7 +400,7 @@ class SMDeviceCentral : public SMDevice {
printf("Please advertise\r\n");

printf("Scanning for: ");
print_address(_peer_address);
print_address(_peer_address.data());
}

private:
Expand All @@ -418,7 +415,7 @@ class SMDeviceCentral : public SMDevice {
}

/* parse the advertising payload, looking for a discoverable device */
if (memcmp(event.getPeerAddress().data(), _peer_address, sizeof(_peer_address)) == 0) {
if (event.getPeerAddress() == _peer_address) {
ble_error_t error = _ble.gap().stopScan();

if (error) {
Expand Down
Loading

0 comments on commit e76a53a

Please sign in to comment.