![]() |
HAN-FUN API
1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
|
This module contains the classes for the provided example applications. More...
Namespaces | |
HF::Application | |
This namespace contains the declaration of the functions that implement the HAN-FUN example applications. | |
Data Structures | |
struct | Base |
This class represents a HAN-FUN Concentrator. More... | |
struct | ICommand |
Example application menu entry API. More... | |
class | Command |
Parent class for the commands API implementations. More... | |
struct | Node |
This class represents a node in the HAN-FUN network. More... | |
struct | SimpleLight |
Unit implementing a Simple Light. More... | |
struct | SimpleSwitch |
Unit implementing a Simple Switch. More... | |
struct | msg_t |
Message sent between the concentrator and the nodes. More... | |
struct | hello_msg_t |
Hello message payload. More... | |
Macros | |
#define | HF_APP_CONFIG_FILE "./hanfun.json" |
JSON database file. More... | |
#define | COMMAND(_name, _key, _help) |
Helper macro to define new commands. | |
#define | COMMAND_ADD(_name) |
Helper macro to add a new command to the registry. | |
#define | STRTOL(X) strtol(X.c_str(), NULL, 10); |
Helper macro to convert a std::string into a number (base 10). | |
#define | STRTOL_HEX(X) strtol(X.c_str(), NULL, 16); |
Helper macro to convert a std::string into a number (base 16). | |
#define | NONE_MSG 0xFFFF |
No message primitive id. More... | |
#define | HELLO_MSG 0x0101 |
Hello message primitive id. More... | |
#define | DATA_MSG 0x0201 |
Data message primitive id. More... | |
#define | CHECK_STATUS() |
Helper macro the check libuv command status. | |
Typedefs | |
typedef HF::Devices::Concentrator::Unit0< HF::Core::DeviceInformation::Server, ::DeviceManagement::Server, HF::Core::AttributeReporting::Server, ::BindManagement::Server > | Unit0 |
Custom Unit0 declaration. | |
Functions | |
void | to_json (const HF::Common::Interface &interface, Json::Value &node) |
Serialize a HF::Common::Interface to the given Json::Value. More... | |
void | to_json (const HF::Core::DeviceManagement::Unit &unit, Json::Value &node) |
Serialize a HF::Core::DeviceManagement::Unit to the given Json::Value. More... | |
void | to_json (const HF::Core::DeviceManagement::Device &device, Json::Value &node) |
Serialize a HF::Core::DeviceManagement::Device to the given Json::Value. More... | |
void | to_json (const HF::Protocol::Address &address, Json::Value &node) |
Serialize a HF::Protocol::Address to the given Json::Value. More... | |
void | to_json (const HF::Core::BindManagement::Entry &entry, Json::Value &node) |
Serialize a HF::Core::BindManagement::Entry to the given Json::Value. More... | |
void | from_json (Json::Value &node, HF::Common::Interface &interface) |
Fill a HF::Common::Interface from the given Json::Value object. More... | |
void | from_json (Json::Value &node, HF::Core::DeviceManagement::Unit &unit) |
Fill a HF::Core::DeviceManagement::Unit from the given Json::Value object. More... | |
void | from_json (Json::Value &node, HF::Core::DeviceManagement::Device &device) |
Fill a HF::Core::DeviceManagement::Device from the given Json::Value object. More... | |
void | from_json (Json::Value &node, HF::Protocol::Address &address) |
Fill a HF::Protocol::Address from the given Json::Value object. More... | |
void | from_json (Json::Value &node, HF::Core::BindManagement::Entry &entry) |
Fill a HF::Core::BindManagement::Entry from the given Json::Value object. More... | |
void | to_json (HF::UID::UID *uid, Json::Value &node) |
Serialize a HF::UID::UID pointer to the given Json::Value. More... | |
void | from_json (Json::Value &node, HF::UID::UID *&uid) |
Create a new HF::UID::UID based on the fields present in the given Json::Value object. More... | |
COMMAND (ListRegs, "lr", "lr:list registrations.") | |
ListRegs List registrations command. | |
COMMAND (ListBinds, "lb", "lb:list binds.") | |
List binds command. | |
COMMAND (Register, "r", "r 1 x:register device x.\ 0:exit registration mode.") | |
Setup registration command. More... | |
COMMAND (Deregister, "d", "d x:de-register device x.") | |
De-register device command. | |
COMMAND (Unbind, "u", "u x y:unbind device x with y.") | |
Destroy bind command. | |
COMMAND (GlobalBind, "gb", "gb 1:create bind to receive all interface events.\ "gb 0:remove bind to receive all interface events.") | |
Global binds command. | |
COMMAND (On, "on", "on d u:Send an ON command to device/unit pair.") | |
Send ON command. | |
COMMAND (Off, "off", "off d u:Send an OFF command to device/unit pair.") | |
Send OFF command. | |
COMMAND (Toggle, "toggle", "toggle d u:Send a TOGGLE command to device/unit pair.") | |
Send TOGGLE command. | |
COMMAND (DevInfo, "di", "di m d:Get device information mandatory attributes.\ "di a d:Get device information all attributes.") | |
Get Device information. | |
uv_buf_t | alloc_buffer (uv_handle_t *handle, size_t suggested_size) |
This function is used to allocate the buffers used with libuv. More... | |
COMMAND (Register, "r", "r:register device") | |
Register node command. | |
COMMAND (Address, "a", "a:device address") | |
Print node address command. | |
COMMAND (SimpleLight, "sl", "sl:set device as a simple light") | |
Change device to a simple light. | |
COMMAND (SimpleSwitch, "ss", "ss:set device as a simple switch") | |
Change device to a simple switch. | |
COMMAND (On, "on", "on:On Command") | |
Send an on command from the simple switch. | |
COMMAND (Off, "off", "off:Off Command") | |
Send an off command from the simple switch. | |
COMMAND (Toggle, "toggle", "toggle:Toggle Command") | |
Send a toggle command from the simple switch. | |
void | print_error (uv_err_t status) |
Print a user friendly string for given status code. More... | |
void | DeviceManagement::Entries::insert (const Device &device) |
Insert a device management entry into the database. More... | |
bool | DeviceManagement::Server::available (uint16_t address) |
Check if the given address is available for registration. More... | |
uint16_t | DeviceManagement::Server::next_address () |
Return next available address for registering a device. More... | |
bool | DeviceManagement::Server::deregister (uint16_t address) |
De-register the device with the given address . More... | |
void | DeviceManagement::Server::save (Json::Value &root) |
Save the device entries into the JSON database. More... | |
void | DeviceManagement::Server::restore (Json::Value root) |
Restore the device entries from the JSON database. More... | |
void | BindManagement::Entries::insert (Entry &entry) |
Insert a bind management entry into the database. More... | |
void | BindManagement::Server::save (Json::Value &root) |
Save the bind entries into the JSON database. More... | |
void | BindManagement::Server::restore (Json::Value root) |
Restore the bind entries from the JSON database. More... | |
void | Base::receive (HF::Protocol::Packet &packet, HF::Common::ByteArray &payload, uint16_t offset) |
Callback to deliver a packet received from the transport layer. More... | |
bool | Base::has_bind (uint16_t dev_addr_1, uint16_t dev_addr_2) |
Check if bind exists. More... | |
uint8_t | Base::bind (uint16_t dev_addr_1, uint16_t dev_addr_2) |
Create a new bind entry. More... | |
bool | Base::unbind (uint16_t dev_addr_1, uint16_t dev_addr_2) |
Remove the binding entry for the given devices. More... | |
void | HF::Application::Initialize (HF::Transport::Layer &transport) |
Initialize the application. More... | |
void | HF::Application::Save () |
Save application configuration. | |
void | HF::Application::Restore () |
Restore application configuration. | |
void | HF::Application::Saved () |
Callback indicating that the application configuration has been saved. | |
void | HF::Application::Restored () |
Callback indicating that the application configuration has been restored. | |
void | Node::receive (HF::Protocol::Packet &packet, HF::Common::ByteArray &payload, uint16_t offset) |
Callback to deliver a packet received from the transport layer. More... | |
void | SimpleLight::on (HF::Protocol::Address &source) |
Callback that is called when a ON_CMD message is received. More... | |
void | SimpleLight::off (HF::Protocol::Address &source) |
Callback that is called when a OFF_CMD message is received. More... | |
void | SimpleLight::toggle (HF::Protocol::Address &source) |
Callback that is called when a TOGGLE_CMD message is received. More... | |
void | HF::Application::Transport::initialize () |
Initialize the associated transport layer. More... | |
void | HF::Application::Transport::destroy () |
Free the system resources associated with this transport layer. | |
void | HF::Application::Link::send (HF::Common::ByteArray &array) |
Send the data in the given ByteArray using the link to the remote end-point. More... | |
Variables | |
uint16_t | arg2 = STRTOL(args[1]) |
Create bind command. | |
This module contains the classes for the provided example applications.
#define DATA_MSG 0x0201 |
Data message primitive id.
Definition at line 45 of file transport.cpp.
#define HELLO_MSG 0x0101 |
Hello message primitive id.
Definition at line 44 of file transport.cpp.
#define HF_APP_CONFIG_FILE "./hanfun.json" |
JSON database file.
Definition at line 47 of file base_app.cpp.
Referenced by HF::Application::Restore(), and HF::Application::Save().
#define NONE_MSG 0xFFFF |
No message primitive id.
Definition at line 43 of file transport.cpp.
uv_buf_t alloc_buffer | ( | uv_handle_t * | handle, |
size_t | suggested_size | ||
) |
This function is used to allocate the buffers used with libuv.
[in] | handle | a pointer to the handle to allocate the buffer for. |
[in] | suggested_size | number bytes to allocate. |
Definition at line 212 of file transport.cpp.
References UNUSED.
bool DeviceManagement::Server::available | ( | uint16_t | address | ) |
Check if the given address
is available for registration.
[in] | address | device address to check. |
<tt>true</tt> | if no device is registered with the given address ; |
<tt>false</tt> | otherwise. |
Definition at line 90 of file base.cpp.
References HF::Core::DeviceManagement::Device::address, and HF::Protocol::BROADCAST_ADDR.
uint8_t Base::bind | ( | uint16_t | dev_addr_1, |
uint16_t | dev_addr_2 | ||
) |
Create a new bind entry.
[in] | dev_addr_1 | HAN-FUN address of the first device. |
[in] | dev_addr_2 | HAN-FUN address of the second device. |
0 | Bind created. |
1 | Bind already created. |
2 | First device does not exist. |
3 | Second device does not exist. |
Definition at line 629 of file base.cpp.
References HF::Common::OK, HF::Interface::ON_OFF, and HF::Interface::SERVER_ROLE.
COMMAND | ( | Register | , |
"r" | , | ||
"r 1 x:register device x.\ 0:exit registration mode." | |||
) |
Setup registration command.
< Disable Registration
< Enable Registration
Definition at line 116 of file base_app.cpp.
References LOG.
bool DeviceManagement::Server::deregister | ( | uint16_t | address | ) |
De-register the device with the given address
.
[in] | address | address for the device to de-register. |
<tt>true</tt> | if the device was de-registered; |
<tt>false</tt> | otherwise. |
Definition at line 136 of file base.cpp.
References HF::Protocol::BROADCAST_ADDR, and HF::Core::DeviceManagement::AbstractServer::deregister().
void from_json | ( | Json::Value & | node, |
HF::UID::UID *& | uid | ||
) |
Create a new HF::UID::UID based on the fields present in the given Json::Value
object.
[in] | node | reference to the Json::Value containing the fields for the HF::UID::UID. |
[out] | uid | reference to the pointer that will hold the created HF::UID::UID object of the correct type (NONE/RFPI/IPUI/MAC/URI). |
void from_json | ( | Json::Value & | node, |
HF::Common::Interface & | interface | ||
) |
Fill a HF::Common::Interface from the given Json::Value
object.
[in] | node | reference to the Json::Value containing the fields for the HF::Common::Interface. |
[out] | interface | reference to the HF::Common::Interface to update. |
Definition at line 845 of file base.cpp.
void from_json | ( | Json::Value & | node, |
HF::Core::DeviceManagement::Unit & | unit | ||
) |
Fill a HF::Core::DeviceManagement::Unit from the given Json::Value
object.
[in] | node | reference to the Json::Value containing the fields for the HF::Core::DeviceManagement::Unit. |
[out] | unit | reference to the HF::Core::DeviceManagement::Unit to update. |
Definition at line 914 of file base.cpp.
void from_json | ( | Json::Value & | node, |
HF::Core::DeviceManagement::Device & | device | ||
) |
Fill a HF::Core::DeviceManagement::Device from the given Json::Value
object.
[in] | node | reference to the Json::Value containing the fields for the HF::Core::DeviceManagement::Device. |
[out] | device | reference to the HF::Core::DeviceManagement::Device to update. |
Definition at line 934 of file base.cpp.
void from_json | ( | Json::Value & | node, |
HF::Protocol::Address & | address | ||
) |
Fill a HF::Protocol::Address from the given Json::Value
object.
[in] | node | reference to the Json::Value containing the fields for the HF::Protocol::Address. |
[out] | address | reference to the HF::Protocol::Address to update. |
void from_json | ( | Json::Value & | node, |
HF::Core::BindManagement::Entry & | entry | ||
) |
Fill a HF::Core::BindManagement::Entry from the given Json::Value
object.
[in] | node | reference to the Json::Value containing the fields for the HF::Core::BindManagement::Entry. |
[out] | entry | reference to the HF::Core::BindManagement::Entry to update. |
Definition at line 970 of file base.cpp.
bool Base::has_bind | ( | uint16_t | dev_addr_1, |
uint16_t | dev_addr_2 | ||
) |
Check if bind exists.
[in] | dev_addr_1 | HAN-FUN address of the first device. |
[in] | dev_addr_2 | HAN-FUN address of the second device. |
true | if the binding exist; |
false | otherwise. |
Definition at line 613 of file base.cpp.
References HF::Interface::ON_OFF, and HF::Interface::SERVER_ROLE.
void HF::Application::Initialize | ( | HF::Transport::Layer & | transport | ) |
Initialize the application.
[in] | transport | reference to the transport layer to use. |
Definition at line 441 of file base_app.cpp.
|
virtual |
Initialize the associated transport layer.
This method should initialize the transport layer using it's default values.
Reimplemented from HF::Transport::AbstractLayer.
Definition at line 474 of file transport.cpp.
References LOG, and HF::Application::Transport::socket.
void Entries::insert | ( | const Device & | device | ) |
void Entries::insert | ( | Entry & | entry | ) |
|
protectedvirtual |
Return next available address for registering a device.
Reimplemented from HF::Core::DeviceManagement::IServer.
Definition at line 115 of file base.cpp.
References HF::Protocol::BROADCAST_ADDR, and HF::Core::DeviceManagement::IServer::next_address().
|
virtual |
Callback that is called when a OFF_CMD
message is received.
[in] | source | device address that sent the command. |
Reimplemented from HF::Interfaces::OnOff::Server.
Definition at line 66 of file node.cpp.
References LOG, and SimpleLight::off().
Referenced by SimpleLight::off().
|
virtual |
Callback that is called when a ON_CMD
message is received.
[in] | source | device address that sent the command. |
Reimplemented from HF::Interfaces::OnOff::Server.
Definition at line 60 of file node.cpp.
References LOG, and SimpleLight::on().
Referenced by SimpleLight::on().
void print_error | ( | uv_err_t | status | ) |
Print a user friendly string for given status
code.
[in] | status | status code to print. |
Definition at line 227 of file transport.cpp.
References LOG.
|
virtual |
Callback to deliver a packet received from the transport layer.
[in] | packet | reference to the received packet. |
[in] | payload | reference a ByteArray containing the received data. |
[in] | offset | offset from where the received data starts on the payload byte array buffer. |
Reimplemented from HF::Devices::Node::Abstract< CoreServices >.
Definition at line 45 of file node.cpp.
References LOG, and Node::receive().
Referenced by Node::receive().
|
virtual |
Callback to deliver a packet received from the transport layer.
[in] | packet | reference to the received packet. |
[in] | payload | reference a ByteArray containing the received data. |
[in] | offset | offset from where the received data starts on the payload byte array buffer. |
Reimplemented from HF::Devices::Concentrator::AbstractBase.
Definition at line 595 of file base.cpp.
References LOG.
void DeviceManagement::Server::restore | ( | Json::Value | root | ) |
Restore the device entries from the JSON database.
[in] | root | database root to start reading the entries. |
Definition at line 184 of file base.cpp.
References LOG.
void BindManagement::Server::restore | ( | Json::Value | root | ) |
Restore the bind entries from the JSON database.
[in] | root | database root to start reading the entries. |
Definition at line 273 of file base.cpp.
References LOG.
void DeviceManagement::Server::save | ( | Json::Value & | root | ) |
Save the device entries into the JSON database.
[in] | root | database root to start saving the entries. |
Definition at line 161 of file base.cpp.
References LOG.
void BindManagement::Server::save | ( | Json::Value & | root | ) |
Save the bind entries into the JSON database.
[in] | root | database root to start saving the entries. |
Definition at line 250 of file base.cpp.
References LOG.
|
virtual |
Send the data in the given ByteArray
using the link to the remote end-point.
[in] | array | reference to the ByteArray containing the data to send. |
Implements HF::Transport::Link.
Definition at line 588 of file transport.cpp.
References LOG.
void to_json | ( | HF::UID::UID * | uid, |
Json::Value & | node | ||
) |
Serialize a HF::UID::UID pointer to the given Json::Value.
[in] | uid | pointer to the HF::UID::UID to serialize to JSON. |
[out] | node | reference to the Json::Value to place the serialization result in. |
void to_json | ( | const HF::Common::Interface & | interface, |
Json::Value & | node | ||
) |
Serialize a HF::Common::Interface to the given Json::Value.
[in] | interface | reference to the HF::Common::Interface to serialize to JSON. |
[out] | node | reference to the Json::Value to place the serialization result in. |
Definition at line 702 of file base.cpp.
void to_json | ( | const HF::Core::DeviceManagement::Unit & | unit, |
Json::Value & | node | ||
) |
Serialize a HF::Core::DeviceManagement::Unit to the given Json::Value.
[in] | unit | reference to the HF::Core::DeviceManagement::Unit to serialize to JSON. |
[out] | node | reference to the Json::Value to place the serialization result in. |
Definition at line 777 of file base.cpp.
void to_json | ( | const HF::Core::DeviceManagement::Device & | device, |
Json::Value & | node | ||
) |
Serialize a HF::Core::DeviceManagement::Device to the given Json::Value.
[in] | device | reference to the HF::Core::DeviceManagement::Device to serialize to JSON. |
[out] | node | reference to the Json::Value to place the serialization result in. |
Definition at line 796 of file base.cpp.
void to_json | ( | const HF::Protocol::Address & | address, |
Json::Value & | node | ||
) |
Serialize a HF::Protocol::Address to the given Json::Value.
[in] | address | reference to the HF::Protocol::Address to serialize to JSON. |
[out] | node | reference to the Json::Value to place the serialization result in. |
Definition at line 817 of file base.cpp.
void to_json | ( | const HF::Core::BindManagement::Entry & | entry, |
Json::Value & | node | ||
) |
Serialize a HF::Core::BindManagement::Entry to the given Json::Value.
[in] | entry | reference to the HF::Core::BindManagement::Entry to serialize to JSON. |
[out] | node | reference to the Json::Value to place the serialization result in. |
Definition at line 831 of file base.cpp.
|
virtual |
Callback that is called when a TOGGLE_CMD
message is received.
[in] | source | device address that sent the command. |
Reimplemented from HF::Interfaces::OnOff::Server.
Definition at line 72 of file node.cpp.
References LOG, and SimpleLight::toggle().
Referenced by SimpleLight::toggle().
bool Base::unbind | ( | uint16_t | dev_addr_1, |
uint16_t | dev_addr_2 | ||
) |
Remove the binding entry for the given devices.
If the bind does not exist, nothing changes.
[in] | dev_addr_1 | HAN-FUN address of the first device. |
[in] | dev_addr_2 | HAN-FUN address of the second device. |
true | if the bind entry was found and removed, |
false | otherwise. |
Definition at line 667 of file base.cpp.
References HF::Common::OK, HF::Interface::ON_OFF, and HF::Interface::SERVER_ROLE.