16 #ifndef HF_ITF_SIMPLE_POWER_METER_H 17 #define HF_ITF_SIMPLE_POWER_METER_H 28 #if HF_ITF_SPM_REPORT_CMD 30 #if !HF_ITF_SPM_REPORT_INTERVAL_ATTR 31 #define HF_ITF_SPM_REPORT_INTERVAL_ATTR 1 36 #if HF_ITF_SPM_RESET_CMD 38 #if !HF_ITF_SPM_ENERGY_ATTR 39 #undef HF_ITF_SPM_ENERGY_ATTR 40 #define HF_ITF_SPM_ENERGY_ATTR 1 43 #if !HF_ITF_SPM_ENERGY_AT_RESET_ATTR 44 #undef HF_ITF_SPM_ENERGY_AT_RESET_ATTR 45 #define HF_ITF_SPM_ENERGY_AT_RESET_ATTR 1 48 #if !HF_ITF_SPM_TIME_AT_RESET_ATTR 49 #undef HF_ITF_SPM_TIME_AT_RESET_ATTR 50 #define HF_ITF_SPM_TIME_AT_RESET_ATTR 1 60 #define ATTR_SETTER(__type, __arg, __uid) \ 66 HF::Attributes::Attribute<__type> *old_attr = \ 67 static_cast<HF::Attributes::Attribute<__type> *>(create_attribute(__uid)); \ 70 HF::Attributes::Attribute<__type> *new_attr = \ 71 static_cast<HF::Attributes::Attribute<__type> *>(attribute(__uid)); \ 73 notify(*old_attr, *new_attr); \ 88 namespace SimplePowerMeter
113 namespace SimplePowerMeter
133 typedef enum _Attributes
155 static constexpr uint16_t
min_size =
sizeof(uint8_t)
172 offset += array.
write(offset, static_cast<uint8_t>(
unit));
184 offset += array.
read(offset, temp);
249 static constexpr uint16_t
min_size =
sizeof(uint8_t);
252 uint16_t
size()
const;
289 return payload_size_helper<Report>();
305 #if HF_ITF_SPM_ENERGY_ATTR 309 #if HF_ITF_SPM_ENERGY_AT_RESET_ATTR 313 #if HF_ITF_SPM_TIME_AT_RESET_ATTR 317 #if HF_ITF_SPM_POWER_ATTR 321 #if HF_ITF_SPM_AVG_POWER_ATTR 325 #if HF_ITF_SPM_AVG_POWER_INTERVAL_ATTR 326 uint16_t _avg_power_interval;
329 #if HF_ITF_SPM_POWER_FACTOR_ATTR 330 uint8_t _power_factor;
333 #if HF_ITF_SPM_VOLTAGE_ATTR 337 #if HF_ITF_SPM_CURRENT_ATTR 341 #if HF_ITF_SPM_FREQUENCY_ATTR 345 #if HF_ITF_SPM_REPORT_CMD 346 uint16_t _report_interval;
348 uint32_t _last_periodic;
368 #if HF_ITF_SPM_ENERGY_ATTR 390 #if HF_ITF_SPM_ENERGY_AT_RESET_ATTR 412 #if HF_ITF_SPM_TIME_AT_RESET_ATTR 434 #if HF_ITF_SPM_POWER_ATTR 456 #if HF_ITF_SPM_AVG_POWER_ATTR 478 #if HF_ITF_SPM_AVG_POWER_INTERVAL_ATTR 484 uint16_t avg_power_interval()
486 return _avg_power_interval;
494 void avg_power_interval(uint16_t value)
500 #if HF_ITF_SPM_POWER_FACTOR_ATTR 506 uint8_t power_factor()
508 return _power_factor;
516 void power_factor(uint8_t value)
522 #if HF_ITF_SPM_VOLTAGE_ATTR 544 #if HF_ITF_SPM_CURRENT_ATTR 566 #if HF_ITF_SPM_FREQUENCY_ATTR 588 #if HF_ITF_SPM_REPORT_CMD 594 uint16_t report_interval()
596 return _report_interval;
604 void report_interval(uint16_t value)
702 std::ostream &
operator<<(std::ostream &stream,
HF::Attributes::IAttribute * attribute(uint8_t uid)
Return a pointer to the interface attribute with the given uid.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Measurement Reset command ID.
uint16_t write(uint16_t offset, uint8_t data)
Write a byte into the array at the given offset.
Average Power Attribute ID.
Simple Power Meter Interface : Server side implementation.
void periodic(uint32_t time)
Handle periodic processing.
Measurement voltage
Voltage measurement.
Power Factor Attribute ID.
Simple Power Meter Interface : Parent.
Instantaneous Power Attribute ID.
Return all mandatory attributes for the interface.
This file contains the common defines for the HAN-FUN library.
Measurement avg_power
Average Power measurement.
Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
Report Interval Attribute ID.
Helper class template for parent class implementation of the interfaces.
This file contains the definitions for the HAN-FUN protocol messages.
uint8_t unit
Measurement precision/type.
Average Power Interval Attribute ID.
int compare(const Measurement &other) const
Compare this attribute with the given attribute in other.
Energy at Last Reset Attribute ID.
#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.
This file contains the definitions common to all interfaces.
This represents a measurement for a given attribute.
virtual Report * report()
Create a report message.
uint16_t size() const
Number bytes needed to serialize the message.
This class represents a byte array.
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Interfaces::SimplePow...
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
virtual void report(Protocol::Address &source, Report &report)
Receive a report message from a server.
Simple Power Meter Interface : Client side implementation.
uint16_t uid() const
This method returns the interface UID.
std::ostream & operator<<(std::ostream &stream, const HF::Interfaces::SimplePowerMeter::CMD command)
Convert the given command into a string and write it to the given stream.
Measurement energy
Energy measurement.
Time at Last Reset Attribute ID.
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 p...
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.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
HF::Attributes::IAttribute * create_attribute(HF::Interfaces::Alert::Server *server, uint8_t uid)
Create an attribute object that can hold the attribute with the given uid.
Interface/Service Attribute API.
Attributes
Attributes IDs.
HF::Attributes::UIDS attributes(uint8_t pack_id=HF::Attributes::Pack::MANDATORY) const
Return a vector containing the attribute UIDs, for the given pack ID.
uint16_t read(uint16_t offset, uint8_t &data) const
Read the byte at offset into data.
Measurement current
Current measurement.
Helper class template for implementing a given interface role.
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.
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.
uint16_t avg_power_interval
Average Power Interval.
uint8_t power_factor
Power Factor.
uint32_t value
Measurement value.
Measurement power
Instantaneous Power measurement.
uint16_t size() const
Number bytes needed to serialize the message.
Measurement last_energy
Energy measurement at last reset.
Measurement frequency
Frequency measurement.
Measurement last_time
Device time measurement at last reset.
#define ATTR_SETTER(__type, __arg, __uid)
Helper macro used to support attribute reporting.
Result
Commands result codes.
uint16_t payload_size(Protocol::Message::Interface &itf) const
Return the minimal payload size that a message should hold when addressed at the given interface...
std::array< bool, __LAST_ATTR__+1 > enabled
This array contains an indication of with attributes should be packed or were unpacked.
Top-level namespace for the HAN-FUN library.