unpack structure for portability
This commit is contained in:
parent
4cd8289a85
commit
9fe57bc363
|
@ -367,12 +367,12 @@ void Responder::actionDiscoverUniqueBranch(const MsgPtr message, MsgPtr response
|
|||
upper.manufacturer = Message::readType<uint16_t>(*message->data(), 6);
|
||||
upper.device = Message::readType<uint32_t>(*message->data(), 8);
|
||||
|
||||
if (id_.uid < lower.uid)
|
||||
if (id_.uid() < lower.uid())
|
||||
{
|
||||
response->do_not_send = true;
|
||||
return;
|
||||
}
|
||||
if (id_.uid > upper.uid)
|
||||
if (id_.uid() > upper.uid())
|
||||
{
|
||||
response->do_not_send = true;
|
||||
return;
|
||||
|
|
|
@ -40,28 +40,36 @@ struct UID {
|
|||
*/
|
||||
UID(uint32_t dev = 0, uint16_t man = 0, bool flag = false)
|
||||
: device(dev)
|
||||
, esta_man(man)
|
||||
, manufacturer(man)
|
||||
, flag(flag)
|
||||
{};
|
||||
union {
|
||||
uint64_t uid : 48;
|
||||
struct __attribute__((packed)) {
|
||||
uint32_t device;
|
||||
union {
|
||||
uint16_t manufacturer;
|
||||
struct {
|
||||
uint16_t esta_man : 15;
|
||||
bool flag : 1;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
uint32_t device; //!< manufacturer assigned device ID
|
||||
uint16_t manufacturer; //!< ESTA assigned manufacturer ID
|
||||
bool flag; //!< dynamic flag
|
||||
|
||||
/**
|
||||
* @brief uid
|
||||
* @return
|
||||
*/
|
||||
uint64_t uid() const {
|
||||
uint64_t uid = device | (manufacturer < 32);
|
||||
if (flag)
|
||||
uid |= (0b1 < 47);
|
||||
return uid; }
|
||||
/**
|
||||
* @brief lower 15 bits of the manufacturer
|
||||
* @return
|
||||
*/
|
||||
uint16_t esta_man() const {
|
||||
return manufacturer & 0x7FFF;
|
||||
}
|
||||
/**
|
||||
* @brief isBroadcast
|
||||
* @return
|
||||
*/
|
||||
bool isBroadcast() const {
|
||||
return (uid == BROADCAST_ALL_DEVICES_ID || device == ALL_DEVICE_ID_MASK);
|
||||
return (uid() == BROADCAST_ALL_DEVICES_ID || device == ALL_DEVICE_ID_MASK);
|
||||
}
|
||||
/**
|
||||
* @brief operator ==
|
||||
|
@ -71,11 +79,11 @@ struct UID {
|
|||
*/
|
||||
friend bool operator== (const UID& a, const UID& b)
|
||||
{
|
||||
if (a.uid == BROADCAST_ALL_DEVICES_ID || b.uid == BROADCAST_ALL_DEVICES_ID)
|
||||
if (a.uid() == BROADCAST_ALL_DEVICES_ID || b.uid() == BROADCAST_ALL_DEVICES_ID)
|
||||
return true;
|
||||
if (a.device == ALL_DEVICE_ID_MASK || b.device == ALL_DEVICE_ID_MASK)
|
||||
return (a.esta_man == b.esta_man);
|
||||
return (a.uid == b.uid);
|
||||
return (a.esta_man() == b.esta_man());
|
||||
return (a.uid() == b.uid());
|
||||
}
|
||||
/**
|
||||
* @brief operator !=
|
||||
|
|
Loading…
Reference in New Issue