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:
Wed Feb 05 18:56:58 2014 +0000
Revision:
24:2cd1094c4fd7
Parent:
13:302e7c1ea0b3
Child:
25:db6874b7ac4b
Remove various classes from XBeeApiCmdAt and extend XBeeApiFrame to allow initialisation of the members so that this class can perform the same task as was previously occupying >3 classes.

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 XBeeApiCmdAtChannelSet : public XBeeApiFrame
johnb 8:1b48b619d7f6 65 {
johnb 8:1b48b619d7f6 66 uint8_t m_buffer[ 10 ];
johnb 8:1b48b619d7f6 67 public:
johnb 8:1b48b619d7f6 68 XBeeApiCmdAtChannelSet( const uint8_t p_chan );
johnb 8:1b48b619d7f6 69 };
johnb 8:1b48b619d7f6 70
johnb 13:302e7c1ea0b3 71 class XBeeApiCmdAtCESet : public XBeeApiFrame
johnb 13:302e7c1ea0b3 72 {
johnb 13:302e7c1ea0b3 73 /* TODO: Magic number */
johnb 13:302e7c1ea0b3 74 uint8_t m_buffer[ 10 ];
johnb 13:302e7c1ea0b3 75 public:
johnb 13:302e7c1ea0b3 76 XBeeApiCmdAtCESet( const bool p_en );
johnb 13:302e7c1ea0b3 77 };
johnb 13:302e7c1ea0b3 78
johnb 13:302e7c1ea0b3 79 class XBeeApiCmdAtPANIdSet : public XBeeApiFrame
johnb 13:302e7c1ea0b3 80 {
johnb 13:302e7c1ea0b3 81 /* TODO: Magic number */
johnb 13:302e7c1ea0b3 82 uint8_t m_buffer[ 10 ];
johnb 13:302e7c1ea0b3 83 public:
johnb 13:302e7c1ea0b3 84 XBeeApiCmdAtPANIdSet( const panId_t p_chan );
johnb 13:302e7c1ea0b3 85 };
johnb 13:302e7c1ea0b3 86
johnb 13:302e7c1ea0b3 87 class XBeeApiCmdAtEDASet : public XBeeApiFrame
johnb 13:302e7c1ea0b3 88 {
johnb 13:302e7c1ea0b3 89 /* TODO: Magic number */
johnb 13:302e7c1ea0b3 90 uint8_t m_buffer[ 10 ];
johnb 13:302e7c1ea0b3 91 public:
johnb 13:302e7c1ea0b3 92 XBeeApiCmdAtEDASet( const bool p_en );
johnb 13:302e7c1ea0b3 93 };
johnb 13:302e7c1ea0b3 94
johnb 8:1b48b619d7f6 95 public:
johnb 13:302e7c1ea0b3 96
johnb 8:1b48b619d7f6 97 XBeeApiCmdAt( );
johnb 8:1b48b619d7f6 98 virtual ~XBeeApiCmdAt( void ) {};
johnb 8:1b48b619d7f6 99
johnb 8:1b48b619d7f6 100 bool requestHardwareVersion( void );
johnb 8:1b48b619d7f6 101 bool requestFirmwareVersion( void );
johnb 8:1b48b619d7f6 102 bool requestChannel( void );
johnb 13:302e7c1ea0b3 103 bool requestCoordinatorEnabled( void );
johnb 13:302e7c1ea0b3 104 bool requestEndDeviceAssociationEnabled( void );
johnb 13:302e7c1ea0b3 105 bool requestPanId( void );
johnb 8:1b48b619d7f6 106
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 13:302e7c1ea0b3 109
johnb 8:1b48b619d7f6 110 virtual bool getChannel( uint8_t* const p_chan );
johnb 13:302e7c1ea0b3 111 virtual bool setChannel( uint8_t const p_chan );
johnb 8:1b48b619d7f6 112
johnb 13:302e7c1ea0b3 113 virtual bool getCoordinatorEnabled( bool* constp_en );
johnb 13:302e7c1ea0b3 114 virtual bool setCoordinatorEnabled( const bool p_en );
johnb 13:302e7c1ea0b3 115
johnb 13:302e7c1ea0b3 116 virtual bool getEndDeviceAssociationEnabled( bool* const p_en );
johnb 13:302e7c1ea0b3 117 virtual bool setEndDeviceAssociationEnabled( const bool p_en );
johnb 13:302e7c1ea0b3 118
johnb 13:302e7c1ea0b3 119 virtual bool getPanId( panId_t* const p_id );
johnb 13:302e7c1ea0b3 120 virtual bool setPanId( const panId_t p_id );
johnb 8:1b48b619d7f6 121
johnb 8:1b48b619d7f6 122 /* Implement XBeeApiCmdDecoder interface */
johnb 8:1b48b619d7f6 123 virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len );
johnb 8:1b48b619d7f6 124
johnb 8:1b48b619d7f6 125 };
johnb 8:1b48b619d7f6 126
johnb 8:1b48b619d7f6 127 class XBeeApiCmdAtBlocking : public XBeeApiCmdAt
johnb 8:1b48b619d7f6 128 {
johnb 8:1b48b619d7f6 129 protected:
johnb 8:1b48b619d7f6 130 uint16_t m_timeout;
johnb 8:1b48b619d7f6 131 uint16_t m_slice;
johnb 8:1b48b619d7f6 132
johnb 8:1b48b619d7f6 133 public:
johnb 8:1b48b619d7f6 134 XBeeApiCmdAtBlocking( const uint16_t p_timeout = 1000, const uint16_t p_slice = 100);
johnb 8:1b48b619d7f6 135
johnb 8:1b48b619d7f6 136 virtual ~XBeeApiCmdAtBlocking( void ) {};
johnb 8:1b48b619d7f6 137 /* Implement XBeeApiCmdAt's virtual methods */
johnb 8:1b48b619d7f6 138 virtual bool getHardwareVersion( uint16_t* const p_ver );
johnb 8:1b48b619d7f6 139 virtual bool getFirmwareVersion( uint16_t* const p_ver );
johnb 13:302e7c1ea0b3 140
johnb 8:1b48b619d7f6 141 virtual bool getChannel( uint8_t* const p_chan );
johnb 13:302e7c1ea0b3 142 virtual bool setChannel( uint8_t const p_chan );
johnb 13:302e7c1ea0b3 143
johnb 13:302e7c1ea0b3 144 virtual bool getCoordinatorEnabled( bool* constp_en );
johnb 13:302e7c1ea0b3 145 virtual bool setCoordinatorEnabled( const bool p_en );
johnb 8:1b48b619d7f6 146
johnb 13:302e7c1ea0b3 147 virtual bool getEndDeviceAssociationEnabled( bool* const p_en );
johnb 13:302e7c1ea0b3 148 virtual bool setEndDeviceAssociationEnabled( const bool p_en );
johnb 13:302e7c1ea0b3 149
johnb 13:302e7c1ea0b3 150 virtual bool getPanId( panId_t* const p_id );
johnb 13:302e7c1ea0b3 151 virtual bool setPanId( const panId_t p_id );
johnb 13:302e7c1ea0b3 152
johnb 8:1b48b619d7f6 153 };
johnb 8:1b48b619d7f6 154
johnb 8:1b48b619d7f6 155 #endif