HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
simple_light_sensor.h
Go to the documentation of this file.
1 // =============================================================================
15 // =============================================================================
16 
17 #ifndef HF_ITF_SIMPLE_LIGHT_SENSOR_H
18 #define HF_ITF_SIMPLE_LIGHT_SENSOR_H
19 
20 #include "hanfun/protocol.h"
21 #include "hanfun/interface.h"
22 
23 namespace HF
24 {
25  namespace Interfaces
26  {
27  // Forward declaration.
28  namespace SimpleLightSensor
29  {
30  class Server;
31  }
32 
48 
52  namespace SimpleLightSensor
53  {
62  typedef enum _Attributes
64  {
65  VALUE_ATTR = 0x01,
66  MINIMUM_ATTR = 0x02,
67  MAXIMUM_ATTR = 0x03,
68  TOLERANCE_ATTR = 0x04,
69  __LAST_ATTR__ = TOLERANCE_ATTR
70  } Attributes;
71 
72  // =============================================================================
73  // Attribute Helper classes
74  // =============================================================================
75 
79  struct Value: public HF::Attributes::Attribute<uint32_t>
80  {
81  static constexpr uint8_t ID = VALUE_ATTR;
82  static constexpr bool WRITABLE = false;
83 
84  Value(uint32_t value = 0, HF::Interface *owner = nullptr):
86  {}
87  };
88 
92  struct Minimum: public HF::Attributes::Attribute<uint32_t>
93  {
94  static constexpr uint8_t ID = MINIMUM_ATTR;
95  static constexpr bool WRITABLE = false;
96 
97  Minimum(uint32_t value = 0, HF::Interface *owner = nullptr):
99  {}
100  };
101 
105  struct Maximum: public HF::Attributes::Attribute<uint32_t>
106  {
107  static constexpr uint8_t ID = MAXIMUM_ATTR;
108  static constexpr bool WRITABLE = false;
109 
110  Maximum(uint32_t value = 0, HF::Interface *owner = nullptr):
111  Attribute<uint32_t>(HF::Interface::SIMPLE_LIGHT_SENSOR, ID, owner, value, WRITABLE)
112  {}
113  };
114 
118  struct Tolerance: public HF::Attributes::Attribute<uint32_t>
119  {
120  static constexpr uint8_t ID = TOLERANCE_ATTR;
121  static constexpr bool WRITABLE = false;
122 
123  Tolerance(uint32_t value = 0, HF::Interface *owner = nullptr):
124  Attribute<uint32_t>(HF::Interface::SIMPLE_LIGHT_SENSOR, ID, owner, value, WRITABLE)
125  {}
126  };
127 
139 
145  struct Base: public Interface<HF::Interface::SIMPLE_LIGHT_SENSOR>
146  {
147  protected:
148 
151  };
152 
158  class Server: public InterfaceRole<SimpleLightSensor::Base, HF::Interface::SERVER_ROLE>
159  {
160  protected:
161 
162  uint32_t _value;
163  uint32_t _minimum;
164  uint32_t _maximum;
165  uint32_t _tolerance;
166 
167  public:
168 
176  Server(uint32_t minimum = std::numeric_limits<uint32_t>::min(),
177  uint32_t maximum = std::numeric_limits<uint32_t>::max(),
178  uint32_t tolerance = 0):
180  {}
181 
183  virtual ~Server() {}
184 
185  // =============================================================================
186  // Get/Set API.
187  // =============================================================================
188 
194  uint32_t value() const;
195 
201  void value(uint32_t __value);
202 
208  uint32_t minimum() const;
209 
215  void minimum(uint32_t __value);
216 
222  uint32_t maximum() const;
223 
229  void maximum(uint32_t __value);
230 
236  uint32_t tolerance() const;
237 
243  void tolerance(uint32_t __value);
244 
245  // =============================================================================
246  // Attribute API.
247  // =============================================================================
248 
250 
251  HF::Attributes::UIDS attributes(uint8_t pack_id =
253 
254  };
255 
261  struct Client: public InterfaceRole<SimpleLightSensor::Base, HF::Interface::CLIENT_ROLE>
262  {
264 
265  virtual ~Client() {}
266 
267  // ======================================================================
268  // Commands
269  // ======================================================================
272 
279  void read_all(Protocol::Address &addr);
280 
287  template<Attributes _Attribute>
289  {
290  Protocol::Message message;
291 
292  message.itf.role = SERVER_ROLE;
294  message.itf.member = _Attribute;
296 
297  send(addr, message);
298  }
299 
301  // ======================================================================
302 
303  // ======================================================================
304  // Events
305  // ======================================================================
308 
309  virtual void read_resp(const Protocol::Address &addr,
311  {
312  UNUSED(addr);
313  UNUSED(attr);
314  }
315 
317  // ======================================================================
318 
319  protected:
320 
322  uint16_t offset);
323  };
324 
327  } // namespace SimpleLightSensor
328 
329  } // namespace Interfaces
330 
331 } // namespace HF
332 
338 // =============================================================================
339 // Stream Helpers
340 // =============================================================================
341 
342 
351 std::ostream &operator<<(std::ostream &stream,
355 #endif /* HF_ITF_SIMPLE_LIGHT_SENSOR_H */
std::ostream & operator<<(std::ostream &stream, const HF::Interfaces::SimpleLightSensor::Attributes attribute)
Convert the given attribute into a string and write it to the given stream.
uint32_t maximum() const
Get the Maximum for the Simple Light Sensor server.
static constexpr uint8_t ID
Attribute UID.
static constexpr bool WRITABLE
Attribute Read/Write.
static constexpr uint8_t ID
Attribute UID.
uint32_t value() const
Get the Value for the Simple Light Sensor server.
virtual void send(const Protocol::Address &addr, Protocol::Message &message)=0
Send message msg to the network address given by addr.
static constexpr bool WRITABLE
Attribute Read/Write.
Allows a unit to provide light readings.
Definition: profiles.h:176
static constexpr bool WRITABLE
Attribute Read/Write.
Helper class to handle the Tolerance attribute for the Simple Light Sensor interface.
List of attributes UIDs.
Definition: attributes.h:176
static constexpr bool WRITABLE
Attribute Read/Write.
Return all mandatory attributes for the interface.
Definition: attributes.h:842
static constexpr uint8_t ID
Attribute UID.
Helper class template for parent class implementation of the interfaces.
Definition: interface.h:371
uint16_t id
Identifier of the interface.
This file contains the definitions for the HAN-FUN protocol messages.
void read(Protocol::Address &addr)
Send a GET_ATTR_REQ to the given address to get the current lux readings.
Type type
Message type.
Definition: protocol.h:127
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Interfaces::SimpleLig...
This file contains the definitions common to all interfaces.
Helper class to handle the Minimum attribute for the Simple Light Sensor interface.
HF::Attributes::IAttribute * attribute(uint8_t uid)
Return a pointer to the interface attribute with the given uid.
uint16_t role
Interface role : Server or Client.
HF::Interface const * owner() const
Definition: attributes.h:414
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...
Simple Light Sensor Interface : Server side implementation.
static constexpr uint8_t ID
Attribute UID.
Simple Light Sensor Interface : Client side implementation.
This class represents a byte array.
uint32_t tolerance() const
Get the Tolerance for the Simple Light Sensor server.
Helper class to handle the Value attribute for the Simple Light Sensor interface. ...
Simple Light Sensor interface UID.
Definition: interface.h:90
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
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.
uint32_t minimum() const
Get the Minimum for the Simple Light Sensor server.
HAN-FUN Protocol Packet.
Definition: protocol.h:298
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
Server(uint32_t minimum=std::numeric_limits< uint32_t >::min(), uint32_t maximum=std::numeric_limits< uint32_t >::max(), uint32_t tolerance=0)
Constructor.
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
Attribute(const uint16_t interface, const uint8_t uid, const HF::Interface *__owner, uint32_t data, bool writable=false)
Attribute template constructor.
Definition: attributes.h:360
Common interface for all Interfaces.
Definition: interface.h:43
Simple Light Sensor Interface : Parent.
Get attributes request.
Definition: protocol.h:71
Helper class to handle the Maximum attribute for the Simple Light Sensor interface.
Common::Result handle_attribute(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
Result
Commands result codes.
Top-level namespace for the HAN-FUN library.
Definition: attributes.h:22