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

HAN-FUN Protocol Packet. More...

#include <protocol.h>

+ Collaboration diagram for HF::Protocol::Packet:

Public Member Functions

 Packet (Message &message)
 Constructor. More...
 
 Packet (Address &dst_addr, Message &message, uint8_t unit=BROADCAST_UNIT)
 Constructor. More...
 
 Packet (Address &src_addr, Address &dst_addr, Message &message)
 Constructor. 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...
 

Data Fields

Address source
 Source Address. More...
 
Address destination
 Destination Address. More...
 
Message message
 Packet message payload;.
 
Transport::Linklink
 Link where this packet originated from.
 

Static Public Attributes

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

Detailed Description

HAN-FUN Protocol Packet.

Definition at line 298 of file protocol.h.

Constructor & Destructor Documentation

◆ Packet() [1/3]

HF::Protocol::Packet::Packet ( Message message)
inline

Constructor.

Parameters
[in]messagemessage this packet holds.

Definition at line 318 of file protocol.h.

318 : message(message), link(nullptr) {}
Message message
Packet message payload;.
Definition: protocol.h:306
Transport::Link * link
Link where this packet originated from.
Definition: protocol.h:309

◆ Packet() [2/3]

HF::Protocol::Packet::Packet ( Address dst_addr,
Message message,
uint8_t  unit = BROADCAST_UNIT 
)
inline

Constructor.

Parameters
[in]dst_addrdestination device address.
[in]messagemessage to be sent.
[in]unitdestination unit for this packet.

Definition at line 327 of file protocol.h.

327  :
328  destination(dst_addr), message(message), link(nullptr)
329  {
332  source.unit = unit;
333  }
uint8_t unit
Source Unit.
Definition: protocol.h:206
Destination address is for single device.
Definition: protocol.h:213
Message message
Packet message payload;.
Definition: protocol.h:306
constexpr uint16_t BROADCAST_ADDR
HAN-FUN Broadcast - device address.
Definition: protocol.h:45
Transport::Link * link
Link where this packet originated from.
Definition: protocol.h:309
Address destination
Destination Address.
Definition: protocol.h:301
Address source
Source Address.
Definition: protocol.h:300
uint16_t mod
Address modifier.
Definition: protocol.h:203
uint16_t device
Device Address.
Definition: protocol.h:204

◆ Packet() [3/3]

HF::Protocol::Packet::Packet ( Address src_addr,
Address dst_addr,
Message message 
)
inline

Constructor.

Parameters
[in]src_addrsource device address for packet.
[in]dst_addrdestination device address for packet.
[in]messagemessage payload.

Definition at line 342 of file protocol.h.

342  :
343  source(src_addr), destination(dst_addr), message(message), link(nullptr)
344  {}
Message message
Packet message payload;.
Definition: protocol.h:306
Transport::Link * link
Link where this packet originated from.
Definition: protocol.h:309
Address destination
Destination Address.
Definition: protocol.h:301
Address source
Source Address.
Definition: protocol.h:300

Member Function Documentation

◆ pack()

uint16_t HF::Protocol::Packet::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::Packet::size ( ) const

Number bytes needed to serialize the message.

Returns
number of bytes the message requires to be serialized.

◆ unpack()

uint16_t HF::Protocol::Packet::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.

Referenced by HF::Transport::AbstractLayer::receive().

+ Here is the caller graph for this function:

Field Documentation

◆ destination

Address HF::Protocol::Packet::destination

Destination Address.

Definition at line 301 of file protocol.h.

Referenced by HF::Devices::AbstractDevice::to_local().

◆ source

Address HF::Protocol::Packet::source

Source Address.

Definition at line 300 of file protocol.h.

Referenced by HF::Devices::AbstractDevice::from_local().


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