HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
attribute_reporting.h
Go to the documentation of this file.
1 // =============================================================================
16 // =============================================================================
17 #ifndef HF_CORE_ATTRIBUTE_REPORTING_H
18 #define HF_CORE_ATTRIBUTE_REPORTING_H
19 
20 #include "hanfun/common.h"
21 #include "hanfun/core.h"
22 
23 #include "hanfun/attributes.h"
24 
25 namespace HF
26 {
27  namespace Core
28  {
29  // Forward declaration.
30  namespace AttributeReporting
31  {
32  struct IServer;
33  } // namespace AttributeReporting
34 
50  uint8_t uid);
51 
58  namespace AttributeReporting
59  {
73  typedef enum _CMD
75  {
86  __LAST_CMD__ = UPDATE_INTERVAL_CMD
87  } CMD;
88 
90  typedef enum _Attributes
91  {
95  __LAST_ATTR__ = EVENT_REPORT_COUNT_ATTR
96  } Attributes;
97 
99  typedef enum _Type
100  {
101  PERIODIC = 0x00,
102  EVENT = 0x01,
103  } Type;
104 
108  struct Reference
109  {
110  uint8_t type : 1;
111  uint8_t id : 7;
112 
119  Reference(uint8_t _type = 0, uint8_t _id = 0):
120  type(_type), id(_id)
121  {}
122 
124  static constexpr uint16_t min_size = sizeof(uint8_t);
125 
127  uint16_t size() const;
128 
130  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
131 
133  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
134  };
135 
139  struct Entry
140  {
141  uint8_t unit;
143 
144  uint8_t pack_id;
145 
147  static constexpr uint16_t min_size = sizeof(uint8_t) // Unit ID.
148  + Common::Interface::min_size // Interface
149  + sizeof(uint8_t); // Attribute Pack ID.
150 
152  uint16_t size() const;
153 
155  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
156 
158  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
159 
160  protected:
161 
162  Entry() {}
163  };
164 
168  struct Rule
169  {
172 
175 
177  static constexpr uint16_t min_size = Reference::min_size // Report ID.
178  + Protocol::Address::min_size; // Destination Address.
179 
181  uint16_t size() const;
182 
184  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
185 
187  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
188 
189  protected:
190 
191  Rule() {}
192 
198  Rule(Type type): report(type) {}
199  };
200 
207  namespace Periodic
208  {
222  {
224 
225  uint16_t size() const;
226 
227  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
228 
229  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
230  };
231 
236  {
237  typedef Common::SimpleList<Entry> Container;
238 
239  typedef Container::iterator iterator;
240 
241  typedef Container::const_iterator const_iterator;
242 
244  uint32_t interval;
245 
247  uint32_t last_time;
248 
254  Rule(uint32_t _interval = 0): AttributeReporting::Rule(PERIODIC),
255  interval(_interval),
256  last_time(0)
257  {}
258 
260  static constexpr uint16_t min_size = AttributeReporting::Rule::min_size // Parent Min. Size.
261  + sizeof(uint32_t) // Interval Value.
262  + sizeof(uint8_t); // Nr. Entries.
263 
264  uint16_t size() const;
265 
266  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
267 
268  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
269 
275  void add(const Entry &entry)
276  {
277  entries.push_front(entry);
278  }
279 
283  void clear()
284  {
285  entries.clear();
286  }
287 
293  uint16_t entries_count()
294  {
295  return std::distance(entries.begin(), entries.end());
296  }
297 
298 
304  iterator begin()
305  {
306  return entries.begin();
307  }
308 
314  iterator end()
315  {
316  return entries.end();
317  }
318 
324  const_iterator cbegin() const
325  {
326  return entries.cbegin();
327  }
328 
334  const_iterator cend() const
335  {
336  return entries.cend();
337  }
338 
339  protected:
340 
342  Container entries;
343  };
344 
347  } // namespace Periodic
348 
352  namespace Event
353  {
366  typedef enum _Type
367  {
368  COV = 0x00,
369  HT = 0x01,
370  LT = 0x02,
371  EQ = 0x03,
372  } Type;
373 
377  struct Field
378  {
381 
383  uint8_t attr_uid;
384 
387 
394  Field(Type _type = COV, uint8_t _attr_uid = 0):
395  type(_type), attr_uid(_attr_uid)
396  {}
397 
399  static constexpr uint16_t min_size = sizeof(uint8_t) // Field type.
400  + sizeof(uint8_t); // Size of value holder or COV value.
401 
408  uint16_t size(bool with_uid) const;
409 
415  uint16_t pack(Common::ByteArray &array, uint16_t offset, bool with_uid) const;
416 
425  uint16_t unpack(const Common::ByteArray &array, uint16_t offset, bool with_uid);
426  };
427 
432  {
434  std::vector<Field> fields;
435 
436  uint16_t size() const;
437 
438  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
439 
440  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
441  };
442 
447  {
448  typedef Common::SimpleList<Entry> Container;
449 
450  typedef Container::iterator iterator;
451 
452  typedef Container::const_iterator const_iterator;
453 
455  {}
456 
458  static constexpr uint16_t min_size = AttributeReporting::Rule::min_size // Parent Min. Size.
459  + sizeof(uint8_t); // Nr. Entries.
460 
461  uint16_t size() const;
462 
463  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
464 
465  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
466 
472  void add(const Entry &entry)
473  {
474  entries.push_front(entry);
475  }
476 
480  void clear()
481  {
482  entries.clear();
483  }
484 
490  uint16_t entries_count()
491  {
492  return std::distance(entries.begin(), entries.end());
493  }
494 
500  iterator begin()
501  {
502  return entries.begin();
503  }
504 
510  iterator end()
511  {
512  return entries.end();
513  }
514 
520  const_iterator cbegin() const
521  {
522  return entries.cbegin();
523  }
524 
530  const_iterator cend() const
531  {
532  return entries.cend();
533  }
534 
535  protected:
536 
538  Container entries;
539  };
540 
543  } // namespace Event
544 
549  namespace Report
550  {
559  // =============================================================================
560  // Notification API
561  // =============================================================================
562 
563  typedef std::shared_ptr<HF::Attributes::IAttribute> Attribute;
564 
569  {
576  Abstract(uint8_t type = 0, uint8_t id = 0):
577  AttributeReporting::Reference(type, id)
578  {}
579  };
580 
584  struct Entry
585  {
586  static constexpr uint16_t min_size = sizeof(uint8_t) // Unit index size.
587  + Common::Interface::min_size // Interface UID size.
588  + sizeof(uint8_t); // Number of attributes/fields.
589 
590  uint8_t unit;
592 
593  Entry(): unit(0), itf(0, 0) {}
594 
601  Entry(uint8_t _unit, Common::Interface _itf):
602  unit(_unit), itf(_itf)
603  {}
604 
605  virtual ~Entry() {}
606 
608  uint16_t size() const;
609 
611  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
612 
620  const Common::ByteArray &array, uint16_t offset = 0);
621 
622  protected:
623 
632  virtual uint16_t unpack(HF::Attributes::Factory factory,
633  const Common::ByteArray &array, uint16_t offset = 0)
634  {
635  UNUSED(factory);
636  UNUSED(array);
637  UNUSED(offset);
638 
639  return 0;
640  }
641 
647  virtual uint8_t count() const
648  {
649  return 0;
650  }
651  };
652 
653  // =============================================================================
654  // Messages
655  // =============================================================================
656 
661  {
664 
666  static constexpr uint16_t min_size = Protocol::Address::min_size; // Destination.
667 
669  uint16_t size() const;
670 
672  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
673 
675  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
676  };
677 
682  {
685 
687  static constexpr uint16_t min_size = Reference::min_size; // Report ID.
688 
690  uint16_t size() const;
691 
693  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
694 
696  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
697  };
698 
704  {
707 
708  virtual ~AddEntryMessage() {}
709 
711  static constexpr uint16_t min_size = Reference::min_size // Destination.
712  + sizeof(uint8_t); // Nr. Entries.
713 
715  uint16_t size() const;
716 
718  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
719 
721  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
722 
723  protected:
724 
725  AddEntryMessage() {}
726 
732  virtual uint16_t unpack_entry(const Common::ByteArray &array, uint16_t offset = 0)
733  {
734  UNUSED(array);
735  UNUSED(offset);
736 
737  return 0;
738  }
739 
745  virtual uint8_t count() const
746  {
747  return 0;
748  }
749 
755  virtual uint16_t entry_size() const
756  {
757  return 0;
758  }
759  };
760 
765  {
767  uint32_t interval;
768 
776  UpdateIntervalMessage(Type report_type, uint8_t ID, uint32_t interval):
777  report(report_type, ID), interval(interval)
778  {}
779 
784  {}
785 
787  static constexpr uint16_t min_size = Reference::min_size // Report ID.
788  + sizeof(interval); // Periodic interval
789 
791  uint16_t size() const;
792 
794  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
795 
797  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
798  };
799 
800  // =============================================================================
801  // Periodic Report Support
802  // =============================================================================
803 
807  struct Periodic: public Abstract
808  {
812  struct Entry: public Report::Entry
813  {
814  std::vector<Report::Attribute> attributes;
815 
816  Entry() {}
817 
824  Entry(uint8_t unit, Common::Interface itf): Report::Entry(unit, itf)
825  {}
826 
827  uint16_t size() const;
828 
829  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
830 
836  void add(HF::Attributes::IAttribute * &attr);
837 
838  using Report::Entry::unpack;
839 
840  protected:
841 
842  uint16_t unpack(HF::Attributes::Factory factory,
843  const Common::ByteArray &array, uint16_t offset = 0);
844 
845  uint8_t count() const
846  {
847  return attributes.size();
848  }
849  };
850 
852  Common::SimpleList<Entry> entries;
853 
859  Periodic(uint8_t id = 0): Abstract(PERIODIC, id)
860  {}
861 
862  uint16_t size() const;
863 
864  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
865 
868  const Common::ByteArray &array, uint16_t offset = 0);
869 
875  void add(Entry &entry);
876 
877  // =============================================================================
878  // Message API
879  // =============================================================================
880 
885  {
887  uint32_t interval;
888 
889  uint16_t size() const;
890 
891  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
892 
893  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
894  };
895 
900  {
901  typedef Common::SimpleList<AttributeReporting::Periodic::Entry> Container;
902 
903  typedef Container::iterator iterator;
904 
905  typedef Container::const_iterator const_iterator;
906 
908  {
909  report.type = PERIODIC;
910  }
911 
912  uint16_t size() const;
913 
914  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
915 
922  {
923  entries.push_front(entry);
924  }
925 
931  iterator begin()
932  {
933  return entries.begin();
934  }
935 
941  iterator end()
942  {
943  return entries.end();
944  }
945 
951  const_iterator cbegin() const
952  {
953  return entries.cbegin();
954  }
955 
961  const_iterator cend() const
962  {
963  return entries.cend();
964  }
965 
966  protected:
967 
969  Container entries;
970 
971  uint16_t unpack_entry(const Common::ByteArray &array, uint16_t offset = 0);
972 
973  uint8_t count() const
974  {
975  return std::distance(entries.begin(), entries.end());
976  }
977 
978  uint16_t entry_size() const
979  {
981  }
982  };
983  };
984 
985  // =============================================================================
986  // Event Report Support
987  // =============================================================================
988 
992  struct Event: public Abstract
993  {
997  struct Field
998  {
999  static constexpr uint16_t min_size = sizeof(uint8_t) // Event Type size.
1000  + sizeof(uint8_t); // Attribute UID.
1001 
1004 
1006  Attribute attribute;
1007 
1009  uint16_t size() const;
1010 
1012  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
1013 
1015  uint16_t unpack(HF::Attributes::Factory factory, const Common::ByteArray &array,
1016  uint16_t offset = 0);
1017 
1024  {
1025  Attribute temp(attr);
1026 
1027  attribute = std::move(temp);
1028  }
1029  };
1030 
1034  struct Entry: public Report::Entry
1035  {
1037  std::vector<Field> fields;
1038 
1039  Entry() {}
1040 
1048  {}
1049 
1050  uint16_t size() const;
1051 
1052  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
1053 
1059  void add(Field &field)
1060  {
1061  fields.push_back(std::move(field));
1062  }
1063 
1064  using Report::Entry::unpack;
1065 
1066  protected:
1067 
1068  uint16_t unpack(HF::Attributes::Factory factory,
1069  const Common::ByteArray &array, uint16_t offset = 0);
1070 
1071  uint8_t count() const
1072  {
1073  return fields.size();
1074  }
1075  };
1076 
1078  Common::SimpleList<Entry> entries;
1079 
1085  Event(uint8_t id = 0): Abstract(EVENT, id)
1086  {}
1087 
1089  uint16_t size() const;
1090 
1092  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
1093 
1096  const Common::ByteArray &array, uint16_t offset = 0);
1097 
1101  void add(Entry &entry)
1102  {
1103  entries.push_front(std::move(entry));
1104  }
1105 
1106  // =============================================================================
1107  // Message API
1108  // =============================================================================
1109 
1114  {};
1115 
1120  {
1121  typedef Common::SimpleList<AttributeReporting::Event::Entry> Container;
1122 
1123  typedef Container::iterator iterator;
1124 
1125  typedef Container::const_iterator const_iterator;
1126 
1127  AddEntryMessage()
1128  {
1129  report.type = EVENT;
1130  }
1131 
1132  uint16_t size() const;
1133 
1134  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
1135 
1142  {
1143  entries.push_front(entry);
1144  }
1145 
1151  iterator begin()
1152  {
1153  return entries.begin();
1154  }
1155 
1161  iterator end()
1162  {
1163  return entries.end();
1164  }
1165 
1171  const_iterator cbegin() const
1172  {
1173  return entries.cbegin();
1174  }
1175 
1181  const_iterator cend() const
1182  {
1183  return entries.cend();
1184  }
1185 
1186  protected:
1187 
1189  Container entries;
1190 
1191  uint16_t unpack_entry(const Common::ByteArray &array, uint16_t offset = 0);
1192 
1193  uint8_t count() const
1194  {
1195  return std::distance(entries.begin(), entries.end());
1196  }
1197 
1198  uint16_t entry_size() const
1199  {
1201  }
1202  };
1203 
1214  static Report::Event::Entry *process(
1215  const AttributeReporting::Event::Entry &entry,
1216  const HF::Attributes::IAttribute &old_value,
1217  const HF::Attributes::IAttribute &new_value);
1218  };
1219 
1222  } // namespace Report
1223 
1228  // =============================================================================
1229  // Message API
1230  // =============================================================================
1231 
1232  struct Response: public HF::Protocol::Response
1233  {
1234  Reference report;
1235 
1236  uint16_t size() const;
1237 
1238  uint16_t pack(Common::ByteArray &array, uint16_t offset = 0) const;
1239 
1240  uint16_t unpack(const Common::ByteArray &array, uint16_t offset = 0);
1241  };
1242 
1243  // =============================================================================
1244  // API
1245  // =============================================================================
1246 
1248  static constexpr uint8_t START_ADDR = 0x01;
1249 
1251  static constexpr uint8_t MAX_ADDR = 0x7E;
1252 
1254  static constexpr uint8_t ALL_ADDR = 0x7F;
1255 
1256  typedef std::vector<Periodic::Entry>::iterator periodic_iterator;
1257  typedef std::vector<Event::Entry>::iterator event_iterator;
1258 
1269 
1280  Protocol::Message *create(Protocol::Address &destination, uint32_t interval);
1281 
1291  Protocol::Message *destroy(Type type, uint8_t report_id);
1292 
1301  Protocol::Message *destroy(Reference report);
1302 
1314  Protocol::Message *add(Reference report, periodic_iterator begin, periodic_iterator end);
1315 
1327  Protocol::Message *add(Reference report, event_iterator begin, event_iterator end);
1328 
1338  Protocol::Message *update(Reference report, uint32_t new_interval);
1339 
1351 
1361  struct Client: public HF::Interfaces::Interface<HF::Interface::ATTRIBUTE_REPORTING>
1362  {
1363  // =============================================================================
1364  // Interface API
1365  // =============================================================================
1366 
1368  {
1370  }
1371 
1372  // =============================================================================
1373  // API
1374  // =============================================================================
1375 
1376  // ======================================================================
1377  // Events
1378  // ======================================================================
1381 
1391  virtual void report(Type type, const Protocol::Address &address,
1392  const Common::ByteArray &payload, uint16_t offset)
1393  {
1394  UNUSED(type);
1395  UNUSED(address);
1396  UNUSED(payload);
1397  UNUSED(offset);
1398  }
1399 
1407  virtual void created(const Protocol::Address &address, const Response &response)
1408  {
1409  UNUSED(address);
1410  UNUSED(response);
1411  }
1412 
1420  virtual void added(const Protocol::Address &address, const Response &response)
1421  {
1422  UNUSED(address);
1423  UNUSED(response);
1424  }
1425 
1432  virtual void deleted(const Protocol::Address &address, const Response &response)
1433  {
1434  UNUSED(address);
1435  UNUSED(response);
1436  }
1437 
1444  virtual void updated(const Protocol::Address &address, const Response &response)
1445  {
1446  UNUSED(address);
1447  UNUSED(response);
1448  }
1449 
1451  // ======================================================================
1452 
1453  protected:
1454 
1455  uint16_t payload_size(Protocol::Message &message) const;
1456 
1457  uint16_t payload_size(Protocol::Message::Interface &itf) const;
1458 
1460  uint16_t offset);
1461 
1462  };
1463 
1467  struct AbstractClient: public Client
1468  {
1469  // =============================================================================
1470  // API
1471  // =============================================================================
1472 
1473  // ======================================================================
1474  // Commands
1475  // ======================================================================
1478 
1485  void create(Protocol::Address &destination);
1486 
1495  void create(Protocol::Address &destination, uint32_t interval);
1496 
1505  void destroy(Protocol::Address &destination, Type type, uint8_t report_id);
1506 
1514  void destroy(Protocol::Address &destination, Reference report);
1515 
1525  void add(Protocol::Address &destination, Reference report,
1526  periodic_iterator begin, periodic_iterator end);
1527 
1538  void add(Protocol::Address &destination, Reference report,
1539  event_iterator begin, event_iterator end);
1540 
1548  void update_interval(Protocol::Address &destination,
1549  Reference report, uint32_t interval);
1550 
1552  // ======================================================================
1553 
1554  protected:
1555 
1561  virtual HF::Units::IUnit &unit() const = 0;
1562  };
1563 
1572  struct IServer: public AbstractService
1573  {
1581  {}
1582 
1583  virtual ~IServer() {}
1584 
1585  // =============================================================================
1586  // API
1587  // =============================================================================
1588 
1589  uint16_t uid() const
1590  {
1592  }
1593 
1595  {
1597  }
1598 
1610  virtual void notify(uint8_t unit, const HF::Attributes::IAttribute &old_value,
1611  const HF::Attributes::IAttribute &new_value)
1612  {
1613  UNUSED(unit);
1614  UNUSED(old_value);
1615  UNUSED(new_value);
1616  }
1617 
1625  virtual uint16_t count(Type type) const
1626  {
1627  UNUSED(type);
1628  return 0;
1629  }
1630 
1631  // =============================================================================
1632  // Interface Attribute API.
1633  // =============================================================================
1634 
1636  {
1637  return Core::create_attribute(this, uid);
1638  }
1639 
1642  {
1643  UNUSED(pack_id);
1646  }
1647 
1648  protected:
1649 
1651 
1653  uint16_t offset);
1654 
1662  void response(Protocol::Packet &packet, Reference &report, Common::Result result);
1663 
1674  virtual bool authorized(uint8_t member, Protocol::Address &source)
1675  {
1676  UNUSED(member);
1677  UNUSED(source);
1678 
1679  return true;
1680  }
1681 
1682  bool check_uid(uint16_t uid) const
1683  {
1684  return IServer::uid() == uid;
1685  }
1686  };
1687 
1691  struct Server: public IServer
1692  {
1693  Common::SimpleList<Periodic::Rule> periodic_rules;
1694  Common::SimpleList<Event::Rule> event_rules;
1695 
1702  IServer(unit), last_time(0)
1703  {}
1704 
1705  virtual ~Server() {}
1706 
1707  // =============================================================================
1708  // API
1709  // =============================================================================
1710 
1719  virtual Common::Result handle(const Report::Periodic::CreateMessage &message);
1720 
1729  virtual Common::Result handle(const Report::Periodic::AddEntryMessage &message);
1730 
1739  virtual Common::Result handle(const Report::Event::CreateMessage &message);
1740 
1749  virtual Common::Result handle(const Report::Event::AddEntryMessage &message);
1750 
1759  virtual Common::Result handle(const Report::DeleteMessage &message);
1760 
1769  virtual Common::Result handle(const Report::UpdateIntervalMessage &message);
1770 
1772 
1773  void periodic(uint32_t time);
1774 
1775  void notify(uint8_t unit, const HF::Attributes::IAttribute &old_value,
1776  const HF::Attributes::IAttribute &new_value);
1777 
1778  uint16_t count(Type type) const;
1779 
1780  protected:
1781 
1783  uint32_t last_time;
1784 
1786 
1787  uint16_t payload_size(Protocol::Message::Interface &itf) const;
1788 
1790  uint16_t offset);
1791  };
1792 
1795  } // namespace AttributeReporting
1796 
1797  } // namespace Core
1798 
1799 } // namespace HF
1800 
1806 // =============================================================================
1807 // Stream Helpers
1808 // =============================================================================
1809 
1818 std::ostream &operator<<(std::ostream &stream, const HF::Core::AttributeReporting::CMD command);
1819 
1828 std::ostream &operator<<(std::ostream &stream,
1830 
1833 #endif /* HF_CORE_ATTRIBUTE_REPORTING_H */
This message is used to delete a reporting rule.
uint32_t interval
Attribute indicating the time interval rule needs to be activated.
uint16_t unpack(HF::Attributes::FactoryGetter get_factory, const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
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.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
uint16_t size() const
Number bytes needed to serialize the message.
iterator end()
Get an iterator to the end of the entries in this rule.
void update_interval(Protocol::Address &destination, Reference report, uint32_t interval)
Update the interval of an existent report.
virtual uint8_t count() const
Get the number of entries is this rule entry.
virtual uint16_t unpack(HF::Attributes::Factory factory, const Common::ByteArray &array, uint16_t offset=0)
Unpack an incoming attribute.
Parent class for all report rules.
This message is used to create a reporting rule.
uint16_t entries_count()
Number of entries present in this rule.
Type
Types of reports send from the server to the client.
uint16_t size() const
Number bytes needed to serialize the message.
Reference report
Identification of the rule to add the entries to.
virtual HF::Units::IUnit & unit() const =0
Get the unit that contains this interface.
uint8_t count() const
Get the number of entries is this rule entry.
bool response(Message::Type type)
Check if message is a response.
const_iterator cbegin() const
Get a constant iterator to the start of the entries in this message.
This message is used to update the report interval.
This represent the special unit with ID/UID = 0.
Definition: core.h:67
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
void notify(uint8_t unit, const HF::Attributes::IAttribute &old_value, const HF::Attributes::IAttribute &new_value)
Process an attribute change from old_value to new_value for the given unit.
GroupAddress DeleteMessage
Message payload for a HF::GroupManagement::DELETE_CMD request.
uint8_t count() const
Get number of entries in this message.
virtual void notify(const HF::Attributes::IAttribute &old_value, const HF::Attributes::IAttribute &new_value) const
Notify that an attribute value as changed.
Definition: interface.h:248
void add(const Entry &entry)
Add the given entry to rule.
Parent class for all notification entries.
void periodic(uint32_t time)
Handle periodic processing.
Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Number of event report entries attribute.
HF::Attributes::IAttribute * attribute(uint8_t uid)
Return a pointer to the interface attribute with the given uid.
virtual void updated(const Protocol::Address &address, const Response &response)
Event indicating the result of a UPDATE_INTERVAL_CMD.
Parent class for all report rule entries.
List of attributes UIDs.
Definition: attributes.h:176
Attribute Reporting interface UID.
Definition: interface.h:65
iterator end()
Get a iterator to the end of the entries in this rule.
This file contains the definitions for the attribute handling API in HAN-FUN.
Reference(uint8_t _type=0, uint8_t _id=0)
Constructor.
void add(Protocol::Address &destination, Reference report, periodic_iterator begin, periodic_iterator end)
Add the periodic entries from start to end into the rule with the given report reference, on the device with the given destination address.
Container entries
Container for the entries of this rule.
uint8_t count() const
Get the number of entries is this rule entry.
uint8_t pack_id
Attribute&#39;s Pack ID.
Return all mandatory attributes for the interface.
Definition: attributes.h:842
This file contains the common defines for the HAN-FUN library.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset, bool with_uid)
Read a message from a ByteArray.
This file contains the forward declarations of the core services and interfaces implementing classes...
Common::Result handle(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
iterator end()
Get a iterator to the end of the entries in this message.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Definition: protocol.h:230
Helper class for using the Attribute Reporting service.
void response(Protocol::Packet &packet, Reference &report, Common::Result result)
Send the response to a command with the given result.
Helper class template for parent class implementation of the interfaces.
Definition: interface.h:371
uint16_t unpack_entry(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
virtual uint16_t entry_size() const
Get the minimum number of bytes required for unpacking an entry.
Number of periodic report entries attribute.
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.
Factory get_factory(Common::Interface itf)
Return the attribute factory associated with the given interface identifier.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
uint16_t unpack(HF::Attributes::FactoryGetter get_factory, const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
const_iterator cbegin() const
Get a constant iterator to the start of the entries in this rule.
void set_attribute(HF::Attributes::IAttribute *attr)
Set the field&#39;s attribute to the given attribute in attr.
This is the parent class for all services implementations.
Definition: core.h:137
uint16_t size() const
Number bytes needed to serialize the message.
Attribute Reporting - Server Role.
uint16_t size() const
Number bytes needed to serialize the message.
uint16_t unpack(HF::Attributes::Factory factory, const Common::ByteArray &array, uint16_t offset=0)
Unpack an incoming attribute.
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.
virtual uint16_t unpack_entry(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Reference report
Report reference this rule generates.
Protocol::Message * add(Reference report, periodic_iterator begin, periodic_iterator end)
Add the periodic entries from start to end into the rule with the given report reference.
Attribute Reporting - Client Role.
Common::SimpleList< Periodic::Rule > periodic_rules
Periodic rules.
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Core::AttributeReport...
uint16_t payload_size(Protocol::Message::Interface &itf) const
Return the minimal payload size that a message should hold when addressed at the given interface...
virtual void deleted(const Protocol::Address &address, const Response &response)
Event indicating the result of a DELETE_REPORT_CMD.
virtual void report(Type type, const Protocol::Address &address, const Common::ByteArray &payload, uint16_t offset)
Event indicating a PERIODIC_REPORT_CMD or a EVENT_REPORT_CMD.
Container entries
Container for the entries of the periodic rule.
uint8_t unit
Unit ID this entry to.
Container entries
Container that holds the entries present in the message.
Protocol::Message * destroy(Type type, uint8_t report_id)
Remove the rule with the given type and the given report_id.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
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.
Role
Interface roles.
Definition: interface.h:48
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
iterator begin()
Get a iterator to the start of the entries in this rule.
virtual Common::Result handle(const Report::Periodic::CreateMessage &message)
Handle a create periodic rule command.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
uint16_t unpack(HF::Attributes::Factory factory, const Common::ByteArray &array, uint16_t offset=0)
Unpack an incoming attribute.
Entry field for a given attribute.
Field for the entries in event notification.
uint8_t count() const
Get number of entries in this message.
Rule(uint32_t _interval=0)
Constructor.
uint16_t count(Type type) const
Get the number of rules for the given type.
Parent class for the messages to create reporting rule entries.
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.
std::vector< Field > fields
Vector containing the fields for the event entry.
uint16_t unpack(HF::Attributes::FactoryGetter get_factory, const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
virtual void added(const Protocol::Address &address, const Response &response)
Event indicating the result of a ADD_PERIODIC_ENTRY_CMD or ADD_EVENT_ENTRY_CMD.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Common::Interface itf
Interface UID this notification relates to.
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
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.
UpdateIntervalMessage(Type report_type, uint8_t ID, uint32_t interval)
Constructor.
virtual bool authorized(uint8_t member, Protocol::Address &source)
Check if the given command is authorized for the device with the given address.
uint16_t size() const
Number bytes needed to serialize the message.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
void destroy(Protocol::Address &destination, Type type, uint8_t report_id)
Remove the rule with the given type and the given report_id, on the device with the given destination...
This class represents a byte array.
iterator end()
Get a iterator to the end of the entries in this message.
Interface::Role role() const
Return the Interface::Role this interface implements.
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.
Update the interval of an existent report.
std::vector< Field > fields
Vector containing the fields for this entry.
uint16_t pack(Common::ByteArray &array, uint16_t offset, bool with_uid) const
Write the object on to a ByteArray so it can be sent over the network.
Number of report entries attribute.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Network Address.
Definition: protocol.h:201
uint16_t size() const
Number bytes needed to serialize the message.
Entry(uint8_t _unit, Common::Interface _itf)
Constructor.
Interface Address.
Definition: protocol.h:93
Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
Network Message.
Definition: protocol.h:60
const_iterator cend() const
Get constant iterator to the end of the entries in this message.
Protocol::Address destination
Device address to create the report rule for.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
IAttribute *(* Factory)(uint8_t)
Attribute factory function type.
Definition: attributes.h:151
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.
Field(Type _type=COV, uint8_t _attr_uid=0)
Constructor.
iterator begin()
Get a iterator to the start of the entries in this rule.
Entry(uint8_t unit, Common::Interface itf)
Constructor.
const_iterator cend() const
Get constant iterator to the end of the entries in this message.
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.
void add(HF::Attributes::IAttribute *&attr)
Add attribute to this periodic report entry.
uint16_t entry_size() const
Get the minimum number of bytes required for unpacking an entry.
Common::SimpleList< Entry > entries
Entries for the event notification.
std::ostream & operator<<(std::ostream &stream, const HF::Core::AttributeReporting::CMD command)
Convert the given command into a string and write it to the given stream.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
uint8_t type
Report type : PERIODIC or EVENT.
bool check_uid(uint16_t uid) const
Check if the given UID matches the interface UID.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
This class represents a periodic rule for attribute reporting.
HAN-FUN Protocol Packet.
Definition: protocol.h:298
Reference report
Identification of the rule to delete.
uint16_t size() const
Number bytes needed to serialize the message.
Interface::Role role() const
Return the Interface::Role this interface implements.
uint16_t size() const
Number bytes needed to serialize the message.
Common::Interface itf
Interface UID.
uint16_t entry_size() const
Get the minimum number of bytes required for unpacking an entry.
Interface/Service Attribute API.
Definition: attributes.h:44
uint8_t unit
Unit id that originated this notification.
const_iterator cbegin() const
Get a constant iterator to the start of the entries in this message.
uint32_t last_time
Attribute indicating the last time rule was activated.
Reference report
Identification of the rule to delete.
const_iterator cbegin() const
Get a constant iterator to the start of the entries in this rule.
uint16_t unpack_entry(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
void clear()
Remove all entries in this rule.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Common::SimpleList< Event::Rule > event_rules
Event rules.
const_iterator cend() const
Get constant iterator to the end of the entries in this rule.
This class represents the interface implemented by all HAN-FUN units.
Definition: units.h:48
Attributes::Factory(* FactoryGetter)(Common::Interface)
Function pointer to a function that returns the attribute factory associated with a given interface...
Definition: attributes.h:157
Parent class for the response messages.
Definition: protocol.h:368
void add(Field &field)
Add the given field into this entry.
void add(const AttributeReporting::Periodic::Entry &entry)
Add a periodic entry into this message.
uint16_t size() const
Number bytes needed to serialize the message.
const_iterator cend() const
Get constant iterator to the end of the entries in this rule.
virtual void created(const Protocol::Address &address, const Response &response)
Event indicating the result of a CREATE_PERIODIC_CMD or CREATE_EVENT_CMD.
virtual void notify(uint8_t unit, const HF::Attributes::IAttribute &old_value, const HF::Attributes::IAttribute &new_value)
Process an attribute change from old_value to new_value for the given unit.
static Report::Event::Entry * process(const AttributeReporting::Event::Entry &entry, const HF::Attributes::IAttribute &old_value, const HF::Attributes::IAttribute &new_value)
This function checks if any fields in the given event rule entry match the change for the attribute g...
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.
void clear()
Remove all entries in this rule.
iterator begin()
Get an iterator to the start of the entries in this rule.
uint16_t payload_size(Protocol::Message &message) const
Return the minimal payload size that should be present for the given message.
uint16_t unpack(HF::Attributes::Factory factory, const Common::ByteArray &array, uint16_t offset=0)
Unpack an incoming attribute.
Common::SimpleList< Entry > entries
Entries associated with this notification.
Abstract(uint8_t type=0, uint8_t id=0)
Constructor.
uint16_t size(bool with_uid) const
Number bytes needed to serialize the message.
Protocol::Message * update(Reference report, uint32_t new_interval)
Change the Update Interval for the specified report.
virtual uint16_t count(Type type) const
Get the number of rules for the given type.
iterator begin()
Get a iterator to the start of the entries in this rule.
This class represents an entry in a periodic rule.
Attribute Reporting - Server Role.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
Protocol::Message * create(Protocol::Address &destination)
Create a new attribute reporting event rule for the device with the given address.
Entry(uint8_t unit, Common::Interface itf)
Constructor.
uint32_t last_time
Last time the periodic function was called.
Protocol::Address destination
Device/unit that will receive the report.
virtual uint8_t count() const
Get number of entries in this message.
void add(const Entry &entry)
Add the given entry to rule.
AttributeReporting::Event::Type type
Event type.
uint16_t entries_count()
Number of entries present in this rule.
Common::Result handle_command(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Handle incoming messages from the network.
Result
Commands result codes.
void add(const AttributeReporting::Event::Entry &entry)
Add a event entry into this message.
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.
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.
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.
uint16_t uid() const
This method returns the interface UID.
void add(Entry &entry)
Add event entry into this event report.
uint16_t unpack(const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
uint32_t interval
Time interval to send the periodic report.
static constexpr uint16_t min_size
Minimum pack/unpack required data size.
void add(Entry &entry)
Add entry into this periodic report.
Top-level namespace for the HAN-FUN library.
Definition: attributes.h:22
void create(Protocol::Address &destination)
Create a new attribute reporting event rule on the device with the given destination address...