33 struct SimpleSwitch:
public HF::Units::Unit<HF::Profiles::SimpleOnOffSwitch>
36 HF::Units::
Unit<
HF::Profiles::SimpleOnOffSwitch>(id, device)
43 struct SimpleSwitchable:
public HF::Units::Unit<HF::Profiles::SimpleOnOffSwitchable>
47 SimpleSwitchable(uint8_t
id,
HF::IDevice &device): _Parent(id, device)
53 LOG(INFO) <<
"Command ON received ..." <<
NL;
59 LOG(INFO) <<
"Command OFF received ..." <<
NL;
64 _Parent::toggle(source);
65 LOG(INFO) <<
"Command TOGGLE received ..." <<
NL;
87 int main(
int argc,
char **argv)
92 LOG(INFO) <<
"Use case : On-Off interface usage" <<
NL;
99 LOG(INFO) <<
"Create the node instances ..." <<
NL;
103 LOG(INFO) <<
"Add unit to node1 instance ..." <<
NL;
104 SimpleSwitch simple_switch(1, node1);
108 LOG(INFO) <<
"Add unit to node2 instance ..." <<
NL;
109 SimpleSwitchable simple_switchable(1, node2);
114 LOG(INFO) <<
"Create the base instance ..." <<
NL;
117 LOG(INFO) <<
"Create transport instance" <<
NL;
126 LOG(INFO) <<
"Network setup ..." <<
NL;
128 loop.set_base(&base);
129 loop.add_node(&node1,
"node_1");
130 loop.add_node(&node2,
"node_2");
137 LOG(INFO) <<
"Registering node1 ... " <<
NL;
138 node1.unit0()->device_management()->register_device();
139 LOG(INFO) <<
"Node1 address ... " << node1.address() <<
NL;
142 assert(node1.address() == 1);
147 LOG(INFO) <<
"Registering node2 ... " <<
NL;
148 node2.unit0()->device_management()->register_device();
149 LOG(INFO) <<
"Node2 address ... " << node2.address() <<
NL;
152 assert(node2.address() == 2);
154 LOG(INFO) <<
"There should be two registered devices ... " 155 << base.
unit0()->device_management()->entries().size() <<
NL;
157 assert(base.
unit0()->device_management()->entries().size() == 2);
163 LOG(INFO) <<
"Send commands to a specific device/unit ..." <<
NL;
168 LOG(INFO) <<
"Send a ON command ..." <<
NL;
169 simple_switch.on(addr);
170 LOG(INFO) <<
"Switchable state should be ON : " << simple_switchable.state() <<
NL;
171 assert(simple_switchable.state() ==
true);
174 LOG(INFO) <<
"Send a OFF command ..." <<
NL;
175 simple_switch.off(addr);
176 LOG(INFO) <<
"Switchable state should be OFF : " << simple_switchable.state() <<
NL;
177 assert(simple_switchable.state() ==
false);
180 LOG(INFO) <<
"Send a TOGGLE command ... " <<
NL;
181 simple_switch.toggle(addr);
182 LOG(INFO) <<
"Switchable state should be ON : " << simple_switchable.state() <<
NL;
183 assert(simple_switchable.state() ==
true);
185 LOG(INFO) <<
"Send a second TOGGLE command ... " <<
NL;
186 simple_switch.toggle(addr);
187 LOG(INFO) <<
"Switchable state should be OFF : " << simple_switchable.state() <<
NL;
188 assert(simple_switchable.state() ==
false);
194 LOG(INFO) <<
"Send commands to the broadcast device/unit ..." <<
NL;
197 LOG(INFO) <<
"Create bind entry on the base ... " <<
NL;
202 base.
unit0()->bind_management()->add(source, destination, itf);
203 LOG(INFO) <<
"There should be one bind entry ... " 204 << base.
unit0()->bind_management()->entries().size() <<
NL;
205 assert(base.
unit0()->bind_management()->entries().size() == 1);
208 LOG(INFO) <<
"Send a ON command ..." <<
NL;
210 LOG(INFO) <<
"Switchable state should be ON : " << simple_switchable.state() <<
NL;
211 assert(simple_switchable.state() ==
true);
214 LOG(INFO) <<
"Send a OFF command ..." <<
NL;
216 LOG(INFO) <<
"Switchable state should be OFF : " << simple_switchable.state() <<
NL;
217 assert(simple_switchable.state() ==
false);
220 LOG(INFO) <<
"Send a TOGGLE command ... " <<
NL;
221 simple_switch.toggle();
222 LOG(INFO) <<
"Switchable state should be ON : " << simple_switchable.state() <<
NL;
223 assert(simple_switchable.state() ==
true);
225 LOG(INFO) <<
"Send a second TOGGLE command ... " <<
NL;
226 simple_switch.toggle();
227 LOG(INFO) <<
"Switchable state should be OFF : " << simple_switchable.state() <<
NL;
228 assert(simple_switchable.state() ==
false);
This class represents a HAN-FUN Concentrator.
This is the top level include file for the HAN-FUN library.
This file contains the prototypes of the debug functionality in HAN-FUN.
constexpr uint16_t BROADCAST_ADDR
HAN-FUN Broadcast - device address.
SimpleSwitch(uint8_t index, HF::IDevice &device)
Constructor.
Helper template class to implement units.
This class represents the interface common to all HAN-FUN devices.
Template for HAN-FUN concentrator devices.
#define NL
Helper define for new-line and stream clear.
CoreServices * unit0() const
Get the unit 0 used by this concentrator device.
Unit(uint8_t id, IDevice &device)
Constructor.
This file contains an implementation of a HAN-FUN transport layer to be used in the example applicati...
#define UNUSED(x)
Helper macro to remove warning about unused function/method argument.
#define LOG(X)
Log messages with the level given by X.
Template for declaring HAN-FUN node devices.
Top-level namespace for the HAN-FUN library.