HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
Common

This module contains common helper classes, functions and definitions. More...

Data Structures

struct  HF::Common::ByteArray
 This class represents a byte array. More...
 
struct  HF::Common::Serializable
 This represents the common interface for message serialization. More...
 
struct  HF::Common::SerializableHelper< T, typename >
 Wrapper for classes that implement the Serializable concept. More...
 
struct  HF::Common::SerializableHelper< T, EnableIf(IsClassPointer(T))>
 Wrapper to pointers for classes that implement the Serializable concept. More...
 
struct  HF::Common::SerializableHelper< T, EnableIf(IsIntegral(T))>
 Wrapper for base integer types implementing the Serializable API. More...
 
struct  HF::Common::SerializableHelper< Common::ByteArray >
 Wrapper for Common::ByteArray implementing the Serializable API. More...
 
struct  HF::Common::SerializableHelper< std::string >
 Wrapper for std::string implementing the Serializable API. More...
 
struct  HF::Common::SerializableHelper< std::vector< uint8_t > >
 Wrapper for std::vector implementing the Serializable API. More...
 
struct  HF::Common::Cloneable< T >
 This class represents the interface that cloneable objects need to implement. More...
 
struct  HF::Common::Interface
 Interface UID. More...
 
class  HF::Common::Pointer< T >
 Simple raw pointer wrapper. More...
 
struct  HF::Common::IEntries< T >
 Basic API for persistent storage implementations. More...
 

Macros

#define UNUSED(x)   (void) x
 Helper macro to remove warning about unused function/method argument.
 
#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 the given __offset. More...
 
#define HF_NOTIFY_HELPER(_Type, _old_value, _new_value)
 Helper macro to implement attribute notifications. More...
 
#define HF_SETTER_HELPER(_Type, _name, _value)
 Helper macro to implement attribute setters. More...
 
#define HF_ASSERT(_expr, _block)
 Helper macro to check for correct assumptions. More...
 

Enumerations

enum  HF::Common::Precision {
  HF::Common::BASE = 0x00, HF::Common::MILI = 0x10, HF::Common::MICRO = 0x11, HF::Common::NANO = 0x12,
  HF::Common::PICO = 0x13, HF::Common::KILO = 0x20, HF::Common::MEGA = 0x21, HF::Common::GIGA = 0x22,
  HF::Common::TERA = 0x23
}
 These constants represent precisions that a measurement can be in. More...
 
enum  HF::Common::Time { HF::Common::UPTIME = 0x00, HF::Common::UTC = 0x01 }
 This represents the type of time that is associated with a time measurement. More...
 
enum  HF::Common::Result {
  HF::Common::OK = 0x00, HF::Common::FAIL_AUTH = 0x01, HF::Common::FAIL_ARG = 0x02, HF::Common::FAIL_SUPPORT = 0x03,
  HF::Common::FAIL_RO_ATTR = 0x04, HF::Common::FAIL_READ_SESSION = 0x20, HF::Common::FAIL_MODIFIED = 0x21, HF::Common::FAIL_RESOURCES = 0xFE,
  HF::Common::FAIL_UNKNOWN = 0xFF
}
 Commands result codes. More...
 

Functions

template<typename T , typename P = float>
HF::Common::from_percent (P value)
 Convert a percentage value into the [0,std::numeric_limits<T>::max()] range. More...
 
template<typename T , typename P = float>
HF::Common::to_percent (T value)
 Convert a value in the [0,std::numeric_limits<T>::max()] range into a percentage. More...
 
std::ostream & operator<< (std::ostream &stream, const uint8_t byte)
 Convert the given byte into a string and write it to the given stream. More...
 
std::ostream & operator<< (std::ostream &stream, const HF::Common::ByteArray &array)
 Convert the given packet into a string and write it to the given stream if stream == std::cout || stream == std::cerr. More...
 
std::ostream & operator<< (std::ostream &stream, const HF::Common::Interface interface)
 Convert the given interface into a string and write it to the given stream. More...
 

Variables

constexpr uint8_t HF::CORE_VERSION = 2
 Core Service & Interfaces major version supported. More...
 
constexpr uint8_t HF::PROFILES_VERSION = 1
 Profiles major version supported. More...
 
constexpr uint8_t HF::INTERFACES_VERSION = 1
 Interfaces major version supported. More...
 

Detailed Description

This module contains common helper classes, functions and definitions.

Macro Definition Documentation

◆ HF_ASSERT

#define HF_ASSERT (   _expr,
  _block 
)
Value:
{ \
assert(_expr); \
if (!(_expr)) {_block} \
}

Helper macro to check for correct assumptions.

Warning
This macro MAY evaluate the _expr twice.
Parameters
[in]_exprhelper class that wraps the attribute.
[in]_blockcode block to run if the condition fails.

Definition at line 125 of file inc/hanfun/common.h.

Referenced by HF::Interfaces::SimpleVisualEffects::BlinkEffect::pack(), HF::Interfaces::SimpleVisualEffects::BreatheEffect::pack(), HF::Core::GroupManagement::Group::reserve(), HF::Core::Time::Server::tick(), HF::Interfaces::SimpleVisualEffects::BlinkEffect::unpack(), HF::Core::SUOTA::CheckVersionResponse::unpack(), HF::Core::Scheduling::Entry< _Type >::unpack(), and HF::Interfaces::SimpleVisualEffects::BreatheEffect::unpack().

◆ HF_NOTIFY_HELPER

#define HF_NOTIFY_HELPER (   _Type,
  _old_value,
  _new_value 
)
Value:
{ \
_Type old_attr(_old_value, this); \
_Type new_attr(_new_value, this); \
\
notify(old_attr, new_attr); \
}

Helper macro to implement attribute notifications.

Parameters
[in]_Typehelper class that wraps the attribute.
[in]_old_valuethe previous value of the attribute.
[in]_new_valuethe current value of the attribute.

Definition at line 88 of file inc/hanfun/common.h.

◆ HF_SERIALIZABLE_CHECK

#define HF_SERIALIZABLE_CHECK (   __array,
  __offset,
  __size 
)
Value:
{ \
HF_ASSERT(__array.available(__offset, __size), {return 0;}); \
}

Helper macro to check if the given __array has enough size so __size bytes can be written/read from the given __offset.

Warning
This macro issues a return 0; when there aren't enough resources, i.e. the __array size is not sufficient for reading/writing to.
Parameters
[in]__arrayreference to the ByteArray containing the data.
[in]__offsetoffset index to check available data from.
[in]__sizenumber of bytes required.

Definition at line 74 of file inc/hanfun/common.h.

Referenced by msg_t::pack(), HF::Interfaces::SimpleVisualEffects::OnEffect::pack(), HF::UID::UID_T::pack(), HF::Core::SessionManagement::GetEntriesMessage::pack(), HF::UID::NONE::pack(), HF::Interfaces::SimpleVisualEffects::BlinkEffect::pack(), hello_msg_t::pack(), HF::Core::SUOTA::CheckVersionResponse::pack(), HF::Interfaces::SimplePowerMeter::Measurement::pack(), HF::Core::GroupTable::Response::pack(), HF::Interfaces::SimpleVisualEffects::FadeEffect::pack(), HF::UID::ByteArray< MAC, 6, MAC_UID >::pack(), HF::Core::Scheduling::Entry< _Type >::pack(), HF::Core::SUOTA::UpgradeStatus::pack(), HF::Core::GroupTable::ReadEntries::pack(), HF::Interfaces::SimpleVisualEffects::BreatheEffect::pack(), HF::Core::GroupTable::ReadEntriesResponse::pack(), HF::Core::Scheduling::GetEntryResponse< _Type >::pack(), HF::Attributes::Attribute< bool >::pack(), HF::UID::URI::pack(), HF::Common::SerializableHelper< bool >::pack(), HF::Common::SerializableHelper< T, EnableIf(IsClassPointer(T))>::pack(), HF::Common::SerializableHelper< T, EnableIf(IsIntegral(T))>::pack(), HF::Attributes::Attribute< T, _Owner, EnableIf(IsParent(HF::Interface, _Owner))>::pack(), HF::Common::SerializableHelper< Common::ByteArray >::pack(), HF::Common::SerializableHelper< std::vector< uint8_t > >::pack(), HF::Protocol::SetAttributePack::Response::Result::pack(), HF::Interfaces::SimpleVisualEffects::OnEffect::unpack(), msg_t::unpack(), HF::UID::UID_T::unpack(), HF::Core::SessionManagement::GetEntriesMessage::unpack(), HF::UID::NONE::unpack(), HF::Interfaces::SimpleVisualEffects::BlinkEffect::unpack(), HF::Core::SUOTA::CheckVersionResponse::unpack(), HF::Interfaces::SimplePowerMeter::Measurement::unpack(), hello_msg_t::unpack(), HF::Core::GroupTable::Response::unpack(), HF::Interfaces::SimpleVisualEffects::FadeEffect::unpack(), HF::Attributes::UIDS::unpack(), HF::UID::ByteArray< MAC, 6, MAC_UID >::unpack(), HF::Core::Scheduling::Entry< _Type >::unpack(), HF::Core::GroupTable::ReadEntries::unpack(), HF::Core::SUOTA::UpgradeStatus::unpack(), HF::Interfaces::SimpleVisualEffects::BreatheEffect::unpack(), HF::Core::GroupTable::ReadEntriesResponse::unpack(), HF::Core::Scheduling::GetEntryResponse< _Type >::unpack(), HF::Attributes::Attribute< bool >::unpack(), HF::UID::URI::unpack(), HF::Common::SerializableHelper< bool >::unpack(), HF::Common::SerializableHelper< T, EnableIf(IsClassPointer(T))>::unpack(), HF::Common::SerializableHelper< T, EnableIf(IsIntegral(T))>::unpack(), HF::Attributes::Attribute< T, _Owner, EnableIf(IsParent(HF::Interface, _Owner))>::unpack(), HF::Common::SerializableHelper< Common::ByteArray >::unpack(), HF::Common::SerializableHelper< std::vector< uint8_t > >::unpack(), and HF::Protocol::SetAttributePack::Response::Result::unpack().

◆ HF_SETTER_HELPER

#define HF_SETTER_HELPER (   _Type,
  _name,
  _value 
)
Value:
{ \
_Type::value_type old = this->_name; \
\
this->_name = _value; \
HF_NOTIFY_HELPER(_Type, old, this->_name) \
}
#define HF_NOTIFY_HELPER(_Type, _old_value, _new_value)
Helper macro to implement attribute notifications.

Helper macro to implement attribute setters.

Parameters
[in]_Typehelper class that wraps the attribute.
[in]_namename of the attribute to generate the setter for.
[in]_valuename of the variable containing the new value.

Definition at line 105 of file inc/hanfun/common.h.

Enumeration Type Documentation

◆ Precision

These constants represent precisions that a measurement can be in.

Enumerator
BASE 

Base unit.

MILI 

Mili.

MICRO 

Micro.

NANO 

Nano.

PICO 

Pico.

KILO 

Kilo.

MEGA 

Mega.

GIGA 

Giga.

TERA 

Tera.

Definition at line 210 of file inc/hanfun/common.h.

211  {
212  BASE = 0x00,
213  MILI = 0x10,
214  MICRO = 0x11,
215  NANO = 0x12,
216  PICO = 0x13,
217  KILO = 0x20,
218  MEGA = 0x21,
219  GIGA = 0x22,
220  TERA = 0x23,
221  } Precision;
Precision
These constants represent precisions that a measurement can be in.

◆ Result

Commands result codes.

Enumerator
OK 

Request OK.

FAIL_AUTH 

Fail - Not Authorized.

FAIL_ARG 

Fail - Invalid Argument.

FAIL_SUPPORT 

Fail - Not Supported.

FAIL_RO_ATTR 

Fail - Read only attribute.

FAIL_READ_SESSION 

Fail - Read Session not established.

FAIL_MODIFIED 

Fail - Entries table modified.

FAIL_RESOURCES 

Fail - Not enough resources.

FAIL_UNKNOWN 

Fail - Unknown reason.

Definition at line 1107 of file inc/hanfun/common.h.

1108  {
1109  OK = 0x00,
1110  FAIL_AUTH = 0x01,
1111  FAIL_ARG = 0x02,
1112  FAIL_SUPPORT = 0x03,
1113  FAIL_RO_ATTR = 0x04,
1114  FAIL_READ_SESSION = 0x20,
1115  FAIL_MODIFIED = 0x21,
1116  FAIL_RESOURCES = 0xFE,
1117  FAIL_UNKNOWN = 0xFF,
1118  } Result;
Fail - Not enough resources.
Fail - Not Authorized.
Fail - Read Session not established.
Fail - Read only attribute.
Fail - Unknown reason.
Fail - Entries table modified.
Fail - Invalid Argument.
Fail - Not Supported.
Result
Commands result codes.

◆ Time

This represents the type of time that is associated with a time measurement.

Enumerator
UPTIME 

Uptime.

UTC 

UTC time.

Definition at line 227 of file inc/hanfun/common.h.

228  {
229  UPTIME = 0x00,
230  UTC = 0x01,
231  } Time;
Time
This represents the type of time that is associated with a time measurement.

Function Documentation

◆ from_percent()

template<typename T , typename P = float>
T HF::Common::from_percent ( value)

Convert a percentage value into the [0,std::numeric_limits<T>::max()] range.

Parameters
[in]valuethe percentage value to convert.
Template Parameters
Tinteger type to convert to.
Returns
the value equivalent to the percentage in the [0,std::numeric_limits<T>::max()] range.

Definition at line 1346 of file inc/hanfun/common.h.

1347  {
1348  return static_cast<T>(round((static_cast<float>(value) *
1349  std::numeric_limits<T>::max()) / 100.0));
1350  }

◆ operator<<() [1/3]

std::ostream& operator<< ( std::ostream &  stream,
const uint8_t  byte 
)

Convert the given byte into a string and write it to the given stream.

Parameters
[in]streamout stream to write the string to.
[in]bytebyte value to convert to a string.
Returns
stream

◆ operator<<() [2/3]

std::ostream& operator<< ( std::ostream &  stream,
const HF::Common::ByteArray array 
)

Convert the given packet into a string and write it to the given stream if stream == std::cout || stream == std::cerr.

Otherwise send bytes to stream.

Parameters
[in]streamout stream to write the string/bytes to.
[in]arraybyte array to convert to a string/sent to the stream.
Returns
stream

◆ operator<<() [3/3]

std::ostream& operator<< ( std::ostream &  stream,
const HF::Common::Interface  interface 
)

Convert the given interface into a string and write it to the given stream.

Parameters
[in]streamout stream to write the string to.
[in]interfaceinterface value to convert to a string.
Returns
stream

◆ to_percent()

template<typename T , typename P = float>
P HF::Common::to_percent ( value)

Convert a value in the [0,std::numeric_limits<T>::max()] range into a percentage.

Parameters
[in]valuethe value to convert to the percentage.
Template Parameters
Tinteger type to convert from.
Returns
the percentage value.

Definition at line 1362 of file inc/hanfun/common.h.

1363  {
1364  return static_cast<P>(round((static_cast<float>(value) * 100.0) /
1365  std::numeric_limits<T>::max()));
1366  }

Variable Documentation

◆ CORE_VERSION

constexpr uint8_t HF::CORE_VERSION = 2

Core Service & Interfaces major version supported.

Definition at line 151 of file inc/hanfun/common.h.

◆ INTERFACES_VERSION

constexpr uint8_t HF::INTERFACES_VERSION = 1

Interfaces major version supported.

Definition at line 153 of file inc/hanfun/common.h.

◆ PROFILES_VERSION

constexpr uint8_t HF::PROFILES_VERSION = 1

Profiles major version supported.

Definition at line 152 of file inc/hanfun/common.h.