30 #include "json/json.h" 50 auto res = HF::Core::DeviceManagement::Entries::save(device);
65 HF::Core::DeviceManagement::Entries::save(device);
98 auto it = std::find_if(entries().begin(), entries().end(),
105 return it == entries().end();
117 uint16_t result = _next_address;
143 auto _entry = entry(address);
145 if (_entry !=
nullptr)
163 LOG(INFO) <<
"Saving registration entries ..." <<
NL;
168 for_each( entries ().begin (), entries ().end (),
186 LOG(INFO) <<
"Restoring registration entries ..." <<
NL;
190 for (
unsigned i = 0; i < root.size(); i++)
210 auto res = HF::Core::BindManagement::Entries::save(entry);
225 HF::Core::BindManagement::Entries::save(entry);
252 LOG(INFO) <<
"Saving binding entries ..." <<
NL;
257 for_each(entries().begin(), entries().end(),
275 LOG(INFO) <<
"Restoring binding entries ..." <<
NL;
277 for (
unsigned i = 0; i < root.size(); i++)
281 entries().insert(entry);
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;
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;
337 LOG(INFO) <<
">>>>>>>>>>>>> ON-OFF <<<<<<<<<<<<<" << std::endl
338 <<
"\tSource | " << source << std::endl
339 <<
"\tCommand | ON" <<
NL;
353 LOG(INFO) <<
">>>>>>>>>>>>> ON-OFF <<<<<<<<<<<<<" << std::endl
354 <<
"\tSource | " << source << std::endl
355 <<
"\tCommand | OFF" <<
NL;
369 LOG(INFO) <<
">>>>>>>>>>>>> ON-OFF <<<<<<<<<<<<<" << std::endl
370 <<
"\tSource | " << source << std::endl
371 <<
"\tCommand | TOGGLE" <<
NL;
387 LOG(INFO) <<
">>>>>>>>>>>>> Simple Power Meter <<<<<<<<<<<<<" << std::endl
388 <<
"\tSource | " << source << std::endl
389 <<
"\tReport | " <<
NL;
406 uint8_t log_width = 20;
408 LOG(INFO) <<
"====== Device Information : Attributes ======" << std::endl
409 << std::right << std::setw(log_width) << std::setfill(
' ');
415 LOG (APP) << std::right << std::setw (log_width) << std::setfill (
' ');
417 switch (attr->uid ())
421 auto *version = adapt <uint8_t>(attr);
422 LOG (APP) <<
"Core (" << Hex <uint8_t>(attr->uid ()) <<
") | 0x" 423 << Hex <uint8_t>(version->get ());
428 auto *version = adapt <uint8_t>(attr);
429 LOG (APP) <<
"Profile (" << Hex <uint8_t>(attr->uid ()) <<
") | 0x" 430 << Hex <uint8_t>(version->get ());
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 ());
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 ());
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 ());
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 ());
463 auto *version = adapt <std::string>(attr);
464 LOG (APP) <<
"APP Version (" << Hex <uint8_t>(attr->uid ()) <<
") | " 470 auto *version = adapt <std::string>(attr);
471 LOG (APP) <<
"HW Version (" << Hex <uint8_t>(attr->uid ()) <<
") | " 477 auto *emc = adapt <uint16_t>(attr);
478 LOG (APP) <<
"EMC (" << Hex <uint8_t>(attr->uid ()) <<
") | 0x" 479 << Hex <uint16_t>(emc->get ());
484 auto *dect = adapt < std::vector < uint8_t >> (attr);
485 LOG (APP) <<
"DECT (" << Hex <uint8_t>(attr->uid ()) <<
") | ";
487 auto value = dect->get ();
489 std::for_each(value.begin (), value.end (), [](uint8_t byte)
498 auto *name = adapt <std::string>(attr);
499 LOG (APP) <<
"Manuf. Name (" << Hex <uint8_t>(attr->uid ()) <<
") | " 505 auto *location = adapt <std::string>(attr);
506 LOG (APP) <<
"Location (" << Hex <uint8_t>(attr->uid ()) <<
") | " 512 auto *enabled = adapt <uint8_t>(attr);
513 LOG (APP) <<
"Enable (" << Hex <uint8_t>(attr->uid ()) <<
") | 0x" 514 << Hex <uint8_t>(enabled->get ());
519 auto *names_attr = adapt <FriendlyName>(attr);
520 LOG (APP) <<
"Friendly Name (" << Hex <uint8_t>(attr->uid ()) <<
") |";
521 auto const &names = names_attr->get ();
523 std::for_each (names.units.begin (), names.units.end (),
526 LOG (APP) <<
" (" << (int) unit.id <<
") " << unit.name;
533 auto *uid = adapt <HF::UID::UID>(attr);
534 LOG (APP) <<
"UID (" << Hex <uint8_t>(attr->uid ()) <<
") | " 540 auto *serial = adapt <std::string>(attr);
541 LOG (APP) <<
"Serial Number (" << Hex <uint8_t>(attr->uid ()) <<
") | " 547 LOG (APP) <<
"Unknown | UID - " << attr->uid () << std::endl;
552 LOG (APP) << std::endl;
557 LOG(INFO) <<
"====== Device Information : Attributes ======" <<
NL;
577 handle_device_infomation(payload, offset);
597 LOG(DEBUG) <<
">>>>>>>>>>>>> Message Received <<<<<<<<<<<<<" <<
NL;
599 LOG(TRACE) <<
"Payload : " << payload <<
NL;
601 LOG(DEBUG) << std::endl << packet <<
NL;
619 return _unit0.bind_management()->entries().find(source, itf, destination) !=
nullptr;
631 if (this->has_bind(dev_addr_1, dev_addr_2))
640 auto res = _unit0.bind_management()->add(source, destination, itf);
647 if (_unit0.device_management()->entry(dev_addr_1) ==
nullptr)
652 if (_unit0.device_management()->entry(dev_addr_2) ==
nullptr)
680 static std::string json_uid(uint16_t uid)
684 convert <<
"0x" << std::setfill(
'0') << std::setw(
sizeof(uint16_t) * 2)
690 static uint16_t json_uid(std::string uid)
706 node[
"role"] =
"server";
710 node[
"role"] =
"client";
713 node[
"id"] = json_uid(interface.
id);
729 node[
"type"] =
"none";
735 node[
"type"] =
"dect";
741 node[
"value"][i] = (int) (*dect)[i];
749 node[
"type"] =
"mac";
753 for (
int i = 0; i < 6; i++)
755 node[
"value"][i] = (int) (*mac)[i];
763 node[
"type"] =
"uri";
779 node[
"id"] = unit.
id;
781 node[
"profile"] = json_uid(unit.
profile);
783 for (
unsigned i = 0; i < unit.
interfaces.size(); i++)
798 node[
"address"] = device.
address;
800 for (
unsigned i = 0; i < device.
units.size(); i++)
805 node[
"emc"] = json_uid(device.
emc);
819 node[
"mod"] = (int) address.
mod;
820 node[
"device"] = (
int) address.
device;
821 node[
"unit"] = (int) address.
unit;
847 std::string role = node.get(
"role",
"client").asString();
849 if (role[0] ==
's' || role[0] ==
'S')
858 interface.
id = json_uid(node.get(
"id",
"0x7FFF").asString());
870 std::string uid_type = node.get(
"type",
"none").asString();
872 if (uid_type ==
"none")
877 else if (uid_type ==
"dect")
881 for (
unsigned i = 0; i < node[
"value"].size(); ++i)
883 (*dect)[i] = (uint8_t) node[
"value"][i].asUInt();
888 else if (uid_type ==
"mac")
892 for (
unsigned i = 0; i < node[
"value"].size(); ++i)
894 (*mac)[i] = (uint8_t) node[
"value"][i].asUInt();
899 else if (uid_type ==
"uri")
902 uri->value = node[
"value"].asString();
918 unit.
profile = json_uid(node.get(
"profile",
"0x7FFF").asString());
920 for (
unsigned i = 0; i < node[
"opts"].size(); i++)
938 for (
unsigned i = 0; i < node[
"units"].size(); i++)
940 dev.
units.push_back(0);
944 dev.
emc = json_uid(node.get(
"emc",
"0x0000").asString());
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();
void insert(Entry &entry)
Insert a bind management entry into the database.
This class represents the payload of a HF::Message::GET_ATTR_PACK_RES message.
bool available(uint16_t address)
Check if the given address is available for registration.
Device friendly name attribute.
HF::Attributes::IAttribute * create_attribute(uint8_t uid)
Create an attribute object that can hold the attribute with the given uid. (HF::Core::DeviceInformati...
HF Core version attribute.
Media Access Control (IEEE-MAC-48)
Minimum sleep time attribute.
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;.
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.
Extra capabilities attribute.
bool deregister(uint16_t address)
De-register the device with the given address.
HF Profile version attribute.
uint16_t profile
Unit UID.
uint8_t type() const
Type of the UID.
virtual uint16_t next_address()
Return next available address for registering a device.
uint16_t type
Unit Type that generated the message.
constexpr uint16_t BROADCAST_ADDR
HAN-FUN Broadcast - device address.
UID_T const * raw() const
Get the underling wrapped UID_T pointer.
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.
#define STRTOL_HEX(X)
Helper macro to convert a std::string into a number (base 16).
Payload for the Status command.
Top-level namespace for debug helper functions.
Device enabled attribute.
uint32_t state
Current state of the server.
Protocol::Address source
Source Address.
uint16_t address
Device Address.
Uniform Resource Identifier.
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.
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.
HF::UID::UID uid
Device UID.
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's.
This class represents a byte array.
#define NL
Helper define for new-line and stream clear.
HF Interface version attribute.
Get pack attributes response.
bool unbind(uint16_t dev_addr_1, uint16_t dev_addr_2)
Remove the binding entry for the given devices.
This is the top-level namespace for the classes that implement the interface's attribute manipulation...
virtual Common::Result deregister(DevicePtr &device)
De-register the device that corresponds to the given Device entry.
Interface itf
Interface Address.
This file contains the definition of the Base class that represents the HAN-FUN Concentrator on the a...
Interface/Service Attribute API.
uint16_t mod
Address modifier.
Actual response time attribute.
This represents a bind entry data structure.
uint16_t device
Device Address.
void receive(HF::Protocol::Packet &packet, HF::Common::ByteArray &payload, uint16_t offset)
Callback to deliver a packet received from the transport layer.
#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.
void restore(Json::Value root)
Restore the device entries from the JSON database.
Hardware version attribute.
void save(Json::Value &root)
Save the device entries into the JSON database.
This class represents an empty UID.
Hardware version attribute.
This file contains the definitions for the common functionality in the HAN-FUN example applications...
Device information interface UID.
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.
uint16_t next_address()
Return next available address for registering a device.
std::vector< Unit > units
Unit list of the interface.
#define LOG(X)
Log messages with the level given by X.
std::vector< Common::Interface > interfaces
Optional interfaces.
void restore(Json::Value root)
Restore the bind entries from the JSON database.
bool has_bind(uint16_t dev_addr_1, uint16_t dev_addr_2)
Check if bind exists.
Result
Commands result codes.
uint8_t bind(uint16_t dev_addr_1, uint16_t dev_addr_2)
Create a new bind entry.
void Save()
Save application configuration.
Protocol::Address destination
Destination Address.
Manufacture's name attribute.
constexpr uint8_t BROADCAST_UNIT
HAN-FUN Broadcast - unit address.