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 Feb 03 23:26:27 2014 +0000
Revision:
13:302e7c1ea0b3
Parent:
11:bfcf1356027b
Child:
24:2cd1094c4fd7
Add implementation for xbeeSetNetworkTypeP2P() and the AT cmds to support it.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnb 8:1b48b619d7f6 1 /**
johnb 8:1b48b619d7f6 2 @file
johnb 8:1b48b619d7f6 3 @brief Class to abstract AT commands send to the XBee API
johnb 8:1b48b619d7f6 4
johnb 8:1b48b619d7f6 5 AT commands have the payload:
johnb 8:1b48b619d7f6 6
johnb 8:1b48b619d7f6 7 Byte 1 : Frame ID
johnb 8:1b48b619d7f6 8 Byte 2 & 3 : AT command
johnb 8:1b48b619d7f6 9 Byte 4-n : Parameter Value
johnb 8:1b48b619d7f6 10
johnb 8:1b48b619d7f6 11 @author John Bailey
johnb 8:1b48b619d7f6 12
johnb 8:1b48b619d7f6 13 @copyright Copyright 2014 John Bailey
johnb 8:1b48b619d7f6 14
johnb 8:1b48b619d7f6 15 @section LICENSE
johnb 8:1b48b619d7f6 16
johnb 8:1b48b619d7f6 17 Licensed under the Apache License, Version 2.0 (the "License");
johnb 8:1b48b619d7f6 18 you may not use this file except in compliance with the License.
johnb 8:1b48b619d7f6 19 You may obtain a copy of the License at
johnb 8:1b48b619d7f6 20
johnb 8:1b48b619d7f6 21 http://www.apache.org/licenses/LICENSE-2.0
johnb 8:1b48b619d7f6 22
johnb 8:1b48b619d7f6 23 Unless required by applicable law or agreed to in writing, software
johnb 8:1b48b619d7f6 24 distributed under the License is distributed on an "AS IS" BASIS,
johnb 8:1b48b619d7f6 25 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
johnb 8:1b48b619d7f6 26 See the License for the specific language governing permissions and
johnb 8:1b48b619d7f6 27 limitations under the License.
johnb 8:1b48b619d7f6 28
johnb 8:1b48b619d7f6 29 */
johnb 8:1b48b619d7f6 30
johnb 8:1b48b619d7f6 31 #if !defined XBEEAPICMDAT_HPP
johnb 8:1b48b619d7f6 32 #define XBEEAPICMDAT_HPP
johnb 8:1b48b619d7f6 33
johnb 8:1b48b619d7f6 34 #include "XBeeApiFrame.hpp"
johnb 8:1b48b619d7f6 35 #include "XBeeDevice.hpp"
johnb 8:1b48b619d7f6 36
johnb 8:1b48b619d7f6 37 #include <stdint.h>
johnb 8:1b48b619d7f6 38
johnb 8:1b48b619d7f6 39 class XBeeApiCmdAt : public XBeeApiFrameDecoder
johnb 8:1b48b619d7f6 40 {
johnb 13:302e7c1ea0b3 41 public:
johnb 13:302e7c1ea0b3 42 typedef uint16_t panId_t;
johnb 13:302e7c1ea0b3 43 typedef uint8_t channel_t;
johnb 13:302e7c1ea0b3 44
johnb 8:1b48b619d7f6 45 protected:
johnb 8:1b48b619d7f6 46 bool m_haveHwVer;
johnb 8:1b48b619d7f6 47 bool m_haveFwVer;
johnb 8:1b48b619d7f6 48 bool m_haveChan;
johnb 13:302e7c1ea0b3 49 bool m_havePANId;
johnb 13:302e7c1ea0b3 50 bool m_haveEDA;
johnb 13:302e7c1ea0b3 51 bool m_haveCE;
johnb 13:302e7c1ea0b3 52
johnb 8:1b48b619d7f6 53 uint16_t m_hwVer;
johnb 8:1b48b619d7f6 54 uint16_t m_fwVer;
johnb 13:302e7c1ea0b3 55 channel_t m_chan;
johnb 13:302e7c1ea0b3 56 channel_t m_chanPend;
johnb 13:302e7c1ea0b3 57 panId_t m_PANId;
johnb 13:302e7c1ea0b3 58 panId_t m_PANIdPend;
johnb 13:302e7c1ea0b3 59 bool m_EDA;
johnb 13:302e7c1ea0b3 60 bool m_EDAPend;
johnb 13:302e7c1ea0b3 61 bool m_CE;
johnb 13:302e7c1ea0b3 62 bool m_CEPend;
johnb 8:1b48b619d7f6 63
johnb 8:1b48b619d7f6 64 class XBeeApiCmdAtFirmwareVersionRequest : public XBeeApiFrame
johnb 8:1b48b619d7f6 65 {
johnb 8:1b48b619d7f6 66 public:
johnb 8:1b48b619d7f6 67 XBeeApiCmdAtFirmwareVersionRequest( void );
johnb 8:1b48b619d7f6 68 };
johnb 8:1b48b619d7f6 69
johnb 8:1b48b619d7f6 70 class XBeeApiCmdAtHardwareVersionRequest : public XBeeApiFrame
johnb 8:1b48b619d7f6 71 {
johnb 8:1b48b619d7f6 72 public:
johnb 8:1b48b619d7f6 73 XBeeApiCmdAtHardwareVersionRequest( void );
johnb 8:1b48b619d7f6 74 };
johnb 8:1b48b619d7f6 75
johnb 8:1b48b619d7f6 76 class XBeeApiCmdAtChannelRequest : public XBeeApiFrame
johnb 8:1b48b619d7f6 77 {
johnb 8:1b48b619d7f6 78 public:
johnb 8:1b48b619d7f6 79 XBeeApiCmdAtChannelRequest( void );
johnb 8:1b48b619d7f6 80 };
johnb 8:1b48b619d7f6 81
johnb 8:1b48b619d7f6 82 class XBeeApiCmdAtChannelSet : public XBeeApiFrame
johnb 8:1b48b619d7f6 83 {
johnb 8:1b48b619d7f6 84 uint8_t m_buffer[ 10 ];
johnb 8:1b48b619d7f6 85 public:
johnb 8:1b48b619d7f6 86 XBeeApiCmdAtChannelSet( const uint8_t p_chan );
johnb 8:1b48b619d7f6 87 };
johnb 8:1b48b619d7f6 88
johnb 13:302e7c1ea0b3 89 class XBeeApiCmdAtCERequest : public XBeeApiFrame
johnb 13:302e7c1ea0b3 90 {
johnb 13:302e7c1ea0b3 91 public:
johnb 13:302e7c1ea0b3 92 XBeeApiCmdAtCERequest( void );
johnb 13:302e7c1ea0b3 93 };
johnb 13:302e7c1ea0b3 94
johnb 13:302e7c1ea0b3 95 class XBeeApiCmdAtCESet : public XBeeApiFrame
johnb 13:302e7c1ea0b3 96 {
johnb 13:302e7c1ea0b3 97 /* TODO: Magic number */
johnb 13:302e7c1ea0b3 98 uint8_t m_buffer[ 10 ];
johnb 13:302e7c1ea0b3 99 public:
johnb 13:302e7c1ea0b3 100 XBeeApiCmdAtCESet( const bool p_en );
johnb 13:302e7c1ea0b3 101 };
johnb 13:302e7c1ea0b3 102
johnb 13:302e7c1ea0b3 103 class XBeeApiCmdAtPANIdRequest : public XBeeApiFrame
johnb 13:302e7c1ea0b3 104 {
johnb 13:302e7c1ea0b3 105 public:
johnb 13:302e7c1ea0b3 106 XBeeApiCmdAtPANIdRequest( void );
johnb 13:302e7c1ea0b3 107 };
johnb 13:302e7c1ea0b3 108
johnb 13:302e7c1ea0b3 109 class XBeeApiCmdAtPANIdSet : public XBeeApiFrame
johnb 13:302e7c1ea0b3 110 {
johnb 13:302e7c1ea0b3 111 /* TODO: Magic number */
johnb 13:302e7c1ea0b3 112 uint8_t m_buffer[ 10 ];
johnb 13:302e7c1ea0b3 113 public:
johnb 13:302e7c1ea0b3 114 XBeeApiCmdAtPANIdSet( const panId_t p_chan );
johnb 13:302e7c1ea0b3 115 };
johnb 13:302e7c1ea0b3 116
johnb 13:302e7c1ea0b3 117 class XBeeApiCmdAtEDARequest : public XBeeApiFrame
johnb 13:302e7c1ea0b3 118 {
johnb 13:302e7c1ea0b3 119 public:
johnb 13:302e7c1ea0b3 120 XBeeApiCmdAtEDARequest( void );
johnb 13:302e7c1ea0b3 121 };
johnb 13:302e7c1ea0b3 122
johnb 13:302e7c1ea0b3 123 class XBeeApiCmdAtEDASet : public XBeeApiFrame
johnb 13:302e7c1ea0b3 124 {
johnb 13:302e7c1ea0b3 125 /* TODO: Magic number */
johnb 13:302e7c1ea0b3 126 uint8_t m_buffer[ 10 ];
johnb 13:302e7c1ea0b3 127 public:
johnb 13:302e7c1ea0b3 128 XBeeApiCmdAtEDASet( const bool p_en );
johnb 13:302e7c1ea0b3 129 };
johnb 13:302e7c1ea0b3 130
johnb 8:1b48b619d7f6 131 public:
johnb 13:302e7c1ea0b3 132
johnb 8:1b48b619d7f6 133 XBeeApiCmdAt( );
johnb 8:1b48b619d7f6 134 virtual ~XBeeApiCmdAt( void ) {};
johnb 8:1b48b619d7f6 135
johnb 8:1b48b619d7f6 136 bool requestHardwareVersion( void );
johnb 8:1b48b619d7f6 137 bool requestFirmwareVersion( void );
johnb 8:1b48b619d7f6 138 bool requestChannel( void );
johnb 13:302e7c1ea0b3 139 bool requestCoordinatorEnabled( void );
johnb 13:302e7c1ea0b3 140 bool requestEndDeviceAssociationEnabled( void );
johnb 13:302e7c1ea0b3 141 bool requestPanId( void );
johnb 8:1b48b619d7f6 142
johnb 8:1b48b619d7f6 143 virtual bool getHardwareVersion( uint16_t* const p_ver );
johnb 8:1b48b619d7f6 144 virtual bool getFirmwareVersion( uint16_t* const p_ver );
johnb 13:302e7c1ea0b3 145
johnb 8:1b48b619d7f6 146 virtual bool getChannel( uint8_t* const p_chan );
johnb 13:302e7c1ea0b3 147 virtual bool setChannel( uint8_t const p_chan );
johnb 8:1b48b619d7f6 148
johnb 13:302e7c1ea0b3 149 virtual bool getCoordinatorEnabled( bool* constp_en );
johnb 13:302e7c1ea0b3 150 virtual bool setCoordinatorEnabled( const bool p_en );
johnb 13:302e7c1ea0b3 151
johnb 13:302e7c1ea0b3 152 virtual bool getEndDeviceAssociationEnabled( bool* const p_en );
johnb 13:302e7c1ea0b3 153 virtual bool setEndDeviceAssociationEnabled( const bool p_en );
johnb 13:302e7c1ea0b3 154
johnb 13:302e7c1ea0b3 155 virtual bool getPanId( panId_t* const p_id );
johnb 13:302e7c1ea0b3 156 virtual bool setPanId( const panId_t p_id );
johnb 8:1b48b619d7f6 157
johnb 8:1b48b619d7f6 158 /* Implement XBeeApiCmdDecoder interface */
johnb 8:1b48b619d7f6 159 virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len );
johnb 8:1b48b619d7f6 160
johnb 8:1b48b619d7f6 161 };
johnb 8:1b48b619d7f6 162
johnb 8:1b48b619d7f6 163 class XBeeApiCmdAtBlocking : public XBeeApiCmdAt
johnb 8:1b48b619d7f6 164 {
johnb 8:1b48b619d7f6 165 protected:
johnb 8:1b48b619d7f6 166 uint16_t m_timeout;
johnb 8:1b48b619d7f6 167 uint16_t m_slice;
johnb 8:1b48b619d7f6 168
johnb 8:1b48b619d7f6 169 public:
johnb 8:1b48b619d7f6 170 XBeeApiCmdAtBlocking( const uint16_t p_timeout = 1000, const uint16_t p_slice = 100);
johnb 8:1b48b619d7f6 171
johnb 8:1b48b619d7f6 172 virtual ~XBeeApiCmdAtBlocking( void ) {};
johnb 8:1b48b619d7f6 173 /* Implement XBeeApiCmdAt's virtual methods */
johnb 8:1b48b619d7f6 174 virtual bool getHardwareVersion( uint16_t* const p_ver );
johnb 8:1b48b619d7f6 175 virtual bool getFirmwareVersion( uint16_t* const p_ver );
johnb 13:302e7c1ea0b3 176
johnb 8:1b48b619d7f6 177 virtual bool getChannel( uint8_t* const p_chan );
johnb 13:302e7c1ea0b3 178 virtual bool setChannel( uint8_t const p_chan );
johnb 13:302e7c1ea0b3 179
johnb 13:302e7c1ea0b3 180 virtual bool getCoordinatorEnabled( bool* constp_en );
johnb 13:302e7c1ea0b3 181 virtual bool setCoordinatorEnabled( const bool p_en );
johnb 8:1b48b619d7f6 182
johnb 13:302e7c1ea0b3 183 virtual bool getEndDeviceAssociationEnabled( bool* const p_en );
johnb 13:302e7c1ea0b3 184 virtual bool setEndDeviceAssociationEnabled( const bool p_en );
johnb 13:302e7c1ea0b3 185
johnb 13:302e7c1ea0b3 186 virtual bool getPanId( panId_t* const p_id );
johnb 13:302e7c1ea0b3 187 virtual bool setPanId( const panId_t p_id );
johnb 13:302e7c1ea0b3 188
johnb 8:1b48b619d7f6 189 };
johnb 8:1b48b619d7f6 190
johnb 8:1b48b619d7f6 191 #endif