32 #define TABLE_LOG(_X) LOG (INFO) << std::right << std::setw (15) << _X << std::left << NL 34 #define TABLE_STREAM(_X) stream << "[INFO ] " << std::right << std::setw (15) << _X << std::left 43 std::ostream &
operator<<(std::ostream &stream,
const Report::Attribute &attr)
45 stream <<
" (idx) " << attr->interface() <<
" (itf) " << (int) attr->uid() <<
" (uid)";
51 TABLE_STREAM(
"ITF : " << entry.
itf.
id <<
" (uid) " << entry.
itf.
role <<
" (role)") <<
NL;
52 TABLE_STREAM(
"Unit : " << (
int) entry.
unit) <<
NL;
54 TABLE_STREAM(
"Attributes : " << (
int) entry.attributes.size() <<
" (#)");
61 TABLE_STREAM(
"ITF : " << entry.
itf.
id <<
" (uid) " << entry.
itf.
role <<
" (role)") <<
NL;
62 TABLE_STREAM(
"Unit : " << (
int) entry.
unit) <<
NL;
64 TABLE_STREAM(
"Fields : " << (
int) entry.
fields.size() <<
" (#)");
71 stream <<
" (idx) " << field.
type <<
" (type) ";
77 stream << (int) report.
id <<
" (id) " << (
int) report.
type <<
" (type) ";
101 LOG(INFO) <<
"Received a periodic notification from device : " 108 TABLE_LOG(
"Report : " << report);
109 TABLE_LOG(
"Entries : " << std::distance(report.
entries.begin(),
110 report.
entries.end()) <<
" (#)");
112 uint8_t unit_count = 0;
117 TABLE_LOG (
"Entry : " << (
int) unit_count++ << std::endl << entry);
119 uint8_t attr_count = 0;
120 std::for_each (entry.attributes.begin (), entry.attributes.end (),
121 [&attr_count](Report::Attribute attr)
123 TABLE_LOG (
" Attribute : " << (
int) attr_count++ << attr);
130 int precent = HF::Common::to_percent <uint8_t>(level_attr->get ());
131 TABLE_LOG (
"Attr Value : " << precent <<
"%");
144 LOG(INFO) <<
"Received an event notification : " << address.
device <<
NL;
150 TABLE_LOG(
"Report : " << report);
151 TABLE_LOG(
"Entries : " << std::distance(report.
entries.begin(),
152 report.
entries.end()) <<
" (#)");
154 uint8_t unit_count = 0;
159 TABLE_LOG (
"Entry : " << (
int) unit_count++ << std::endl << entry);
161 uint8_t field_count = 0;
162 std::for_each (entry.
fields.begin (), entry.
fields.end (),
165 TABLE_LOG (
" Field : " << (
int) field_count++ << field);
166 TABLE_LOG (
" Attribute : " << field.attribute->interface () <<
" (itf) " 167 << (int) field.attribute->uid () <<
" (uid)");
174 int precent = HF::Common::to_percent <uint8_t>(level_attr->get ());
175 TABLE_LOG (
"Attr Value : " << precent <<
"%");
190 const HF::Core::AttributeReporting::Response &
response)
192 LOG(INFO) <<
"Report rule created on device : " << address.
device <<
NL;
199 const HF::Core::AttributeReporting::Response &
response)
201 LOG(INFO) <<
"Report rule entries created on device : " << address.
device <<
NL;
211 struct SimpleLevelControl:
public HF::Units::Unit<HF::Profiles::SimpleLevelControl,
214 SimpleLevelControl(uint8_t
id,
HF::IDevice &device):
215 HF::Units::Unit<
HF::Profiles::SimpleLevelControl, AttributeReporting>(id, device)
218 AttributeReporting *attribute_reporting()
const 220 return const_cast<AttributeReporting *
>(get<0>());
227 struct SimpleLevelControllable:
public HF::Units::Unit<HF::Profiles::SimpleLevelControllable>
231 SimpleLevelControllable(uint8_t
id,
HF::IDevice &device):
237 _Parent::level_change(source, old_level, new_level);
238 LOG(INFO) <<
"Level Change : " 264 int main(
int argc,
char **argv)
269 LOG(INFO) <<
"Use case : Level Control interface usage" <<
NL;
276 LOG(INFO) <<
"Create the node instances ..." <<
NL;
280 LOG(INFO) <<
"Add unit to node1 instance ..." <<
NL;
281 SimpleLevelControl level_control(1, node1);
285 LOG(INFO) <<
"Add unit to node2 instance ..." <<
NL;
286 SimpleLevelControllable level_controllable(1, node2);
291 LOG(INFO) <<
"Create the base instance ..." <<
NL;
294 LOG(INFO) <<
"Create transport instance" <<
NL;
303 LOG(INFO) <<
"Network setup ..." <<
NL;
305 loop.set_base(&base);
306 loop.add_node(&node1,
"node_1");
307 loop.add_node(&node2,
"node_2");
314 LOG(INFO) <<
"Registering node1 ... " <<
NL;
315 node1.
unit0()->device_management()->register_device();
316 LOG(INFO) <<
"Node1 address ... " << node1.
address() <<
NL;
324 LOG(INFO) <<
"Registering node2 ... " <<
NL;
325 node2.
unit0()->device_management()->register_device();
326 LOG(INFO) <<
"Node2 address ... " << node2.
address() <<
NL;
331 LOG(INFO) <<
"There should be two registered devices ... " 332 << base.unit0()->device_management()->entries().size() <<
NL;
334 assert(base.unit0()->device_management()->entries().size() == 2);
336 LOG(INFO) <<
"Set initial level value ... 15\%" <<
NL;
337 level_controllable.level(15.0f);
347 LOG(INFO) <<
"====== Periodic Notifications ======" <<
NL;
350 level_control.attribute_reporting()->create(addr, 6);
353 level_control.attribute_reporting()->create(addr, 15);
356 std::vector<Periodic::Entry> periodic_entries(1);
358 auto &entry = periodic_entries.front();
369 level_control.attribute_reporting()->add(addr, report_ref, periodic_entries.begin(),
370 periodic_entries.end());
375 level_control.attribute_reporting()->add(addr, report_ref, periodic_entries.begin(),
376 periodic_entries.end());
379 LOG(INFO) <<
">>> Simulate node periodic processing <<<" <<
NL;
381 for (
int time = 0; time < 35; time++)
383 LOG(INFO) <<
"Time : " << time <<
"s" <<
NL;
390 LOG(INFO) <<
"Level changes to 25 % by an another node." <<
NL;
392 level_control.level(addr, 25.0f);
397 LOG(INFO) <<
"Level changes to 55 % on the actual node." <<
NL;
398 level_controllable.level(55.0f);
406 LOG(INFO) <<
"====== Event Notifications ======" <<
NL;
408 LOG(INFO) <<
"Set initial level value ... 15\%" <<
NL;
409 level_controllable.level(15.0f);
412 level_control.attribute_reporting()->create(addr);
415 level_control.attribute_reporting()->create(addr);
418 std::vector<Event::Entry> event_entries;
430 field.value = {HF::Common::from_percent<uint8_t>(5.0f)};
432 evt_entry.
fields.push_back(field);
436 field.value = {HF::Common::from_percent<uint8_t>(60.0f)};
438 evt_entry.
fields.push_back(field);
442 field.value = {HF::Common::from_percent<uint8_t>(85.0f)};
444 evt_entry.
fields.push_back(field);
448 event_entries.push_back(evt_entry);
451 level_control.attribute_reporting()->add(addr, evt_report_ref, event_entries.begin(),
452 event_entries.end());
455 event_entries.clear();
460 field.value = {HF::Common::from_percent<uint8_t>(10.0f)};
462 evt_entry.
fields.push_back(field);
465 field.value = {HF::Common::from_percent<uint8_t>(40.0f)};
467 evt_entry.
fields.push_back(field);
471 field.value = {HF::Common::from_percent<uint8_t>(75.0f)};
473 evt_entry.
fields.push_back(field);
475 event_entries.push_back(evt_entry);
478 evt_report_ref.id = 2;
479 level_control.attribute_reporting()->add(addr, evt_report_ref, event_entries.begin(),
480 event_entries.end());
482 LOG(INFO) <<
">>> Simulate node level change <<<" <<
NL;
486 LOG(INFO) <<
"== Change level to 30 % ..." <<
NL;
487 level_control.level(addr, 30.0f);
489 LOG(INFO) <<
"== Change level to 40 % ..." <<
NL;
490 level_control.level(addr, 40.0f);
492 LOG(INFO) <<
"== Change level to 50 % ..." <<
NL;
493 level_control.level(addr, 50.0f);
495 LOG(INFO) <<
"== Change level to 60 % ..." <<
NL;
496 level_control.level(addr, 60.0f);
498 LOG(INFO) <<
"== Change level to 70 % ..." <<
NL;
499 level_control.level(addr, 40.0f);
501 LOG(INFO) <<
"== Change level to 80 % ..." <<
NL;
502 level_control.level(addr, 80.0f);
504 LOG(INFO) <<
"== Change level to 90 % ..." <<
NL;
505 level_control.level(addr, 90.0f);
507 LOG(INFO) <<
"== Change level to 20% ..." <<
NL;
508 level_control.level(addr, 20.0f);
510 LOG(INFO) <<
"== Change level to 15% ..." <<
NL;
511 level_control.level(addr, 15.0f);
513 LOG(INFO) <<
"== Change level to 10% ..." <<
NL;
514 level_control.level(addr, 10.0f);
516 LOG(INFO) <<
"== Change level to 7% ..." <<
NL;
517 level_control.level(addr, 7.0f);
519 LOG(INFO) <<
"== Change level to 5% ..." <<
NL;
520 level_control.level(addr, 5.0f);
522 LOG(INFO) <<
"== Change level to 1% ..." <<
NL;
523 level_control.level(addr, 1.0f);
uint16_t unpack(HF::Attributes::FactoryGetter get_factory, const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
Event notification entry.
Type
Types of reports send from the server to the client.
This namespace contains the classes that implement the Attribute Reporting service.
bool response(Message::Type type)
Check if message is a response.
This is the top level include file for the HAN-FUN library.
This file contains the prototypes of the debug functionality in HAN-FUN.
std::ostream & operator<<(std::ostream &stream, const uint8_t byte)
Convert the given byte into a string and write it to the given stream.
uint8_t pack_id
Attribute's Pack ID.
Return all mandatory attributes for the interface.
This class represents a node in the HAN-FUN network.
Helper class to handle the Level attribute for the Level Control interface.
Helper class for using the Attribute Reporting service.
Periodic notification entry.
Factory get_factory(Common::Interface itf)
Return the attribute factory associated with the given interface identifier.
constexpr uint16_t BROADCAST_ADDR
HAN-FUN Broadcast - device address.
uint16_t id
Identifier of the interface.
uint16_t unpack(HF::Attributes::FactoryGetter get_factory, const Common::ByteArray &array, uint16_t offset=0)
Read a message from a ByteArray.
High Threshold reached event.
Periodic report notification.
uint8_t unit
Unit ID this entry to.
Helper template class to implement units.
uint16_t address() const _override
Return the device address on the HAN-FUN network, when the device is registered, or HF_BROADCAST_ADDR...
This class represents the interface common to all HAN-FUN devices.
Return the attributes with the given attributes.
P to_percent(T value)
Convert a value in the [0,std::numeric_limits<T>::max()] range into a percentage. ...
Entry field for a given attribute.
Field for the entries in event notification.
std::vector< Field > fields
Vector containing the fields for the event entry.
void periodic(uint32_t time)
Handle periodic processing.
Common::Interface itf
Interface UID this notification relates to.
uint16_t role
Interface role : Server or Client.
Parent call for all reports.
Template for HAN-FUN concentrator devices.
This class represents a byte array.
#define NL
Helper define for new-line and stream clear.
std::vector< Field > fields
Vector containing the fields for this entry.
Level Control interface UID.
Common::SimpleList< Entry > entries
Entries for the event notification.
uint8_t type
Report type : PERIODIC or EVENT.
Common::Interface itf
Interface UID.
uint8_t unit
Unit id that originated this notification.
This file contains an implementation of a HAN-FUN transport layer to be used in the example applicati...
uint16_t device
Device Address.
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.
CoreServices * unit0() const _override
Return pointer to the unit 0 for this device.
Common::SimpleList< Entry > entries
Entries associated with this notification.
Low Threshold reached event.
#define LOG(X)
Log messages with the level given by X.
AttributeReporting::Event::Type type
Event type.
Template for declaring HAN-FUN node devices.
Top-level namespace for the HAN-FUN library.