Library to easily communicate with XBee modules.

Dependencies:   DigiLogger

Dependents:   WaterLogger XbeeGateway XBee_Cooker ProjetReceiver ... more

Debugging the library

Table of Contents

  1. Logging
  2. Assertions

There are two mechanisms available to help with debugging in the XBee library:

  • Logging
  • Assertions

Logging

When logging is enabled, the XBee library will report information on the configured logging serial port (typically the USB connection with the PC).

Enabling

Enable logging in your code with following define in config.h:

/** Library configuration options */
#define ENABLE_LOGGING

Levels

The following logging levels are available:

LogLevelNone
LogLevelError
LogLevelWarning
LogLevelInfo
LogLevelDebug
LogLevelFrameData
LogLevelAll

Warning

LogLevelFrameData or higher produces a lot of logging information that can alter the library's behavior. Receive frame process will be delayed leading to possible frame drops. Use this level with care.
We recommend increasing the logging baud-rate to 115200bps to minimize impact.

Initialization

In your application, create and configure a DigiLoggerMbedSerial object before you instantiate the XBee class. DigiLoggerMbedSerial object has following arguments:

  • You must pass the Serial object the destination for logging information. It's responsibility of the user to create the serial object before creating a new DigiLoggerMbedSerial and also to delete it afterwards.
  • It's optional to provide the desired Loglevel. If LogLevel is specified, a default LogLevelInfo level is taken.

Example:

#include "mbed.h"
#include "XBeeLib.h"
#if defined(ENABLE_LOGGING)
#include "DigiLoggerMbedSerial.h"
using namespace DigiLog;
#endif
 
using namespace XBeeLib;
 
int main()
{
    /* Open and configure a new serial port on the USB connected to the PC */
    log_serial = new Serial(P0_2, P0_3);
    log_serial->baud(9600);
    log_serial->printf(XB_LIB_BANNER);
 
#if defined(ENABLE_LOGGING)
    /* Create a DigiLogger object, tell it to use the opened serial port and initially set LogLevel to LogLevelDebug */
    DigiLoggerMbedSerial *logger = new DigiLoggerMbedSerial(log_serial, LogLevelDebug); 
#endif
 
    XBeeZB xbee1 = XBeeZB(RADIO_TX, RADIO_RX);
    xbee1.init();

Configuration

You can change the logging level at any time through following method:

#if defined(ENABLE_LOGGING)
    /* Configure logging to the desired level */
    logger->set_level(LogLevelInfo);
#endif

Assertions

When assertions are enabled, the XBee library will check at run-time that certain conditions succeed. If the conditions don't pass, the library will log (if logging is enabled) the problem and call mbed_die() to stop execution. Enable assertions in your code with following define in config.h:

/** Library configuration options */
#define ENABLE_ASSERTIONS

Troubleshooting!

DigiRadio Library depends on DigiLogger Library when logging is enabled. Make sure DigiLogger library (Available here TODO) is included in your program.


All wikipages