HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
simple_thermostat.h
Go to the documentation of this file.
1 // =============================================================================
15 // =============================================================================
16 
17 #ifndef HF_ITF_SIMPLE_THERMOSTAT_H
18 #define HF_ITF_SIMPLE_THERMOSTAT_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 SimpleThermostat
29  {
30  class Server;
31  }
32 
48 
52  namespace SimpleThermostat
53  {
61  typedef enum _CMD
63  {
64  BOOST_START_CMD = 0x01,
65  BOOST_STOP_CMD = 0x02,
66  __LAST_CMD__ = 0xFF,
67  } CMD;
68 
70  typedef enum _Attributes
71  {
74  FAN_MODE_ATTR = 0x03,
82  __LAST_ATTR__ = BOOST_DURATION_ATTR
83  } Attributes;
84 
86  typedef enum _SupportedModesMasks
87  {
88  HEAT_MODE = 0x01,
89  COOL_MODE = 0x02,
90  AUTO_MODE = 0x04,
91  FAN_OFF_MODE = 0x10,
92  FAN_ON_MODE = 0x20,
93  FAN_AUTO_MODE = 0x40,
94  ALL_MODES_MASK = HEAT_MODE | COOL_MODE | AUTO_MODE | FAN_ON_MODE |
97 
98  // =============================================================================
99  // Attribute Helper classes
100  // =============================================================================
101 
106  {
107  static constexpr uint8_t ID = SUPPORTED_MODES_ATTR;
108  static constexpr bool WRITABLE = false;
109 
110  SupportedModes(uint8_t mode = 0, HF::Interface *owner = nullptr):
111  Attribute<uint8_t>(HF::Interface::SIMPLE_THERMOSTAT, ID, owner, mode, WRITABLE)
112  {}
113  };
114 
118  struct HeatCoolMode: public HF::Attributes::Attribute<uint8_t>
119  {
120  static constexpr uint8_t ID = HEAT_COOL_MODE_ATTR;
121  static constexpr bool WRITABLE = true;
122 
123  HeatCoolMode(uint8_t mode = 0, HF::Interface *owner = nullptr):
124  Attribute<uint8_t>(HF::Interface::SIMPLE_THERMOSTAT, ID, owner, mode, WRITABLE)
125  {}
126  };
127 
131  struct FanMode: public HF::Attributes::Attribute<uint8_t>
132  {
133  static constexpr uint8_t ID = FAN_MODE_ATTR;
134  static constexpr bool WRITABLE = true;
135 
136  FanMode(uint8_t mode = 0, HF::Interface *owner = nullptr):
137  Attribute<uint8_t>(HF::Interface::SIMPLE_THERMOSTAT, ID, owner, mode, WRITABLE)
138  {}
139  };
140 
144  template<uint8_t _ID>
145  struct Attribute: public HF::Attributes::Attribute<int16_t>
146  {
147  static constexpr uint8_t ID = _ID;
148  static constexpr bool WRITABLE = true;
149 
150  Attribute(int16_t value = 0, HF::Interface *owner = nullptr):
151  HF::Attributes::Attribute<int16_t>(HF::Interface::SIMPLE_THERMOSTAT, ID, owner,
152  value,
153  WRITABLE)
154  {}
155  };
156 
159 
162 
165 
168 
171 
174 
178  struct BoostDuration: public HF::Attributes::Attribute<uint8_t>
179  {
180  static constexpr uint8_t ID = BOOST_DURATION_ATTR;
181  static constexpr bool WRITABLE = true;
182 
183  BoostDuration(uint8_t mode = 0, HF::Interface *owner = nullptr):
184  Attribute<uint8_t>(HF::Interface::SIMPLE_THERMOSTAT, ID, owner, mode, WRITABLE)
185  {}
186  };
187 
199 
205  struct Base: public Interface<HF::Interface::SIMPLE_THERMOSTAT>
206  {
207  protected:
208 
209  Base() {}
210  };
211 
217  class Server: public InterfaceRole<SimpleThermostat::Base, HF::Interface::SERVER_ROLE>
218  {
219  protected:
220 
222  uint8_t _mode;
223 
224 #if HF_ITF_STS_FAN_MODE
225  uint8_t _fan_mode;
226 #endif
227 #if HF_ITF_STS_HEAT_MODE
228  int16_t _heat_mode_temperature;
229 #endif
230 #if HF_ITF_STS_COOL_MODE
231  int16_t _cool_mode_temperature;
232 #endif
233 #if HF_ITF_STS_AUTO_MODE
234  int16_t _auto_mode_heat_temperature;
235  int16_t _auto_mode_cool_temperature;
236 #endif
237 #if HF_ITF_STS_HEAT_MODE && HF_ITF_STS_HEAT_OFFSET_ATTR
238  int16_t _heat_mode_temperature_offset;
239 #endif
240 #if HF_ITF_STS_COOL_MODE && HF_ITF_STS_COOL_OFFSET_ATTR
241  int16_t _cool_mode_temperature_offset;
242 #endif
243 #if HF_ITF_STS_BOOST_CMD
244  uint8_t _boost_duration;
245 #endif
246  public:
247 
249  Server(const uint8_t __supported_modes = ALL_MODES_MASK):
250  _supported_modes(__supported_modes)
251  {}
252 
254  virtual ~Server() {}
255 
256  // ======================================================================
257  // Events
258  // ======================================================================
261 #if HF_ITF_STS_BOOST_CMD
262 
267  virtual Common::Result boost_start(const Protocol::Address &source)
268  {
269  UNUSED(source);
270  return Common::Result::OK;
271  }
272 
278  virtual Common::Result boost_stop(const Protocol::Address &source)
279  {
280  UNUSED(source);
281  return Common::Result::OK;
282  }
283 #endif
284 
286  // =============================================================================
287  // Get/Set API.
288  // =============================================================================
289 
297  uint8_t supported_modes() const;
298 
306  void supported_modes(uint8_t __supported_modes);
307 
315  uint8_t mode() const;
316 
324  virtual void mode(uint8_t __mode);
325 
326 #if HF_ITF_STS_FAN_MODE
327 
334  uint8_t fan_mode() const;
335 
343  virtual void fan_mode(uint8_t __fan_mode);
344 #endif
345 
346 #if HF_ITF_STS_HEAT_MODE
347 
352  int16_t heat_mode_temperature() const;
353 
359  virtual void heat_mode_temperature(int16_t __temperature);
360 #endif
361 
362 #if HF_ITF_STS_COOL_MODE
363 
368  int16_t cool_mode_temperature() const;
369 
375  virtual void cool_mode_temperature(int16_t __temperature);
376 #endif
377 
378 #if HF_ITF_STS_AUTO_MODE
379 
384  int16_t auto_mode_heat_temperature() const;
385 
391  virtual void auto_mode_heat_temperature(int16_t __temperature);
392 
398  int16_t auto_mode_cool_temperature() const;
399 
405  virtual void auto_mode_cool_temperature(int16_t __temperature);
406 #endif
407 
408 #if HF_ITF_STS_HEAT_MODE && HF_ITF_STS_HEAT_OFFSET_ATTR
409 
414  int16_t heat_mode_temperature_offset() const;
415 
421  virtual void heat_mode_temperature_offset(int16_t __offset);
422 #endif
423 
424 #if HF_ITF_STS_COOL_MODE && HF_ITF_STS_COOL_OFFSET_ATTR
425 
430  int16_t cool_mode_temperature_offset() const;
431 
437  virtual void cool_mode_temperature_offset(int16_t __offset);
438 #endif
439 
440 #if HF_ITF_STS_BOOST_CMD
441 
446  uint8_t boost_duration() const;
447 
453  virtual void boost_duration(uint8_t __duration);
454 #endif
455 
456  // =============================================================================
457  // Attribute API.
458  // =============================================================================
459 
461  {
462  return Interfaces::create_attribute(this, uid);
463  }
464 
465  HF::Attributes::UIDS attributes(uint8_t pack_id =
467 #if HF_ITF_STS_BOOST_CMD
468  protected:
469 
471  uint16_t offset);
472 #endif
473  };
474 
480  struct Client: public InterfaceRole<SimpleThermostat::Base, HF::Interface::CLIENT_ROLE>
481  {
482  // ======================================================================
483  // Commands
484  // ======================================================================
487 #if HF_ITF_STS_BOOST_CMD
488 
494  void boost_start(const Protocol::Address &address);
495 
502  void boost_stop(const Protocol::Address &address);
503 #endif
504  // ======================================================================
506 
507  // ======================================================================
508  // Events
509  // ======================================================================
513 
514 #if HF_ITF_STS_BOOST_CMD
515 
521  virtual void boost_start(const Protocol::Address &source, Common::Result result)
522  {
523  UNUSED(source);
524  UNUSED(result);
525  }
526 
533  virtual void boost_stop(const Protocol::Address &source, Common::Result result)
534  {
535  UNUSED(source);
536  UNUSED(result);
537  }
538 #endif
539  // =============================================================================
541 
542 #if HF_ITF_STS_BOOST_CMD
543  protected:
544 
546  uint16_t offset);
547 #endif
548  };
549 
552  } // namespace SimpleThermostat
553 
554  } // namespace Interfaces
555 
556 } // namespace HF
557 
563 // =============================================================================
564 // Stream Helpers
565 // =============================================================================
566 
575 std::ostream &operator<<(std::ostream &stream, const HF::Interfaces::SimpleThermostat::CMD command);
576 
585 std::ostream &operator<<(std::ostream &stream,
587 
590 #endif /* HF_ITF_SIMPLE_THERMOSTAT_H */
Attribute< COOL_MODE_TEMP_OFFSET_ATTR > CoolModeTemperatureOffset
Helper class to handle the Cool Mode temperature offset attribute for the Simple Thermostat interface...
Attribute< HEAT_MODE_TEMP_ATTR > HeatModeTemperature
Helper class to handle the Heat Mode temperature attribute for the Simple Thermostat interface...
Helper class to handle the Heat/Cool Mode attribute for the Simple Thermostat interface.
static constexpr uint8_t ID
Attribute UID.
Helper class to handle the Boost Duration attribute for the Simple Thermostat interface.
Attribute< COOL_MODE_TEMP_ATTR > CoolModeTemperature
Helper class to handle the Cool Mode temperature attribute for the Simple Thermostat interface...
Attribute< AUTO_MODE_HEAT_TEMP_ATTR > AutoModeHeatTemperature
Helper class to handle the Heat/Cool Mode heat temperature attribute for the Simple Thermostat interf...
HF::Attributes::IAttribute * attribute(uint8_t uid)
Return a pointer to the interface attribute with the given uid.
virtual Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
Helper class to handle the Supported Modes attribute for the Simple Thermostat interface.
List of attributes UIDs.
Definition: attributes.h:176
Attribute< AUTO_MODE_COOL_TEMP_ATTR > AutoModeCoolTemperature
Helper class to handle the Heat/Cool Mode cool temperature attribute for the Simple Thermostat interf...
Return all mandatory attributes for the interface.
Definition: attributes.h:842
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.
static constexpr bool WRITABLE
Attribute Read/Write.
Helper class template for parent class implementation of the interfaces.
Definition: interface.h:371
Simple Thermostat Interface : Server side implementation.
This file contains the definitions for the HAN-FUN protocol messages.
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Interfaces::SimpleThe...
uint8_t supported_modes() const
Get the supported modes for the Simple Thermostat server.
static constexpr uint8_t ID
Attribute UID.
Simple Thermostat Interface : Parent.
This file contains the definitions common to all interfaces.
static constexpr uint8_t ID
Attribute UID.
Simple Thermostat Interface : Client side implementation.
static constexpr bool WRITABLE
Attribute Read/Write.
Helper template class to handle attributes for the Simple Thermostat interface.
Helper class to handle the Fan Mode attribute for the Simple Thermostat interface.
HF::Interface const * owner() const
Definition: attributes.h:414
This class represents a byte array.
Attribute< HEAT_MODE_TEMP_OFFSET_ATTR > HeatModeTemperatureOffset
Helper class to handle the Heat Mode temperature offset attribute for the Simple Thermostat interface...
Network Address.
Definition: protocol.h:201
uint16_t uid() const
This method returns the interface UID.
Definition: interface.h:374
std::ostream & operator<<(std::ostream &stream, const HF::Interfaces::SimpleThermostat::CMD command)
Convert the given command into a string and write it to the given stream.
uint8_t mode() const
Get the current Heat/Cool mode for the Simple Thermostat server.
static constexpr uint8_t ID
Attribute UID.
static constexpr bool WRITABLE
Attribute Read/Write.
HAN-FUN Protocol Packet.
Definition: protocol.h:298
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
SupportedModesMasks
Masks for the Simple Thermostat supported modes.
Server(const uint8_t __supported_modes=ALL_MODES_MASK)
Constructor.
static constexpr bool WRITABLE
Attribute Read/Write.
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
static constexpr bool WRITABLE
Attribute Read/Write.
Common interface for all Interfaces.
Definition: interface.h:43
Result
Commands result codes.
static constexpr uint8_t ID
Attribute UID.
Top-level namespace for the HAN-FUN library.
Definition: attributes.h:22