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 Aug 08 11:59:52 2014 +0000
Revision:
56:7fe74b03e6b1
Parent:
55:610aa4a2ed3b
Add support for setting up encrypted communications; Re-jig XBeeApiCmdAt virtual functions to make inheritance by XBeeDeviceRemoteAt cleaner.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnb 50:f76b7e7959a2 1 /**
johnb 50:f76b7e7959a2 2 @file
johnb 50:f76b7e7959a2 3 @brief Class to provide an abstract representation of a remote
johnb 50:f76b7e7959a2 4 XBee device's AT command interface
johnb 50:f76b7e7959a2 5
johnb 50:f76b7e7959a2 6 @author John Bailey
johnb 50:f76b7e7959a2 7
johnb 50:f76b7e7959a2 8 @copyright Copyright 2014 John Bailey
johnb 50:f76b7e7959a2 9
johnb 50:f76b7e7959a2 10 @section LICENSE
johnb 50:f76b7e7959a2 11
johnb 50:f76b7e7959a2 12 Licensed under the Apache License, Version 2.0 (the "License");
johnb 50:f76b7e7959a2 13 you may not use this file except in compliance with the License.
johnb 50:f76b7e7959a2 14 You may obtain a copy of the License at
johnb 50:f76b7e7959a2 15
johnb 50:f76b7e7959a2 16 http://www.apache.org/licenses/LICENSE-2.0
johnb 50:f76b7e7959a2 17
johnb 50:f76b7e7959a2 18 Unless required by applicable law or agreed to in writing, software
johnb 50:f76b7e7959a2 19 distributed under the License is distributed on an "AS IS" BASIS,
johnb 50:f76b7e7959a2 20 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
johnb 50:f76b7e7959a2 21 See the License for the specific language governing permissions and
johnb 50:f76b7e7959a2 22 limitations under the License.
johnb 50:f76b7e7959a2 23
johnb 50:f76b7e7959a2 24 */
johnb 50:f76b7e7959a2 25
johnb 50:f76b7e7959a2 26 #if !defined XBEEDEVICEREMOTEAT_HPP
johnb 50:f76b7e7959a2 27 #define XBEEDEVICEREMOTEAT_HPP
johnb 50:f76b7e7959a2 28
johnb 50:f76b7e7959a2 29 #include "XBeeApiCfg.hpp"
johnb 50:f76b7e7959a2 30 #include "XBeeApiFrame.hpp"
johnb 50:f76b7e7959a2 31 #include "XBeeApiCmdAt.hpp"
johnb 50:f76b7e7959a2 32
johnb 53:7b65422d7a32 33 /** Class used to provide a command interface to a remove XBee via the Remote AT interface.
johnb 53:7b65422d7a32 34 The class inherits from XBeeApiCmdAt, hence the interface for the local and remote
johnb 53:7b65422d7a32 35 XBees is generally the same.
johnb 53:7b65422d7a32 36 */
johnb 50:f76b7e7959a2 37 class XBeeDeviceRemoteAt : public XBeeApiCmdAt
johnb 50:f76b7e7959a2 38 {
johnb 50:f76b7e7959a2 39 protected:
johnb 50:f76b7e7959a2 40 /** Called by XBeeDevice in order to offer frame data to the object for
johnb 50:f76b7e7959a2 41 decoding
johnb 50:f76b7e7959a2 42
johnb 50:f76b7e7959a2 43 \param p_data Pointer to the content of the received data
johnb 50:f76b7e7959a2 44 \param p_len Length of the data pointed to by p_data
johnb 50:f76b7e7959a2 45 */
johnb 50:f76b7e7959a2 46 virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len );
johnb 50:f76b7e7959a2 47
johnb 56:7fe74b03e6b1 48 virtual void SendCmd( const uint8_t p_frameId,
johnb 56:7fe74b03e6b1 49 const uint8_t* const p_data,
johnb 56:7fe74b03e6b1 50 const uint8_t* const p_val,
johnb 56:7fe74b03e6b1 51 const uint8_t p_len );
johnb 50:f76b7e7959a2 52
johnb 53:7b65422d7a32 53 /* TODO: doc */
johnb 50:f76b7e7959a2 54 virtual size_t getResponseStatusPos( void ) const;
johnb 50:f76b7e7959a2 55
johnb 53:7b65422d7a32 56 /** Keep track of whether we're applying changes when the AT command is sent
johnb 53:7b65422d7a32 57 or not */
johnb 51:a7d0d2ef9261 58 bool m_applyChanges;
johnb 50:f76b7e7959a2 59
johnb 55:610aa4a2ed3b 60 /** Keep track of which type of addressing we're using for transmitted frames */
johnb 55:610aa4a2ed3b 61 XBeeDevice::XBeeApiAddrType_t m_addressingType;
johnb 55:610aa4a2ed3b 62
johnb 55:610aa4a2ed3b 63 /** Set m_snLow/m_snHigh or m_sourceAddress depending on the parameters specified and
johnb 55:610aa4a2ed3b 64 set up suplementary attributes such as the addressing type to be used
johnb 55:610aa4a2ed3b 65
johnb 55:610aa4a2ed3b 66 \param p_addr16Bit 16-bit address of the remote XBee (or XBEE_BROADCAST_ADDR for broadcast or XBEE_USE_64BIT_ADDR to use 64-bit addressing (see p_addr64Bit)
johnb 55:610aa4a2ed3b 67 \param p_addr64Bit 64-bit address of the remote XBee, only used in the case that the 16-bit address is XBEE_USE_64BIT_ADDR
johnb 55:610aa4a2ed3b 68 */
johnb 55:610aa4a2ed3b 69 void setAddress( const uint16_t& p_addr16Bit,
johnb 55:610aa4a2ed3b 70 const uint64_t& p_addr64Bit = 0 );
johnb 55:610aa4a2ed3b 71
johnb 50:f76b7e7959a2 72 public:
johnb 53:7b65422d7a32 73
johnb 55:610aa4a2ed3b 74 /** Constructor
johnb 55:610aa4a2ed3b 75
johnb 55:610aa4a2ed3b 76 \param p_device Pointer to the XBee device used to communicate with the remote XBee
johnb 55:610aa4a2ed3b 77 \param p_addr16Bit 16-bit address of the remote XBee (or XBEE_BROADCAST_ADDR for broadcast or XBEE_USE_64BIT_ADDR to use 64-bit addressing (see p_addr64Bit)
johnb 55:610aa4a2ed3b 78 \param p_addr64Bit 64-bit address of the remote XBee, only used in the case that the 16-bit address is XBEE_USE_64BIT_ADDR
johnb 55:610aa4a2ed3b 79 \param p_applyChanges Indicate whether or not changes should be applied with each message/method call. Seed setApplyChanges() */
johnb 50:f76b7e7959a2 80 XBeeDeviceRemoteAt( XBeeDevice* p_device,
johnb 50:f76b7e7959a2 81 const uint16_t& p_addr16Bit,
johnb 51:a7d0d2ef9261 82 const uint64_t& p_addr64Bit = 0,
johnb 51:a7d0d2ef9261 83 const bool p_applyChanges = false );
johnb 50:f76b7e7959a2 84
johnb 50:f76b7e7959a2 85 /** Destructor */
johnb 50:f76b7e7959a2 86 virtual ~XBeeDeviceRemoteAt( void );
johnb 51:a7d0d2ef9261 87
johnb 53:7b65422d7a32 88 /** Control whether or not changes are applied when the command is sent or not.
johnb 53:7b65422d7a32 89 There are three possibilities for appling changes on the remote:
johnb 53:7b65422d7a32 90 1) Use this method, specifying a 'true' parameter so that changes are applied as soon as a command is sent
johnb 53:7b65422d7a32 91 2) Use requestApplyChanges() to apply all pending changes
johnb 53:7b65422d7a32 92 3) Use requestWriteSettings() followed by requestReset() to write the settings to non-volatile memory and reset the device
johnb 53:7b65422d7a32 93
johnb 53:7b65422d7a32 94 \param Specified whether or not the settings should be applied when the command is sent to the remote device */
johnb 51:a7d0d2ef9261 95 void setApplyChanges( const bool p_apply );
johnb 55:610aa4a2ed3b 96
johnb 55:610aa4a2ed3b 97 /** Set the type of addressing used for transmitted frames to the remote XBee. If specifying 16-bit addressing then the
johnb 55:610aa4a2ed3b 98 remote node's 16-bit address must be known. If specifying 64-bit addressing then the remote node's 64-bit address must
johnb 55:610aa4a2ed3b 99 be known. The addresses are learned either by specifying them to the constructor or by successful requests via
johnb 55:610aa4a2ed3b 100 requestSourceAddress (16-bit) or requestSerialNumber (64-bit), or by using reassociate()
johnb 55:610aa4a2ed3b 101
johnb 55:610aa4a2ed3b 102 \param p_type The type of addressing to use for future transmitted frames
johnb 55:610aa4a2ed3b 103 \returns true in the case that the address type was succesfully changed,
johnb 55:610aa4a2ed3b 104 false in the case that the address type could not be changed, either because p_type was not valid
johnb 55:610aa4a2ed3b 105 or because the appropriate address wasn't known */
johnb 55:610aa4a2ed3b 106 bool setAddressingType( const XBeeDevice::XBeeApiAddrType_t p_type );
johnb 55:610aa4a2ed3b 107
johnb 55:610aa4a2ed3b 108 /** Reassociated this object with a new remote XBee (or update the addressing used). Calling this method will reset
johnb 55:610aa4a2ed3b 109 any cached values held within the object associated with the remote XBee's settings.
johnb 55:610aa4a2ed3b 110
johnb 55:610aa4a2ed3b 111 \param p_addr16Bit 16-bit address of the remote XBee (or XBEE_BROADCAST_ADDR for broadcast or XBEE_USE_64BIT_ADDR to use 64-bit addressing (see p_addr64Bit)
johnb 55:610aa4a2ed3b 112 \param p_addr64Bit 64-bit address of the remote XBee, only used in the case that the 16-bit address is XBEE_USE_64BIT_ADDR
johnb 55:610aa4a2ed3b 113 */
johnb 55:610aa4a2ed3b 114 void reassociate( const uint16_t& p_addr16Bit,
johnb 55:610aa4a2ed3b 115 const uint64_t& p_addr64Bit = 0 );
johnb 50:f76b7e7959a2 116 };
johnb 50:f76b7e7959a2 117
johnb 50:f76b7e7959a2 118 #endif