2021-08-08 17:25:41 -04:00
|
|
|
/*
|
|
|
|
uid.h
|
|
|
|
|
|
|
|
Copyright (c) 2021 Kevin Matz (kevin.matz@gmail.com)
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2021-08-10 01:24:52 -04:00
|
|
|
#include "rdm.h"
|
2021-08-08 17:25:41 -04:00
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
namespace RDM {
|
|
|
|
|
2021-08-16 22:23:06 -04:00
|
|
|
/**
|
|
|
|
* @brief The UID struct
|
|
|
|
*/
|
2021-08-08 17:25:41 -04:00
|
|
|
struct UID {
|
2021-08-25 17:20:33 -04:00
|
|
|
/**
|
|
|
|
* @brief UID
|
|
|
|
* @param dev
|
|
|
|
* @param man
|
|
|
|
* @param flag
|
|
|
|
*/
|
2021-08-13 09:57:53 -04:00
|
|
|
UID(uint32_t dev = 0, uint16_t man = 0, bool flag = false)
|
|
|
|
: device(dev)
|
|
|
|
, esta_man(man)
|
|
|
|
, flag(flag)
|
|
|
|
{};
|
2021-08-08 17:25:41 -04:00
|
|
|
union {
|
|
|
|
uint64_t uid : 48;
|
2021-08-12 15:42:28 -04:00
|
|
|
struct __attribute__((packed)) {
|
2021-08-08 17:25:41 -04:00
|
|
|
uint32_t device;
|
2021-08-13 09:57:53 -04:00
|
|
|
union {
|
|
|
|
uint16_t manufacturer;
|
|
|
|
struct {
|
|
|
|
uint16_t esta_man : 15;
|
|
|
|
bool flag : 1;
|
|
|
|
};
|
|
|
|
};
|
2021-08-08 17:25:41 -04:00
|
|
|
};
|
|
|
|
};
|
2021-08-25 17:20:33 -04:00
|
|
|
/**
|
|
|
|
* @brief isBroadcast
|
|
|
|
* @return
|
|
|
|
*/
|
2021-08-11 00:04:08 -04:00
|
|
|
bool isBroadcast() const {
|
|
|
|
return (uid == BROADCAST_ALL_DEVICES_ID || device == ALL_DEVICE_ID_MASK);
|
|
|
|
}
|
2021-08-25 17:20:33 -04:00
|
|
|
/**
|
|
|
|
* @brief operator ==
|
|
|
|
* @param a
|
|
|
|
* @param b
|
|
|
|
* @return
|
|
|
|
*/
|
2021-08-10 01:24:52 -04:00
|
|
|
friend bool operator== (const UID& a, const UID& b)
|
|
|
|
{
|
|
|
|
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)
|
2021-08-13 09:57:53 -04:00
|
|
|
return (a.esta_man == b.esta_man);
|
2021-08-10 01:24:52 -04:00
|
|
|
return (a.uid == b.uid);
|
|
|
|
}
|
2021-08-25 17:20:33 -04:00
|
|
|
/**
|
|
|
|
* @brief operator !=
|
|
|
|
* @param a
|
|
|
|
* @param b
|
|
|
|
* @return
|
|
|
|
*/
|
2021-08-10 01:24:52 -04:00
|
|
|
friend bool operator!= (const UID& a, const UID& b)
|
|
|
|
{
|
|
|
|
return !(a == b);
|
|
|
|
}
|
2021-08-08 17:25:41 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace RDM
|