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 Jan 27 21:08:06 2014 +0000
Revision:
3:c3d96b94041a
Documentation & misc changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnb 3:c3d96b94041a 1 /**
johnb 3:c3d96b94041a 2 @file
johnb 3:c3d96b94041a 3 @brief Class to abstract commands send to the XBee API
johnb 3:c3d96b94041a 4
johnb 3:c3d96b94041a 5 @author John Bailey
johnb 3:c3d96b94041a 6
johnb 3:c3d96b94041a 7 @copyright Copyright 2013 John Bailey
johnb 3:c3d96b94041a 8
johnb 3:c3d96b94041a 9 @section LICENSE
johnb 3:c3d96b94041a 10
johnb 3:c3d96b94041a 11 Licensed under the Apache License, Version 2.0 (the "License");
johnb 3:c3d96b94041a 12 you may not use this file except in compliance with the License.
johnb 3:c3d96b94041a 13 You may obtain a copy of the License at
johnb 3:c3d96b94041a 14
johnb 3:c3d96b94041a 15 http://www.apache.org/licenses/LICENSE-2.0
johnb 3:c3d96b94041a 16
johnb 3:c3d96b94041a 17 Unless required by applicable law or agreed to in writing, software
johnb 3:c3d96b94041a 18 distributed under the License is distributed on an "AS IS" BASIS,
johnb 3:c3d96b94041a 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
johnb 3:c3d96b94041a 20 See the License for the specific language governing permissions and
johnb 3:c3d96b94041a 21 limitations under the License.
johnb 3:c3d96b94041a 22
johnb 3:c3d96b94041a 23 */
johnb 3:c3d96b94041a 24
johnb 3:c3d96b94041a 25 #if !defined XBEEAPICMD_HPP
johnb 3:c3d96b94041a 26 #define XBEEAPICMD_HPP
johnb 3:c3d96b94041a 27
johnb 3:c3d96b94041a 28 #include <stdint.h>
johnb 3:c3d96b94041a 29 #include <stddef.h> // for size_t
johnb 3:c3d96b94041a 30
johnb 3:c3d96b94041a 31 typedef enum
johnb 3:c3d96b94041a 32 {
johnb 3:c3d96b94041a 33 XBEE_CMD_AT_CMD = 0x08,
johnb 3:c3d96b94041a 34 XBEE_CMD_QUEUE_PARAM_VAL = 0x09,
johnb 3:c3d96b94041a 35 XBEE_CMD_AT_RESPONSE = 0x88,
johnb 3:c3d96b94041a 36 XBEE_CMD_MODEM_STATUS = 0x8A,
johnb 3:c3d96b94041a 37 XBEE_CMD_INVALID = 0xFFF
johnb 3:c3d96b94041a 38 } XBeeApiCmdId_e;
johnb 3:c3d96b94041a 39
johnb 3:c3d96b94041a 40 enum
johnb 3:c3d96b94041a 41 {
johnb 3:c3d96b94041a 42 XBEE_CMD_POSN_HEADER = 0x00,
johnb 3:c3d96b94041a 43 XBEE_CMD_POSN_LEN_HI = 0x01,
johnb 3:c3d96b94041a 44 XBEE_CMD_POSN_LEN_LO = 0x02,
johnb 3:c3d96b94041a 45 XBEE_CMD_POSN_API_ID = 0x03
johnb 3:c3d96b94041a 46 };
johnb 3:c3d96b94041a 47
johnb 3:c3d96b94041a 48 #define MSG_LEN_IN_BUFFER( _b ) ((((uint16_t)_b[ XBEE_CMD_POSN_LEN_HI ]) << 8U) + _b[XBEE_CMD_POSN_LEN_LO])
johnb 3:c3d96b94041a 49
johnb 3:c3d96b94041a 50 class XBeeApiFrame
johnb 3:c3d96b94041a 51 {
johnb 3:c3d96b94041a 52 private:
johnb 3:c3d96b94041a 53 static const uint8_t m_cmdHeaderLen = 1;
johnb 3:c3d96b94041a 54
johnb 3:c3d96b94041a 55 protected:
johnb 3:c3d96b94041a 56 XBeeApiCmdId_e m_cmdId;
johnb 3:c3d96b94041a 57 const uint8_t* m_data;
johnb 3:c3d96b94041a 58 uint16_t m_dataLen;
johnb 3:c3d96b94041a 59
johnb 3:c3d96b94041a 60 public:
johnb 3:c3d96b94041a 61 XBeeApiFrame( void );
johnb 3:c3d96b94041a 62
johnb 3:c3d96b94041a 63 uint16_t getCmdLen( void ) const;
johnb 3:c3d96b94041a 64
johnb 3:c3d96b94041a 65 XBeeApiCmdId_e getCmdId( void ) const;
johnb 3:c3d96b94041a 66
johnb 3:c3d96b94041a 67 const uint8_t* getDataPtr( void ) const;
johnb 3:c3d96b94041a 68
johnb 3:c3d96b94041a 69 };
johnb 3:c3d96b94041a 70
johnb 3:c3d96b94041a 71 class XBeeDevice;
johnb 3:c3d96b94041a 72
johnb 3:c3d96b94041a 73 class XBeeApiFrameDecoder
johnb 3:c3d96b94041a 74 {
johnb 3:c3d96b94041a 75 protected:
johnb 3:c3d96b94041a 76 XBeeDevice* m_device;
johnb 3:c3d96b94041a 77
johnb 3:c3d96b94041a 78 public:
johnb 3:c3d96b94041a 79
johnb 3:c3d96b94041a 80 XBeeApiFrameDecoder();
johnb 3:c3d96b94041a 81
johnb 3:c3d96b94041a 82 virtual ~XBeeApiFrameDecoder();
johnb 3:c3d96b94041a 83
johnb 3:c3d96b94041a 84 virtual bool decodeCallback( const uint8_t* const p_data, size_t p_len ) = 0;
johnb 3:c3d96b94041a 85
johnb 3:c3d96b94041a 86 virtual uint8_t getCmdType( void ) const = 0;
johnb 3:c3d96b94041a 87
johnb 3:c3d96b94041a 88 void registerCallback( XBeeDevice* const p_device );
johnb 3:c3d96b94041a 89
johnb 3:c3d96b94041a 90 void unregisterCallback( void );
johnb 3:c3d96b94041a 91 };
johnb 3:c3d96b94041a 92
johnb 3:c3d96b94041a 93 #endif