HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
simple_humidity.h
Go to the documentation of this file.
1 // =============================================================================
15 // =============================================================================
16 #ifndef HF_ITF_SIMPLE_HUMIDITY_H
17 #define HF_ITF_SIMPLE_HUMIDITY_H
18 
19 #include "hanfun/common.h"
20 
21 #include "hanfun/interface.h"
22 
23 namespace HF
24 {
25  namespace Interfaces
26  {
27  namespace SimpleHumidity
28  {
29  class Server;
30  }
31 
47  uint8_t uid);
48 
52  namespace SimpleHumidity
53  {
63  typedef enum _Attributes
65  {
66  VALUE_ATTR = 0x01,
67  TOLERANCE_ATTR = 0x02,
68  __LAST_ATTR__ = TOLERANCE_ATTR,
69  } Attributes;
70 
75  struct Humidity: public HF::Attributes::Attribute<uint16_t>
76  {
77  static constexpr uint8_t ID = VALUE_ATTR;
78  static constexpr bool WRITABBLE = false;
79 
80  Humidity(uint16_t value = 0, HF::Interface *owner = nullptr):
81  Attribute<uint16_t>(HF::Interface::SIMPLE_HUMIDITY, ID, owner, value, WRITABBLE)
82  {}
83  };
84 
88  struct Tolerance: public HF::Attributes::Attribute<uint16_t>
89  {
90  static constexpr uint8_t ID = TOLERANCE_ATTR;
91  static constexpr bool WRITABBLE = false;
92 
93  Tolerance(uint16_t value = 0, HF::Interface *owner = nullptr):
94  Attribute<uint16_t>(HF::Interface::SIMPLE_HUMIDITY, ID, owner, value, WRITABBLE)
95  {}
96  };
97 
109  {
110  return Interfaces::create_attribute(static_cast<SimpleHumidity::Server *>(nullptr),
111  uid);
112  }
113 
119  struct Base: public Interface<HF::Interface::SIMPLE_HUMIDITY>
120  {
121  protected:
122 
123  Base() {}
124  };
125 
131  class Server: public InterfaceRole<SimpleHumidity::Base, HF::Interface::SERVER_ROLE>
132  {
133  protected:
134 
136  uint16_t _value;
137 
138  const uint16_t _tolerance;
139 
140  public:
141 
143  Server(uint16_t tolerance = 0): _value(0), _tolerance(tolerance)
144  {}
145 
146  virtual ~Server() {}
147 
148  // ======================================================================
149  // API
150  // ======================================================================
151 
157  uint16_t humidity();
158 
164  void humidity(uint16_t __value);
165 
171  uint16_t tolerance();
172 
173  // =============================================================================
174  // Attributes API
175  // =============================================================================
176 
178  {
179  return Interfaces::create_attribute(this, uid);
180  }
181 
182  HF::Attributes::UIDS attributes(uint8_t pack_id =
184  };
185 
191  class Client: public InterfaceRole<SimpleHumidity::Base, HF::Interface::CLIENT_ROLE>
192  {
193  public:
194 
195  // ======================================================================
196  // Commands
197  // ======================================================================
200 
207  void read_all(Protocol::Address &addr);
208 
215  template<Attributes _Attribute>
217  {
218  Protocol::Message message;
219 
220  message.itf.role = SERVER_ROLE;
221  message.itf.id = SimpleHumidity::Client::uid();
222  message.itf.member = _Attribute;
224 
225  send(addr, message);
226  }
227 
229  // ======================================================================
230 
231  // ======================================================================
232  // Events
233  // ======================================================================
236 
237  virtual void read_resp(const Protocol::Address &addr,
239  {
240  UNUSED(addr);
241  UNUSED(attr);
242  }
243 
245  // ======================================================================
246 
247  protected:
248 
250  uint16_t offset);
251 
252  };
253 
255  }
256  }
257 }
258 
259 #endif /* HF_ITF_SIMPLE_HUMIDITY_H */
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.
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Interfaces::SimpleHum...
void read(Protocol::Address &addr)
Send a GET_ATTR_REQ to the given address to get the current humidity.
Measured humidity attribute UID.
virtual void send(const Protocol::Address &addr, Protocol::Message &message)=0
Send message msg to the network address given by addr.
Server(uint16_t tolerance=0)
Constructor.
void read_all(Protocol::Address &addr)
Send a GET_ATTR_PACK_REQ to the given address to get the values for all the attributes in the server...
List of attributes UIDs.
Definition: attributes.h:176
Return all mandatory attributes for the interface.
Definition: attributes.h:842
This file contains the common defines for the HAN-FUN library.
Simple Humidity Interface : Server side interface.
Helper class template for parent class implementation of the interfaces.
Definition: interface.h:371
uint16_t tolerance()
Getter for the tolerance attribute.
uint16_t id
Identifier of the interface.
Simple Humidity Interface : Parent.
Type type
Message type.
Definition: protocol.h:127
Common::Result handle_attribute(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
This file contains the definitions common to all interfaces.
HF::Attributes::IAttribute * attribute(uint8_t uid)
Return a pointer to the interface attribute with the given uid.
Level Control Interface : Client side implementation.
uint16_t role
Interface role : Server or Client.
HF::Interface const * owner() const
Definition: attributes.h:414
This class represents a byte array.
Network Address.
Definition: protocol.h:201
uint8_t member
Interface destination member.
Definition: protocol.h:99
uint16_t uid() const
This method returns the interface UID.
Definition: interface.h:374
Network Message.
Definition: protocol.h:60
uint16_t _value
Current measured humidity.
Simple Humidity interface UID.
Definition: interface.h:85
HAN-FUN Protocol Packet.
Definition: protocol.h:298
uint16_t humidity()
Getter for the current measured humidity.
Interface itf
Interface Address.
Definition: protocol.h:129
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.
Definition: attributes.h:44
Helper class to handle the Measured Humidity attribute for the Simple Humidity interface.
Helper class template for implementing a given interface role.
Definition: interface.h:394
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.
Helper template class to declare an attribute with the given T type.
Definition: attributes.h:349
Helper class to handle the Tolerance attribute for the Simple Humidity interface. ...
Common interface for all Interfaces.
Definition: interface.h:43
Get attributes request.
Definition: protocol.h:71
Result
Commands result codes.
Top-level namespace for the HAN-FUN library.
Definition: attributes.h:22