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

Network Message. More...

#include <protocol.h>

Inherited by HF::Core::BatchProgramManagement::Action.

+ Collaboration diagram for HF::Protocol::Message:

Data Structures

struct  Interface
 Interface Address. More...
 

Public Types

enum  Type {
  COMMAND_REQ = 0x01, COMMAND_RESP_REQ = 0x02, COMMAND_RES = 0x03, GET_ATTR_REQ = 0x04,
  GET_ATTR_RES = 0x05, SET_ATTR_REQ = 0x06, SET_ATTR_RESP_REQ = 0x07, SET_ATTR_RES = 0x08,
  GET_ATTR_PACK_REQ = 0x09, GET_ATTR_PACK_RES = 0x0A, SET_ATTR_PACK_REQ = 0x0B, SET_ATTR_PACK_RESP_REQ = 0x0C,
  SET_ATTR_PACK_RES = 0x0D, ATOMIC_SET_ATTR_PACK_REQ = 0x0E, ATOMIC_SET_ATTR_PACK_RESP_REQ = 0x0F, ATOMIC_SET_ATTR_PACK_RES = 0x10
}
 Message types. More...
 

Public Member Functions

 Message (uint16_t size=0, Type _type=COMMAND_REQ)
 Constructor. More...
 
 Message (const Message &parent, uint16_t size)
 Create a new message that is a response to the given message in parent. 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 isCommand () const
 Check if message type is equal to COMMAND_REQ or to COMMAND_RESP_REQ. More...
 
bool isCommandResponse () const
 Check if message type is equal to COMMAND_RES. More...
 

Data Fields

uint8_t reference
 Application reference. More...
 
Type type
 Message type. More...
 
Interface itf
 Interface Address. More...
 
Common::ByteArray payload
 Message payload.
 
uint16_t length
 The payload length value read when unpacking the message.
 

Static Public Attributes

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

Detailed Description

Network Message.

Definition at line 60 of file protocol.h.

Member Enumeration Documentation

◆ Type

Message types.

Enumerator
COMMAND_REQ 

Command request.

COMMAND_RESP_REQ 

Command request with response required.

COMMAND_RES 

Command response.

GET_ATTR_REQ 

Get attributes request.

GET_ATTR_RES 

Get attributes response.

SET_ATTR_REQ 

Set attributes request.

SET_ATTR_RESP_REQ 

Set attributes request with response required.

SET_ATTR_RES 

Set attributes response.

GET_ATTR_PACK_REQ 

Get pack attributes request.

GET_ATTR_PACK_RES 

Get pack attributes response.

SET_ATTR_PACK_REQ 

Set pack attributes request.

SET_ATTR_PACK_RESP_REQ 

Set pack attributes request with response required.

SET_ATTR_PACK_RES 

Set pack attributes response.

ATOMIC_SET_ATTR_PACK_REQ 

Atomic set pack attributes request.

ATOMIC_SET_ATTR_PACK_RESP_REQ 

Atomic set pack attributes request with response required.

ATOMIC_SET_ATTR_PACK_RES 

Atomic set pack attributes response.

Definition at line 65 of file protocol.h.

66  {
67  COMMAND_REQ = 0x01,
68  COMMAND_RESP_REQ = 0x02,
69  COMMAND_RES = 0x03,
70 
71  GET_ATTR_REQ = 0x04,
72  GET_ATTR_RES = 0x05,
73 
74  SET_ATTR_REQ = 0x06,
75  SET_ATTR_RESP_REQ = 0x07,
76  SET_ATTR_RES = 0x08,
77 
78  GET_ATTR_PACK_REQ = 0x09,
79  GET_ATTR_PACK_RES = 0x0A,
80 
81  SET_ATTR_PACK_REQ = 0x0B,
82  SET_ATTR_PACK_RESP_REQ = 0x0C,
83  SET_ATTR_PACK_RES = 0x0D,
84 
88  } Type;
Set pack attributes request.
Definition: protocol.h:81
Type
Message types.
Definition: protocol.h:65
Get pack attributes request.
Definition: protocol.h:78
Set attributes request with response required.
Definition: protocol.h:75
Set pack attributes response.
Definition: protocol.h:83
Set attributes request.
Definition: protocol.h:74
Atomic set pack attributes response.
Definition: protocol.h:87
Atomic set pack attributes request with response required.
Definition: protocol.h:86
Get pack attributes response.
Definition: protocol.h:79
Get attributes response.
Definition: protocol.h:72
Command request with response required.
Definition: protocol.h:68
Set attributes response.
Definition: protocol.h:76
Atomic set pack attributes request.
Definition: protocol.h:85
Get attributes request.
Definition: protocol.h:71
Set pack attributes request with response required.
Definition: protocol.h:82

Constructor & Destructor Documentation

◆ Message() [1/2]

HF::Protocol::Message::Message ( uint16_t  size = 0,
Type  _type = COMMAND_REQ 
)
inline

Constructor.

Parameters
[in]sizemessage payload size.
[in]_typemessage type.

Definition at line 145 of file protocol.h.

References HF::Protocol::MAX_PAYLOAD, and size().

145  :
146  reference(0), type(_type), payload(Common::ByteArray(size)), length(0)
147  {
148  assert(size <= MAX_PAYLOAD);
149  }
constexpr uint16_t MAX_PAYLOAD
HAN-FUN Network - Maximum application payload length.
Definition: protocol.h:51
Common::ByteArray payload
Message payload.
Definition: protocol.h:134
Type type
Message type.
Definition: protocol.h:127
uint16_t length
The payload length value read when unpacking the message.
Definition: protocol.h:137
uint8_t reference
Application reference.
Definition: protocol.h:126
uint16_t size() const
Number bytes needed to serialize the message.
+ Here is the call graph for this function:

◆ Message() [2/2]

HF::Protocol::Message::Message ( const Message parent,
uint16_t  size 
)

Create a new message that is a response to the given message in parent.

Note
If parent is already a response then the new message has the same type.
Parameters
[in]parentreference to the message to create a response for.
[in]sizesize of the payload buffer.

Member Function Documentation

◆ isCommand()

bool HF::Protocol::Message::isCommand ( ) const

Check if message type is equal to COMMAND_REQ or to COMMAND_RESP_REQ.

Return values
trueif message type is equal to COMMAND_REQ or to COMMAND_RESP_REQ.
falseotherwise.

◆ isCommandResponse()

bool HF::Protocol::Message::isCommandResponse ( ) const

Check if message type is equal to COMMAND_RES.

Return values
trueif message type is equal to COMMAND_RES..
falseotherwise.

◆ pack()

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

Number bytes needed to serialize the message.

Returns
number of bytes the message requires to be serialized.

Referenced by Message().

+ Here is the caller graph for this function:

◆ unpack()

uint16_t HF::Protocol::Message::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.
Warning
This DOES NOT copy the payload portion from the given array into the payload field in this object.

Field Documentation

◆ itf

◆ reference

uint8_t HF::Protocol::Message::reference

Application reference.

Definition at line 126 of file protocol.h.

◆ type


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