Library to easily communicate with XBee modules.

Dependencies:   DigiLogger

Dependents:   WaterLogger XbeeGateway XBee_Cooker ProjetReceiver ... more

Frame Receive Process

Frame Buffer Size

Frames arriving the XBee device are stored in an internal circular Frame Buffer. The size of that Frame Buffer is configured through following define in config.h file:

#define FRAME_BUFFER_SIZE   4

If more frames than the configured arrive to the device without being delivered to the user, older frames will be dropped (overwritten by newer). The library keeps track of the number of dropped frames and returns its value when process_rx_frames() function is called.
See process_rx_frames() method below for more info.

Frame Payload Length

The payload length of the received frames is also limited. It is configured through following define in config.h file:

#define MAX_FRAME_PAYLOAD_LEN 128

If a frame bigger than the configured arrive to the device, the frame will be dropped. Following message will be displayed if logging is enabled to LogLevelWarning:

Warning

Frame dropped, frame too long. Increase MAX_FRAME_PAYLOAD_LEN define

User Function Callbacks

User has to register function callbacks to process desired frame types. See Receiving Data from other module, Discovering nodes in the network...

process_rx_frames() method

The process_rx_frames() method has to be called periodically by the user so the XBee library delivers the frames inside the internal FrameBuffer to the corresponding registered callbacks.
So make sure you call this method periodically:

#include "XBeeLib.h"
  
using namespace XBeeLib;
 
void main()
{
    ...
    while (true) {
        xbee.process_rx_frames();
        wait_ms(100);
        printf(".");
    }
    ...
}

Frames in the internal Frame Buffer of a type that has not a corresponding function callback are discarded when process_rx_frames() method is called.

The process_rx_frames() method return the number of frames that have been dropped (overwritten by newer) since the latest call to this method. Evaluating this method return value can help the user to detect under-runs and decide to increase the FRAME_BUFFER_SIZE define or to call process_rx_frames() method more often:

#include "XBeeLib.h"
  
using namespace XBeeLib;
 
void main()
{
    ...
    while (true) {
        const uint32_t dropped_frames = xbee.process_rx_frames();
        if (dropped_frames != 0)
        {
            log_serial->printf("There have been %d dropped frames since latest process_rx_frames() call.\r\n", dropped_frames);
            log_serial->printf("Increase FRAME_BUFFER_SIZE define or call process_rx_frames() more frequently\r\n");
        }
        wait_ms(100);
 
    }
    ...
}

You will also see following warning if LogLevelWarning or higher is selected if frames are dropped:

process_rx_frames: x frames dropped!!!

All wikipages