HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
device_information.h
Go to the documentation of this file.
1 // =============================================================================
16 // =============================================================================
17 #ifndef HF_DEVICE_INFORMATION_H
18 #define HF_DEVICE_INFORMATION_H
19 
20 #include "hanfun/common.h"
21 
22 #include "hanfun/interface.h"
23 
24 #include "hanfun/core.h"
25 
26 // =============================================================================
27 // Defines
28 // =============================================================================
29 
30 #ifndef HF_DEVICE_MANUFACTURER_CODE
31  #warning "HF_DEVICE_MANUFACTURER_CODE not defined ! Using default value '0x0000'"
32  #define HF_DEVICE_MANUFACTURER_CODE 0x0000
34 #endif
35 
36 #ifndef HF_APPLICATION_VERSION
37  #warning "HF_APPLICATION_VERSION not defined ! Using default empty value !"
38  #define HF_APPLICATION_VERSION ""
40 #endif
41 
42 #ifndef HF_HARDWARE_VERSION
43  #warning "HF_HARDWARE_VERSION not defined ! Using default empty value !"
44  #define HF_HARDWARE_VERSION ""
46 #endif
47 
48 #ifndef HF_MANUFACTURER_NAME
49  #warning "HF_MANUFACTURER_NAME not defined ! Using default empty value !"
50  #define HF_MANUFACTURER_NAME ""
52 #endif
53 
54 // =============================================================================
55 // API
56 // =============================================================================
57 namespace HF
58 {
59  namespace Core
60  {
61  // Forward declaration.
62  namespace DeviceInformation
63  {
64  struct Server;
65  } // namespace DeviceInformation
66 
82  uint8_t uid);
83 
95  namespace DeviceInformation
96  {
105  constexpr static uint8_t CORE_VERSION = HF::CORE_VERSION;
106  constexpr static uint8_t PROFILE_VERSION = HF::PROFILES_VERSION;
107  constexpr static uint8_t INTERFACE_VERSION = HF::INTERFACES_VERSION;
108 
109  constexpr static uint16_t EMC = HF_DEVICE_MANUFACTURER_CODE;
110 
111 #if HF_CORE_DEV_INFO_APP_VERSION_ATTR
112  constexpr static _const char *APPLICATION_VERSION = HF_APPLICATION_VERSION;
113 #endif
114 #if HF_CORE_DEV_INFO_HW_VERSION_ATTR
115  constexpr static _const char *HARDWARE_VERSION = HF_HARDWARE_VERSION;
116 #endif
117 #if HF_CORE_DEV_INFO_MANUFACTURER_NAME_ATTR
118  constexpr static _const char *MANUFACTURER_NAME = HF_MANUFACTURER_NAME;
119 #endif
120 
122  typedef enum _Attributes
123  {
127  EXTRA_CAP_ATTR = 0x04,
132  EMC_ATTR = 0x09,
133  DECT_ID_ATTR = 0x0A,
135  LOCATION_ATTR = 0x0C,
136  ENABLED_ATTR = 0x0D,
138  UID_ATTR = 0x0F,
140  __LAST_ATTR__ = SERIAL_NUMBER_ATTR,
141  } Attributes;
142 
154 
159  {
163  struct Unit
164  {
165  uint8_t id;
166  std::string name;
167 
169 
171  static constexpr uint16_t min_size = sizeof(uint8_t) + string_helper::min_size;
172 
174  uint16_t size() const;
175 
177  uint16_t pack(HF::Common::ByteArray &array, uint16_t offset = 0) const;
178 
180  uint16_t unpack(const HF::Common::ByteArray &array, uint16_t offset = 0);
181  };
182 
184  std::vector<Unit> units;
185 
187  static constexpr uint16_t min_size = sizeof(uint8_t);
188 
190  uint16_t size() const;
191 
193  uint16_t pack(HF::Common::ByteArray &array, uint16_t offset = 0) const;
194 
196  uint16_t unpack(const HF::Common::ByteArray &array, uint16_t offset = 0);
197 
199  float changed(const FriendlyName &other) const
200  {
201  UNUSED(other);
202  return 0.0;
203  }
204 
206  int compare(const FriendlyName &other) const;
207  };
208 
212  class Base: public Service<HF::Interface::DEVICE_INFORMATION>
213  {
214  protected:
215 
222  };
223 
227  struct Server: public ServiceRole<Base, HF::Interface::SERVER_ROLE>
228  {
229  HF::UID::UID device_uid;
230 
237  ServiceRole<Base, HF::Interface::SERVER_ROLE>(unit), _capabilities(0)
238  {}
239 
240  virtual ~Server() {}
241 
242  // =============================================================================
243  // Interface Attribute API.
244  // =============================================================================
245 
246  HF::Attributes::IAttribute *attribute(uint8_t uid);
247 
248  HF::Attributes::UIDS attributes(uint8_t pack_id =
250 
256  void paging(bool value);
257 
264  bool has_paging() const;
265 
271  void broadcast(bool value);
272 
279  bool has_broadcast() const;
280 
286  void capabilities(uint8_t value);
287 
293  uint8_t capabilities();
294 
295 #if HF_CORE_DEV_INFO_APP_VERSION_ATTR
296 
301  const std::string application_version() const
302  {
303  return std::string(APPLICATION_VERSION);
304  }
305 #endif
306 #if HF_CORE_DEV_INFO_HW_VERSION_ATTR
307 
312  virtual const std::string hardware_version() const
313  {
314  return std::string(HARDWARE_VERSION);
315  }
316 #endif
317 #if HF_CORE_DEV_INFO_MANUFACTURER_NAME_ATTR
318 
323  const std::string manufacturer_name() const
324  {
325  return std::string(MANUFACTURER_NAME);
326  }
327 #endif
328  protected:
329 
330  uint8_t _capabilities;
331  };
332 
339  Protocol::Message *mandatory();
340 
347  Protocol::Message *all();
348 
357  Protocol::Message *get(HF::Attributes::UIDS &uids);
358 
366  Protocol::Message *get(uint8_t uid);
367 
370  } // namespace DeviceInformation
371 
372  } // namespace Core
373 
374 } // namespace HF
375 
381 // =============================================================================
382 // Stream Helpers
383 // =============================================================================
384 
393 std::ostream &operator<<(std::ostream &stream,
395 
398 #endif /* HF_DEVICE_INFORMATION_H */
#define HF_MANUFACTURER_NAME
Manufacturer name.
void broadcast(bool value)
Set extra capabilities attribute broadcast bit to given value.
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Core::DeviceInformati...
constexpr uint8_t CORE_VERSION
Core Service & Interfaces major version supported.
This represent the special unit with ID/UID = 0.
Definition: core.h:67
constexpr uint8_t PROFILES_VERSION
Profiles major version supported.
uint16_t unpack(const HF::Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
void paging(bool value)
Set extra capabilities attribute paging bit to given value.
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.
Units::IUnit * unit(uint8_t id) const
Return pointer to the unit with the given id.
This file contains the forward declarations of the core services and interfaces implementing classes...
uint16_t unpack(const HF::Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
float changed(const FriendlyName &other) const
This method is used to get the percentage of change that the attribute has in relation to the value p...
Protocol::Message * all()
Create a message that can be used to retrieve all the attributes on a remote device.
int compare(const FriendlyName &other) const
Compare this attribute with the given attribute in other.
This file contains the definitions common to all interfaces.
Parent class for the Device Information interface implementation.
bool has_broadcast() const
Get extra capabilities attribute broadcast bit.
#define HF_APPLICATION_VERSION
Application version.
Data type representing a unit0&#39;s friendly name.
Electronic Manufacture Code attribute.
uint16_t size() const
Number bytes needed to serialize the message.
Unit0 & unit() const
The device this unit is associated with.
Definition: core.h:142
constexpr uint8_t INTERFACES_VERSION
Interfaces major version supported.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
std::ostream & operator<<(std::ostream &stream, const HF::Core::DeviceInformation::Attributes attribute)
Convert the given attribute into a string and write it to the given stream.
uint16_t size() const
Number bytes needed to serialize the message.
Wrapper around UID_T pointer&#39;s.
Definition: uids.h:531
This class represents a byte array.
#define HF_DEVICE_MANUFACTURER_CODE
Device Electronic Manufacturer Code.
std::vector< Unit > units
Device unit&#39;s friendly names.
uint8_t capabilities()
Getter for the extra capabilities attribute bitmask.
uint16_t pack(HF::Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
Wrapper for std::string implementing the Serializable API.
Server(HF::Core::Unit0 &unit)
Device UID.
Interface/Service Attribute API.
Definition: attributes.h:44
Data type to contain the Friendly name attribute.
Class template for all interfaces role implementations.
Definition: core.h:225
Base(Unit0 &unit)
Constructor.
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Device Information interface : Server side.
Device information interface UID.
Definition: interface.h:64
Common interface for all Interfaces.
Definition: interface.h:43
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
uint16_t pack(HF::Common::ByteArray &array, uint16_t offset=0) const
Write the object on to a ByteArray so it can be sent over the network.
Class template for all core services implementations.
Definition: core.h:188
Protocol::Message * mandatory()
Create a message that can be used to retrieve the mandatory attributes on a remote device...
bool has_paging() const
Get extra capabilities attribute paging bit.
HF::Attributes::IAttribute * create_attribute(HF::Core::AttributeReporting::IServer *server, uint8_t uid)
Create an attribute object that can hold the attribute with the given uid.
#define HF_HARDWARE_VERSION
Hardware Version.
Top-level namespace for the HAN-FUN library.
Definition: attributes.h:22