Docs

You are here:
Network operation

Joining and leaving the network

Once the RCM radio module is configured, what we want to do is to allow it to connect to a network, or establish a new network in case of a coordinator device. To do that we simply call RCM_StartNetworking function. The returned value will tell us, whether we have joined (or established) the network successfully or not.

Complementary, in order to disconnect from the network, we can call RCM_StopNetworking function.

We can always call the RCM_GetNetworkState function to determine the actual networking state.

Network neighbors

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. In order to make use of these messages, the user can register a callback function, that will be called whenever such message arrives. This is done through the RCM_SetNeighborhoodIndicationCallback function.

The remote nodes can be addressed using 64-bit unique ID (UID) or 16-bit short network address. Sometimes it is feasible to convert one address to another, which generally requires communication with the node using one address and asking it for the other, unless such information is already cached in the RCM stack. To perform such action two functions are provided: RCM_GetUIDFromNwkShort and RCM_GetNwkShortFromUID.

The following example illustrates how to establish the network:

#include "rcm.h"
// Structure holding information about the connection
static RCMConnection rcm;
// Declare a structure named frameBuffer, that will fit infinite SCOM packets
static SCOM_DECLARE_FRAME_BUFFER_USING_HEAP(frameBufferInHeap);
// Declare a structure named messageBufferInHeap that can fit unlimited number of RCM messages
static RCM_DECLARE_MESSAGE_BUFFER_USING_HEAP(messageBufferInHeap);
int rcm_networking_example(IODevice iodevice)
{
int result = 0;
OSTime startTime;
// get current time
startTime = OS_GetSystemTime();
// try to open the connection using specified IODevice
if (RCM_RESULT_OK == RCM_Open(&rcm, iodevice, &frameBufferInHeap, &messageBufferInHeap, OS_GetSystemTime)) {
// connection opened, run it
if (RCM_RESULT_OK == RCM_Run(&rcm)) {
// threads run successfully
// configure the RCM module
RCM_SetUID(&rcm, 0x0123456789abcdef);
if (RCM_RESULT_OK == RCM_StartNetworking(&rcm)) {
// network established successfully
while (0 == result) {
// ... do something with the RCM module (read on!)
// check connection
if (RCM_RESULT_OK != RCM_GetConnectionState(&rcm)) {
// connection broke down (hardware error?)
// exit with error code
result = 2;
}
// check timeout
if (OS_GetSystemTime() - startTime > 5000) {
// timeout
break;
}
}
}
// stop the RCM threads
RCM_Stop(&rcm);
} else {
// error
result = 2;
}
// finally close the connection
RCM_Close(&rcm);
} else {
// error
result = 1;
}
return result;
}
Go to Top