HAN-FUN API  1.5.3
This project provides the common implementation of ULE Alliance's HAN-FUN application protocol.
example_01.cpp
Go to the documentation of this file.
1 // =============================================================================
15 // =============================================================================
16 
17 #include "hanfun.h"
18 #include "hanfun/debug.h"
19 
20 #include "localloop.h"
21 
22 // =============================================================================
23 // Implementation
24 // =============================================================================
25 
26 namespace
27 {
28  /*
29  * Example node.
30  */
31  struct Node: public HF::Devices::Node::Node
32  {};
33 
34  /*
35  * Example concentrator.
36  */
38  {};
39 
40 } // namespace
41 
42 // =============================================================================
43 // MAIN
44 // =============================================================================
45 
46 int main(int argc, char **argv)
47 {
48  UNUSED(argc);
49  UNUSED(argv);
50 
51  LOG(INFO) << "Use case : Basic registration" << NL;
52 
53  /*
54  * Each node variable is a remote device, i.e.,
55  * the Node variables are declared on the remote device
56  * code and are not used on the base code.
57  */
58  LOG(INFO) << "Create the node instances ..." << NL;
59 
60  Node node1;
61  Node node2;
62 
63  /*
64  * This instance represents the base application.
65  */
66  LOG(INFO) << "Create the base instance ..." << NL;
67  Base base;
68 
69  LOG(INFO) << "Create transport instance" << NL;
70  Localloop loop;
71 
72  /*
73  * Setup the network.
74  *
75  * This simulates the devices connecting to the base using for
76  * example a TCP/IP connection or a DECT ULE PVC.
77  */
78  LOG(INFO) << "Network setup ..." << NL;
79 
80  loop.set_base(&base);
81  loop.add_node(&node1, "node_1");
82  loop.add_node(&node2, "node_2");
83 
84  // Register two devices.
85 
86  // Node 1 is unregistered.
87  assert(node1.address() == HF::Protocol::BROADCAST_ADDR);
88 
89  LOG(INFO) << "Registering node1 ... " << NL;
90  node1.unit0()->device_management()->register_device();
91  LOG(INFO) << "Node1 address ... " << node1.address() << NL;
92 
93  // Node 1 is registered
94  assert(node1.address() == 1);
95 
96  // Node 2 is unregistered.
97  assert(node2.address() == HF::Protocol::BROADCAST_ADDR);
98 
99  LOG(INFO) << "Registering node2 ... " << NL;
100  node2.unit0()->device_management()->register_device();
101  LOG(INFO) << "Node2 address ... " << node2.address() << NL;
102 
103  // Node 2 is registered
104  assert(node2.address() == 2);
105 
106  LOG(INFO) << "There should be two registered devices ... "
107  << base.unit0()->device_management()->entries().size() << NL;
108 
109  assert(base.unit0()->device_management()->entries().size() == 2);
110 
111  return 0;
112 }
This class represents a HAN-FUN Concentrator.
Definition: base.h:302
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.
Definition: protocol.h:45
Template for HAN-FUN concentrator devices.
Definition: devices.h:906
#define NL
Helper define for new-line and stream clear.
Definition: debug.h:34
CoreServices * unit0() const
Get the unit 0 used by this concentrator device.
Definition: devices.h:910
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.
Definition: debug.h:81
Template for declaring HAN-FUN node devices.
Definition: devices.h:425