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.
Remote/XBeeDeviceRemoteAt.hpp@53:7b65422d7a32, 2014-07-28 (annotated)
- Committer:
- johnb
- Date:
- Mon Jul 28 13:27:58 2014 +0000
- Revision:
- 53:7b65422d7a32
- Parent:
- 52:0950b05d5270
- Child:
- 55:610aa4a2ed3b
Comments & clean-up
Who changed what in which revision?
User | Revision | Line number | New 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 | 53:7b65422d7a32 | 48 | /* TODO: doc */ |
johnb | 50:f76b7e7959a2 | 49 | virtual void SendCmd_uint8_t( const uint8_t p_frameId, |
johnb | 50:f76b7e7959a2 | 50 | const uint8_t* const p_data, |
johnb | 50:f76b7e7959a2 | 51 | const uint8_t& p_val ); |
johnb | 53:7b65422d7a32 | 52 | /* TODO: doc */ |
johnb | 50:f76b7e7959a2 | 53 | virtual void SendCmd_uint16_t( const uint8_t p_frameId, |
johnb | 50:f76b7e7959a2 | 54 | const uint8_t* const p_data, |
johnb | 50:f76b7e7959a2 | 55 | const uint16_t& p_val ); |
johnb | 53:7b65422d7a32 | 56 | /* TODO: doc */ |
johnb | 51:a7d0d2ef9261 | 57 | virtual void SendCmd_uint32_t( const uint8_t p_frameId, |
johnb | 51:a7d0d2ef9261 | 58 | const uint8_t* const p_data, |
johnb | 51:a7d0d2ef9261 | 59 | const uint32_t& p_val ); |
johnb | 53:7b65422d7a32 | 60 | /* TODO: doc */ |
johnb | 50:f76b7e7959a2 | 61 | virtual void SendReq( const uint8_t p_frameId, |
johnb | 50:f76b7e7959a2 | 62 | const uint8_t* p_data ); |
johnb | 50:f76b7e7959a2 | 63 | |
johnb | 53:7b65422d7a32 | 64 | /* TODO: doc */ |
johnb | 50:f76b7e7959a2 | 65 | virtual size_t getResponseStatusPos( void ) const; |
johnb | 50:f76b7e7959a2 | 66 | |
johnb | 53:7b65422d7a32 | 67 | /** Keep track of whether we're applying changes when the AT command is sent |
johnb | 53:7b65422d7a32 | 68 | or not */ |
johnb | 51:a7d0d2ef9261 | 69 | bool m_applyChanges; |
johnb | 50:f76b7e7959a2 | 70 | |
johnb | 50:f76b7e7959a2 | 71 | public: |
johnb | 53:7b65422d7a32 | 72 | |
johnb | 53:7b65422d7a32 | 73 | /* TODO: doc */ |
johnb | 50:f76b7e7959a2 | 74 | /** Constructor */ |
johnb | 50:f76b7e7959a2 | 75 | XBeeDeviceRemoteAt( XBeeDevice* p_device, |
johnb | 50:f76b7e7959a2 | 76 | const uint16_t& p_addr16Bit, |
johnb | 51:a7d0d2ef9261 | 77 | const uint64_t& p_addr64Bit = 0, |
johnb | 51:a7d0d2ef9261 | 78 | const bool p_applyChanges = false ); |
johnb | 50:f76b7e7959a2 | 79 | |
johnb | 50:f76b7e7959a2 | 80 | /** Destructor */ |
johnb | 50:f76b7e7959a2 | 81 | virtual ~XBeeDeviceRemoteAt( void ); |
johnb | 51:a7d0d2ef9261 | 82 | |
johnb | 53:7b65422d7a32 | 83 | /** Control whether or not changes are applied when the command is sent or not. |
johnb | 53:7b65422d7a32 | 84 | There are three possibilities for appling changes on the remote: |
johnb | 53:7b65422d7a32 | 85 | 1) Use this method, specifying a 'true' parameter so that changes are applied as soon as a command is sent |
johnb | 53:7b65422d7a32 | 86 | 2) Use requestApplyChanges() to apply all pending changes |
johnb | 53:7b65422d7a32 | 87 | 3) Use requestWriteSettings() followed by requestReset() to write the settings to non-volatile memory and reset the device |
johnb | 53:7b65422d7a32 | 88 | |
johnb | 53:7b65422d7a32 | 89 | \param Specified whether or not the settings should be applied when the command is sent to the remote device */ |
johnb | 51:a7d0d2ef9261 | 90 | void setApplyChanges( const bool p_apply ); |
johnb | 50:f76b7e7959a2 | 91 | }; |
johnb | 50:f76b7e7959a2 | 92 | |
johnb | 50:f76b7e7959a2 | 93 | #endif |