28 #ifndef INCLUDE_OLA_RDM_UID_H_ 29 #define INCLUDE_OLA_RDM_UID_H_ 33 #include <ola/util/Utils.h> 66 UID(uint16_t esta_id, uint32_t device_id) {
67 m_uid.esta_id = esta_id;
68 m_uid.device_id = device_id;
75 explicit UID(uint64_t uid) {
76 m_uid.esta_id =
static_cast<uint16_t
>(uid >> 32);
77 m_uid.device_id =
static_cast<uint32_t
>(uid);
85 m_uid.esta_id = uid.m_uid.esta_id;
86 m_uid.device_id = uid.m_uid.device_id;
94 explicit UID(
const uint8_t *data) {
104 if (
this != &other) {
105 m_uid.esta_id = other.m_uid.esta_id;
106 m_uid.device_id = other.m_uid.device_id;
116 return 0 == cmp(*
this, other);
124 return 0 != cmp(*
this, other);
132 return cmp(*
this, other) > 0;
140 return cmp(*
this, other) < 0;
148 return cmp(*
this, other) >= 0;
156 return cmp(*
this, other) <= 0;
169 uint32_t
DeviceId()
const {
return m_uid.device_id; }
201 return *
this == uid ||
212 return ((static_cast<uint64_t>(m_uid.esta_id) << 32) + m_uid.device_id);
220 std::ostringstream str;
221 str << std::setfill(
'0') << std::setw(4) << std::hex << m_uid.esta_id
222 <<
":" << std::setw(8) << m_uid.device_id;
241 bool Pack(uint8_t *buffer,
unsigned int length)
const {
244 buffer[0] =
static_cast<uint8_t
>(m_uid.esta_id >> 8);
245 buffer[1] =
static_cast<uint8_t
>(m_uid.esta_id & 0xff);
246 buffer[2] =
static_cast<uint8_t
>(m_uid.device_id >> 24);
247 buffer[3] =
static_cast<uint8_t
>(m_uid.device_id >> 16);
248 buffer[4] =
static_cast<uint8_t
>(m_uid.device_id >> 8);
249 buffer[5] =
static_cast<uint8_t
>(m_uid.device_id & 0xff);
312 struct rdm_uid m_uid;
314 int cmp(
const UID &a,
const UID &b)
const {
315 if (a.m_uid.esta_id == b.m_uid.esta_id) {
316 return cmp(a.m_uid.device_id, b.m_uid.device_id);
318 return cmp(a.m_uid.esta_id, b.m_uid.esta_id);
321 int cmp(uint32_t a, uint32_t b)
const {
325 return a < b ? -1 : 1;
330 #endif // INCLUDE_OLA_RDM_UID_H_ UID(const UID &uid)
Copy constructor.
Definition: UID.h:84
bool operator<=(const UID &other) const
Less than or equal to.
Definition: UID.h:155
static const uint16_t ALL_MANUFACTURERS
The value for the 'all manufacturers' id.
Definition: UID.h:299
bool IsBroadcast() const
Check if this UID is a broadcast or vendorcast UID.
Definition: UID.h:175
bool DirectedToUID(const UID &uid) const
Check if this UID matches against another.
Definition: UID.h:200
static const uint32_t ALL_DEVICES
The value for the 'all devices' id.
Definition: UID.h:304
uint16_t ManufacturerId() const
The manufacturer ID for this UID.
Definition: UID.h:163
bool operator==(const UID &other) const
Equality operator.
Definition: UID.h:115
UID(uint64_t uid)
Constructs a new UID from a uint64_t.
Definition: UID.h:75
static UID VendorcastAddress(uint16_t esta_id)
Returns a UID that matches all devices for a particular manufacturer.
Definition: UID.h:267
UID(const uint8_t *data)
Construct a new UID from binary data.
Definition: UID.h:94
friend std::ostream & operator<<(std::ostream &out, const UID &uid)
A helper function to write a UID to an ostream.
Definition: UID.h:231
uint16_t JoinUInt8(uint8_t high, uint8_t low)
Convert two uint8_t's to a uint16_t.
Definition: Utils.h:50
UID & operator=(const UID &other)
Assignment operator.
Definition: UID.h:103
UID(uint16_t esta_id, uint32_t device_id)
Constructs a new UID.
Definition: UID.h:66
static UID * FromString(const std::string &uid)
Return a new UID from a string.
Definition: UID.cpp:32
Represents a RDM UID.
Definition: UID.h:57
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
bool operator>(const UID &other) const
Greater than.
Definition: UID.h:131
uint64_t ToUInt64() const
Convert a UID to a uint64_t.
Definition: UID.h:211
uint32_t DeviceId() const
The device ID for this UID.
Definition: UID.h:169
std::string ToString() const
Convert a UID to a human readable string.
Definition: UID.h:219
static UID VendorcastAddress(UID uid)
Returns a UID that matches all devices for a particular manufacturer.
Definition: UID.h:277
bool operator!=(const UID &other) const
Inequality operator.
Definition: UID.h:123
bool operator<(const UID &other) const
Less than.
Definition: UID.h:139
static UID AllDevices()
Returns a UID that matches all devices (ffff:ffffffff).
Definition: UID.h:257
bool operator>=(const UID &other) const
Greater than or equal to.
Definition: UID.h:147
bool Pack(uint8_t *buffer, unsigned int length) const
Write the binary representation of the UID to memory.
Definition: UID.h:241