HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
simple_temperature.h
Go to the documentation of this file.
1 // =============================================================================
15 // =============================================================================
16 #ifndef HF_ITF_SIMPLE_TEMPERATURE_H
17 #define HF_ITF_SIMPLE_TEMPERATURE_H
18 
19 #include "hanfun/common.h"
20 
21 #include "hanfun/interface.h"
22 
23 namespace HF
24 {
25  namespace Interfaces
26  {
27  namespace SimpleTemperature
28  {
29  class Server;
30  }
31 
47 
51  namespace SimpleTemperature
52  {
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 
76  struct Temperature: public HF::Attributes::Attribute<int16_t>
77  {
78  static constexpr uint8_t ID = VALUE_ATTR;
79  static constexpr bool WRITABBLE = false;
80 
81  Temperature(int16_t value = 0, HF::Interface *owner = nullptr):
82  Attribute<int16_t>(HF::Interface::SIMPLE_TEMPERATURE, ID, owner, value, WRITABBLE)
83  {}
84  };
85 
91  {
92  static constexpr uint8_t ID = MINIMUM_ATTR;
93  static constexpr bool WRITABBLE = false;
94 
95  MininumTemperature(int16_t value = 0, HF::Interface *owner = nullptr):
96  Attribute<int16_t>(HF::Interface::SIMPLE_TEMPERATURE, ID, owner, value, WRITABBLE)
97  {}
98  };
99 
105  {
106  static constexpr uint8_t ID = MAXIMUM_ATTR;
107  static constexpr bool WRITABBLE = false;
108 
109  MaximumTemperature(int16_t value = 0, HF::Interface *owner = nullptr):
110  Attribute<int16_t>(HF::Interface::SIMPLE_TEMPERATURE, ID, owner, value, WRITABBLE)
111  {}
112  };
113 
117  struct Tolerance: public HF::Attributes::Attribute<uint16_t>
118  {
119  static constexpr uint8_t ID = TOLERANCE_ATTR;
120  static constexpr bool WRITABBLE = false;
121 
122  Tolerance(uint16_t value = 0, HF::Interface *owner = nullptr):
123  Attribute<uint16_t>(HF::Interface::SIMPLE_TEMPERATURE, ID, owner, value, WRITABBLE)
124  {}
125  };
126 
138  {
139  return Interfaces::create_attribute(static_cast<SimpleTemperature::Server *>(nullptr),
140  uid);
141  }
142 
148  struct Base: public Interface<HF::Interface::SIMPLE_TEMPERATURE>
149  {
150  protected:
151 
152  Base() {}
153  };
154 
160  class Server: public InterfaceRole<SimpleTemperature::Base, HF::Interface::SERVER_ROLE>
161  {
162  protected:
163 
165  int16_t _value;
166 
167  const int16_t _minimum;
168  const int16_t _maximum;
169  const uint16_t _tolerance;
170 
171  public:
172 
180  Server(int16_t minimum = std::numeric_limits<int16_t>::min(),
181  int16_t maximum = std::numeric_limits<int16_t>::max(),
182  int16_t tolerance = 0):
183  _value(0), _minimum(minimum), _maximum(maximum),
185  {}
186 
187  virtual ~Server() {}
188 
189  // ======================================================================
190  // API
191  // ======================================================================
192 
198  int16_t temperature();
199 
205  void temperature(int16_t __value);
206 
212  int16_t minimum_temperature();
213 
219  int16_t maximum_temperature();
220 
226  uint16_t tolerance();
227 
228  // =============================================================================
229  // Attributes API
230  // =============================================================================
231 
233  {
234  return Interfaces::create_attribute(this, uid);
235  }
236 
237  HF::Attributes::UIDS attributes(uint8_t pack_id =
239  };
240 
246  class Client: public InterfaceRole<SimpleTemperature::Base, HF::Interface::CLIENT_ROLE>
247  {
248  public:
249 
250  // ======================================================================
251  // Commands
252  // ======================================================================
255 
262  void read_all(Protocol::Address &addr);
263 
270  template<Attributes _Attribute>
272  {
273  Protocol::Message message;
274 
275  message.itf.role = SERVER_ROLE;
277  message.itf.member = _Attribute;
279 
280  send(addr, message);
281  }
282 
284  // ======================================================================
285 
286  // ======================================================================
287  // Events
288  // ======================================================================
291 
292  virtual void read_resp(const Protocol::Address &addr,
294  {
295  UNUSED(addr);
296  UNUSED(attr);
297  }
298 
299  virtual void read_resp(const Protocol::Address &addr,
301  {
302  UNUSED(addr);
303  UNUSED(attr);
304  }
305 
307  // ======================================================================
308 
309  protected:
310 
312  uint16_t offset);
313 
314  };
315 
317  }
318  }
319 }
320 
321 #endif /* HF_ITF_SIMPLE_TEMPERATURE_H */
int16_t maximum_temperature()
Getter for the maximum measurable temperature.
int16_t minimum_temperature()
Getter for the minimum measurable temperature.
virtual void send(const Protocol::Address &addr, Protocol::Message &message)=0
Send message msg to the network address given by addr.
const int16_t _maximum
Maximum measurable temperature.
List of attributes UIDs.
Definition: attributes.h:176
Helper class to handle the Minimum Measured Temperature attribute for the Simple Temperature interfac...
void read(Protocol::Address &addr)
Send a GET_ATTR_REQ to the given address to get the current temperature.
Return all mandatory attributes for the interface.
Definition: attributes.h:842
This file contains the common defines for the HAN-FUN library.
Simple Temperature interface UID.
Definition: interface.h:84
Helper class template for parent class implementation of the interfaces.
Definition: interface.h:371
Level Control Interface : Client side implementation.
uint16_t id
Identifier of the interface.
int16_t temperature()
Getter for the current measured temperature.
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.
Type type
Message type.
Definition: protocol.h:127
HF::Attributes::IAttribute * attribute(uint8_t uid)
Return a pointer to the interface attribute with the given uid.
Simple Temperature Interface : Server side interface.
This file contains the definitions common to all interfaces.
Server(int16_t minimum=std::numeric_limits< int16_t >::min(), int16_t maximum=std::numeric_limits< int16_t >::max(), int16_t tolerance=0)
Constructor.
Helper class to handle the Tolerance attribute for the Simple Temperature interface.
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...
Helper class to handle the Measured Temperature attribute for the Simple Temperature interface...
uint16_t role
Interface role : Server or Client.
HF::Interface const * owner() const
Definition: attributes.h:414
int16_t _value
Current measured temperature.
This class represents a byte array.
uint16_t tolerance()
Getter for the tolerance attribute.
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
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
const int16_t _minimum
Minimum measurable temperature.
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Interfaces::SimpleTem...
Measured temperature attribute UID.
Maximum measured temperature attribute UID.
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.
Common::Result handle_attribute(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
Helper template class to declare an attribute with the given T type.
Definition: attributes.h:349
Common interface for all Interfaces.
Definition: interface.h:43
Get attributes request.
Definition: protocol.h:71
Helper class to handle the Maximum Measured Temperature attribute for the Simple Temperature interfac...
Minimum measured temperature attribute UID.
Simple Temperature Interface : Parent.
Result
Commands result codes.
Top-level namespace for the HAN-FUN library.
Definition: attributes.h:22