Skip to content

Commit 12f5901

Browse files
committed
Update address types to align with the latest Mbed OS API changes
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.
1 parent 21bfa30 commit 12f5901

File tree

16 files changed

+72
-75
lines changed

16 files changed

+72
-75
lines changed

BLE_BatteryLevel/source/pretty_printer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
6565
}
6666

6767
/** print device address to the terminal */
68-
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
68+
inline void print_address(const ble::address_t &addr)
6969
{
7070
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
7171
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
@@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
7474
inline void print_mac_address()
7575
{
7676
/* Print out device MAC address to the console*/
77-
BLEProtocol::AddressType_t addr_type;
78-
BLEProtocol::AddressBytes_t address;
79-
BLE::Instance().gap().getAddress(&addr_type, address);
77+
ble::own_address_type_t addr_type;
78+
ble::address_t address;
79+
BLE::Instance().gap().getAddress(addr_type, address);
8080
printf("DEVICE MAC ADDRESS: ");
8181
print_address(address);
8282
}

BLE_Beacon/source/pretty_printer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
6565
}
6666

6767
/** print device address to the terminal */
68-
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
68+
inline void print_address(const ble::address_t &addr)
6969
{
7070
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
7171
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
@@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
7474
inline void print_mac_address()
7575
{
7676
/* Print out device MAC address to the console*/
77-
BLEProtocol::AddressType_t addr_type;
78-
BLEProtocol::AddressBytes_t address;
79-
BLE::Instance().gap().getAddress(&addr_type, address);
77+
ble::own_address_type_t addr_type;
78+
ble::address_t address;
79+
BLE::Instance().gap().getAddress(addr_type, address);
8080
printf("DEVICE MAC ADDRESS: ");
8181
print_address(address);
8282
}

BLE_Button/source/pretty_printer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
6565
}
6666

6767
/** print device address to the terminal */
68-
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
68+
inline void print_address(const ble::address_t &addr)
6969
{
7070
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
7171
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
@@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
7474
inline void print_mac_address()
7575
{
7676
/* Print out device MAC address to the console*/
77-
BLEProtocol::AddressType_t addr_type;
78-
BLEProtocol::AddressBytes_t address;
79-
BLE::Instance().gap().getAddress(&addr_type, address);
77+
ble::own_address_type_t addr_type;
78+
ble::address_t address;
79+
BLE::Instance().gap().getAddress(addr_type, address);
8080
printf("DEVICE MAC ADDRESS: ");
8181
print_address(address);
8282
}

BLE_GAP/source/pretty_printer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
6565
}
6666

6767
/** print device address to the terminal */
68-
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
68+
inline void print_address(const ble::address_t &addr)
6969
{
7070
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
7171
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
@@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
7474
inline void print_mac_address()
7575
{
7676
/* Print out device MAC address to the console*/
77-
BLEProtocol::AddressType_t addr_type;
78-
BLEProtocol::AddressBytes_t address;
79-
BLE::Instance().gap().getAddress(&addr_type, address);
77+
ble::own_address_type_t addr_type;
78+
ble::address_t address;
79+
BLE::Instance().gap().getAddress(addr_type, address);
8080
printf("DEVICE MAC ADDRESS: ");
8181
print_address(address);
8282
}

BLE_GAPButton/source/pretty_printer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
6565
}
6666

6767
/** print device address to the terminal */
68-
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
68+
inline void print_address(const ble::address_t &addr)
6969
{
7070
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
7171
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
@@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
7474
inline void print_mac_address()
7575
{
7676
/* Print out device MAC address to the console*/
77-
BLEProtocol::AddressType_t addr_type;
78-
BLEProtocol::AddressBytes_t address;
79-
BLE::Instance().gap().getAddress(&addr_type, address);
77+
ble::own_address_type_t addr_type;
78+
ble::address_t address;
79+
BLE::Instance().gap().getAddress(addr_type, address);
8080
printf("DEVICE MAC ADDRESS: ");
8181
print_address(address);
8282
}

BLE_GattClient/source/pretty_printer.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ inline void print_error(ble_error_t error, const char* msg)
7171
}
7272

7373
/** print device address to the terminal */
74-
inline void print_address(const uint8_t *addr)
74+
inline void print_address(const ble::address_t addr)
7575
{
7676
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
7777
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
@@ -80,16 +80,16 @@ inline void print_address(const uint8_t *addr)
8080
inline void print_mac_address()
8181
{
8282
/* Print out device MAC address to the console*/
83-
BLEProtocol::AddressType_t addr_type;
84-
BLEProtocol::AddressBytes_t address;
85-
BLE::Instance().gap().getAddress(&addr_type, address);
83+
ble::own_address_type_t addr_type;
84+
ble::address_t address;
85+
BLE::Instance().gap().getAddress(addr_type, address);
8686
printf("DEVICE MAC ADDRESS: ");
8787
print_address(address);
8888

8989
if (!seeded) {
9090
seeded = true;
9191
/* use the address as a seed */
92-
uint8_t* random_data = address;
92+
uint8_t* random_data = address.data();
9393
srand(*((unsigned int*)random_data));
9494
}
9595
}

BLE_GattServer/source/pretty_printer.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ inline void print_error(ble_error_t error, const char* msg)
7171
}
7272

7373
/** print device address to the terminal */
74-
inline void print_address(const uint8_t *addr)
74+
inline void print_address(const ble::address_t &addr)
7575
{
7676
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
7777
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
@@ -80,16 +80,16 @@ inline void print_address(const uint8_t *addr)
8080
inline void print_mac_address()
8181
{
8282
/* Print out device MAC address to the console*/
83-
BLEProtocol::AddressType_t addr_type;
84-
BLEProtocol::AddressBytes_t address;
85-
BLE::Instance().gap().getAddress(&addr_type, address);
83+
ble::own_address_type_t addr_type;
84+
ble::address_t address;
85+
BLE::Instance().gap().getAddress(addr_type, address);
8686
printf("DEVICE MAC ADDRESS: ");
8787
print_address(address);
8888

8989
if (!seeded) {
9090
seeded = true;
9191
/* use the address as a seed */
92-
uint8_t* random_data = address;
92+
uint8_t* random_data = address.data();
9393
srand(*((unsigned int*)random_data));
9494
}
9595
}

BLE_HeartRate/source/pretty_printer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
6565
}
6666

6767
/** print device address to the terminal */
68-
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
68+
inline void print_address(const ble::address_t &addr)
6969
{
7070
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
7171
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
@@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
7474
inline void print_mac_address()
7575
{
7676
/* Print out device MAC address to the console*/
77-
BLEProtocol::AddressType_t addr_type;
78-
BLEProtocol::AddressBytes_t address;
79-
BLE::Instance().gap().getAddress(&addr_type, address);
77+
ble::own_address_type_t addr_type;
78+
ble::address_t address;
79+
BLE::Instance().gap().getAddress(addr_type, address);
8080
printf("DEVICE MAC ADDRESS: ");
8181
print_address(address);
8282
}

BLE_LED/source/pretty_printer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
6565
}
6666

6767
/** print device address to the terminal */
68-
inline void print_address(const BLEProtocol::AddressBytes_t &addr)
68+
inline void print_address(const ble::address_t &addr)
6969
{
7070
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
7171
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
@@ -74,9 +74,9 @@ inline void print_address(const BLEProtocol::AddressBytes_t &addr)
7474
inline void print_mac_address()
7575
{
7676
/* Print out device MAC address to the console*/
77-
BLEProtocol::AddressType_t addr_type;
78-
BLEProtocol::AddressBytes_t address;
79-
BLE::Instance().gap().getAddress(&addr_type, address);
77+
ble::own_address_type_t addr_type;
78+
ble::address_t address;
79+
BLE::Instance().gap().getAddress(addr_type, address);
8080
printf("DEVICE MAC ADDRESS: ");
8181
print_address(address);
8282
}

BLE_LEDBlinker/source/pretty_printer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
6565
}
6666

6767
/** print device address to the terminal */
68-
void print_address(const uint8_t *addr)
68+
void print_address(const ble::address_t &addr)
6969
{
7070
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
7171
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
@@ -74,9 +74,9 @@ void print_address(const uint8_t *addr)
7474
inline void print_mac_address()
7575
{
7676
/* Print out device MAC address to the console*/
77-
BLEProtocol::AddressType_t addr_type;
78-
BLEProtocol::AddressBytes_t address;
79-
BLE::Instance().gap().getAddress(&addr_type, address);
77+
ble::own_address_type_t addr_type;
78+
ble::address_t address;
79+
BLE::Instance().gap().getAddress(addr_type, address);
8080
printf("DEVICE MAC ADDRESS: ");
8181
print_address(address);
8282
}

BLE_PeriodicAdvertising/source/pretty_printer.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ inline void print_error(ble_error_t error, const char* msg)
6868
}
6969

7070
/** print device address to the terminal */
71-
inline void print_address(const uint8_t *addr)
71+
inline void print_address(const ble::address_t &addr)
7272
{
7373
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
7474
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
@@ -77,16 +77,16 @@ inline void print_address(const uint8_t *addr)
7777
inline void print_mac_address()
7878
{
7979
/* Print out device MAC address to the console*/
80-
BLEProtocol::AddressType_t addr_type;
81-
BLEProtocol::AddressBytes_t address;
82-
BLE::Instance().gap().getAddress(&addr_type, address);
80+
ble::own_address_type_t addr_type;
81+
ble::address_t address;
82+
BLE::Instance().gap().getAddress(addr_type, address);
8383
printf("DEVICE MAC ADDRESS: ");
8484
print_address(address);
8585

8686
if (!seeded) {
8787
seeded = true;
8888
/* use the address as a seed */
89-
uint8_t* random_data = address;
89+
uint8_t* random_data = address.data();
9090
srand(*((unsigned int*)random_data));
9191
}
9292
}

BLE_Privacy/source/main.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,16 @@ class PrivacyDevice : private mbed::NonCopyable<PrivacyDevice>,
172172
void print_local_address()
173173
{
174174
/* show what address we are using now */
175-
BLEProtocol::AddressType_t addr_type;
176-
BLEProtocol::AddressBytes_t addr;
177-
_ble.gap().getAddress(&addr_type, addr);
175+
ble::own_address_type_t addr_type;
176+
ble::address_t addr;
177+
_ble.gap().getAddress(addr_type, addr);
178178
printf("Device address: ");
179179
print_address(addr);
180180

181181
if (!_seeded) {
182182
_seeded = true;
183183
/* use the address as a seed */
184-
uint8_t* random_data = addr;
184+
uint8_t* random_data = addr.data();
185185
srand(*((unsigned int*)random_data));
186186
}
187187
}

BLE_Privacy/source/pretty_printer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ inline void print_error(ble_error_t error, const char* msg)
6565
}
6666

6767
/** print device address to the terminal */
68-
void print_address(const uint8_t *addr)
68+
void print_address(const ble::address_t &addr)
6969
{
7070
printf("%02x:%02x:%02x:%02x:%02x:%02x\r\n",
7171
addr[5], addr[4], addr[3], addr[2], addr[1], addr[0]);
@@ -74,9 +74,9 @@ void print_address(const uint8_t *addr)
7474
inline void print_mac_address()
7575
{
7676
/* Print out device MAC address to the console*/
77-
BLEProtocol::AddressType_t addr_type;
78-
BLEProtocol::AddressBytes_t address;
79-
BLE::Instance().gap().getAddress(&addr_type, address);
77+
ble::own_address_type_t addr_type;
78+
ble::address_t address;
79+
BLE::Instance().gap().getAddress(addr_type, address);
8080
printf("DEVICE MAC ADDRESS: ");
8181
print_address(address);
8282
}

BLE_SM/source/main.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const static disconnect_call_t disconnect_call = &Gap::disconnect;
4848
/* for demonstration purposes we will store the peer device address
4949
* of the device that connects to us in the first demonstration
5050
* so we can use its address to reconnect to it later */
51-
static BLEProtocol::AddressBytes_t peer_address;
51+
static ble::address_t peer_address;
5252

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

182182
/* print device address */
183-
BLEProtocol::AddressType_t addr_type;
184-
BLEProtocol::AddressBytes_t addr;
185-
_ble.gap().getAddress(&addr_type, addr);
186-
print_address(addr);
183+
print_mac_address();
187184

188185
/* start test in 500 ms */
189186
_event_queue.call_in(500, this, &SMDevice::start);
@@ -278,7 +275,7 @@ class SMDevice : private mbed::NonCopyable<SMDevice>,
278275
protected:
279276
BLE &_ble;
280277
events::EventQueue &_event_queue;
281-
BLEProtocol::AddressBytes_t &_peer_address;
278+
ble::address_t &_peer_address;
282279
ble::connection_handle_t _handle;
283280
bool _is_connecting;
284281
};
@@ -287,7 +284,7 @@ class SMDevice : private mbed::NonCopyable<SMDevice>,
287284
* a change in link security. */
288285
class SMDevicePeripheral : public SMDevice {
289286
public:
290-
SMDevicePeripheral(BLE &ble, events::EventQueue &event_queue, BLEProtocol::AddressBytes_t &peer_address)
287+
SMDevicePeripheral(BLE &ble, events::EventQueue &event_queue, ble::address_t &peer_address)
291288
: SMDevice(ble, event_queue, peer_address) { }
292289

293290
virtual void start()
@@ -352,7 +349,7 @@ class SMDevicePeripheral : public SMDevice {
352349

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

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

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

405402
printf("Scanning for: ");
406-
print_address(_peer_address);
403+
print_address(_peer_address.data());
407404
}
408405

409406
private:
@@ -418,7 +415,7 @@ class SMDeviceCentral : public SMDevice {
418415
}
419416

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

424421
if (error) {

0 commit comments

Comments
 (0)