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

This represents a measurement for a given attribute. More...

#include <simple_power_meter.h>

+ Collaboration diagram for HF::Interfaces::SimplePowerMeter::Measurement:

Public Member Functions

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...
 
int compare (const Measurement &other) const
 Compare this attribute with the given attribute in other. More...
 
float changed (const Measurement &other) const
 This method is used to get the percentage of change that the attribute has in relation to the value present in other. More...
 

Data Fields

uint8_t unit
 Measurement precision/type. More...
 
uint32_t value
 Measurement value. More...
 

Static Public Attributes

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

Detailed Description

This represents a measurement for a given attribute.

Definition at line 152 of file simple_power_meter.h.

Member Function Documentation

◆ changed()

float HF::Interfaces::SimplePowerMeter::Measurement::changed ( const Measurement other) const
inline

This method is used to get the percentage of change that the attribute has in relation to the value present in other.

Parameters
[in]otherattribute holding a previous value.
Returns
float indicating the percentage of change.
Todo:
Take unit into consideration.

Definition at line 210 of file simple_power_meter.h.

References value.

211  {
212  return (((float) (value - other.value)) / other.value);
213  }

◆ compare()

int HF::Interfaces::SimplePowerMeter::Measurement::compare ( const Measurement other) const
inline

Compare this attribute with the given attribute in other.

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

Parameters
[in]otherattribute to compare to.
Return values
<0if attribute less than other;
0if attribute equal to other;
>0if attribute greater than other.
Todo:
Take unit into consideration.

Definition at line 198 of file simple_power_meter.h.

References value.

199  {
200  int res = value - other.value;
201 
202  return res;
203  }

◆ pack()

uint16_t HF::Interfaces::SimplePowerMeter::Measurement::pack ( 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 168 of file simple_power_meter.h.

References HF_SERIALIZABLE_CHECK, min_size, unit, value, and HF::Common::ByteArray::write().

169  {
170  HF_SERIALIZABLE_CHECK(array, offset, min_size);
171 
172  offset += array.write(offset, static_cast<uint8_t>(unit));
173  array.write(offset, value);
174 
175  return min_size;
176  }
uint8_t unit
Measurement precision/type.
#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...
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
+ Here is the call graph for this function:

◆ size()

uint16_t HF::Interfaces::SimplePowerMeter::Measurement::size ( ) const
inline

Number bytes needed to serialize the message.

Returns
number of bytes the message requires to be serialized.

Definition at line 162 of file simple_power_meter.h.

References min_size.

163  {
164  return min_size;
165  }
static constexpr uint16_t min_size
Minimum pack/unpack required data size.

◆ unpack()

uint16_t HF::Interfaces::SimplePowerMeter::Measurement::unpack ( const 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 179 of file simple_power_meter.h.

References HF_SERIALIZABLE_CHECK, min_size, HF::Common::ByteArray::read(), unit, and value.

180  {
181  HF_SERIALIZABLE_CHECK(array, offset, min_size);
182 
183  uint8_t temp;
184  offset += array.read(offset, temp);
185 
186  unit = static_cast<Common::Precision>(temp);
187 
188  offset += array.read(offset, value);
189 
190  return min_size;
191  }
uint8_t unit
Measurement precision/type.
#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...
Precision
These constants represent precisions that a measurement can be in.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
+ Here is the call graph for this function:

Field Documentation

◆ unit

uint8_t HF::Interfaces::SimplePowerMeter::Measurement::unit

Measurement precision/type.

Definition at line 158 of file simple_power_meter.h.

Referenced by pack(), and unpack().

◆ value

uint32_t HF::Interfaces::SimplePowerMeter::Measurement::value

Measurement value.

Definition at line 159 of file simple_power_meter.h.

Referenced by changed(), compare(), pack(), and unpack().


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