HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
base.cpp
Go to the documentation of this file.
1 // =============================================================================
16 // =============================================================================
17 
18 #include <iostream>
19 #include <iomanip>
20 #include <sstream>
21 #include <fstream>
22 
23 #include "base.h"
24 
25 #include "common.h"
26 
27 // #define HF_LOG_LEVEL HF_LOG_LEVEL_TRACE
28 #include "application.h"
29 
30 #include "json/json.h"
31 
37 // =============================================================================
38 // DeviceManagement
39 // =============================================================================
40 
41 // =============================================================================
42 // DeviceManagement::Entries::save
43 // =============================================================================
47 // =============================================================================
48 HF::Common::Result DeviceManagement::Entries::save(const Device &device)
49 {
50  auto res = HF::Core::DeviceManagement::Entries::save(device);
51 
53  return res;
54 }
55 
56 // =============================================================================
57 // DeviceManagement::Entries::insert
58 // =============================================================================
62 // =============================================================================
64 {
65  HF::Core::DeviceManagement::Entries::save(device);
66 }
67 
68 // =============================================================================
69 // DeviceManagement::Entries::destroy
70 // =============================================================================
74 // =============================================================================
75 HF::Common::Result DeviceManagement::Entries::destroy(const Device &device)
76 {
78 
80  return res;
81 }
82 
83 // =============================================================================
84 // DeviceManagement::Server::available
85 // =============================================================================
89 // =============================================================================
91 {
92  if (address == 0 || address == HF::Protocol::BROADCAST_ADDR)
93  {
94  return false;
95  }
96 
97  /* *INDENT-OFF* */
98  auto it = std::find_if(entries().begin(), entries().end(),
99  [address](const HF::Core::DeviceManagement::Device &dev)
100  {
101  return address == dev.address;
102  });
103  /* *INDENT-ON* */
104 
105  return it == entries().end();
106 }
107 
108 // =============================================================================
109 // DeviceManagement::Server::next_address
110 // =============================================================================
114 // =============================================================================
116 {
117  uint16_t result = _next_address;
118 
119  _next_address = HF::Protocol::BROADCAST_ADDR;
120 
121  if (result == HF::Protocol::BROADCAST_ADDR)
122  {
124  }
125 
126  return result;
127 }
128 
129 // =============================================================================
130 // DeviceManagement::Server::deregister
131 // =============================================================================
135 // =============================================================================
137 {
138  if (address == 0 || address == HF::Protocol::BROADCAST_ADDR)
139  {
140  return false;
141  }
142 
143  auto _entry = entry(address);
144 
145  if (_entry != nullptr)
146  {
148  return true;
149  }
150 
151  return false;
152 }
153 
154 // =============================================================================
155 // DeviceManagement::Server::save
156 // =============================================================================
160 // =============================================================================
161 void DeviceManagement::Server::save(Json::Value &root)
162 {
163  LOG(INFO) << "Saving registration entries ..." << NL;
164 
165  unsigned i = 0;
166 
167  /* *INDENT-OFF* */
168  for_each( entries ().begin (), entries ().end (),
169  [&root, &i](HF::Core::DeviceManagement::Device &device)
170  {
171  to_json (device, root[i]);
172  i++;
173  });
174  /* *INDENT-ON* */
175 }
176 
177 // =============================================================================
178 // DeviceManagement::Server::restore
179 // =============================================================================
183 // =============================================================================
184 void DeviceManagement::Server::restore(Json::Value root)
185 {
186  LOG(INFO) << "Restoring registration entries ..." << NL;
187 
189 
190  for (unsigned i = 0; i < root.size(); i++)
191  {
192  from_json(root[i], device);
194  }
195 }
196 
197 // =============================================================================
198 // BindManagement
199 // =============================================================================
200 
201 // =============================================================================
202 // BindManagement::Entries::save
203 // =============================================================================
207 // =============================================================================
208 HF::Common::Result BindManagement::Entries::save(const Entry &entry)
209 {
210  auto res = HF::Core::BindManagement::Entries::save(entry);
211 
213  return res;
214 }
215 
216 // =============================================================================
217 // BindManagement::Entries::insert
218 // =============================================================================
222 // =============================================================================
224 {
225  HF::Core::BindManagement::Entries::save(entry);
226 }
227 
228 // =============================================================================
229 // DeviceManagement::Entries::destroy
230 // =============================================================================
234 // =============================================================================
235 HF::Common::Result BindManagement::Entries::destroy(const Entry &entry)
236 {
238 
240  return res;
241 }
242 
243 // =============================================================================
244 // BindManagement::Server::save
245 // =============================================================================
249 // =============================================================================
250 void BindManagement::Server::save(Json::Value &root)
251 {
252  LOG(INFO) << "Saving binding entries ..." << NL;
253 
254  unsigned i = 0;
255 
256  /* *INDENT-OFF* */
257  for_each(entries().begin(), entries().end(),
258  [&root, &i](const HF::Core::BindManagement::Entry &entry)
259  {
260  to_json (entry, root[i]);
261  i++;
262  });
263  /* *INDENT-ON* */
264 }
265 
266 // =============================================================================
267 // BindManagement::Server::restore
268 // =============================================================================
272 // =============================================================================
273 void BindManagement::Server::restore(Json::Value root)
274 {
275  LOG(INFO) << "Restoring binding entries ..." << NL;
276 
277  for (unsigned i = 0; i < root.size(); i++)
278  {
280  from_json(root[i], entry);
281  entries().insert(entry);
282  LOG(TRACE) << "Bind Add : " << entry.source.device
283  << " -> " << entry.destination.device << NL;
284  }
285 }
286 
287 // =============================================================================
288 // Events
289 // =============================================================================
290 
291 // =============================================================================
292 // Events::Alert::status
293 // =============================================================================
297 // =============================================================================
298 void Events::Alert::status(HF::Protocol::Address &source, HF::Interfaces::Alert::Message &message)
299 {
300  using namespace HF::Debug;
301 
302  LOG(INFO) << ">>>>>>>>>>>>> ALERT <<<<<<<<<<<<<" << std::endl
303  << "\tSource | " << source << std::endl
304  << "\tType | 0x" << Hex<uint16_t>(message.type) << std::endl
305  << "\tState | 0x" << Hex<uint32_t>(message.state) << NL;
306 }
307 
308 // =============================================================================
309 // Events::LevelControl::level_change
310 // =============================================================================
314 // =============================================================================
315 void Events::LevelControl::level_change(HF::Protocol::Address &source, uint8_t old_level,
316  uint8_t new_level)
317 {
318  using namespace HF::Debug;
319 
320  LOG(INFO) << ">>>>>>>>>>>>> LEVEL CONTROL <<<<<<<<<<<<<" << std::endl
321  << "\tSource | " << source << std::endl
322  << "\t Old | " << Hex<uint8_t>(old_level) << std::endl
323  << "\t New | " << Hex<uint8_t>(new_level) << NL;
324 }
325 
326 // =============================================================================
327 // Events::OnOff::on
328 // =============================================================================
332 // =============================================================================
333 void Events::OnOff::on(HF::Protocol::Address &source)
334 {
335  using namespace HF::Debug;
336 
337  LOG(INFO) << ">>>>>>>>>>>>> ON-OFF <<<<<<<<<<<<<" << std::endl
338  << "\tSource | " << source << std::endl
339  << "\tCommand | ON" << NL;
340 }
341 
342 // =============================================================================
343 // Events::OnOff::off
344 // =============================================================================
348 // =============================================================================
349 void Events::OnOff::off(HF::Protocol::Address &source)
350 {
351  using namespace HF::Debug;
352 
353  LOG(INFO) << ">>>>>>>>>>>>> ON-OFF <<<<<<<<<<<<<" << std::endl
354  << "\tSource | " << source << std::endl
355  << "\tCommand | OFF" << NL;
356 }
357 
358 // =============================================================================
359 // Events::OnOff::toggle
360 // =============================================================================
364 // =============================================================================
365 void Events::OnOff::toggle(HF::Protocol::Address &source)
366 {
367  using namespace HF::Debug;
368 
369  LOG(INFO) << ">>>>>>>>>>>>> ON-OFF <<<<<<<<<<<<<" << std::endl
370  << "\tSource | " << source << std::endl
371  << "\tCommand | TOGGLE" << NL;
372 }
373 
374 // =============================================================================
375 // Events::SimplePowerMeter::report
376 // =============================================================================
380 // =============================================================================
381 void Events::SimplePowerMeter::report(HF::Protocol::Address &source,
383 {
384  using namespace HF::Debug;
385 
386  UNUSED(report);
387  LOG(INFO) << ">>>>>>>>>>>>> Simple Power Meter <<<<<<<<<<<<<" << std::endl
388  << "\tSource | " << source << std::endl
389  << "\tReport | " << NL;
390 }
391 
392 // =============================================================================
393 // Commands
394 // =============================================================================
395 
396 static void handle_device_infomation(HF::Common::ByteArray &payload, uint16_t offset)
397 {
399 
400  response.unpack(payload, offset);
401 
402  using namespace HF::Core::DeviceInformation;
403  using namespace HF::Attributes;
404  using namespace HF::Debug;
405 
406  uint8_t log_width = 20;
407 
408  LOG(INFO) << "====== Device Information : Attributes ======" << std::endl
409  << std::right << std::setw(log_width) << std::setfill(' ');
410 
411  /* *INDENT-OFF* */
412  std::for_each (response.attributes.begin (), response.attributes.end (),
413  [log_width](const HF::Attributes::IAttribute *attr)
414  {
415  LOG (APP) << std::right << std::setw (log_width) << std::setfill (' ');
416 
417  switch (attr->uid ())
418  {
419  case CORE_VERSION_ATTR:
420  {
421  auto *version = adapt <uint8_t>(attr);
422  LOG (APP) << "Core (" << Hex <uint8_t>(attr->uid ()) << ") | 0x"
423  << Hex <uint8_t>(version->get ());
424  break;
425  }
427  {
428  auto *version = adapt <uint8_t>(attr);
429  LOG (APP) << "Profile (" << Hex <uint8_t>(attr->uid ()) << ") | 0x"
430  << Hex <uint8_t>(version->get ());
431  break;
432  }
434  {
435  auto *version = adapt <uint8_t>(attr);
436  LOG (APP) << "Interface (" << Hex <uint8_t>(attr->uid ()) << ") | 0x"
437  << std::right << Hex <uint8_t>(version->get ());
438  break;
439  }
440  case EXTRA_CAP_ATTR:
441  {
442  auto *extra_cap = adapt <uint8_t>(attr);
443  LOG (APP) << "Extra Cap. (" << Hex <uint8_t>(attr->uid ()) << ") | 0x"
444  << Hex <uint8_t>(extra_cap->get ());
445  break;
446  }
447  case MIN_SLEEP_TIME_ATTR:
448  {
449  auto *min_sleep = adapt <uint32_t>(attr);
450  LOG (APP) << "Min. Sleep (" << Hex <uint8_t>(attr->uid ()) << ") | 0x"
451  << Hex <uint32_t>(min_sleep->get ());
452  break;
453  }
455  {
456  auto *actual_time = adapt <uint32_t>(attr);
457  LOG (APP) << "Actual Resp. Time (" << Hex <uint8_t>(attr->uid ()) << ") | 0x"
458  << Hex <uint32_t>(actual_time->get ());
459  break;
460  }
461  case APP_VERSION_ATTR:
462  {
463  auto *version = adapt <std::string>(attr);
464  LOG (APP) << "APP Version (" << Hex <uint8_t>(attr->uid ()) << ") | "
465  << version->get ();
466  break;
467  }
468  case HW_VERSION_ATTR:
469  {
470  auto *version = adapt <std::string>(attr);
471  LOG (APP) << "HW Version (" << Hex <uint8_t>(attr->uid ()) << ") | "
472  << version->get ();
473  break;
474  }
475  case EMC_ATTR:
476  {
477  auto *emc = adapt <uint16_t>(attr);
478  LOG (APP) << "EMC (" << Hex <uint8_t>(attr->uid ()) << ") | 0x"
479  << Hex <uint16_t>(emc->get ());
480  break;
481  }
482  case DECT_ID_ATTR:
483  {
484  auto *dect = adapt < std::vector < uint8_t >> (attr);
485  LOG (APP) << "DECT (" << Hex <uint8_t>(attr->uid ()) << ") | ";
486 
487  auto value = dect->get ();
488 
489  std::for_each(value.begin (), value.end (), [](uint8_t byte)
490  {
491  LOG (APP) << byte;
492  });
493 
494  break;
495  }
497  {
498  auto *name = adapt <std::string>(attr);
499  LOG (APP) << "Manuf. Name (" << Hex <uint8_t>(attr->uid ()) << ") | "
500  << name->get ();
501  break;
502  }
503  case LOCATION_ATTR:
504  {
505  auto *location = adapt <std::string>(attr);
506  LOG (APP) << "Location (" << Hex <uint8_t>(attr->uid ()) << ") | "
507  << location->get ();
508  break;
509  }
510  case ENABLED_ATTR:
511  {
512  auto *enabled = adapt <uint8_t>(attr);
513  LOG (APP) << "Enable (" << Hex <uint8_t>(attr->uid ()) << ") | 0x"
514  << Hex <uint8_t>(enabled->get ());
515  break;
516  }
517  case FRIENDLY_NAME_ATTR:
518  {
519  auto *names_attr = adapt <FriendlyName>(attr);
520  LOG (APP) << "Friendly Name (" << Hex <uint8_t>(attr->uid ()) << ") |";
521  auto const &names = names_attr->get ();
522 
523  std::for_each (names.units.begin (), names.units.end (),
524  [](const FriendlyName::Unit &unit)
525  {
526  LOG (APP) << " (" << (int) unit.id << ") " << unit.name;
527  });
528 
529  break;
530  }
531  case UID_ATTR:
532  {
533  auto *uid = adapt <HF::UID::UID>(attr);
534  LOG (APP) << "UID (" << Hex <uint8_t>(attr->uid ()) << ") | "
535  << uid->get ();
536  break;
537  }
538  case SERIAL_NUMBER_ATTR:
539  {
540  auto *serial = adapt <std::string>(attr);
541  LOG (APP) << "Serial Number (" << Hex <uint8_t>(attr->uid ()) << ") | "
542  << serial->get ();
543  break;
544  }
545  default:
546  {
547  LOG (APP) << "Unknown | UID - " << attr->uid () << std::endl;
548  break;
549  }
550  }
551 
552  LOG (APP) << std::endl;
553 
554  });
555  /* *INDENT-ON* */
556 
557  LOG(INFO) << "====== Device Information : Attributes ======" << NL;
558 }
559 
560 // =============================================================================
561 // Commands::Unit::handle
562 // =============================================================================
566 // =============================================================================
567 HF::Common::Result Commands::Unit::handle(HF::Protocol::Packet &packet,
568  HF::Common::ByteArray &payload, uint16_t offset)
569 {
570  UNUSED(packet);
571  UNUSED(payload);
572  UNUSED(offset);
573 
576  {
577  handle_device_infomation(payload, offset);
578  return HF::Common::Result::OK;
579  }
580 
582 }
583 
584 // =============================================================================
585 // Base
586 // =============================================================================
587 
588 // =============================================================================
589 // Base::receive
590 // =============================================================================
594 // =============================================================================
595 void Base::receive(HF::Protocol::Packet &packet, HF::Common::ByteArray &payload, uint16_t offset)
596 {
597  LOG(DEBUG) << ">>>>>>>>>>>>> Message Received <<<<<<<<<<<<<" << NL;
598 
599  LOG(TRACE) << "Payload : " << payload << NL;
600 
601  LOG(DEBUG) << std::endl << packet << NL;
602 
604 }
605 
606 // =============================================================================
607 // Base::has_bind
608 // =============================================================================
612 // =============================================================================
613 bool Base::has_bind(uint16_t dev_addr_1, uint16_t dev_addr_2)
614 {
615  HF::Protocol::Address source(dev_addr_1, 1);
617  HF::Protocol::Address destination(dev_addr_2, 1);
618 
619  return _unit0.bind_management()->entries().find(source, itf, destination) != nullptr;
620 }
621 
622 // =============================================================================
623 // Base::bind
624 // =============================================================================
628 // =============================================================================
629 uint8_t Base::bind(uint16_t dev_addr_1, uint16_t dev_addr_2)
630 {
631  if (this->has_bind(dev_addr_1, dev_addr_2))
632  {
633  return 1;
634  }
635 
636  HF::Protocol::Address source(dev_addr_1, 1);
638  HF::Protocol::Address destination(dev_addr_2, 1);
639 
640  auto res = _unit0.bind_management()->add(source, destination, itf);
641 
642  if (res == HF::Common::OK)
643  {
644  return 0;
645  }
646 
647  if (_unit0.device_management()->entry(dev_addr_1) == nullptr)
648  {
649  return 2;
650  }
651 
652  if (_unit0.device_management()->entry(dev_addr_2) == nullptr)
653  {
654  return 3;
655  }
656 
657  return 4;
658 }
659 
660 // =============================================================================
661 // Base::unbind
662 // =============================================================================
666 // =============================================================================
667 bool Base::unbind(uint16_t dev_addr_1, uint16_t dev_addr_2)
668 {
669  HF::Protocol::Address source(dev_addr_1, 1);
671  HF::Protocol::Address destination(dev_addr_2, 1);
672 
673  return _unit0.bind_management()->remove(source, destination, itf) == HF::Common::Result::OK;
674 }
675 
676 // =============================================================================
677 // Helper Functions
678 // =============================================================================
679 
680 static std::string json_uid(uint16_t uid)
681 {
682  std::ostringstream convert;
683 
684  convert << "0x" << std::setfill('0') << std::setw(sizeof(uint16_t) * 2)
685  << std::hex << uid;
686 
687  return convert.str();
688 }
689 
690 static uint16_t json_uid(std::string uid)
691 {
692  return STRTOL_HEX(uid.substr(2));
693 }
694 
695 // =============================================================================
696 // to_json
697 // =============================================================================
701 // =============================================================================
702 void to_json(const HF::Common::Interface &interface, Json::Value &node)
703 {
704  if (interface.role == HF::Interface::SERVER_ROLE)
705  {
706  node["role"] = "server";
707  }
708  else
709  {
710  node["role"] = "client";
711  }
712 
713  node["id"] = json_uid(interface.id);
714 }
715 
716 // =============================================================================
717 // to_json
718 // =============================================================================
722 // =============================================================================
723 void to_json(const HF::UID::UID &uid, Json::Value &node)
724 {
725  switch (uid.type())
726  {
727  case HF::UID::NONE_UID:
728  {
729  node["type"] = "none";
730  node["value"] = 0;
731  }
732 
733  case HF::UID::DECT_UID: // RFPI
734  {
735  node["type"] = "dect";
736 
737  const HF::UID::DECT *dect = static_cast<const HF::UID::DECT *>(uid.raw());
738 
739  for (uint8_t i = 0; i < HF::UID::DECT::length(); i++)
740  {
741  node["value"][i] = (int) (*dect)[i];
742  }
743 
744  break;
745  }
746 
747  case HF::UID::MAC_UID:
748  {
749  node["type"] = "mac";
750 
751  const HF::UID::MAC *mac = static_cast<const HF::UID::MAC *>(uid.raw());
752 
753  for (int i = 0; i < 6; i++)
754  {
755  node["value"][i] = (int) (*mac)[i];
756  }
757 
758  break;
759  }
760 
761  case HF::UID::URI_UID:
762  {
763  node["type"] = "uri";
764  node["value"] = static_cast<const HF::UID::URI *>(uid.raw())->str();
765  break;
766  }
767  }
768 }
769 
770 // =============================================================================
771 // to_json
772 // =============================================================================
776 // =============================================================================
777 void to_json(const HF::Core::DeviceManagement::Unit &unit, Json::Value &node)
778 {
779  node["id"] = unit.id;
780 
781  node["profile"] = json_uid(unit.profile);
782 
783  for (unsigned i = 0; i < unit.interfaces.size(); i++)
784  {
785  to_json(unit.interfaces[i], node["opts"][i]);
786  }
787 }
788 
789 // =============================================================================
790 // to_json
791 // =============================================================================
795 // =============================================================================
796 void to_json(const HF::Core::DeviceManagement::Device &device, Json::Value &node)
797 {
798  node["address"] = device.address;
799 
800  for (unsigned i = 0; i < device.units.size(); i++)
801  {
802  to_json(device.units[i], node["units"][i]);
803  }
804 
805  node["emc"] = json_uid(device.emc);
806 
807  to_json(device.uid, node["uid"]);
808 }
809 
810 // =============================================================================
811 // to_json
812 // =============================================================================
816 // =============================================================================
817 void to_json(const HF::Protocol::Address &address, Json::Value &node)
818 {
819  node["mod"] = (int) address.mod;
820  node["device"] = (int) address.device;
821  node["unit"] = (int) address.unit;
822 }
823 
824 // =============================================================================
825 // to_json
826 // =============================================================================
830 // =============================================================================
831 void to_json(const HF::Core::BindManagement::Entry &entry, Json::Value &node)
832 {
833  to_json(entry.source, node["src"]);
834  to_json(entry.destination, node["dst"]);
835  to_json(entry.itf, node["itf"]);
836 }
837 
838 // =============================================================================
839 // from_json
840 // =============================================================================
844 // =============================================================================
845 void from_json(Json::Value &node, HF::Common::Interface &interface)
846 {
847  std::string role = node.get("role", "client").asString();
848 
849  if (role[0] == 's' || role[0] == 'S')
850  {
851  interface.role = HF::Interface::SERVER_ROLE;
852  }
853  else
854  {
855  interface.role = HF::Interface::CLIENT_ROLE;
856  }
857 
858  interface.id = json_uid(node.get("id", "0x7FFF").asString());
859 }
860 
861 // =============================================================================
862 // from_json
863 // =============================================================================
867 // =============================================================================
868 void from_json(Json::Value &node, HF::UID::UID &uid)
869 {
870  std::string uid_type = node.get("type", "none").asString();
871 
872  if (uid_type == "none")
873  {
874  HF::UID::NONE *none = new HF::UID::NONE;
875  uid = none;
876  }
877  else if (uid_type == "dect")
878  {
879  HF::UID::DECT *dect = new HF::UID::DECT;
880 
881  for (unsigned i = 0; i < node["value"].size(); ++i)
882  {
883  (*dect)[i] = (uint8_t) node["value"][i].asUInt();
884  }
885 
886  uid = dect;
887  }
888  else if (uid_type == "mac")
889  {
890  HF::UID::MAC *mac = new HF::UID::MAC;
891 
892  for (unsigned i = 0; i < node["value"].size(); ++i)
893  {
894  (*mac)[i] = (uint8_t) node["value"][i].asUInt();
895  }
896 
897  uid = mac;
898  }
899  else if (uid_type == "uri")
900  {
901  HF::UID::URI *uri = new HF::UID::URI;
902  uri->value = node["value"].asString();
903  uid = uri;
904  }
905 }
906 
907 // =============================================================================
908 // from_json
909 // =============================================================================
913 // =============================================================================
914 void from_json(Json::Value &node, HF::Core::DeviceManagement::Unit &unit)
915 {
916  unit.id = (uint8_t) node.get("id", HF::Protocol::BROADCAST_UNIT).asUInt();
917 
918  unit.profile = json_uid(node.get("profile", "0x7FFF").asString());
919 
920  for (unsigned i = 0; i < node["opts"].size(); i++)
921  {
922  unit.interfaces.push_back(0);
923  from_json(node["opts"][i], unit.interfaces[i]);
924  }
925 }
926 
927 // =============================================================================
928 // from_json
929 // =============================================================================
933 // =============================================================================
934 void from_json(Json::Value &node, HF::Core::DeviceManagement::Device &dev)
935 {
936  dev.address = (uint16_t) node.get("address", HF::Protocol::BROADCAST_ADDR).asUInt();
937 
938  for (unsigned i = 0; i < node["units"].size(); i++)
939  {
940  dev.units.push_back(0);
941  from_json(node["units"][i], dev.units[i]);
942  }
943 
944  dev.emc = json_uid(node.get("emc", "0x0000").asString());
945 
946  from_json(node["uid"], dev.uid);
947 }
948 
949 // =============================================================================
950 // from_json
951 // =============================================================================
955 // =============================================================================
956 void from_json(Json::Value &node, HF::Protocol::Address &addr)
957 {
958  addr.mod = (uint16_t) node.get("mod", 0).asUInt();
959  addr.device = (uint16_t) node.get("device", 0).asUInt();
960  addr.unit = (uint8_t) node.get("unit", 0).asUInt();
961 }
962 
963 // =============================================================================
964 // from_json
965 // =============================================================================
969 // =============================================================================
970 void from_json(Json::Value &node, HF::Core::BindManagement::Entry &entry)
971 {
972  from_json(node["src"], entry.source);
973  from_json(node["dst"], entry.destination);
974  from_json(node["itf"], entry.itf);
975 }
976 
void insert(Entry &entry)
Insert a bind management entry into the database.
Definition: base.cpp:223
This class represents the payload of a HF::Message::GET_ATTR_PACK_RES message.
Definition: attributes.h:934
bool available(uint16_t address)
Check if the given address is available for registration.
Definition: base.cpp:90
uint8_t unit
Source Unit.
Definition: protocol.h:206
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Core::DeviceInformati...
Media Access Control (IEEE-MAC-48)
Definition: uids.h:46
bool response(Message::Type type)
Check if message is a response.
This file contains the definitions for the HAN-FUN example applications.
Message message
Packet message payload;.
Definition: protocol.h:306
Common::Result destroy(const Entry &entry)
Destroy the given entry in the persistent storage.
void insert(const Device &device)
Insert a device management entry into the database.
Definition: base.cpp:63
bool deregister(uint16_t address)
De-register the device with the given address.
Definition: base.cpp:136
uint8_t type() const
Type of the UID.
Definition: uids.h:589
virtual uint16_t next_address()
Return next available address for registering a device.
uint16_t type
Unit Type that generated the message.
Definition: alert.h:92
constexpr uint16_t BROADCAST_ADDR
HAN-FUN Broadcast - device address.
Definition: protocol.h:45
UID_T const * raw() const
Get the underling wrapped UID_T pointer.
Definition: uids.h:704
uint16_t id
Identifier of the interface.
Scheduling::Entry< Interval > Entry
Specific part for the Event Scheduler of the HF::Scheduling::Entry.
void save(Json::Value &root)
Save the bind entries into the JSON database.
Definition: base.cpp:250
RFPI or IPUI.
Definition: uids.h:45
#define STRTOL_HEX(X)
Helper macro to convert a std::string into a number (base 16).
Definition: apps/common.h:179
Payload for the Status command.
Definition: alert.h:86
Top-level namespace for debug helper functions.
Definition: debug.h:88
URI UID class.
Definition: uids.h:431
uint32_t state
Current state of the server.
Definition: alert.h:93
Protocol::Address source
Source Address.
uint16_t address
Device Address.
Uniform Resource Identifier.
Definition: uids.h:47
uint32_t convert(const Date &date)
Convert the date given by date to the corresponding time value.
void receive(Protocol::Packet &packet, Common::ByteArray &payload, uint16_t offset)
Callback to deliver a packet received from the transport layer.
Type type
Message type.
Definition: protocol.h:127
IEEE MAC-48b UID class.
Definition: uids.h:407
Common::Interface itf
Destination Interface.
void from_json(Json::Value &node, HF::Common::Interface &interface)
Fill a HF::Common::Interface from the given Json::Value object.
Definition: base.cpp:845
Data type representing a unit0&#39;s friendly name.
Electronic Manufacture Code attribute.
uint16_t role
Interface role : Server or Client.
uint16_t emc
Device EMC if applicable, 0 otherwise.
Wrapper around UID_T pointer&#39;s.
Definition: uids.h:531
This class represents a byte array.
#define NL
Helper define for new-line and stream clear.
Definition: debug.h:34
Network Address.
Definition: protocol.h:201
Get pack attributes response.
Definition: protocol.h:79
Empty UID.
Definition: uids.h:44
bool unbind(uint16_t dev_addr_1, uint16_t dev_addr_2)
Remove the binding entry for the given devices.
Definition: base.cpp:667
This is the top-level namespace for the classes that implement the interface&#39;s attribute manipulation...
Definition: attributes.h:30
Fail - Invalid Argument.
HAN-FUN Protocol Packet.
Definition: protocol.h:298
virtual Common::Result deregister(DevicePtr &device)
De-register the device that corresponds to the given Device entry.
Interface itf
Interface Address.
Definition: protocol.h:129
This file contains the definition of the Base class that represents the HAN-FUN Concentrator on the a...
Interface/Service Attribute API.
Definition: attributes.h:44
uint16_t mod
Address modifier.
Definition: protocol.h:203
ON-OFF interface UID.
Definition: interface.h:79
This represents a bind entry data structure.
uint16_t device
Device Address.
Definition: protocol.h:204
void receive(HF::Protocol::Packet &packet, HF::Common::ByteArray &payload, uint16_t offset)
Callback to deliver a packet received from the transport layer.
Definition: base.cpp:595
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.
static uint16_t length()
Return the number of bytes in the underlining byte array.
Definition: uids.h:369
DECT UID class.
Definition: uids.h:378
This namespace contains the classes that implement the Device Information service.
void restore(Json::Value root)
Restore the device entries from the JSON database.
Definition: base.cpp:184
void save(Json::Value &root)
Save the device entries into the JSON database.
Definition: base.cpp:161
This class represents an empty UID.
Definition: uids.h:144
This file contains the definitions for the common functionality in the HAN-FUN example applications...
Device information interface UID.
Definition: interface.h:64
Container & entries() const
Get a reference to the current object implementing the persistence API, for the device information...
Common::Result destroy(const Device &entry)
Destroy the given entry in the persistent storage.
void to_json(const HF::Common::Interface &interface, Json::Value &node)
Serialize a HF::Common::Interface to the given Json::Value.
Definition: base.cpp:702
uint16_t next_address()
Return next available address for registering a device.
Definition: base.cpp:115
std::vector< Unit > units
Unit list of the interface.
#define LOG(X)
Log messages with the level given by X.
Definition: debug.h:81
std::vector< Common::Interface > interfaces
Optional interfaces.
void restore(Json::Value root)
Restore the bind entries from the JSON database.
Definition: base.cpp:273
bool has_bind(uint16_t dev_addr_1, uint16_t dev_addr_2)
Check if bind exists.
Definition: base.cpp:613
Result
Commands result codes.
uint8_t bind(uint16_t dev_addr_1, uint16_t dev_addr_2)
Create a new bind entry.
Definition: base.cpp:629
void Save()
Save application configuration.
Definition: base_app.cpp:473
Protocol::Address destination
Destination Address.
constexpr uint8_t BROADCAST_UNIT
HAN-FUN Broadcast - unit address.
Definition: protocol.h:48