Library to easily communicate with XBee modules.
Dependencies: DigiLogger
Dependents: WaterLogger XbeeGateway XBee_Cooker ProjetReceiver ... more
You are viewing an older revision! See the latest version
Debugging the library
There are two mechanisms available to help debugging 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
Initialization¶
In your application, create and configure a DigiLoggerMbedSerial object before you instantiate the XBee class. DigiLoggerMbedSerial object has following arguments:
- It's required to pass the Serial object where to send the 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 some conditions success. 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.