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

Message sent between the concentrator and the nodes. More...

+ Collaboration diagram for msg_t:

Public Member Functions

 msg_t (uint16_t primitive=NONE_MSG)
 Constructor. More...
 
 msg_t (uint16_t primitive, HF::Common::ByteArray &data)
 Constructor. More...
 
uint16_t size () const
 Number bytes needed to serialize the message. More...
 
uint16_t pack (HF::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 (HF::Common::ByteArray &array, uint16_t offset=0)
 Read a message from a ByteArray. More...
 

Data Fields

uint16_t nbytes
 Number of bytes in the message. More...
 
uint16_t primitive
 Message type. More...
 
HF::Common::ByteArray data
 Message payload. More...
 

Static Public Attributes

static constexpr uint16_t min_size = sizeof(nbytes) + sizeof(primitive)
 Minimum pack/unpack required data size.
 

Detailed Description

Message sent between the concentrator and the nodes.

Definition at line 60 of file transport.cpp.

Constructor & Destructor Documentation

◆ msg_t() [1/2]

msg_t::msg_t ( uint16_t  primitive = NONE_MSG)
inline

Constructor.

Parameters
[in]primitivemessage type.

Definition at line 71 of file transport.cpp.

71  :
73  {}
uint16_t primitive
Message type.
Definition: transport.cpp:63

◆ msg_t() [2/2]

msg_t::msg_t ( uint16_t  primitive,
HF::Common::ByteArray data 
)
inline

Constructor.

Parameters
[in]primitivemessage type.
[in]datamessage payload.

Definition at line 81 of file transport.cpp.

81  :
83  {}
uint16_t primitive
Message type.
Definition: transport.cpp:63
HF::Common::ByteArray data
Message payload.
Definition: transport.cpp:64

Member Function Documentation

◆ pack()

uint16_t msg_t::pack ( HF::Common::ByteArray array,
uint16_t  offset = 0 
) const
inline

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.

Definition at line 95 of file transport.cpp.

References data, HF_SERIALIZABLE_CHECK, primitive, size(), and HF::Common::ByteArray::write().

96  {
97  HF_SERIALIZABLE_CHECK(array, offset, size());
98 
99  uint16_t start = offset;
100 
101  uint16_t temp = (uint16_t) (sizeof(uint16_t) + data.size());
102 
103  offset += array.write(offset, temp);
104 
105  offset += array.write(offset, primitive);
106 
107  std::copy(data.begin(), data.end(), array.begin() + offset);
108 
109  return offset - start;
110  }
uint16_t write(uint16_t offset, uint8_t data)
Write a byte into the array at the given offset.
#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...
uint16_t primitive
Message type.
Definition: transport.cpp:63
HF::Common::ByteArray data
Message payload.
Definition: transport.cpp:64
uint16_t size() const
Number bytes needed to serialize the message.
Definition: transport.cpp:89
+ Here is the call graph for this function:

◆ size()

uint16_t msg_t::size ( ) const
inline

Number bytes needed to serialize the message.

Returns
number of bytes the message requires to be serialized.

Definition at line 89 of file transport.cpp.

References data, and min_size.

Referenced by pack().

90  {
91  return min_size + data.size();
92  }
HF::Common::ByteArray data
Message payload.
Definition: transport.cpp:64
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Definition: transport.cpp:86
+ Here is the caller graph for this function:

◆ unpack()

uint16_t msg_t::unpack ( HF::Common::ByteArray array,
uint16_t  offset = 0 
)
inline

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.

Definition at line 113 of file transport.cpp.

References data, HF_SERIALIZABLE_CHECK, min_size, nbytes, primitive, and HF::Common::ByteArray::read().

114  {
115  HF_SERIALIZABLE_CHECK(array, offset, min_size);
116 
117  uint16_t start = offset;
118 
119  offset += array.read(offset, nbytes);
120 
121  offset += array.read(offset, primitive);
122 
123  uint16_t data_size = nbytes - sizeof(primitive);
124 
125  data = HF::Common::ByteArray(data_size);
126 
127  auto begin = array.begin();
128 
129  begin += offset;
130 
131  auto end = begin + data_size;
132 
133  std::copy(begin, end, data.begin());
134 
135  return offset - start;
136  }
#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...
uint16_t primitive
Message type.
Definition: transport.cpp:63
uint16_t nbytes
Number of bytes in the message.
Definition: transport.cpp:62
This class represents a byte array.
HF::Common::ByteArray data
Message payload.
Definition: transport.cpp:64
uint16_t read(uint16_t offset, uint8_t &data) const
Read the byte at offset into data.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Definition: transport.cpp:86
+ Here is the call graph for this function:

Field Documentation

◆ data

HF::Common::ByteArray msg_t::data

Message payload.

Definition at line 64 of file transport.cpp.

Referenced by pack(), size(), and unpack().

◆ nbytes

uint16_t msg_t::nbytes

Number of bytes in the message.

Definition at line 62 of file transport.cpp.

Referenced by unpack().

◆ primitive

uint16_t msg_t::primitive

Message type.

Definition at line 63 of file transport.cpp.

Referenced by pack(), and unpack().


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