HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
HF::Protocol::Address Struct Reference

Network Address. More...

#include <protocol.h>

+ Inheritance diagram for HF::Protocol::Address:
+ Collaboration diagram for HF::Protocol::Address:

Public Types

enum  Type { DEVICE = 0, GROUP = 1 }
 HAN-FUN Network Destination Address Types. More...
 

Public Member Functions

 Address (uint16_t _dev=BROADCAST_ADDR, uint8_t _unit=BROADCAST_UNIT, Type _mod=DEVICE)
 Create a new message address. More...
 
uint16_t size () const
 Number bytes needed to serialize the message. More...
 
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. More...
 
uint16_t unpack (const Common::ByteArray &array, uint16_t offset=0)
 Read a message from a ByteArray. More...
 
bool is_broadcast ()
 Checks if this address if for the Protocol::BROADCAST_ADDR and Protocol::BROADCAST_UNIT. More...
 
bool is_local (uint16_t address)
 Checks if the given device address is equal to the device address present in this Protocol::Address object. More...
 
int compare (const Address &other) const
 Compare this address with the given address in other. More...
 

Data Fields

uint16_t mod: 1
 Address modifier. More...
 
uint16_t device: 15
 Device Address. More...
 
uint8_t unit
 Source Unit. More...
 

Static Public Attributes

static constexpr uint16_t min_size
 Minimum pack/unpack required data size.
 

Detailed Description

Network Address.

Definition at line 201 of file protocol.h.

Member Enumeration Documentation

◆ Type

HAN-FUN Network Destination Address Types.

Enumerator
DEVICE 

Destination address is for single device.

GROUP 

Destination address is for a group of devices.

Definition at line 211 of file protocol.h.

212  {
213  DEVICE = 0,
214  GROUP = 1,
215  } Type;
Destination address is for single device.
Definition: protocol.h:213
Type
HAN-FUN Network Destination Address Types.
Definition: protocol.h:211
Destination address is for a group of devices.
Definition: protocol.h:214

Constructor & Destructor Documentation

◆ Address()

HF::Protocol::Address::Address ( uint16_t  _dev = BROADCAST_ADDR,
uint8_t  _unit = BROADCAST_UNIT,
Type  _mod = DEVICE 
)
inline

Create a new message address.

Parameters
[in]_devdevice address. Default HF_BROADCAST_ADDR.
[in]_unitunit address. Default HF_BROADCAST_UNIT.
[in]_modaddress modifier. Default DEVICE_ADDR.

Definition at line 224 of file protocol.h.

225  :
226  mod(_mod), device(_dev), unit(_unit)
227  {}
uint8_t unit
Source Unit.
Definition: protocol.h:206
uint16_t mod
Address modifier.
Definition: protocol.h:203
uint16_t device
Device Address.
Definition: protocol.h:204

Member Function Documentation

◆ compare()

int HF::Protocol::Address::compare ( const Address other) const
inline

Compare this address with the given address in other.

This method should return < 0 if this address is less that, 0 if it is equal and > 0 if greater that the other address.

Parameters
[in]otheraddress to compare to.
Return values
<0if address less than other;
0if address equal to other;
>0if address greater than other.

Definition at line 280 of file protocol.h.

References HF::Protocol::BROADCAST_ADDR.

281  {
282  auto serialize = [this](const Address &a)
283  {
284  return (((a.mod & 0x01) << 15) | (a.device & BROADCAST_ADDR)) |
285  a.unit;
286  };
287 
288  uint32_t t = serialize(*this);
289  uint32_t o = serialize(other);
290 
291  return t - o;
292  }
constexpr uint16_t BROADCAST_ADDR
HAN-FUN Broadcast - device address.
Definition: protocol.h:45
Address(uint16_t _dev=BROADCAST_ADDR, uint8_t _unit=BROADCAST_UNIT, Type _mod=DEVICE)
Create a new message address.
Definition: protocol.h:224

◆ is_broadcast()

bool HF::Protocol::Address::is_broadcast ( )
inline

Checks if this address if for the Protocol::BROADCAST_ADDR and Protocol::BROADCAST_UNIT.

Return values
trueif it is the network's broadcast address,
falseotherwise.

Definition at line 249 of file protocol.h.

References HF::Protocol::BROADCAST_ADDR, HF::Protocol::BROADCAST_UNIT, device, and unit.

250  {
251  return device == BROADCAST_ADDR && unit == BROADCAST_UNIT;
252  }
uint8_t unit
Source Unit.
Definition: protocol.h:206
constexpr uint16_t BROADCAST_ADDR
HAN-FUN Broadcast - device address.
Definition: protocol.h:45
uint16_t device
Device Address.
Definition: protocol.h:204
constexpr uint8_t BROADCAST_UNIT
HAN-FUN Broadcast - unit address.
Definition: protocol.h:48

◆ is_local()

bool HF::Protocol::Address::is_local ( uint16_t  address)
inline

Checks if the given device address is equal to the device address present in this Protocol::Address object.

Parameters
[in]addressnetwork address to match.
Return values
trueif it is the network's address are equal,
falseotherwise.

Definition at line 263 of file protocol.h.

References device.

264  {
265  return this->device == address;
266  }
uint16_t device
Device Address.
Definition: protocol.h:204

◆ pack()

uint16_t HF::Protocol::Address::pack ( Common::ByteArray array,
uint16_t  offset = 0 
) const

Write the object on to a ByteArray so it can be sent over the network.

The buffer passed in MUST have enough size to hold the serialized object, e.g.,

Serializable obj;
ByteArray payload(obj.size());
obj.pack(payload);
Parameters
[in,out]arrayByteArray reference to write the object to.
[in]offsetoffset to start writing to.
Returns
the number of bytes written.

◆ size()

uint16_t HF::Protocol::Address::size ( ) const

Number bytes needed to serialize the message.

Returns
number of bytes the message requires to be serialized.

◆ unpack()

uint16_t HF::Protocol::Address::unpack ( const Common::ByteArray array,
uint16_t  offset = 0 
)

Read a message from a ByteArray.

Parameters
[in]arrayByteArray reference to read the message from.
[in]offsetoffset to start reading from.
Returns
the number of bytes read.

Field Documentation

◆ device

uint16_t HF::Protocol::Address::device

◆ mod

uint16_t HF::Protocol::Address::mod

Address modifier.

Definition at line 203 of file protocol.h.

◆ unit

uint8_t HF::Protocol::Address::unit

Source Unit.

Definition at line 206 of file protocol.h.

Referenced by is_broadcast().


The documentation for this struct was generated from the following file: