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:
Fri Jan 31 23:53:16 2014 +0000
Revision:
11:bfcf1356027b
Parent:
8:1b48b619d7f6
Child:
13:302e7c1ea0b3
Switch to using macros to implement the access functions in XBeeApiCmdAtBlocking.; Implement XBeeApiCmdAtBlocking::setChannel()

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 8:1b48b619d7f6 41 protected:
johnb 8:1b48b619d7f6 42 bool m_haveHwVer;
johnb 8:1b48b619d7f6 43 bool m_haveFwVer;
johnb 8:1b48b619d7f6 44 bool m_haveChan;
johnb 8:1b48b619d7f6 45 uint16_t m_hwVer;
johnb 8:1b48b619d7f6 46 uint16_t m_fwVer;
johnb 8:1b48b619d7f6 47 uint8_t m_chan;
johnb 8:1b48b619d7f6 48 uint8_t m_chanPend;
johnb 8:1b48b619d7f6 49
johnb 8:1b48b619d7f6 50 class XBeeApiCmdAtFirmwareVersionRequest : public XBeeApiFrame
johnb 8:1b48b619d7f6 51 {
johnb 8:1b48b619d7f6 52 public:
johnb 8:1b48b619d7f6 53 XBeeApiCmdAtFirmwareVersionRequest( void );
johnb 8:1b48b619d7f6 54 };
johnb 8:1b48b619d7f6 55
johnb 8:1b48b619d7f6 56 class XBeeApiCmdAtHardwareVersionRequest : public XBeeApiFrame
johnb 8:1b48b619d7f6 57 {
johnb 8:1b48b619d7f6 58 public:
johnb 8:1b48b619d7f6 59 XBeeApiCmdAtHardwareVersionRequest( void );
johnb 8:1b48b619d7f6 60 };
johnb 8:1b48b619d7f6 61
johnb 8:1b48b619d7f6 62 class XBeeApiCmdAtChannelRequest : public XBeeApiFrame
johnb 8:1b48b619d7f6 63 {
johnb 8:1b48b619d7f6 64 public:
johnb 8:1b48b619d7f6 65 XBeeApiCmdAtChannelRequest( void );
johnb 8:1b48b619d7f6 66 };
johnb 8:1b48b619d7f6 67
johnb 8:1b48b619d7f6 68 class XBeeApiCmdAtChannelSet : public XBeeApiFrame
johnb 8:1b48b619d7f6 69 {
johnb 8:1b48b619d7f6 70 uint8_t m_buffer[ 10 ];
johnb 8:1b48b619d7f6 71 public:
johnb 8:1b48b619d7f6 72 XBeeApiCmdAtChannelSet( const uint8_t p_chan );
johnb 8:1b48b619d7f6 73 };
johnb 8:1b48b619d7f6 74
johnb 8:1b48b619d7f6 75 public:
johnb 8:1b48b619d7f6 76 XBeeApiCmdAt( );
johnb 8:1b48b619d7f6 77 virtual ~XBeeApiCmdAt( void ) {};
johnb 8:1b48b619d7f6 78
johnb 8:1b48b619d7f6 79 bool requestHardwareVersion( void );
johnb 8:1b48b619d7f6 80 bool requestFirmwareVersion( void );
johnb 8:1b48b619d7f6 81 bool requestChannel( void );
johnb 8:1b48b619d7f6 82
johnb 8:1b48b619d7f6 83 virtual bool getHardwareVersion( uint16_t* const p_ver );
johnb 8:1b48b619d7f6 84 virtual bool getFirmwareVersion( uint16_t* const p_ver );
johnb 8:1b48b619d7f6 85 virtual bool getChannel( uint8_t* const p_chan );
johnb 8:1b48b619d7f6 86
johnb 8:1b48b619d7f6 87 virtual bool setChannel( uint8_t const p_chan );
johnb 8:1b48b619d7f6 88
johnb 8:1b48b619d7f6 89 /* Implement XBeeApiCmdDecoder interface */
johnb 8:1b48b619d7f6 90 virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len );
johnb 8:1b48b619d7f6 91
johnb 8:1b48b619d7f6 92 typedef uint16_t panId_t;
johnb 8:1b48b619d7f6 93 typedef uint8_t channel_t;
johnb 8:1b48b619d7f6 94 };
johnb 8:1b48b619d7f6 95
johnb 8:1b48b619d7f6 96 class XBeeApiCmdAtBlocking : public XBeeApiCmdAt
johnb 8:1b48b619d7f6 97 {
johnb 8:1b48b619d7f6 98 protected:
johnb 8:1b48b619d7f6 99 uint16_t m_timeout;
johnb 8:1b48b619d7f6 100 uint16_t m_slice;
johnb 8:1b48b619d7f6 101
johnb 8:1b48b619d7f6 102 public:
johnb 8:1b48b619d7f6 103 XBeeApiCmdAtBlocking( const uint16_t p_timeout = 1000, const uint16_t p_slice = 100);
johnb 8:1b48b619d7f6 104
johnb 8:1b48b619d7f6 105 virtual ~XBeeApiCmdAtBlocking( void ) {};
johnb 8:1b48b619d7f6 106 /* Implement XBeeApiCmdAt's virtual methods */
johnb 8:1b48b619d7f6 107 virtual bool getHardwareVersion( uint16_t* const p_ver );
johnb 8:1b48b619d7f6 108 virtual bool getFirmwareVersion( uint16_t* const p_ver );
johnb 8:1b48b619d7f6 109 virtual bool getChannel( uint8_t* const p_chan );
johnb 8:1b48b619d7f6 110
johnb 8:1b48b619d7f6 111 virtual bool setChannel( uint8_t const p_chan );
johnb 8:1b48b619d7f6 112 };
johnb 8:1b48b619d7f6 113
johnb 8:1b48b619d7f6 114 #endif