62 virtual uint8_t
type()
const = 0;
64 bool operator==(
const UID_T &other)
const 66 return (this->
compare(other) == 0);
69 bool operator!=(
const UID_T &other)
const 71 return !(*
this == other);
90 return (this->
type() - other.
type());
94 static constexpr uint16_t
min_size =
sizeof(uint8_t)
110 return sizeof(uint8_t);
121 assert((
type & (~0x80)) == this->
type());
123 return sizeof(uint8_t);
132 template<u
int8_t _type>
152 array.
write(offset, (uint8_t) 0);
180 return new NONE(*
this);
191 template<
typename _Class, u
int8_t _size, u
int8_t _type>
196 uint8_t value[_size];
209 memcpy(value, _value, _size *
sizeof(uint8_t));
219 memset(value, _value, _size *
sizeof(uint8_t));
236 offset += array.
write(offset, (uint8_t)
sizeof(value));
238 for (uint8_t i = 0; i <
sizeof(value); i++)
240 offset += array.
write(offset, value[i]);
255 assert(
size ==
sizeof(value));
257 if (
size !=
sizeof(value))
262 for (uint8_t i = 0; i <
size; i++)
264 offset += array.
read(offset, value[i]);
279 0 ? memcmp(value, ((_Class *) &other)->value,
sizeof(value)) : res);
320 uint8_t
const &
at(uint16_t index)
const 322 assert(index < _size);
336 uint8_t &
at(uint16_t index)
338 assert(index < _size);
353 memset(value, byte,
sizeof(value));
361 memset(value, 0,
sizeof(value));
381 constexpr
static uint8_t
SIZE = 5;
400 return new DECT(*
this);
410 constexpr
static uint8_t
SIZE = 6;
424 return new MAC(*
this);
438 URI(
const std::string &value):
451 uint16_t start = offset;
455 assert(value.size() <= 0xFF);
456 offset += array.
write(offset, (uint8_t) value.size());
458 for (uint8_t i = 0; i < value.size(); i++)
460 offset += array.
write(offset, (uint8_t) value[i]);
463 return offset - start;
470 uint16_t start = offset;
479 value = std::string(
size, 0);
481 for (uint8_t i = 0; i <
size; i++)
484 offset += array.
read(offset, c);
488 return offset - start;
497 return new URI(*
this);
508 return (res == 0 ? value.compare(((
URI *) &other)->value) : res);
541 UID(): _raw(
new NONE()), owner(
true)
551 _raw(_uid), owner(_owner)
553 assert(_uid !=
nullptr);
561 UID(
UID &&other): _raw(other._raw), owner(other.owner)
573 UID(
const UID &other): _raw(other._raw->clone()), owner(true)
594 bool operator==(
const UID &other)
const 596 return (this->_raw->
compare(*(other._raw)) == 0);
599 bool operator!=(
const UID &other)
const 601 return !(*
this == other);
611 return _raw->
pack(array, offset);
642 this->_raw = other._raw->
clone();
657 std::swap(this->_raw, other._raw);
658 std::swap(this->owner, other.owner);
690 return _raw->
compare(*(other._raw));
734 return (lhs.
compare(rhs) == 0);
739 return (rhs.
compare(lhs) == 0);
744 return !(lhs == rhs);
749 return !(lhs == rhs);
uint8_t const & at(uint16_t index) const
Get byte at the given index, asserting that the index is within the correct range.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
std::ostream & operator<<(std::ostream &stream, const HF::UID::UID &uid)
Convert the given uid into a string and write it to the given stream.
Media Access Control (IEEE-MAC-48)
uint16_t size() const
Number bytes needed to serialize the message.
uint16_t write(uint16_t offset, uint8_t data)
Write a byte into the array at the given offset.
This class represents the interface that cloneable objects need to implement.
virtual uint8_t type() const =0
Type of the UID.
Helper template parent class for all UID's implementation.
Type
Types of UIDs available.
void clear()
Fill the underlining byte array with 0.
virtual T * clone() const =0
Create a clone object of the object where this method is being called.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
This file contains the common defines for the HAN-FUN library.
UID(UID_T *_uid, bool _owner=false)
Constructor.
This represents the common interface for message serialization.
uint16_t size() const
Number bytes needed to serialize the message.
float changed(const UID &other) const
This method is used to get the percentage of change that the attribute has in relation to the value p...
UID(const UID &other)
Copy constructor.
uint16_t size() const
Number bytes needed to serialize the message.
uint8_t type() const
Type of the UID.
void fill(uint8_t byte)
Fill the underlining byte array with the given value.
uint8_t type() const
Type of the UID.
UID_T const * raw() const
Get the underling wrapped UID_T pointer.
URI * clone() const
Create a clone object of the object where this method is being called.
uint16_t pack(Common::ByteArray &array, uint16_t offset) const
Write the object on to a ByteArray so it can be sent over the network.
Uniform Resource Identifier.
static constexpr uint8_t SIZE
Number of bytes in a RFPI UID.
UID & operator=(UID_T *_uid)
Use the given pointer as the pointer of the underlining UID to wrap around of.
Helper template parent class for all UIDs based on fixed number of bytes.
#define HF_SERIALIZABLE_CHECK(__array, __offset, __size)
Helper macro to check if the given __array has enough size so __size bytes can be written/read from t...
ByteArray(uint8_t _value)
Constructor.
ByteArray(uint8_t _value[_size])
Constructor.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
int compare(const UID &other) const
Compare the current UID with the given UID.
virtual int compare(const UID_T &other) const
Compare the current UID with the given UID.
uint8_t const & operator[](uint16_t index) const
Get byte at the given index.
uint8_t & at(uint16_t index)
Get byte at the given index, asserting that the index is within the correct range.
Wrapper around UID_T pointer's.
This class represents a byte array.
UID(UID &&other)
Move constructor.
DECT(uint8_t _value[5])
Constructor.
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
uint16_t size() const
Number bytes needed to serialize the message.
UID & operator=(UID &&other)
Move assignment operator.
std::string str() const
Return the string value associated with this URI.
NONE * clone() const
Create a clone object of the object where this method is being called.
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
DECT * clone() const
Create a clone object of the object where this method is being called.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
uint16_t read(uint16_t offset, uint8_t &data) const
Read the byte at offset into data.
int compare(const UID_T &other) const
Compare the current UID with the given UID.
int compare(const UID_T &other) const
Compare the current UID with the given UID.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
MAC * clone() const
Create a clone object of the object where this method is being called.
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.
static uint16_t length()
Return the number of bytes in the underlining byte array.
This class represents an empty UID.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
uint8_t & operator[](uint16_t index)
Get byte at the given index.
static constexpr uint8_t SIZE
Number of bytes in a MAC UID.
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset)
Read a message from a ByteArray.
UID & operator=(const UID &other)
Copy assignment operator.
int compare(const UID_T &other) const
Compare the current UID with the given UID.
Top-level namespace for the HAN-FUN library.