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:
Sun Jul 13 15:47:40 2014 +0000
Revision:
50:f76b7e7959a2
Parent:
36:cc7e8d1e35dd
Child:
51:a7d0d2ef9261
Add support for Remote AT commands

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnb 8:1b48b619d7f6 1 /**
johnb 8:1b48b619d7f6 2
johnb 8:1b48b619d7f6 3 Copyright 2014 John Bailey
johnb 13:302e7c1ea0b3 4
johnb 8:1b48b619d7f6 5 Licensed under the Apache License, Version 2.0 (the "License");
johnb 8:1b48b619d7f6 6 you may not use this file except in compliance with the License.
johnb 8:1b48b619d7f6 7 You may obtain a copy of the License at
johnb 8:1b48b619d7f6 8
johnb 8:1b48b619d7f6 9 http://www.apache.org/licenses/LICENSE-2.0
johnb 8:1b48b619d7f6 10
johnb 8:1b48b619d7f6 11 Unless required by applicable law or agreed to in writing, software
johnb 8:1b48b619d7f6 12 distributed under the License is distributed on an "AS IS" BASIS,
johnb 8:1b48b619d7f6 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
johnb 8:1b48b619d7f6 14 See the License for the specific language governing permissions and
johnb 8:1b48b619d7f6 15 limitations under the License.
johnb 8:1b48b619d7f6 16
johnb 8:1b48b619d7f6 17 */
johnb 8:1b48b619d7f6 18
johnb 8:1b48b619d7f6 19 #include "XBeeApiCmdAt.hpp"
johnb 8:1b48b619d7f6 20
johnb 8:1b48b619d7f6 21 /* Set of Frame ID codes for the various commands (see XBEE_CMD_POSN_FRAME_ID) */
johnb 8:1b48b619d7f6 22
johnb 13:302e7c1ea0b3 23 #define CMD_RESPONSE_GET_VR '1'
johnb 13:302e7c1ea0b3 24 #define CMD_RESPONSE_GET_HV '2'
johnb 13:302e7c1ea0b3 25 #define CMD_RESPONSE_GET_CH '3'
johnb 13:302e7c1ea0b3 26 #define CMD_RESPONSE_SET_CH '4'
johnb 13:302e7c1ea0b3 27 #define CMD_RESPONSE_SET_CE '5'
johnb 13:302e7c1ea0b3 28 #define CMD_RESPONSE_GET_CE '6'
johnb 13:302e7c1ea0b3 29 #define CMD_RESPONSE_SET_EDA '7'
johnb 13:302e7c1ea0b3 30 #define CMD_RESPONSE_GET_EDA '8'
johnb 13:302e7c1ea0b3 31 #define CMD_RESPONSE_SET_PID '9'
johnb 13:302e7c1ea0b3 32 #define CMD_RESPONSE_GET_PID '0'
johnb 31:c144106e55b5 33 #define CMD_RESPONSE_SET_MY 'a'
johnb 31:c144106e55b5 34 #define CMD_RESPONSE_GET_MY 'b'
johnb 32:af4e495afd62 35 #define CMD_RESPONSE_GET_SH 'c'
johnb 32:af4e495afd62 36 #define CMD_RESPONSE_GET_SL 'd'
johnb 32:af4e495afd62 37 #define CMD_RESPONSE_SET_RR 'e'
johnb 32:af4e495afd62 38 #define CMD_RESPONSE_GET_RR 'f'
johnb 32:af4e495afd62 39 #define CMD_RESPONSE_SET_RN 'g'
johnb 32:af4e495afd62 40 #define CMD_RESPONSE_GET_RN 'h'
johnb 32:af4e495afd62 41 #define CMD_RESPONSE_SET_MM 'i'
johnb 32:af4e495afd62 42 #define CMD_RESPONSE_GET_MM 'j'
johnb 50:f76b7e7959a2 43 #define CMD_RESPONSE_GET_D0 'k'
johnb 50:f76b7e7959a2 44 #define CMD_RESPONSE_GET_D1 'l'
johnb 50:f76b7e7959a2 45 #define CMD_RESPONSE_GET_D2 'm'
johnb 50:f76b7e7959a2 46 #define CMD_RESPONSE_GET_D3 'n'
johnb 50:f76b7e7959a2 47 #define CMD_RESPONSE_GET_D4 'o'
johnb 50:f76b7e7959a2 48 #define CMD_RESPONSE_GET_D5 'p'
johnb 50:f76b7e7959a2 49 #define CMD_RESPONSE_GET_D6 'q'
johnb 50:f76b7e7959a2 50 #define CMD_RESPONSE_GET_D7 'r'
johnb 13:302e7c1ea0b3 51
johnb 30:9532b01a1ae1 52 /** Lowest channel supported by the XBee S1 */
johnb 30:9532b01a1ae1 53 #define XBEE_CHAN_MIN 0x0b
johnb 30:9532b01a1ae1 54 /** Highest channel supported by the XBee S1 */
johnb 30:9532b01a1ae1 55 #define XBEE_CHAN_MAX 0x1a
johnb 13:302e7c1ea0b3 56
johnb 30:9532b01a1ae1 57 /** Lowest channel supported by the XBee S1 Pro */
johnb 30:9532b01a1ae1 58 #define XBEE_PRO_CHAN_MIN 0x0c
johnb 30:9532b01a1ae1 59 /** Highest channel supported by the XBee S1 Pro */
johnb 30:9532b01a1ae1 60 #define XBEE_PRO_CHAN_MAX 0x17
johnb 8:1b48b619d7f6 61
johnb 8:1b48b619d7f6 62 /* Content for the various commands - value of 0 indicates a value to be populated (i.e. variable) */
johnb 8:1b48b619d7f6 63
johnb 50:f76b7e7959a2 64 static const uint8_t cmd_vr[] = { 'V', 'R' };
johnb 50:f76b7e7959a2 65 static const uint8_t cmd_vr_get_fid = CMD_RESPONSE_GET_VR;
johnb 50:f76b7e7959a2 66
johnb 50:f76b7e7959a2 67 static const uint8_t cmd_hv[] = { 'H', 'V' };
johnb 50:f76b7e7959a2 68 static const uint8_t cmd_hv_get_fid = CMD_RESPONSE_GET_HV;
johnb 50:f76b7e7959a2 69
johnb 50:f76b7e7959a2 70 static const uint8_t cmd_sh[] = { 'S', 'H' };
johnb 50:f76b7e7959a2 71 static const uint8_t cmd_sh_get_fid = CMD_RESPONSE_GET_SH;
johnb 50:f76b7e7959a2 72
johnb 50:f76b7e7959a2 73 static const uint8_t cmd_sl[] = { 'S', 'L' };
johnb 50:f76b7e7959a2 74 static const uint8_t cmd_sl_get_fid = CMD_RESPONSE_GET_SL;
johnb 13:302e7c1ea0b3 75
johnb 50:f76b7e7959a2 76 static const uint8_t cmd_ch[] = { 'C', 'H' };
johnb 50:f76b7e7959a2 77 static const uint8_t cmd_ch_get_fid = CMD_RESPONSE_GET_CH;
johnb 50:f76b7e7959a2 78 static const uint8_t cmd_ch_set[] = { 'C', 'H', 0 };
johnb 50:f76b7e7959a2 79 static const uint8_t cmd_ch_set_fid = CMD_RESPONSE_SET_CH;
johnb 50:f76b7e7959a2 80
johnb 50:f76b7e7959a2 81 static const uint8_t cmd_ce[] = { 'C', 'E' };
johnb 50:f76b7e7959a2 82 static const uint8_t cmd_ce_get_fid = CMD_RESPONSE_GET_CE;
johnb 50:f76b7e7959a2 83 static const uint8_t cmd_ce_set[] = { 'C', 'E', 0 };
johnb 50:f76b7e7959a2 84 static const uint8_t cmd_ce_set_fid = CMD_RESPONSE_SET_CE;
johnb 13:302e7c1ea0b3 85
johnb 50:f76b7e7959a2 86 static const uint8_t cmd_eda[] = { 'A', '1' };
johnb 50:f76b7e7959a2 87 static const uint8_t cmd_eda_get_fid = CMD_RESPONSE_GET_EDA;
johnb 50:f76b7e7959a2 88 static const uint8_t cmd_eda_set[] = { 'A', '1', 0 };
johnb 50:f76b7e7959a2 89 static const uint8_t cmd_eda_set_fid = CMD_RESPONSE_SET_EDA;
johnb 32:af4e495afd62 90
johnb 50:f76b7e7959a2 91 static const uint8_t cmd_pid[] = { 'I', 'D' };
johnb 50:f76b7e7959a2 92 static const uint8_t cmd_pid_get_fid = CMD_RESPONSE_GET_PID;
johnb 50:f76b7e7959a2 93 static const uint8_t cmd_pid_set[] = { 'I', 'D', 0, 0 };
johnb 50:f76b7e7959a2 94 static const uint8_t cmd_pid_set_fid = CMD_RESPONSE_SET_PID;
johnb 13:302e7c1ea0b3 95
johnb 50:f76b7e7959a2 96 static const uint8_t cmd_my[] = { 'M', 'Y' };
johnb 50:f76b7e7959a2 97 static const uint8_t cmd_my_get_fid = CMD_RESPONSE_GET_MY;
johnb 50:f76b7e7959a2 98 static const uint8_t cmd_my_set[] = { 'M', 'Y', 0, 0 };
johnb 50:f76b7e7959a2 99 static const uint8_t cmd_my_set_fid = CMD_RESPONSE_SET_MY;
johnb 32:af4e495afd62 100
johnb 50:f76b7e7959a2 101 static const uint8_t cmd_rr[] = { 'R', 'R' };
johnb 50:f76b7e7959a2 102 static const uint8_t cmd_rr_get_fid = CMD_RESPONSE_GET_RR;
johnb 50:f76b7e7959a2 103 static const uint8_t cmd_rr_set[] = { 'R', 'R', 0 };
johnb 50:f76b7e7959a2 104 static const uint8_t cmd_rr_set_fid = CMD_RESPONSE_SET_RR;
johnb 50:f76b7e7959a2 105
johnb 50:f76b7e7959a2 106 static const uint8_t cmd_rn[] = { 'R', 'N' };
johnb 50:f76b7e7959a2 107 static const uint8_t cmd_rn_get_fid = CMD_RESPONSE_GET_RN;
johnb 50:f76b7e7959a2 108 static const uint8_t cmd_rn_set[] = { 'R', 'N', 0 };
johnb 50:f76b7e7959a2 109 static const uint8_t cmd_rn_set_fid = CMD_RESPONSE_SET_RN;
johnb 13:302e7c1ea0b3 110
johnb 50:f76b7e7959a2 111 static const uint8_t cmd_mm[] = { 'M', 'M' };
johnb 50:f76b7e7959a2 112 static const uint8_t cmd_mm_get_fid = CMD_RESPONSE_GET_MM;
johnb 50:f76b7e7959a2 113 static const uint8_t cmd_mm_set[] = { 'M', 'M', 0 };
johnb 50:f76b7e7959a2 114 static const uint8_t cmd_mm_set_fid = CMD_RESPONSE_SET_MM;
johnb 8:1b48b619d7f6 115
johnb 50:f76b7e7959a2 116 static const uint8_t cmd_d[ XBEE_API_DIO_CHANNEL_COUNT ][2] = {{ 'D', '0' },
johnb 50:f76b7e7959a2 117 { 'D', '1' },
johnb 50:f76b7e7959a2 118 { 'D', '2' },
johnb 50:f76b7e7959a2 119 { 'D', '3' },
johnb 50:f76b7e7959a2 120 { 'D', '4' },
johnb 50:f76b7e7959a2 121 { 'D', '5' },
johnb 50:f76b7e7959a2 122 { 'D', '6' },
johnb 50:f76b7e7959a2 123 { 'D', '7' }};
johnb 50:f76b7e7959a2 124 static const uint8_t cmd_d_get_fid[ XBEE_API_DIO_CHANNEL_COUNT ] = { CMD_RESPONSE_GET_D0,
johnb 50:f76b7e7959a2 125 CMD_RESPONSE_GET_D1,
johnb 50:f76b7e7959a2 126 CMD_RESPONSE_GET_D2,
johnb 50:f76b7e7959a2 127 CMD_RESPONSE_GET_D3,
johnb 50:f76b7e7959a2 128 CMD_RESPONSE_GET_D4,
johnb 50:f76b7e7959a2 129 CMD_RESPONSE_GET_D5,
johnb 50:f76b7e7959a2 130 CMD_RESPONSE_GET_D6,
johnb 50:f76b7e7959a2 131 CMD_RESPONSE_GET_D7 };
johnb 31:c144106e55b5 132
johnb 50:f76b7e7959a2 133 #define XBEE_CMD_POSN_FRAME_ID XBEE_CMD_POSN_ID_SPECIFIC_DATA
johnb 13:302e7c1ea0b3 134 #define XBEE_CMD_POSN_STATUS (7U)
johnb 8:1b48b619d7f6 135 #define XBEE_CMD_POSN_PARAM_START (8U)
johnb 8:1b48b619d7f6 136
johnb 13:302e7c1ea0b3 137 #define XBEE_CMD_RESPONS_HAS_DATA( _p_len ) ((_p_len > ( XBEE_CMD_POSN_PARAM_START + 1 ))
johnb 13:302e7c1ea0b3 138
johnb 50:f76b7e7959a2 139 /** Template class to create an XBeeApiFrame which can be used to change
johnb 50:f76b7e7959a2 140 the value of one of the XBee parameters. This class is used by the
johnb 50:f76b7e7959a2 141 setXXX methods in XBeeApiCmdAt */
johnb 50:f76b7e7959a2 142 template< typename T >
johnb 50:f76b7e7959a2 143 class XBeeApiCmdAtSet : public XBeeApiFrame {
johnb 50:f76b7e7959a2 144 uint8_t m_buffer[ XBEE_API_CMD_SET_HEADER_LEN + sizeof( T ) ];
johnb 50:f76b7e7959a2 145 public:
johnb 50:f76b7e7959a2 146 /** Constructor
johnb 50:f76b7e7959a2 147
johnb 50:f76b7e7959a2 148 \param p_data Pointer to a buffer of length 2 bytes identifying
johnb 50:f76b7e7959a2 149 the command, e.g. 'V', 'R' would set up a version
johnb 50:f76b7e7959a2 150 request
johnb 50:f76b7e7959a2 151 \param p_val New value for the parameter
johnb 50:f76b7e7959a2 152 */
johnb 50:f76b7e7959a2 153 XBeeApiCmdAtSet( const uint8_t p_frameId,
johnb 50:f76b7e7959a2 154 const uint8_t* const p_data,
johnb 50:f76b7e7959a2 155 const T p_val );
johnb 50:f76b7e7959a2 156 /** Destructor */
johnb 50:f76b7e7959a2 157 virtual ~XBeeApiCmdAtSet();
johnb 50:f76b7e7959a2 158 };
johnb 50:f76b7e7959a2 159
johnb 50:f76b7e7959a2 160 class XBeeApiCmdAtReq : public XBeeApiFrame {
johnb 50:f76b7e7959a2 161 uint8_t m_buffer[ XBEE_API_CMD_REQ_HEADER_LEN ];
johnb 50:f76b7e7959a2 162 public:
johnb 50:f76b7e7959a2 163 /** Constructor
johnb 50:f76b7e7959a2 164
johnb 50:f76b7e7959a2 165 \param p_data Pointer to a buffer of length 2 bytes identifying
johnb 50:f76b7e7959a2 166 the command, e.g. 'V', 'R' would set up a version
johnb 50:f76b7e7959a2 167 request
johnb 50:f76b7e7959a2 168 \param p_val New value for the parameter
johnb 50:f76b7e7959a2 169 */
johnb 50:f76b7e7959a2 170 XBeeApiCmdAtReq( const uint8_t p_frameId,
johnb 50:f76b7e7959a2 171 const uint8_t* const p_data );
johnb 50:f76b7e7959a2 172 /** Destructor */
johnb 50:f76b7e7959a2 173 virtual ~XBeeApiCmdAtReq();
johnb 50:f76b7e7959a2 174 };
johnb 50:f76b7e7959a2 175
johnb 29:c6d037cceb02 176 XBeeApiCmdAt::XBeeApiCmdAt( XBeeDevice* const p_device ) : XBeeApiFrameDecoder( p_device ) ,
johnb 31:c144106e55b5 177 m_have_hwVer( false ),
johnb 31:c144106e55b5 178 m_have_fwVer( false ),
johnb 31:c144106e55b5 179 m_have_chan( false ),
johnb 31:c144106e55b5 180 m_have_PANId( false ),
johnb 31:c144106e55b5 181 m_have_EDA( false ),
johnb 31:c144106e55b5 182 m_have_CE( false ),
johnb 32:af4e495afd62 183 m_have_sourceAddress( false ),
johnb 32:af4e495afd62 184 m_have_snLow( false ),
johnb 32:af4e495afd62 185 m_have_snHigh( false ),
johnb 32:af4e495afd62 186 m_have_retries( false ),
johnb 32:af4e495afd62 187 m_have_randomDelaySlots( false ),
johnb 32:af4e495afd62 188 m_have_macMode( false )
johnb 8:1b48b619d7f6 189 {
johnb 8:1b48b619d7f6 190 }
johnb 8:1b48b619d7f6 191
johnb 32:af4e495afd62 192 #define PROCESS_SET_GET_RESPONSE_GENERIC( _type, _var, _src, _t ) \
johnb 32:af4e495afd62 193 case CMD_RESPONSE_SET_ ## _type: \
johnb 32:af4e495afd62 194 case CMD_RESPONSE_GET_ ## _type: \
johnb 50:f76b7e7959a2 195 if( p_data[ statusPosn ] == 0 ) \
johnb 32:af4e495afd62 196 { \
johnb 50:f76b7e7959a2 197 if( CMD_RESPONSE_GET_ ## _type == p_data[ XBEE_CMD_POSN_FRAME_ID ] ) \
johnb 32:af4e495afd62 198 { \
johnb 32:af4e495afd62 199 m_ ##_var = (_t) (_src); \
johnb 32:af4e495afd62 200 } \
johnb 32:af4e495afd62 201 else \
johnb 32:af4e495afd62 202 { \
johnb 32:af4e495afd62 203 m_ ## _var = m_ ## _var ## Pend; \
johnb 32:af4e495afd62 204 } \
johnb 32:af4e495afd62 205 m_have_ ## _var = true; \
johnb 32:af4e495afd62 206 } \
johnb 32:af4e495afd62 207 else \
johnb 32:af4e495afd62 208 { \
johnb 32:af4e495afd62 209 /* TODO */ \
johnb 32:af4e495afd62 210 } \
johnb 32:af4e495afd62 211 ret_val = true; \
johnb 32:af4e495afd62 212 break;
johnb 32:af4e495afd62 213
johnb 32:af4e495afd62 214 #define PROCESS_GET_RESPONSE_GENERIC( _type, _var, _src ) \
johnb 32:af4e495afd62 215 case CMD_RESPONSE_GET_ ## _type: \
johnb 50:f76b7e7959a2 216 if( p_data[ statusPosn ] == 0 ) \
johnb 32:af4e495afd62 217 { \
johnb 32:af4e495afd62 218 m_ ##_var = _src; \
johnb 32:af4e495afd62 219 m_have_ ## _var = true; \
johnb 32:af4e495afd62 220 } \
johnb 32:af4e495afd62 221 else \
johnb 32:af4e495afd62 222 { \
johnb 32:af4e495afd62 223 /* TODO */ \
johnb 32:af4e495afd62 224 } \
johnb 32:af4e495afd62 225 ret_val = true; \
johnb 32:af4e495afd62 226 break;
johnb 32:af4e495afd62 227
johnb 50:f76b7e7959a2 228 #define PROCESS_SET_GET_RESPONSE_8BIT_WITHCAST( _type, _var, _t ) PROCESS_SET_GET_RESPONSE_GENERIC( _type, _var, p_data[ dataPosn ], _t )
johnb 50:f76b7e7959a2 229 #define PROCESS_SET_GET_RESPONSE_8BIT( _type, _var ) PROCESS_SET_GET_RESPONSE_GENERIC( _type, _var, p_data[ dataPosn ], uint8_t )
johnb 50:f76b7e7959a2 230 #define PROCESS_SET_GET_RESPONSE_16BIT( _type, _var ) PROCESS_SET_GET_RESPONSE_GENERIC( _type, _var, ((uint16_t)p_data[ dataPosn ] << 8) | p_data[ dataPosn + 1 ], uint16_t )
johnb 50:f76b7e7959a2 231
johnb 50:f76b7e7959a2 232 #define PROCESS_GET_RESPONSE_16BIT( _type, _var ) PROCESS_GET_RESPONSE_GENERIC( _type, _var, ((uint16_t)p_data[ dataPosn ] << 8) | p_data[ dataPosn + 1 ] )
johnb 50:f76b7e7959a2 233 #define PROCESS_GET_RESPONSE_32BIT( _type, _var ) PROCESS_GET_RESPONSE_GENERIC( _type, _var, ((uint32_t)p_data[ dataPosn ] << 24) |\
johnb 50:f76b7e7959a2 234 ((uint32_t)p_data[ dataPosn + 1 ] << 16) |\
johnb 50:f76b7e7959a2 235 ((uint32_t)p_data[ dataPosn + 2 ] << 8) |\
johnb 50:f76b7e7959a2 236 ((uint32_t)p_data[ dataPosn + 3 ]))
johnb 50:f76b7e7959a2 237
johnb 50:f76b7e7959a2 238 size_t XBeeApiCmdAt::getResponseStatusPos( void ) const
johnb 50:f76b7e7959a2 239 {
johnb 50:f76b7e7959a2 240 return XBEE_CMD_POSN_STATUS;
johnb 50:f76b7e7959a2 241 }
johnb 32:af4e495afd62 242
johnb 50:f76b7e7959a2 243 bool XBeeApiCmdAt::processResponseFrame( const uint8_t* const p_data, size_t p_len )
johnb 50:f76b7e7959a2 244 {
johnb 50:f76b7e7959a2 245 bool ret_val = false;
johnb 50:f76b7e7959a2 246 size_t statusPosn = getResponseStatusPos();
johnb 50:f76b7e7959a2 247 size_t dataPosn = statusPosn + 1;
johnb 50:f76b7e7959a2 248
johnb 50:f76b7e7959a2 249 switch( p_data[ XBEE_CMD_POSN_FRAME_ID ] )
johnb 50:f76b7e7959a2 250 {
johnb 50:f76b7e7959a2 251
johnb 50:f76b7e7959a2 252 PROCESS_GET_RESPONSE_16BIT( HV, hwVer )
johnb 50:f76b7e7959a2 253 PROCESS_GET_RESPONSE_16BIT( VR, fwVer )
johnb 50:f76b7e7959a2 254
johnb 50:f76b7e7959a2 255 PROCESS_SET_GET_RESPONSE_8BIT( CH, chan )
johnb 50:f76b7e7959a2 256 PROCESS_SET_GET_RESPONSE_8BIT( CE, CE )
johnb 50:f76b7e7959a2 257 PROCESS_SET_GET_RESPONSE_16BIT( PID, PANId )
johnb 50:f76b7e7959a2 258 PROCESS_SET_GET_RESPONSE_8BIT( EDA, EDA )
johnb 50:f76b7e7959a2 259 PROCESS_SET_GET_RESPONSE_8BIT( RR, retries )
johnb 50:f76b7e7959a2 260 PROCESS_SET_GET_RESPONSE_16BIT( MY, sourceAddress )
johnb 50:f76b7e7959a2 261 PROCESS_GET_RESPONSE_32BIT( SH, snHigh )
johnb 50:f76b7e7959a2 262 PROCESS_GET_RESPONSE_32BIT( SL, snLow )
johnb 50:f76b7e7959a2 263 PROCESS_SET_GET_RESPONSE_8BIT( RN, randomDelaySlots )
johnb 50:f76b7e7959a2 264 PROCESS_SET_GET_RESPONSE_8BIT_WITHCAST( MM, macMode, XBeeApiMACMode_e )
johnb 50:f76b7e7959a2 265 /* TODO: Add D0, D1, D2 response handling */
johnb 50:f76b7e7959a2 266 }
johnb 32:af4e495afd62 267
johnb 50:f76b7e7959a2 268 return ret_val;
johnb 50:f76b7e7959a2 269 }
johnb 32:af4e495afd62 270
johnb 8:1b48b619d7f6 271 bool XBeeApiCmdAt::decodeCallback( const uint8_t* const p_data, size_t p_len )
johnb 8:1b48b619d7f6 272 {
johnb 8:1b48b619d7f6 273 bool ret_val = false;
johnb 13:302e7c1ea0b3 274
johnb 50:f76b7e7959a2 275 if( XBEE_CMD_AT_RESPONSE == p_data[ XBEE_CMD_POSN_API_ID ] )
johnb 50:f76b7e7959a2 276 {
johnb 50:f76b7e7959a2 277 ret_val = processResponseFrame( p_data, p_len );
johnb 8:1b48b619d7f6 278 }
johnb 8:1b48b619d7f6 279 return ret_val;
johnb 8:1b48b619d7f6 280 }
johnb 8:1b48b619d7f6 281
johnb 8:1b48b619d7f6 282 bool XBeeApiCmdAt::setChannel( uint8_t const p_chan )
johnb 8:1b48b619d7f6 283 {
johnb 29:c6d037cceb02 284 bool ret_val = false;
johnb 29:c6d037cceb02 285
johnb 29:c6d037cceb02 286 if((( m_device->getXBeeModel() == XBeeDevice::XBEEDEVICE_S1 ) &&
johnb 29:c6d037cceb02 287 ( p_chan >= XBEE_CHAN_MIN ) &&
johnb 29:c6d037cceb02 288 ( p_chan <= XBEE_CHAN_MAX )) ||
johnb 29:c6d037cceb02 289 (( m_device->getXBeeModel() == XBeeDevice::XBEEDEVICE_S1_PRO ) &&
johnb 29:c6d037cceb02 290 ( p_chan >= XBEE_PRO_CHAN_MIN ) &&
johnb 29:c6d037cceb02 291 ( p_chan <= XBEE_PRO_CHAN_MAX )))
johnb 29:c6d037cceb02 292 {
johnb 29:c6d037cceb02 293 m_chanPend = p_chan;
johnb 50:f76b7e7959a2 294 SendCmd_uint8_t( cmd_ch_set_fid, cmd_ch_set, p_chan );
johnb 29:c6d037cceb02 295 ret_val = true;
johnb 29:c6d037cceb02 296 }
johnb 29:c6d037cceb02 297 return ret_val;
johnb 8:1b48b619d7f6 298 }
johnb 8:1b48b619d7f6 299
johnb 50:f76b7e7959a2 300 void XBeeApiCmdAt::SendReq( const uint8_t p_frameId,
johnb 50:f76b7e7959a2 301 const uint8_t* p_data )
johnb 50:f76b7e7959a2 302 {
johnb 50:f76b7e7959a2 303 XBeeApiCmdAtReq req( p_frameId, p_data );
johnb 50:f76b7e7959a2 304 m_device->SendFrame( &req );
johnb 50:f76b7e7959a2 305 }
johnb 50:f76b7e7959a2 306
johnb 50:f76b7e7959a2 307
johnb 31:c144106e55b5 308 #define MAKE_REQUEST( _name, _mnemonic, _cmd ) \
johnb 31:c144106e55b5 309 bool XBeeApiCmdAt::request ## _name( void ) \
johnb 31:c144106e55b5 310 {\
johnb 50:f76b7e7959a2 311 m_have_ ## _mnemonic = false; \
johnb 50:f76b7e7959a2 312 SendReq( _cmd ## _get_fid, _cmd ); \
johnb 31:c144106e55b5 313 return true;\
johnb 8:1b48b619d7f6 314 }
johnb 8:1b48b619d7f6 315
johnb 50:f76b7e7959a2 316 MAKE_REQUEST( HardwareVersion, hwVer, cmd_hv )
johnb 50:f76b7e7959a2 317 MAKE_REQUEST( FirmwareVersion, fwVer, cmd_vr )
johnb 50:f76b7e7959a2 318 MAKE_REQUEST( Channel, chan, cmd_ch )
johnb 50:f76b7e7959a2 319 MAKE_REQUEST( PanId, PANId, cmd_pid )
johnb 50:f76b7e7959a2 320 MAKE_REQUEST( CoordinatorEnabled, CE, cmd_ce )
johnb 50:f76b7e7959a2 321 MAKE_REQUEST( EndDeviceAssociationEnabled, EDA, cmd_eda )
johnb 50:f76b7e7959a2 322 MAKE_REQUEST( SourceAddress, sourceAddress, cmd_my )
johnb 50:f76b7e7959a2 323 MAKE_REQUEST( Retries, retries, cmd_rr )
johnb 50:f76b7e7959a2 324 MAKE_REQUEST( RandomDelaySlots, randomDelaySlots, cmd_rn )
johnb 50:f76b7e7959a2 325 MAKE_REQUEST( MacMode, macMode, cmd_mm );
johnb 50:f76b7e7959a2 326 MAKE_REQUEST( SerialNumberHigh, snHigh, cmd_sh );
johnb 50:f76b7e7959a2 327 MAKE_REQUEST( SerialNumberLow, snLow, cmd_sl );
johnb 32:af4e495afd62 328
johnb 32:af4e495afd62 329 bool XBeeApiCmdAt::requestSerialNumber( void )
johnb 32:af4e495afd62 330 {
johnb 50:f76b7e7959a2 331 requestSerialNumberHigh();
johnb 50:f76b7e7959a2 332 requestSerialNumberLow();
johnb 32:af4e495afd62 333 return true;
johnb 32:af4e495afd62 334 }
johnb 8:1b48b619d7f6 335
johnb 50:f76b7e7959a2 336 bool XBeeApiCmdAt::requestDioConfig( const uint8_t p_chanNo )
johnb 50:f76b7e7959a2 337 {
johnb 50:f76b7e7959a2 338 bool ret_val = false;
johnb 50:f76b7e7959a2 339 if( p_chanNo < XBEE_API_DIO_CHANNEL_COUNT )
johnb 50:f76b7e7959a2 340 {
johnb 50:f76b7e7959a2 341 m_have_d[ p_chanNo ] = false;
johnb 50:f76b7e7959a2 342 SendReq( cmd_d_get_fid[ p_chanNo ], cmd_d[ p_chanNo ] );
johnb 50:f76b7e7959a2 343 ret_val = true;
johnb 50:f76b7e7959a2 344 }
johnb 50:f76b7e7959a2 345 return ret_val;
johnb 50:f76b7e7959a2 346 }
johnb 50:f76b7e7959a2 347
johnb 50:f76b7e7959a2 348
johnb 31:c144106e55b5 349 #define MAKE_GET(_name, _mnemonic, _type ) \
johnb 31:c144106e55b5 350 bool XBeeApiCmdAt::get ## _name( _type* const p_param ) \
johnb 31:c144106e55b5 351 {\
johnb 31:c144106e55b5 352 if( m_have_ ## _mnemonic ) {\
johnb 31:c144106e55b5 353 *p_param = m_ ## _mnemonic;\
johnb 31:c144106e55b5 354 } \
johnb 31:c144106e55b5 355 return m_have_ ## _mnemonic; \
johnb 13:302e7c1ea0b3 356 }
johnb 13:302e7c1ea0b3 357
johnb 50:f76b7e7959a2 358 MAKE_GET( FirmwareVersion, fwVer, uint16_t )
johnb 50:f76b7e7959a2 359 MAKE_GET( HardwareVersion, hwVer, uint16_t )
johnb 50:f76b7e7959a2 360 MAKE_GET( Channel, chan, uint8_t )
johnb 50:f76b7e7959a2 361 MAKE_GET( CoordinatorEnabled, CE, bool )
johnb 50:f76b7e7959a2 362 MAKE_GET( EndDeviceAssociationEnabled, EDA, bool )
johnb 50:f76b7e7959a2 363 MAKE_GET( PanId, PANId, panId_t )
johnb 50:f76b7e7959a2 364 MAKE_GET( SourceAddress, sourceAddress, uint16_t )
johnb 50:f76b7e7959a2 365 MAKE_GET( Retries, retries, uint8_t )
johnb 50:f76b7e7959a2 366 MAKE_GET( RandomDelaySlots, randomDelaySlots, uint8_t )
johnb 50:f76b7e7959a2 367 MAKE_GET( MacMode, macMode, XBeeApiMACMode_e )
johnb 32:af4e495afd62 368
johnb 32:af4e495afd62 369 bool XBeeApiCmdAt::getSerialNumber( uint64_t* const p_sn )
johnb 32:af4e495afd62 370 {
johnb 32:af4e495afd62 371 /* Need both halves to have the complete serial number */
johnb 32:af4e495afd62 372 bool have_sn = m_have_snLow && m_have_snHigh;
johnb 32:af4e495afd62 373 if( have_sn )
johnb 32:af4e495afd62 374 {
johnb 32:af4e495afd62 375 *p_sn = m_snHigh;
johnb 32:af4e495afd62 376 *p_sn = *p_sn << 32U;
johnb 32:af4e495afd62 377 *p_sn |= m_snLow;
johnb 32:af4e495afd62 378 }
johnb 32:af4e495afd62 379 return( have_sn );
johnb 32:af4e495afd62 380 }
johnb 25:db6874b7ac4b 381
johnb 50:f76b7e7959a2 382 bool XBeeApiCmdAt::getDioConfig( const uint8_t p_chanNo, XBeeApiDioConfig_e* const p_conf )
johnb 50:f76b7e7959a2 383 {
johnb 50:f76b7e7959a2 384 bool ret_val = false;
johnb 50:f76b7e7959a2 385 if( p_chanNo < XBEE_API_DIO_CHANNEL_COUNT )
johnb 50:f76b7e7959a2 386 {
johnb 50:f76b7e7959a2 387 if( m_have_d[ p_chanNo ] )
johnb 50:f76b7e7959a2 388 {
johnb 50:f76b7e7959a2 389 *p_conf = m_d[ p_chanNo ];
johnb 50:f76b7e7959a2 390 ret_val = true;
johnb 50:f76b7e7959a2 391 }
johnb 50:f76b7e7959a2 392 }
johnb 50:f76b7e7959a2 393 return ret_val;
johnb 50:f76b7e7959a2 394 }
johnb 50:f76b7e7959a2 395
johnb 50:f76b7e7959a2 396 #define MAKE_SET( _name, _mnemonic, _cmd, _type, _transmit_type ) \
johnb 31:c144106e55b5 397 bool XBeeApiCmdAt::set ## _name( const _type p_param ) \
johnb 31:c144106e55b5 398 {\
johnb 31:c144106e55b5 399 m_have_ ## _mnemonic = false;\
johnb 31:c144106e55b5 400 m_## _mnemonic ## Pend = p_param;\
johnb 50:f76b7e7959a2 401 SendCmd_ ## _transmit_type ( _cmd ## _fid, _cmd, p_param ); \
johnb 31:c144106e55b5 402 return true;\
johnb 13:302e7c1ea0b3 403 }
johnb 13:302e7c1ea0b3 404
johnb 50:f76b7e7959a2 405 MAKE_SET( CoordinatorEnabled, CE, cmd_ce_set, bool, uint8_t )
johnb 50:f76b7e7959a2 406 MAKE_SET( EndDeviceAssociationEnabled, EDA, cmd_eda_set, bool, uint8_t )
johnb 50:f76b7e7959a2 407 MAKE_SET( PanId, PANId, cmd_pid_set, uint16_t, uint16_t )
johnb 50:f76b7e7959a2 408 MAKE_SET( SourceAddress, sourceAddress, cmd_my_set, uint16_t, uint16_t )
johnb 50:f76b7e7959a2 409 MAKE_SET( Retries, retries, cmd_rr_set, uint8_t, uint16_t )
johnb 50:f76b7e7959a2 410 MAKE_SET( RandomDelaySlots, randomDelaySlots, cmd_rn_set, uint8_t, uint16_t )
johnb 50:f76b7e7959a2 411 MAKE_SET( MacMode, macMode, cmd_mm_set, XBeeApiMACMode_e, uint8_t )
johnb 50:f76b7e7959a2 412
johnb 50:f76b7e7959a2 413
johnb 50:f76b7e7959a2 414 bool XBeeApiCmdAt::setDioConfig( const uint8_t p_chanNo, const XBeeApiDioConfig_e p_conf )
johnb 50:f76b7e7959a2 415 {
johnb 50:f76b7e7959a2 416 bool ret_val = false;
johnb 50:f76b7e7959a2 417 if( p_chanNo < XBEE_API_DIO_CHANNEL_COUNT )
johnb 50:f76b7e7959a2 418 {
johnb 50:f76b7e7959a2 419 m_have_d[ p_chanNo ] = false;
johnb 50:f76b7e7959a2 420 m_dPend[ p_chanNo ] = p_conf;
johnb 50:f76b7e7959a2 421 SendCmd_uint8_t( cmd_d_get_fid[ p_chanNo ], cmd_d[ p_chanNo ], p_conf );
johnb 50:f76b7e7959a2 422 }
johnb 50:f76b7e7959a2 423 return ret_val;
johnb 50:f76b7e7959a2 424 }
johnb 50:f76b7e7959a2 425
johnb 50:f76b7e7959a2 426 void XBeeApiCmdAt::SendCmd_uint8_t( const uint8_t p_frameId,
johnb 50:f76b7e7959a2 427 const uint8_t* const p_data,
johnb 50:f76b7e7959a2 428 const uint8_t& p_val )
johnb 50:f76b7e7959a2 429 {
johnb 50:f76b7e7959a2 430 XBeeApiCmdAtSet<uint8_t> req( p_frameId, p_data, p_val );
johnb 50:f76b7e7959a2 431 m_device->SendFrame( &req );
johnb 50:f76b7e7959a2 432 }
johnb 50:f76b7e7959a2 433
johnb 50:f76b7e7959a2 434 void XBeeApiCmdAt::SendCmd_uint16_t( const uint8_t p_frameId,
johnb 50:f76b7e7959a2 435 const uint8_t* const p_data,
johnb 50:f76b7e7959a2 436 const uint16_t& p_val )
johnb 50:f76b7e7959a2 437 {
johnb 50:f76b7e7959a2 438 XBeeApiCmdAtSet<uint16_t> req( p_frameId, p_data, p_val );
johnb 50:f76b7e7959a2 439 m_device->SendFrame( &req );
johnb 50:f76b7e7959a2 440 }
johnb 13:302e7c1ea0b3 441
johnb 29:c6d037cceb02 442 XBeeApiCmdAtBlocking::XBeeApiCmdAtBlocking( XBeeDevice* const p_device, const uint16_t p_timeout, const uint16_t p_slice ) :
johnb 29:c6d037cceb02 443 XBeeApiCmdAt( p_device ),
johnb 13:302e7c1ea0b3 444 m_timeout( p_timeout ),
johnb 13:302e7c1ea0b3 445 m_slice( p_slice )
johnb 8:1b48b619d7f6 446 {
johnb 8:1b48b619d7f6 447 }
johnb 8:1b48b619d7f6 448
johnb 13:302e7c1ea0b3 449 /**
johnb 11:bfcf1356027b 450 Macro to wrap around the "requestXXX" & "getXXX" methods and implement a blocking call.
johnb 11:bfcf1356027b 451 This macro is used as the basis for getXXX functions in XBeeApiCmdAtBlocking.
johnb 8:1b48b619d7f6 452
johnb 13:302e7c1ea0b3 453 Originally looked to achieve this using a template function passing method pointers, however
johnb 13:302e7c1ea0b3 454 there's no way to get a method pointer to the parent class implementation as opposed to the
johnb 13:302e7c1ea0b3 455 implementation in this class, meaning that the result was a recursive method call. The joys of
johnb 11:bfcf1356027b 456 polymorphism.
johnb 13:302e7c1ea0b3 457
johnb 11:bfcf1356027b 458 e.g. We pass a pointer to method getHardwareVersion(). The function receiving the pointer
johnb 11:bfcf1356027b 459 uses it to make a function call. The actual function that's called is (correctly)
johnb 11:bfcf1356027b 460 the one implemented in this class, however what we actually wanted in this case
johnb 11:bfcf1356027b 461 was to call the implementation in the base class. Using static_cast<> doesn't have
johnb 11:bfcf1356027b 462 any effect and taking the address of XBeeApiCmdAt::getHardwareVersion ends up with
johnb 11:bfcf1356027b 463 XBeeApiCmdAtBlocking::getHardwareVersion being called due to polymorphism. */
johnb 11:bfcf1356027b 464 #define BLOCKING_GET( _REQ_FN, _GET_FN, _VAR ) \
johnb 11:bfcf1356027b 465 bool ret_val = false; \
johnb 11:bfcf1356027b 466 \
johnb 11:bfcf1356027b 467 if( _GET_FN( _VAR ) )\
johnb 11:bfcf1356027b 468 {\
johnb 11:bfcf1356027b 469 ret_val = true;\
johnb 11:bfcf1356027b 470 } \
johnb 11:bfcf1356027b 471 else if( _REQ_FN() )\
johnb 11:bfcf1356027b 472 {\
johnb 31:c144106e55b5 473 uint16_t counter = m_timeout; \
johnb 31:c144106e55b5 474 bool cont;\
johnb 11:bfcf1356027b 475 \
johnb 11:bfcf1356027b 476 do{\
johnb 31:c144106e55b5 477 cont = false; \
johnb 11:bfcf1356027b 478 wait_ms( m_slice );\
johnb 11:bfcf1356027b 479 if( _GET_FN( _VAR ) )\
johnb 11:bfcf1356027b 480 {\
johnb 11:bfcf1356027b 481 ret_val = true;\
johnb 11:bfcf1356027b 482 }\
johnb 11:bfcf1356027b 483 else if( counter > m_slice ) {\
johnb 11:bfcf1356027b 484 counter -= m_slice; \
johnb 11:bfcf1356027b 485 cont = true;\
johnb 11:bfcf1356027b 486 } \
johnb 11:bfcf1356027b 487 } while( cont );\
johnb 11:bfcf1356027b 488 }\
johnb 11:bfcf1356027b 489 \
johnb 8:1b48b619d7f6 490 return( ret_val );
johnb 8:1b48b619d7f6 491
johnb 13:302e7c1ea0b3 492 /**
johnb 11:bfcf1356027b 493 Macro to wrap around the "setXXX" & "getXXX" methods and implement a blocking call.
johnb 11:bfcf1356027b 494 This macro is used as the basis for setXXX functions in XBeeApiCmdAtBlocking.
johnb 11:bfcf1356027b 495 */
johnb 11:bfcf1356027b 496 #define BLOCKING_SET( _SET_FN, _GET_FN, _VAR, _TYPE ) \
johnb 11:bfcf1356027b 497 bool ret_val = false; \
johnb 11:bfcf1356027b 498 uint16_t counter = m_timeout; \
johnb 11:bfcf1356027b 499 _TYPE readback; \
johnb 11:bfcf1356027b 500 \
johnb 11:bfcf1356027b 501 if( _SET_FN( _VAR ) )\
johnb 11:bfcf1356027b 502 {\
johnb 31:c144106e55b5 503 bool cont;\
johnb 11:bfcf1356027b 504 \
johnb 11:bfcf1356027b 505 do{\
johnb 31:c144106e55b5 506 cont = false;\
johnb 11:bfcf1356027b 507 wait_ms( m_slice );\
johnb 11:bfcf1356027b 508 if( _GET_FN( &readback ) &&\
johnb 13:302e7c1ea0b3 509 ( readback == _VAR ))\
johnb 11:bfcf1356027b 510 {\
johnb 11:bfcf1356027b 511 ret_val = true;\
johnb 11:bfcf1356027b 512 }\
johnb 11:bfcf1356027b 513 else if( counter > m_slice ) {\
johnb 11:bfcf1356027b 514 counter -= m_slice; \
johnb 11:bfcf1356027b 515 cont = true;\
johnb 11:bfcf1356027b 516 } \
johnb 11:bfcf1356027b 517 } while( cont );\
johnb 11:bfcf1356027b 518 }\
johnb 11:bfcf1356027b 519 \
johnb 11:bfcf1356027b 520 return( ret_val );
johnb 8:1b48b619d7f6 521
johnb 13:302e7c1ea0b3 522
johnb 8:1b48b619d7f6 523 bool XBeeApiCmdAtBlocking::getHardwareVersion( uint16_t* const p_ver )
johnb 8:1b48b619d7f6 524 {
johnb 13:302e7c1ea0b3 525 BLOCKING_GET( XBeeApiCmdAt::requestHardwareVersion,
johnb 13:302e7c1ea0b3 526 XBeeApiCmdAt::getHardwareVersion,
johnb 11:bfcf1356027b 527 p_ver );
johnb 8:1b48b619d7f6 528 }
johnb 8:1b48b619d7f6 529
johnb 8:1b48b619d7f6 530 bool XBeeApiCmdAtBlocking::getFirmwareVersion( uint16_t* const p_ver )
johnb 8:1b48b619d7f6 531 {
johnb 14:edec6cd78ffb 532 BLOCKING_GET( XBeeApiCmdAt::requestFirmwareVersion,
johnb 14:edec6cd78ffb 533 XBeeApiCmdAt::getFirmwareVersion,
johnb 11:bfcf1356027b 534 p_ver );
johnb 8:1b48b619d7f6 535 }
johnb 8:1b48b619d7f6 536
johnb 32:af4e495afd62 537 bool XBeeApiCmdAtBlocking::getSerialNumber( uint64_t* const p_sn )
johnb 32:af4e495afd62 538 {
johnb 32:af4e495afd62 539 BLOCKING_GET( XBeeApiCmdAt::requestSerialNumber,
johnb 32:af4e495afd62 540 XBeeApiCmdAt::getSerialNumber,
johnb 32:af4e495afd62 541 p_sn );
johnb 32:af4e495afd62 542 }
johnb 32:af4e495afd62 543
johnb 8:1b48b619d7f6 544 bool XBeeApiCmdAtBlocking::getChannel( uint8_t* const p_chan )
johnb 8:1b48b619d7f6 545 {
johnb 14:edec6cd78ffb 546 BLOCKING_GET( XBeeApiCmdAt::requestChannel,
johnb 14:edec6cd78ffb 547 XBeeApiCmdAt::getChannel,
johnb 11:bfcf1356027b 548 p_chan );
johnb 8:1b48b619d7f6 549 }
johnb 13:302e7c1ea0b3 550
johnb 8:1b48b619d7f6 551 bool XBeeApiCmdAtBlocking::setChannel( uint8_t const p_chan )
johnb 8:1b48b619d7f6 552 {
johnb 14:edec6cd78ffb 553 BLOCKING_SET( XBeeApiCmdAt::setChannel,
johnb 14:edec6cd78ffb 554 XBeeApiCmdAt::getChannel,
johnb 11:bfcf1356027b 555 p_chan,
johnb 13:302e7c1ea0b3 556 uint8_t );
johnb 13:302e7c1ea0b3 557 }
johnb 13:302e7c1ea0b3 558
johnb 13:302e7c1ea0b3 559 bool XBeeApiCmdAtBlocking::getCoordinatorEnabled( bool* const p_en )
johnb 13:302e7c1ea0b3 560 {
johnb 13:302e7c1ea0b3 561 BLOCKING_GET( XBeeApiCmdAt::requestCoordinatorEnabled,
johnb 13:302e7c1ea0b3 562 XBeeApiCmdAt::getCoordinatorEnabled,
johnb 13:302e7c1ea0b3 563 p_en );
johnb 13:302e7c1ea0b3 564 }
johnb 13:302e7c1ea0b3 565
johnb 13:302e7c1ea0b3 566 bool XBeeApiCmdAtBlocking::setCoordinatorEnabled( const bool p_en )
johnb 13:302e7c1ea0b3 567 {
johnb 14:edec6cd78ffb 568 BLOCKING_SET( XBeeApiCmdAt::setCoordinatorEnabled,
johnb 14:edec6cd78ffb 569 XBeeApiCmdAt::getCoordinatorEnabled,
johnb 13:302e7c1ea0b3 570 p_en,
johnb 13:302e7c1ea0b3 571 bool );
johnb 13:302e7c1ea0b3 572 }
johnb 13:302e7c1ea0b3 573
johnb 13:302e7c1ea0b3 574 bool XBeeApiCmdAtBlocking::getEndDeviceAssociationEnabled( bool* const p_en )
johnb 13:302e7c1ea0b3 575 {
johnb 13:302e7c1ea0b3 576 BLOCKING_GET( XBeeApiCmdAt::requestEndDeviceAssociationEnabled,
johnb 13:302e7c1ea0b3 577 XBeeApiCmdAt::getEndDeviceAssociationEnabled,
johnb 13:302e7c1ea0b3 578 p_en );
johnb 8:1b48b619d7f6 579 }
johnb 8:1b48b619d7f6 580
johnb 13:302e7c1ea0b3 581 bool XBeeApiCmdAtBlocking::setEndDeviceAssociationEnabled( const bool p_en )
johnb 13:302e7c1ea0b3 582 {
johnb 14:edec6cd78ffb 583 BLOCKING_SET( XBeeApiCmdAt::setEndDeviceAssociationEnabled,
johnb 14:edec6cd78ffb 584 XBeeApiCmdAt::getEndDeviceAssociationEnabled,
johnb 13:302e7c1ea0b3 585 p_en,
johnb 13:302e7c1ea0b3 586 bool );
johnb 13:302e7c1ea0b3 587 }
johnb 13:302e7c1ea0b3 588
johnb 13:302e7c1ea0b3 589 bool XBeeApiCmdAtBlocking::getPanId( panId_t* const p_chan )
johnb 13:302e7c1ea0b3 590 {
johnb 13:302e7c1ea0b3 591 BLOCKING_GET( XBeeApiCmdAt::requestPanId,
johnb 13:302e7c1ea0b3 592 XBeeApiCmdAt::getPanId,
johnb 13:302e7c1ea0b3 593 p_chan );
johnb 13:302e7c1ea0b3 594 }
johnb 13:302e7c1ea0b3 595
johnb 13:302e7c1ea0b3 596 bool XBeeApiCmdAtBlocking::setPanId( const panId_t p_chan )
johnb 13:302e7c1ea0b3 597 {
johnb 14:edec6cd78ffb 598 BLOCKING_SET( XBeeApiCmdAt::setPanId,
johnb 14:edec6cd78ffb 599 XBeeApiCmdAt::getPanId,
johnb 13:302e7c1ea0b3 600 p_chan,
johnb 13:302e7c1ea0b3 601 panId_t );
johnb 13:302e7c1ea0b3 602 }
johnb 13:302e7c1ea0b3 603
johnb 31:c144106e55b5 604 bool XBeeApiCmdAtBlocking::getSourceAddress( uint16_t* const p_addr )
johnb 31:c144106e55b5 605 {
johnb 31:c144106e55b5 606 BLOCKING_GET( XBeeApiCmdAt::requestSourceAddress,
johnb 31:c144106e55b5 607 XBeeApiCmdAt::getSourceAddress,
johnb 31:c144106e55b5 608 p_addr );
johnb 31:c144106e55b5 609 }
johnb 31:c144106e55b5 610
johnb 31:c144106e55b5 611 bool XBeeApiCmdAtBlocking::setSourceAddress( const uint16_t p_addr )
johnb 31:c144106e55b5 612 {
johnb 31:c144106e55b5 613 BLOCKING_SET( XBeeApiCmdAt::setSourceAddress,
johnb 31:c144106e55b5 614 XBeeApiCmdAt::getSourceAddress,
johnb 31:c144106e55b5 615 p_addr,
johnb 31:c144106e55b5 616 uint16_t );
johnb 31:c144106e55b5 617 }
johnb 31:c144106e55b5 618
johnb 32:af4e495afd62 619 bool XBeeApiCmdAtBlocking::getRetries( uint8_t* const p_addr )
johnb 32:af4e495afd62 620 {
johnb 32:af4e495afd62 621 BLOCKING_GET( XBeeApiCmdAt::requestRetries,
johnb 32:af4e495afd62 622 XBeeApiCmdAt::getRetries,
johnb 32:af4e495afd62 623 p_addr );
johnb 32:af4e495afd62 624 }
johnb 32:af4e495afd62 625
johnb 32:af4e495afd62 626 bool XBeeApiCmdAtBlocking::setRetries( const uint8_t p_addr )
johnb 32:af4e495afd62 627 {
johnb 32:af4e495afd62 628 BLOCKING_SET( XBeeApiCmdAt::setRetries,
johnb 32:af4e495afd62 629 XBeeApiCmdAt::getRetries,
johnb 32:af4e495afd62 630 p_addr,
johnb 32:af4e495afd62 631 uint8_t );
johnb 32:af4e495afd62 632 }
johnb 32:af4e495afd62 633
johnb 32:af4e495afd62 634 bool XBeeApiCmdAtBlocking::getRandomDelaySlots( uint8_t* const p_addr )
johnb 32:af4e495afd62 635 {
johnb 32:af4e495afd62 636 BLOCKING_GET( XBeeApiCmdAt::requestRandomDelaySlots,
johnb 32:af4e495afd62 637 XBeeApiCmdAt::getRandomDelaySlots,
johnb 32:af4e495afd62 638 p_addr );
johnb 32:af4e495afd62 639 }
johnb 32:af4e495afd62 640
johnb 32:af4e495afd62 641 bool XBeeApiCmdAtBlocking::setRandomDelaySlots( const uint8_t p_addr )
johnb 32:af4e495afd62 642 {
johnb 32:af4e495afd62 643 BLOCKING_SET( XBeeApiCmdAt::setRandomDelaySlots,
johnb 32:af4e495afd62 644 XBeeApiCmdAt::getRandomDelaySlots,
johnb 32:af4e495afd62 645 p_addr,
johnb 32:af4e495afd62 646 uint8_t );
johnb 32:af4e495afd62 647 }
johnb 32:af4e495afd62 648
johnb 32:af4e495afd62 649 bool XBeeApiCmdAtBlocking::getMacMode( XBeeApiMACMode_e* const p_mode )
johnb 32:af4e495afd62 650 {
johnb 32:af4e495afd62 651 BLOCKING_GET( XBeeApiCmdAt::requestMacMode,
johnb 32:af4e495afd62 652 XBeeApiCmdAt::getMacMode,
johnb 32:af4e495afd62 653 p_mode );
johnb 32:af4e495afd62 654 }
johnb 32:af4e495afd62 655
johnb 32:af4e495afd62 656 bool XBeeApiCmdAtBlocking::setMacMode( const XBeeApiMACMode_e p_mode )
johnb 32:af4e495afd62 657 {
johnb 32:af4e495afd62 658 BLOCKING_SET( XBeeApiCmdAt::setMacMode,
johnb 32:af4e495afd62 659 XBeeApiCmdAt::getMacMode,
johnb 32:af4e495afd62 660 p_mode,
johnb 32:af4e495afd62 661 XBeeApiMACMode_e );
johnb 32:af4e495afd62 662 }
johnb 32:af4e495afd62 663
johnb 50:f76b7e7959a2 664 bool XBeeApiCmdAtBlocking::getDioConfig( const uint8_t p_chanNo, XBeeApiDioConfig_e* const p_conf )
johnb 50:f76b7e7959a2 665 {
johnb 50:f76b7e7959a2 666 /* TODO */
johnb 50:f76b7e7959a2 667 return false;
johnb 50:f76b7e7959a2 668 }
johnb 32:af4e495afd62 669
johnb 50:f76b7e7959a2 670 bool XBeeApiCmdAtBlocking::setDioConfig( const uint8_t p_chanNo, const XBeeApiDioConfig_e p_conf )
johnb 50:f76b7e7959a2 671 {
johnb 50:f76b7e7959a2 672 /* TODO */
johnb 50:f76b7e7959a2 673 return false;
johnb 50:f76b7e7959a2 674 }
johnb 31:c144106e55b5 675
johnb 25:db6874b7ac4b 676 template < typename T >
johnb 50:f76b7e7959a2 677 XBeeApiCmdAtSet<T>::XBeeApiCmdAtSet( const uint8_t p_frameId,
johnb 50:f76b7e7959a2 678 const uint8_t* const p_data,
johnb 50:f76b7e7959a2 679 const T p_val ) : XBeeApiFrame( )
johnb 8:1b48b619d7f6 680 {
johnb 25:db6874b7ac4b 681 size_t s;
johnb 25:db6874b7ac4b 682 uint8_t* dest;
johnb 25:db6874b7ac4b 683 const uint8_t* src = (uint8_t*)(&p_val);
johnb 25:db6874b7ac4b 684
johnb 13:302e7c1ea0b3 685 m_apiId = XBEE_CMD_AT_CMD;
johnb 25:db6874b7ac4b 686
johnb 50:f76b7e7959a2 687 m_buffer[0] = p_frameId;
johnb 50:f76b7e7959a2 688 m_buffer[1] = p_data[0];
johnb 50:f76b7e7959a2 689 m_buffer[2] = p_data[1];
johnb 25:db6874b7ac4b 690
johnb 36:cc7e8d1e35dd 691 m_dataLen = sizeof( m_buffer );
johnb 36:cc7e8d1e35dd 692
johnb 36:cc7e8d1e35dd 693 /* TODO: This copy code isn't portable - it's assuming that the data in
johnb 36:cc7e8d1e35dd 694 * p_data is little endian */
johnb 36:cc7e8d1e35dd 695
johnb 36:cc7e8d1e35dd 696 dest = &( m_buffer[ m_dataLen - 1 ] );
johnb 25:db6874b7ac4b 697
johnb 25:db6874b7ac4b 698 for( s = 0;
johnb 25:db6874b7ac4b 699 s < sizeof( T );
johnb 36:cc7e8d1e35dd 700 s++, dest--, src++ ) {
johnb 25:db6874b7ac4b 701 *dest = *src;
johnb 25:db6874b7ac4b 702 }
johnb 25:db6874b7ac4b 703
johnb 50:f76b7e7959a2 704 m_data = m_buffer;
johnb 50:f76b7e7959a2 705 }
johnb 13:302e7c1ea0b3 706
johnb 25:db6874b7ac4b 707 template < typename T >
johnb 50:f76b7e7959a2 708 XBeeApiCmdAtSet<T>::~XBeeApiCmdAtSet()
johnb 50:f76b7e7959a2 709 {
johnb 50:f76b7e7959a2 710 }
johnb 50:f76b7e7959a2 711
johnb 50:f76b7e7959a2 712 XBeeApiCmdAtReq::XBeeApiCmdAtReq( const uint8_t p_frameId,
johnb 50:f76b7e7959a2 713 const uint8_t* const p_data )
johnb 50:f76b7e7959a2 714 {
johnb 50:f76b7e7959a2 715 m_apiId = XBEE_CMD_AT_CMD;
johnb 50:f76b7e7959a2 716
johnb 50:f76b7e7959a2 717 m_buffer[0] = p_frameId;
johnb 50:f76b7e7959a2 718 m_buffer[1] = p_data[0];
johnb 50:f76b7e7959a2 719 m_buffer[2] = p_data[1];
johnb 50:f76b7e7959a2 720
johnb 50:f76b7e7959a2 721 m_dataLen = sizeof( m_buffer );
johnb 50:f76b7e7959a2 722 m_data = m_buffer;
johnb 50:f76b7e7959a2 723 }
johnb 50:f76b7e7959a2 724
johnb 50:f76b7e7959a2 725 XBeeApiCmdAtReq::~XBeeApiCmdAtReq()
johnb 13:302e7c1ea0b3 726 {
johnb 25:db6874b7ac4b 727 }