Bike service
Fork of BLE_API by
Diff: ble/BLEProtocol.h
- Revision:
- 1115:82d4a8a56d91
- Parent:
- 1078:79c089630b38
- Child:
- 1119:7a487d506451
--- a/ble/BLEProtocol.h Mon Jan 11 08:52:00 2016 +0000 +++ b/ble/BLEProtocol.h Mon Jan 11 08:52:01 2016 +0000 @@ -19,6 +19,8 @@ #include <stddef.h> #include <stdint.h> +#include <algorithm> +#include <string.h> /** * A common namespace for types and constants used everywhere in BLE API. @@ -43,7 +45,31 @@ typedef AddressType::Type AddressType_t; /**< Alias for AddressType::Type */ static const size_t ADDR_LEN = 6; /**< Length (in octets) of the BLE MAC address. */ - typedef uint8_t Address_t[ADDR_LEN]; /**< 48-bit address, in LSB format. */ + typedef uint8_t AddressBytes_t[ADDR_LEN]; /**< 48-bit address, in LSB format. */ + + /** + * BLE address. It contains an address-type (@ref AddressType_t) and bytes (@ref AddressBytes_t). + */ + struct Address_t { + AddressType_t type; /**< @ref AddressType_t */ + AddressBytes_t address; /**< @ref AddressBytes_t */ + + Address_t(AddressType_t typeIn, const AddressBytes_t& addressIn) : type(typeIn) { + std::copy(addressIn, addressIn + ADDR_LEN, address); + } + + Address_t(void) : type(AddressType::PUBLIC), address() { + } + + bool operator<(const Address_t &rhs) const { + if (type < rhs.type) { + return true; + } else if (type > rhs.type) { + return false; + } + return (memcmp(address, rhs.address, sizeof(AddressBytes_t)) < 0) ? true : false; + } + }; }; #endif /* __BLE_PROTOCOL_H__ */ \ No newline at end of file