API for communicating with XBee devices.

Dependencies:   CircularBuffer FixedLengthList

Dependents:   XBeeApiTest XBeeApiSimpleATCmdsExample XBeeApiBroadcastExample XBeeApiBroadcastExampleRTOS ... more

Overview

XBeeApi is intended to be a library for providing a high-level API interface to the XBee - for example getChannel() and setChannel(2) methods rather than needing to send( "ATCH" ) and send( "ATCH 2" ) - and then de-code the responses.

See the notebook page here for a description of how the API works & some details on the various classes.

Features:

  • Support for transmission & reception of data packets
  • Support for reading & changing settings
  • Support for "Remote AT" interface to access settings & I/O channels on remote XBees
  • XBeeApi should work if you're using mbed-rtos, though it is not currently threadsafe. Take a look at the XBeeApiBroadcastExampleRTOS example if you're including mbed-rtos.

Example Programs

There are also example programs available:

Transmit

Import programXBeeApiSimpleBroadcastExample

Simple example of how to use XBeeApi - set up the XBee, configure P2P networking then transmit a frame.

Import programXBeeApiBroadcastExample

Example for XBeeAPI; a little more involved than XBeeApiSimpleBroadcastExample with report on failure to set up the XBee and on the transmit status of the message.

Import programXBeeApiBroadcastExampleRTOS

Example of using the XBeeApi library to broadcast a message, based on XBeeApiBroadcastExample. This example shows how to use the library when using mbed-rtos. Before compiling you must open "XbeeApi\Config\XBeeApiCfg.hpp" and change the '#if 0' to '#if 1' on the line above the comment reading "Use RTOS features to make XBeeApi threadsafe"

Settings/Status

Import programXBeeApiSimpleATCmdsExample

Simple example of using XBeeApi to send AT-style commands to the XBee

Import programXBeeApiRemoteATCmdsExample

Example of using the XBeeApi library to send AT commands to remote XBee devices in order to read/write settings

Receive

Import programXBeeApiSimpleReceiveExample

Simple example of using XBeeApi to receive data packets via wireless

Import programXBeeApiReceiveCallbackExample

Example of using the XBeeApi library to receive a message via a callback method

Import programXBeeApiReceiveCallbackExampleRTOS

Example of using the XBeeApi library to receive a message via a callback method. This example shows how to use the library when using mbed-rtos. See the comment at the top of main.cpp

Remote I/O

Import programXBeeApiRemoteIOExample

Example of using the XBeeApi library to read inputs on a remote XBee

If you have 2 mbed connected XBees available then you can use XBeeApiSimpleReceiveExample and XBeeApiSimpleBroadcastExample as a pair.

Note that this is still a work in progress! XBeeApiTodoList tracks some of the functionality still to be added.

Committer:
johnb
Date:
Mon Jul 28 10:24:16 2014 +0000
Revision:
51:a7d0d2ef9261
Child:
56:7fe74b03e6b1
Additional infrastructure for AT & remote AT commands.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnb 51:a7d0d2ef9261 1 /**
johnb 51:a7d0d2ef9261 2 @file
johnb 51:a7d0d2ef9261 3 @brief Class to abstract AT commands send to the XBee API
johnb 51:a7d0d2ef9261 4 using a blocking API.
johnb 51:a7d0d2ef9261 5
johnb 51:a7d0d2ef9261 6 @author John Bailey
johnb 51:a7d0d2ef9261 7
johnb 51:a7d0d2ef9261 8 @copyright Copyright 2014 John Bailey
johnb 51:a7d0d2ef9261 9
johnb 51:a7d0d2ef9261 10 @section LICENSE
johnb 51:a7d0d2ef9261 11
johnb 51:a7d0d2ef9261 12 Licensed under the Apache License, Version 2.0 (the "License");
johnb 51:a7d0d2ef9261 13 you may not use this file except in compliance with the License.
johnb 51:a7d0d2ef9261 14 You may obtain a copy of the License at
johnb 51:a7d0d2ef9261 15
johnb 51:a7d0d2ef9261 16 http://www.apache.org/licenses/LICENSE-2.0
johnb 51:a7d0d2ef9261 17
johnb 51:a7d0d2ef9261 18 Unless required by applicable law or agreed to in writing, software
johnb 51:a7d0d2ef9261 19 distributed under the License is distributed on an "AS IS" BASIS,
johnb 51:a7d0d2ef9261 20 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
johnb 51:a7d0d2ef9261 21 See the License for the specific language governing permissions and
johnb 51:a7d0d2ef9261 22 limitations under the License.
johnb 51:a7d0d2ef9261 23
johnb 51:a7d0d2ef9261 24 */
johnb 51:a7d0d2ef9261 25
johnb 51:a7d0d2ef9261 26 #if !defined XBEEAPICMDATBLOCKING_HPP
johnb 51:a7d0d2ef9261 27 #define XBEEAPICMDATBLOCKING_HPP
johnb 51:a7d0d2ef9261 28
johnb 51:a7d0d2ef9261 29 #include "XBeeApiCmdAt.hpp"
johnb 51:a7d0d2ef9261 30
johnb 51:a7d0d2ef9261 31 #include <stdint.h>
johnb 51:a7d0d2ef9261 32
johnb 51:a7d0d2ef9261 33 /** Class to access the configuration interface of the XBee.
johnb 51:a7d0d2ef9261 34 In contrast to XBeeApiCmdAt, the getXXX methods block
johnb 51:a7d0d2ef9261 35 until the data is received (or a timeout has occurred)
johnb 51:a7d0d2ef9261 36 which means that the caller doesn't have to deal with the
johnb 51:a7d0d2ef9261 37 asynchronous nature of the API provided by XBeeApiCmdAt.
johnb 51:a7d0d2ef9261 38
johnb 51:a7d0d2ef9261 39 It's not necessary to use any of the requestXXX methods
johnb 51:a7d0d2ef9261 40 (as the getXXX methods will take care of this, however
johnb 51:a7d0d2ef9261 41 calling a requestXXX method will effectively pre-fetch the
johnb 51:a7d0d2ef9261 42 data meaning that getXXX will not have to block */
johnb 51:a7d0d2ef9261 43 class XBeeApiCmdAtBlocking : public XBeeApiCmdAt
johnb 51:a7d0d2ef9261 44 {
johnb 51:a7d0d2ef9261 45 protected:
johnb 51:a7d0d2ef9261 46 /** Timeout used for blocking methods in milliseconds */
johnb 51:a7d0d2ef9261 47 uint16_t m_timeout;
johnb 51:a7d0d2ef9261 48
johnb 51:a7d0d2ef9261 49 /** Wait slice time while blocking. The function will
johnb 51:a7d0d2ef9261 50 wait_ms(m_slice) until the XBee responds with the
johnb 51:a7d0d2ef9261 51 data or m_timeout elapses */
johnb 51:a7d0d2ef9261 52 uint16_t m_slice;
johnb 51:a7d0d2ef9261 53
johnb 51:a7d0d2ef9261 54 public:
johnb 51:a7d0d2ef9261 55 /** Constructor
johnb 51:a7d0d2ef9261 56
johnb 51:a7d0d2ef9261 57 \param p_device XBee device with which this object should
johnb 51:a7d0d2ef9261 58 be associated
johnb 51:a7d0d2ef9261 59 \param p_timeout Timeout to be used when waiting for
johnb 51:a7d0d2ef9261 60 data from the XBee, specified in
johnb 51:a7d0d2ef9261 61 milliseconds
johnb 51:a7d0d2ef9261 62 \param p_slice While waiting for data, blocking methods
johnb 51:a7d0d2ef9261 63 will call the OS wait_ms() function, using
johnb 51:a7d0d2ef9261 64 the value specified by p_slice */
johnb 51:a7d0d2ef9261 65 XBeeApiCmdAtBlocking( XBeeDevice* const p_device = NULL,
johnb 51:a7d0d2ef9261 66 const uint16_t p_timeout = 1000,
johnb 51:a7d0d2ef9261 67 const uint16_t p_slice = 100);
johnb 51:a7d0d2ef9261 68
johnb 51:a7d0d2ef9261 69 /** Destructor */
johnb 51:a7d0d2ef9261 70 virtual ~XBeeApiCmdAtBlocking( void ) {};
johnb 51:a7d0d2ef9261 71
johnb 51:a7d0d2ef9261 72 /* Implement XBeeApiCmdAt's virtual methods */
johnb 51:a7d0d2ef9261 73
johnb 51:a7d0d2ef9261 74 virtual bool getHardwareVersion( uint16_t* const p_ver );
johnb 51:a7d0d2ef9261 75 virtual bool getFirmwareVersion( uint16_t* const p_ver );
johnb 51:a7d0d2ef9261 76 virtual bool getSerialNumber( uint64_t* const p_sn );
johnb 51:a7d0d2ef9261 77
johnb 51:a7d0d2ef9261 78 virtual bool getChannel( uint8_t* const p_chan );
johnb 51:a7d0d2ef9261 79 virtual bool setChannel( uint8_t const p_chan );
johnb 51:a7d0d2ef9261 80
johnb 51:a7d0d2ef9261 81 virtual bool getCoordinatorEnabled( bool* constp_en );
johnb 51:a7d0d2ef9261 82 virtual bool setCoordinatorEnabled( const bool p_en );
johnb 51:a7d0d2ef9261 83
johnb 51:a7d0d2ef9261 84 virtual bool getEndDeviceAssociationEnabled( bool* const p_en );
johnb 51:a7d0d2ef9261 85 virtual bool setEndDeviceAssociationEnabled( const bool p_en );
johnb 51:a7d0d2ef9261 86
johnb 51:a7d0d2ef9261 87 virtual bool getPanId( panId_t* const p_id );
johnb 51:a7d0d2ef9261 88 virtual bool setPanId( const panId_t p_id );
johnb 51:a7d0d2ef9261 89
johnb 51:a7d0d2ef9261 90 virtual bool getSourceAddress( uint16_t* const p_addr );
johnb 51:a7d0d2ef9261 91 virtual bool setSourceAddress( const uint16_t p_addr );
johnb 51:a7d0d2ef9261 92
johnb 51:a7d0d2ef9261 93 virtual bool getRetries( uint8_t* const p_addr );
johnb 51:a7d0d2ef9261 94 virtual bool setRetries( const uint8_t p_addr );
johnb 51:a7d0d2ef9261 95
johnb 51:a7d0d2ef9261 96 virtual bool getRandomDelaySlots( uint8_t* const p_addr );
johnb 51:a7d0d2ef9261 97 virtual bool setRandomDelaySlots( const uint8_t p_addr );
johnb 51:a7d0d2ef9261 98
johnb 51:a7d0d2ef9261 99 virtual bool getMacMode( XBeeApiMACMode_e* const p_mode );
johnb 51:a7d0d2ef9261 100 virtual bool setMacMode( const XBeeApiMACMode_e p_mode );
johnb 51:a7d0d2ef9261 101
johnb 51:a7d0d2ef9261 102 virtual bool getDioConfig( const uint8_t p_chanNo, XBeeApiDioConfig_e* const p_conf );
johnb 51:a7d0d2ef9261 103 virtual bool setDioConfig( const uint8_t p_chanNo, const XBeeApiDioConfig_e p_conf );
johnb 51:a7d0d2ef9261 104
johnb 51:a7d0d2ef9261 105 virtual bool getDioChangeDetectMask( uint8_t* const p_mask );
johnb 51:a7d0d2ef9261 106 virtual bool setDioChangeDetectMask( const uint8_t p_mask );
johnb 51:a7d0d2ef9261 107
johnb 51:a7d0d2ef9261 108 virtual bool getDioLevels( uint8_t* const p_mask );
johnb 51:a7d0d2ef9261 109 virtual bool setDioLevels( const uint8_t p_mask );
johnb 51:a7d0d2ef9261 110
johnb 51:a7d0d2ef9261 111 virtual bool getSampleRate( uint16_t* const p_interval );
johnb 51:a7d0d2ef9261 112 virtual bool setSampleRate( const uint16_t p_interval );
johnb 51:a7d0d2ef9261 113
johnb 51:a7d0d2ef9261 114 virtual bool getDestinationAddress( uint64_t* const p_address );
johnb 51:a7d0d2ef9261 115 virtual bool setDestinationAddress( const uint64_t p_address );
johnb 51:a7d0d2ef9261 116
johnb 51:a7d0d2ef9261 117 virtual bool getDestinationAddressHigh( uint32_t* const p_address );
johnb 51:a7d0d2ef9261 118 virtual bool setDestinationAddressHigh( const uint32_t p_address );
johnb 51:a7d0d2ef9261 119
johnb 51:a7d0d2ef9261 120 virtual bool getDestinationAddressLow( uint32_t* const p_address );
johnb 51:a7d0d2ef9261 121 virtual bool setDestinationAddressLow( const uint32_t p_address );
johnb 51:a7d0d2ef9261 122
johnb 51:a7d0d2ef9261 123 };
johnb 51:a7d0d2ef9261 124
johnb 51:a7d0d2ef9261 125 #endif