HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
simple_keypad.h
Go to the documentation of this file.
1 // =============================================================================
15 // =============================================================================
16 
17 #ifndef HF_ITF_SIMPLE_KEYPAD_H
18 #define HF_ITF_SIMPLE_KEYPAD_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 SimpleKeypad
29  {
30  class Server;
31  }
32 
48 
52  namespace SimpleKeypad
53  {
61  typedef enum _CMD
63  {
64  KEYPRESSED_CMD = 0x01,
65  __LAST_CMD__ = KEYPRESSED_CMD
66  } CMD;
67 
71  struct KeyPressed
72  {
73  uint32_t key_id;
74 
75  KeyPressed(uint32_t _key_id = 0): key_id(_key_id)
76  {}
77 
79  static constexpr uint16_t min_size = sizeof(uint32_t);
80 
82  uint16_t size() const
83  {
84  return min_size;
85  }
86 
88  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
89 
91  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
92  };
93 
105 
111  struct Base: public Interface<HF::Interface::SIMPLE_KEYPAD>
112  {
113  protected:
114 
117  };
118 
124  class Server: public InterfaceRole<SimpleKeypad::Base, HF::Interface::SERVER_ROLE>
125  {
126  public:
127 
129  Server(): InterfaceRole<SimpleKeypad::Base, HF::Interface::SERVER_ROLE>() {}
130 
132  virtual ~Server() {}
133 
134  // ======================================================================
135  // Events
136  // ======================================================================
139 
147  virtual void key_pressed(const Protocol::Address &addr, KeyPressed &msg);
148 
157  virtual void key_received(const uint32_t key_id)
158  {
159  UNUSED(key_id);
160  }
161 
163  // ======================================================================
164  protected:
165 
167  uint16_t offset);
168  };
169 
175  struct Client: public InterfaceRole<SimpleKeypad::Base, HF::Interface::CLIENT_ROLE>
176  {
178 
179  virtual ~Client() {}
180 
181  // ======================================================================
182  // Commands
183  // ======================================================================
186 
194  void key_pressed(const Protocol::Address &addr, uint32_t key_id);
195 
197  // ======================================================================
198  };
199 
202  } // namespace SimpleKeypad
203 
204  } // namespace Interfaces
205 
206 } // namespace HF
207 
213 // =============================================================================
214 // Stream Helpers
215 // =============================================================================
216 
225 std::ostream &operator<<(std::ostream &stream, const HF::Interfaces::SimpleKeypad::CMD command);
226 
229 #endif /* HF_ITF_SIMPLE_KEYPAD_H */
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Definition: simple_keypad.h:79
std::ostream & operator<<(std::ostream &stream, const HF::Interfaces::SimpleKeypad::CMD command)
Convert the given command into a string and write it to the given stream.
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Interfaces::SimpleKey...
Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
Simple Keypad Interface : Server side implementation.
Helper class template for parent class implementation of the interfaces.
Definition: interface.h:371
Simple Keypad interface UID.
Definition: interface.h:82
This file contains the definitions for the HAN-FUN protocol messages.
Simple Keypad Interface : Parent.
void key_pressed(const Protocol::Address &addr, uint32_t key_id)
Send a HAN-FUN message containing a SimpleKeypad::KEYPRESSED_CMD, to the given network address...
uint16_t pack(Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
This file contains the definitions common to all interfaces.
virtual void key_received(const uint32_t key_id)
Callback that informs the app that a key was pressed on the client.
This class represents a byte array.
uint16_t size() const
Number bytes needed to serialize the message.
Definition: simple_keypad.h:82
Network Address.
Definition: protocol.h:201
Message payload for a HF::SimpleKeypad::KEYPRESED request.
Definition: simple_keypad.h:71
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
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.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Result
Commands result codes.
Simple Keypad Interface : Client side implementation.
virtual void key_pressed(const Protocol::Address &addr, KeyPressed &msg)
Callback that is called when a SimpleKeypad::KEYPRESSED_CMD, is received.
Top-level namespace for the HAN-FUN library.
Definition: attributes.h:22