Docs

You are here:
Network map

Many times it is required to know what nodes are in the network - not only in the nearest neighborhood but in the entire reachable network. To provide this information RCM radio modules periodically send to the coordinator a list of all nearest neighbors that they know about. This mechanism is called neighbor indication.

It is possible to control the neighborhood indication interval as well as to disable it completely. The rcm::Connection::setNeighborhoodIndicationInterval method serves this purpose. The complementary method rcm::Connection::getNeighborhoodIndicationInterval allows to retrieve the currently set value of indication interval.

Once the neighborhood interval was configured, the node starts to send neighborhood indication messages to the coordinator. Based on this information, the coordinator maintains a complete network map. This map is available through a call to rcm::Connection::getNetworkMapSnapshot method, which produces a snapshot of the current network state and provides it by returning a reference to the internally managed rcm::NetworkMap object.

The rcm::NetworkMap object holds a list of rcm::NetworkNeighbor objects. Each rcm::NetworkNode object represents a single node in the network. The rcm::NetworkMap::getNodeCount returns the total number of nodes that the map is aware of. The rcm::NetworkMap::getNode allows to access a single node. In addition Each rcm::NetworkNode object holds a list of his neighbors, that can be accessed using rcm::NetworkNode::getNeighborCount and rcm::NetworkNode::getNeighbor.

The following example illustrates how to use the network map:

#include "rcmpp.h"
#include <iostream>
using namespace std;
int rcmpp_network_map_example(const char* portName)
{
int result = 0;
try {
// construct the connection object
rcm::Connection rcm(portName);
// set UID
rcm.setUID(0x0123456789abcdef);
// configure networking
rcm.configureNode(RCM_DEVICE_TYPE_COORDINATOR, 0x1122334455667788, RCM_ADDRESSING_SCHEME_STATIC, 0);
// start networking
if (rcm.startNetworking()) {
// delay
OS_Sleep(5000);
// get the network map
rcm::NetworkMap map = rcm.getNetworkMapSnapshot();
// print a list of nodes
cout << "List of nodes:" << endl;
for (int n = 0; n < map.getNodeCount(); n++) {
// get node under given index
node = map.getNode(n);
// print some information
cout << "node " << n << " shortAddr=0x" << hex << node->shortAddr << dec << endl;
}
// leave the network
rcm.stopNetworking();
}
}
catch(rcm::exception &e) {
result = 100;
}
catch(std::exception &e) {
result = 101;
}
catch (...) {
result = 102;
}
return result;
}
Go to Top