16 #ifndef HF_INTERFACE_H 17 #define HF_INTERFACE_H 127 virtual uint16_t
uid()
const = 0;
149 uint16_t offset) = 0;
156 virtual void periodic(uint32_t time) = 0;
224 return uid() == other.
uid();
227 bool operator!=(AbstractInterface &other)
229 return !(*
this == other);
240 virtual void send(
const Protocol::Address &addr, Protocol::Message &message) = 0;
321 template<
typename _Message>
326 return message.size();
370 template<u
int16_t _u
id,
typename Parent = AbstractInterface>
381 bool check_uid(uint16_t
uid)
const 393 template<
typename Itf, HF::Interface::Role _role>
411 template<
typename _Interface,
typename _Proxy>
414 static_assert(std::is_base_of<Interfaces::AbstractInterface, _Interface>::value,
415 "Interface MUST be of type HF::Interfaces::AbstractInterface !");
417 typedef _Interface base;
425 proxy.send(addr, message);
432 proxy.notify(old_value, new_value);
444 template<
typename Base,
typename... Proxies>
447 typedef std::tuple<Proxies...> interfaces_t;
450 interfaces_t _interfaces;
470 return itf->
handle(packet, payload, offset);
497 std::vector<Common::Interface> result;
498 result.reserve(
sizeof ... (Proxies));
504 temp.
id = itf.
uid ();
506 result.push_back (temp);
513 void periodic(uint32_t time)
528 const typename std::tuple_element<N, interfaces_t>::type::base *
get()
const 530 return &std::get<N>(_interfaces);
569 template<uint8_t N,
typename Head,
typename... Tail>
572 static_assert(std::is_base_of<HF::Interface, Head>::value,
573 "Head must be of type HF::Interface");
575 const Head &head = std::get<N>(_interfaces);
577 if (head.uid() == itf_uid)
579 return const_cast<Head *
>(&head);
583 return find<N + 1, Tail...>(itf_uid);
614 template<uint8_t N,
typename Head,
typename... Tail>
617 const auto &head = std::get<N>(this->_interfaces);
619 func(*(const_cast<HF::Interface *>(static_cast<const HF::Interface *>(&head))));
652 template<uint8_t N,
typename Head,
typename... Tail>
656 const auto &head = std::get<N>(this->_interfaces);
658 if (head.uid() == itf.
id)
Common::Result check(Protocol::Message &message, Common::ByteArray &payload, uint16_t offset)
Check if message has correct attributes to be processed by the interface.
This class represents a HAN-FUN Concentrator.
virtual HF::Attributes::IAttribute * attribute(uint8_t uid)=0
Return a pointer to the interface attribute with the given uid.
virtual void periodic(uint32_t time)=0
Handle periodic processing.
List get(const HF::Interface &itf, uint8_t pack_id, const UIDS &uids)
Get a list with the attributes for the given interface, pack id or the uids passed in...
UID
Interfaces Unique Identifiers (UID).
Group Management interface UID.
Top-level parent class for all implemented interfaces.
HF::Interface::Role role() const
Return the Interface::Role this interface implements.
HF::Interface * find(uint16_t itf_uid) const
Final template instantiation that finds the wrapped interface with the given UID. ...
HF::Interface * find(uint16_t itf_uid) const
Find the interface with the given UID.
virtual void notify(const HF::Attributes::IAttribute &old_value, const HF::Attributes::IAttribute &new_value) const
Notify that an attribute value as changed.
virtual void send(const Protocol::Address &addr, Protocol::Message &message)=0
Send message msg to the network address given by addr.
virtual Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
Message message
Packet message payload;.
void attributes_itf(HF::Attributes::List &attrs, Common::Interface itf, uint8_t pack_id, const HF::Attributes::UIDS &uids) const
Helper function used to provide HF::Units::Unit::attributes functionality.
Attribute Reporting interface UID.
Weekly Scheduling interface UID.
This file contains the definitions for the attribute handling API in HAN-FUN.
HF::Attributes::IAttribute * attribute(uint8_t uid)
Return a pointer to the interface attribute with the given uid.
Colour Control interface UID.
Return all mandatory attributes for the interface.
This file contains the common defines for the HAN-FUN library.
Common::Result handle(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
uint16_t payload_size_helper() const
Helper function template to retrieve minimum size required for serializing/deserializing the class gi...
Simple Temperature interface UID.
Helper class template for parent class implementation of the interfaces.
Container(Base &base)
Constructor.
_Proxy & proxy
Referent to the class providing the required functionality.
Helper class to add optional interfaces to other classes.
virtual Common::Result handle_attribute(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
uint16_t id
Identifier of the interface.
This class has the same behavior has a list, however the list element access methods where overwritte...
Simple Keypad interface UID.
This file contains the definitions for the HAN-FUN protocol messages.
void for_each(std::function< void(HF::Interface &)> func) const
Helper template function to implement the HF::Units::Unit::for_each functionality.
Helper template class to allow interfaces implementation to be added as fields to other classes...
Helper class to match any interface.
virtual 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::vector< Common::Interface > interfaces() const
Return the list of interfaces present in the wrapper.
void for_each(std::function< void(HF::Interface &)> func) const
Call the given function for all the interfaces.
Simple Button interface UID.
Device Management interface UID.
void notify(const HF::Attributes::IAttribute &old_value, const HF::Attributes::IAttribute &new_value) const
Notify that an attribute value as changed.
uint16_t role
Interface role : Server or Client.
virtual HF::Attributes::UIDS attributes(uint8_t pack_id=HF::Attributes::Pack::MANDATORY) const =0
Return a vector containing the attribute UIDs, for the given pack ID.
void send(const Protocol::Address &addr, Protocol::Message &message)
Send message msg to the network address given by addr.
Simple Power Meter interface UID.
This class represents a byte array.
static constexpr uint8_t MAX_CMD_ID
Maximum value for command IDs in interfaces.
Simple Light Sensor interface UID.
Common::Result check_payload_size(Protocol::Message &message, Common::ByteArray &payload, uint16_t offset)
Check if payload data size if sufficient for processing the message.
Common::Result handle(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
Group Table interface UID.
Simple Visual Effects interface UID.
Level Control interface UID.
uint16_t uid() const
This method returns the interface UID.
virtual bool check_uid(uint16_t uid) const =0
Check if the given UID matches the interface UID.
void for_each(std::function< void(HF::Interface &)> func)
Call the given function for all the interfaces.
virtual uint16_t payload_size(Protocol::Message &message) const
Return the minimal payload size that should be present for the given message.
std::ostream & operator<<(std::ostream &stream, const HF::Interface::Role role)
Convert the given role into a string and write it to the given stream.
Simple Humidity interface UID.
Event Scheduling interface UID.
Interface itf
Interface Address.
Interface/Service Attribute API.
Simple Air Pressure interface UID.
Tamper Alert interface UID.
virtual Interface::Role role() const =0
Return the Interface::Role this interface implements.
Helper class template for implementing a given interface role.
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.
void for_each(std::function< void(HF::Interface &)> func) const
Helper template function to implement the HF::Units::Unit::for_each functionality.
Bind Management interface UID.
virtual Common::Result handle(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)=0
Handle incoming messages from the network.
Device information interface UID.
Common interface for all Interfaces.
Simple Thermostat interface UID.
virtual 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.
void attributes(HF::Attributes::List &attr_list, Common::Interface itf, uint8_t pack_id, const HF::Attributes::UIDS &uids) const
Return a list of all the attributes for a given interface, pack id and list of attributes UID's...
void attributes_itf(HF::Attributes::List &attrs, Common::Interface itf, uint8_t pack_id, const HF::Attributes::UIDS &uids) const
Helper function used to provide HF::Units::Unit::attributes functionality.
void periodic(uint32_t time)
Handle periodic processing.
virtual uint16_t uid() const =0
This method returns the interface UID.
Batch Program Management interface UID.
Result
Commands result codes.
Keep Alive interface UID.
Top-level namespace for the HAN-FUN library.