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 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 51:a7d0d2ef9261 51 #define CMD_RESPONSE_SET_D0 's'
johnb 51:a7d0d2ef9261 52 #define CMD_RESPONSE_SET_D1 't'
johnb 51:a7d0d2ef9261 53 #define CMD_RESPONSE_SET_D2 'u'
johnb 51:a7d0d2ef9261 54 #define CMD_RESPONSE_SET_D3 'v'
johnb 51:a7d0d2ef9261 55 #define CMD_RESPONSE_SET_D4 'w'
johnb 51:a7d0d2ef9261 56 #define CMD_RESPONSE_SET_D5 'x'
johnb 51:a7d0d2ef9261 57 #define CMD_RESPONSE_SET_D6 'y'
johnb 51:a7d0d2ef9261 58 #define CMD_RESPONSE_SET_D7 'z'
johnb 51:a7d0d2ef9261 59 #define CMD_RESPONSE_SET_IC 'A'
johnb 51:a7d0d2ef9261 60 #define CMD_RESPONSE_GET_IC 'B'
johnb 51:a7d0d2ef9261 61 #define CMD_RESPONSE_SET_IO 'C'
johnb 51:a7d0d2ef9261 62 #define CMD_RESPONSE_SET_IR 'D'
johnb 51:a7d0d2ef9261 63 #define CMD_RESPONSE_GET_IR 'E'
johnb 51:a7d0d2ef9261 64 #define CMD_RESPONSE_SET_DH 'F'
johnb 51:a7d0d2ef9261 65 #define CMD_RESPONSE_GET_DH 'G'
johnb 51:a7d0d2ef9261 66 #define CMD_RESPONSE_SET_DL 'H'
johnb 51:a7d0d2ef9261 67 #define CMD_RESPONSE_GET_DL 'I'
johnb 51:a7d0d2ef9261 68 #define CMD_RESPONSE_SET_WR 'J'
johnb 51:a7d0d2ef9261 69 #define CMD_RESPONSE_SET_AC 'K'
johnb 51:a7d0d2ef9261 70 #define CMD_RESPONSE_SET_FR 'L'
johnb 51:a7d0d2ef9261 71 #define CMD_RESPONSE_SET_IS 'M'
johnb 55:610aa4a2ed3b 72 #define CMD_RESPONSE_SET_RE 'N'
johnb 56:7fe74b03e6b1 73 #define CMD_RESPONSE_SET_KY 'O'
johnb 56:7fe74b03e6b1 74 #define CMD_RESPONSE_GET_EE 'P'
johnb 56:7fe74b03e6b1 75 #define CMD_RESPONSE_SET_EE 'Q'
johnb 13:302e7c1ea0b3 76
johnb 30:9532b01a1ae1 77 /** Lowest channel supported by the XBee S1 */
johnb 30:9532b01a1ae1 78 #define XBEE_CHAN_MIN 0x0b
johnb 30:9532b01a1ae1 79 /** Highest channel supported by the XBee S1 */
johnb 30:9532b01a1ae1 80 #define XBEE_CHAN_MAX 0x1a
johnb 13:302e7c1ea0b3 81
johnb 30:9532b01a1ae1 82 /** Lowest channel supported by the XBee S1 Pro */
johnb 30:9532b01a1ae1 83 #define XBEE_PRO_CHAN_MIN 0x0c
johnb 30:9532b01a1ae1 84 /** Highest channel supported by the XBee S1 Pro */
johnb 30:9532b01a1ae1 85 #define XBEE_PRO_CHAN_MAX 0x17
johnb 8:1b48b619d7f6 86
johnb 8:1b48b619d7f6 87 /* Content for the various commands - value of 0 indicates a value to be populated (i.e. variable) */
johnb 8:1b48b619d7f6 88
johnb 50:f76b7e7959a2 89 static const uint8_t cmd_vr[] = { 'V', 'R' };
johnb 50:f76b7e7959a2 90 static const uint8_t cmd_vr_get_fid = CMD_RESPONSE_GET_VR;
johnb 50:f76b7e7959a2 91
johnb 50:f76b7e7959a2 92 static const uint8_t cmd_hv[] = { 'H', 'V' };
johnb 50:f76b7e7959a2 93 static const uint8_t cmd_hv_get_fid = CMD_RESPONSE_GET_HV;
johnb 50:f76b7e7959a2 94
johnb 50:f76b7e7959a2 95 static const uint8_t cmd_sh[] = { 'S', 'H' };
johnb 50:f76b7e7959a2 96 static const uint8_t cmd_sh_get_fid = CMD_RESPONSE_GET_SH;
johnb 50:f76b7e7959a2 97
johnb 50:f76b7e7959a2 98 static const uint8_t cmd_sl[] = { 'S', 'L' };
johnb 50:f76b7e7959a2 99 static const uint8_t cmd_sl_get_fid = CMD_RESPONSE_GET_SL;
johnb 13:302e7c1ea0b3 100
johnb 50:f76b7e7959a2 101 static const uint8_t cmd_ch[] = { 'C', 'H' };
johnb 50:f76b7e7959a2 102 static const uint8_t cmd_ch_get_fid = CMD_RESPONSE_GET_CH;
johnb 50:f76b7e7959a2 103 static const uint8_t cmd_ch_set[] = { 'C', 'H', 0 };
johnb 50:f76b7e7959a2 104 static const uint8_t cmd_ch_set_fid = CMD_RESPONSE_SET_CH;
johnb 50:f76b7e7959a2 105
johnb 50:f76b7e7959a2 106 static const uint8_t cmd_ce[] = { 'C', 'E' };
johnb 50:f76b7e7959a2 107 static const uint8_t cmd_ce_get_fid = CMD_RESPONSE_GET_CE;
johnb 50:f76b7e7959a2 108 static const uint8_t cmd_ce_set[] = { 'C', 'E', 0 };
johnb 50:f76b7e7959a2 109 static const uint8_t cmd_ce_set_fid = CMD_RESPONSE_SET_CE;
johnb 13:302e7c1ea0b3 110
johnb 50:f76b7e7959a2 111 static const uint8_t cmd_eda[] = { 'A', '1' };
johnb 50:f76b7e7959a2 112 static const uint8_t cmd_eda_get_fid = CMD_RESPONSE_GET_EDA;
johnb 50:f76b7e7959a2 113 static const uint8_t cmd_eda_set[] = { 'A', '1', 0 };
johnb 50:f76b7e7959a2 114 static const uint8_t cmd_eda_set_fid = CMD_RESPONSE_SET_EDA;
johnb 32:af4e495afd62 115
johnb 50:f76b7e7959a2 116 static const uint8_t cmd_pid[] = { 'I', 'D' };
johnb 50:f76b7e7959a2 117 static const uint8_t cmd_pid_get_fid = CMD_RESPONSE_GET_PID;
johnb 50:f76b7e7959a2 118 static const uint8_t cmd_pid_set[] = { 'I', 'D', 0, 0 };
johnb 50:f76b7e7959a2 119 static const uint8_t cmd_pid_set_fid = CMD_RESPONSE_SET_PID;
johnb 13:302e7c1ea0b3 120
johnb 50:f76b7e7959a2 121 static const uint8_t cmd_my[] = { 'M', 'Y' };
johnb 50:f76b7e7959a2 122 static const uint8_t cmd_my_get_fid = CMD_RESPONSE_GET_MY;
johnb 50:f76b7e7959a2 123 static const uint8_t cmd_my_set[] = { 'M', 'Y', 0, 0 };
johnb 50:f76b7e7959a2 124 static const uint8_t cmd_my_set_fid = CMD_RESPONSE_SET_MY;
johnb 32:af4e495afd62 125
johnb 50:f76b7e7959a2 126 static const uint8_t cmd_rr[] = { 'R', 'R' };
johnb 50:f76b7e7959a2 127 static const uint8_t cmd_rr_get_fid = CMD_RESPONSE_GET_RR;
johnb 50:f76b7e7959a2 128 static const uint8_t cmd_rr_set[] = { 'R', 'R', 0 };
johnb 50:f76b7e7959a2 129 static const uint8_t cmd_rr_set_fid = CMD_RESPONSE_SET_RR;
johnb 50:f76b7e7959a2 130
johnb 50:f76b7e7959a2 131 static const uint8_t cmd_rn[] = { 'R', 'N' };
johnb 50:f76b7e7959a2 132 static const uint8_t cmd_rn_get_fid = CMD_RESPONSE_GET_RN;
johnb 50:f76b7e7959a2 133 static const uint8_t cmd_rn_set[] = { 'R', 'N', 0 };
johnb 50:f76b7e7959a2 134 static const uint8_t cmd_rn_set_fid = CMD_RESPONSE_SET_RN;
johnb 13:302e7c1ea0b3 135
johnb 50:f76b7e7959a2 136 static const uint8_t cmd_mm[] = { 'M', 'M' };
johnb 50:f76b7e7959a2 137 static const uint8_t cmd_mm_get_fid = CMD_RESPONSE_GET_MM;
johnb 50:f76b7e7959a2 138 static const uint8_t cmd_mm_set[] = { 'M', 'M', 0 };
johnb 50:f76b7e7959a2 139 static const uint8_t cmd_mm_set_fid = CMD_RESPONSE_SET_MM;
johnb 8:1b48b619d7f6 140
johnb 51:a7d0d2ef9261 141 static const uint8_t cmd_ic[] = { 'I', 'C' };
johnb 51:a7d0d2ef9261 142 static const uint8_t cmd_ic_get_fid = CMD_RESPONSE_GET_IC;
johnb 51:a7d0d2ef9261 143 static const uint8_t cmd_ic_set[] = { 'I', 'C', 0 };
johnb 51:a7d0d2ef9261 144 static const uint8_t cmd_ic_set_fid = CMD_RESPONSE_SET_IC;
johnb 51:a7d0d2ef9261 145
johnb 51:a7d0d2ef9261 146 static const uint8_t cmd_io_set[] = { 'I', 'O', 0 };
johnb 51:a7d0d2ef9261 147 static const uint8_t cmd_io_set_fid = CMD_RESPONSE_SET_IO;
johnb 51:a7d0d2ef9261 148
johnb 51:a7d0d2ef9261 149 static const uint8_t cmd_ir[] = { 'I', 'R' };
johnb 51:a7d0d2ef9261 150 static const uint8_t cmd_ir_get_fid = CMD_RESPONSE_GET_IR;
johnb 51:a7d0d2ef9261 151 static const uint8_t cmd_ir_set[] = { 'I', 'R', 0, 0 };
johnb 51:a7d0d2ef9261 152 static const uint8_t cmd_ir_set_fid = CMD_RESPONSE_SET_IR;
johnb 51:a7d0d2ef9261 153
johnb 51:a7d0d2ef9261 154 static const uint8_t cmd_dh[] = { 'D', 'H' };
johnb 51:a7d0d2ef9261 155 static const uint8_t cmd_dh_get_fid = CMD_RESPONSE_GET_DH;
johnb 51:a7d0d2ef9261 156 static const uint8_t cmd_dh_set[] = { 'D', 'H', 0, 0, 0, 0 };
johnb 51:a7d0d2ef9261 157 static const uint8_t cmd_dh_set_fid = CMD_RESPONSE_SET_DH;
johnb 51:a7d0d2ef9261 158
johnb 51:a7d0d2ef9261 159 static const uint8_t cmd_dl[] = { 'D', 'L' };
johnb 51:a7d0d2ef9261 160 static const uint8_t cmd_dl_get_fid = CMD_RESPONSE_GET_DL;
johnb 51:a7d0d2ef9261 161 static const uint8_t cmd_dl_set[] = { 'D', 'L', 0, 0, 0, 0 };
johnb 51:a7d0d2ef9261 162 static const uint8_t cmd_dl_set_fid = CMD_RESPONSE_SET_DL;
johnb 51:a7d0d2ef9261 163
johnb 51:a7d0d2ef9261 164 static const uint8_t cmd_wr[] = { 'W', 'R' };
johnb 51:a7d0d2ef9261 165 static const uint8_t cmd_wr_set_fid = CMD_RESPONSE_SET_WR;
johnb 51:a7d0d2ef9261 166
johnb 51:a7d0d2ef9261 167 static const uint8_t cmd_ac[] = { 'A', 'C' };
johnb 51:a7d0d2ef9261 168 static const uint8_t cmd_ac_set_fid = CMD_RESPONSE_SET_AC;
johnb 51:a7d0d2ef9261 169
johnb 51:a7d0d2ef9261 170 static const uint8_t cmd_fr[] = { 'F', 'R' };
johnb 51:a7d0d2ef9261 171 static const uint8_t cmd_fr_set_fid = CMD_RESPONSE_SET_FR;
johnb 51:a7d0d2ef9261 172
johnb 51:a7d0d2ef9261 173 static const uint8_t cmd_is[] = { 'I', 'S' };
johnb 51:a7d0d2ef9261 174 static const uint8_t cmd_is_set_fid = CMD_RESPONSE_SET_IS;
johnb 51:a7d0d2ef9261 175
johnb 55:610aa4a2ed3b 176 static const uint8_t cmd_re[] = { 'R', 'E' };
johnb 55:610aa4a2ed3b 177 static const uint8_t cmd_re_set_fid = CMD_RESPONSE_SET_RE;
johnb 55:610aa4a2ed3b 178
johnb 56:7fe74b03e6b1 179 static const uint8_t cmd_ky_set[] = { 'K', 'Y', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
johnb 56:7fe74b03e6b1 180 static const uint8_t cmd_ky_set_fid = CMD_RESPONSE_SET_KY;
johnb 56:7fe74b03e6b1 181
johnb 56:7fe74b03e6b1 182 static const uint8_t cmd_ee[] = { 'E', 'E' };
johnb 56:7fe74b03e6b1 183 static const uint8_t cmd_ee_get_fid = CMD_RESPONSE_GET_EE;
johnb 56:7fe74b03e6b1 184 static const uint8_t cmd_ee_set[] = { 'E', 'E', 0 };
johnb 56:7fe74b03e6b1 185 static const uint8_t cmd_ee_set_fid = CMD_RESPONSE_SET_EE;
johnb 56:7fe74b03e6b1 186
johnb 55:610aa4a2ed3b 187
johnb 50:f76b7e7959a2 188 static const uint8_t cmd_d[ XBEE_API_DIO_CHANNEL_COUNT ][2] = {{ 'D', '0' },
johnb 50:f76b7e7959a2 189 { 'D', '1' },
johnb 50:f76b7e7959a2 190 { 'D', '2' },
johnb 50:f76b7e7959a2 191 { 'D', '3' },
johnb 50:f76b7e7959a2 192 { 'D', '4' },
johnb 50:f76b7e7959a2 193 { 'D', '5' },
johnb 50:f76b7e7959a2 194 { 'D', '6' },
johnb 50:f76b7e7959a2 195 { 'D', '7' }};
johnb 50:f76b7e7959a2 196 static const uint8_t cmd_d_get_fid[ XBEE_API_DIO_CHANNEL_COUNT ] = { CMD_RESPONSE_GET_D0,
johnb 50:f76b7e7959a2 197 CMD_RESPONSE_GET_D1,
johnb 50:f76b7e7959a2 198 CMD_RESPONSE_GET_D2,
johnb 50:f76b7e7959a2 199 CMD_RESPONSE_GET_D3,
johnb 50:f76b7e7959a2 200 CMD_RESPONSE_GET_D4,
johnb 50:f76b7e7959a2 201 CMD_RESPONSE_GET_D5,
johnb 50:f76b7e7959a2 202 CMD_RESPONSE_GET_D6,
johnb 50:f76b7e7959a2 203 CMD_RESPONSE_GET_D7 };
johnb 31:c144106e55b5 204
johnb 53:7b65422d7a32 205 #define XBEE_CMD_POSN_FRAME_ID (XBEE_CMD_POSN_ID_SPECIFIC_DATA)
johnb 53:7b65422d7a32 206 #define XBEE_CMD_POSN_STATUS (7U)
johnb 8:1b48b619d7f6 207 #define XBEE_CMD_POSN_PARAM_START (8U)
johnb 8:1b48b619d7f6 208
johnb 13:302e7c1ea0b3 209 #define XBEE_CMD_RESPONS_HAS_DATA( _p_len ) ((_p_len > ( XBEE_CMD_POSN_PARAM_START + 1 ))
johnb 13:302e7c1ea0b3 210
johnb 56:7fe74b03e6b1 211 /** Class to create an XBeeApiFrame which can be used to read or change
johnb 50:f76b7e7959a2 212 the value of one of the XBee parameters. This class is used by the
johnb 56:7fe74b03e6b1 213 requestXXX and setXXX methods in XBeeApiCmdAt */
johnb 56:7fe74b03e6b1 214 class XBeeApiCmdAtFrame : public XBeeApiFrame {
johnb 56:7fe74b03e6b1 215 uint8_t m_buffer[ XBEE_API_CMD_SET_HEADER_LEN + XBEE_CMD_MAX_PARAM_LENGTH ];
johnb 50:f76b7e7959a2 216 public:
johnb 50:f76b7e7959a2 217 /** Constructor
johnb 50:f76b7e7959a2 218
johnb 50:f76b7e7959a2 219 \param p_data Pointer to a buffer of length 2 bytes identifying
johnb 50:f76b7e7959a2 220 the command, e.g. 'V', 'R' would set up a version
johnb 50:f76b7e7959a2 221 request
johnb 56:7fe74b03e6b1 222 \param p_val Pointer to the new value for the parameter, most
johnb 56:7fe74b03e6b1 223 significant byte (MSB) first
johnb 56:7fe74b03e6b1 224 \param p_len The length of the data pointed to by p_val
johnb 50:f76b7e7959a2 225 */
johnb 56:7fe74b03e6b1 226 XBeeApiCmdAtFrame( const uint8_t p_frameId,
johnb 56:7fe74b03e6b1 227 const uint8_t* const p_data,
johnb 56:7fe74b03e6b1 228 const uint8_t* const p_val,
johnb 56:7fe74b03e6b1 229 const uint8_t p_len );
johnb 50:f76b7e7959a2 230 /** Destructor */
johnb 56:7fe74b03e6b1 231 virtual ~XBeeApiCmdAtFrame();
johnb 50:f76b7e7959a2 232 };
johnb 50:f76b7e7959a2 233
johnb 55:610aa4a2ed3b 234 void XBeeApiCmdAt::resetCachedData( void )
johnb 8:1b48b619d7f6 235 {
johnb 52:0950b05d5270 236 uint8_t i;
johnb 55:610aa4a2ed3b 237
johnb 55:610aa4a2ed3b 238 m_have_hwVer = false;
johnb 55:610aa4a2ed3b 239 m_have_fwVer = false;
johnb 55:610aa4a2ed3b 240 m_have_chan = false;
johnb 55:610aa4a2ed3b 241 m_have_PANId = false;
johnb 55:610aa4a2ed3b 242 m_have_EDA = false;
johnb 55:610aa4a2ed3b 243 m_have_CE = false;
johnb 55:610aa4a2ed3b 244 m_have_sourceAddress = false;
johnb 55:610aa4a2ed3b 245 m_have_retries = false;
johnb 55:610aa4a2ed3b 246 m_have_randomDelaySlots = false;
johnb 55:610aa4a2ed3b 247 m_have_macMode = false;
johnb 55:610aa4a2ed3b 248 m_have_dioChangeDetectMask = false;
johnb 55:610aa4a2ed3b 249 m_have_dioLevels = false;
johnb 55:610aa4a2ed3b 250 m_have_sampleRate = false;
johnb 55:610aa4a2ed3b 251 m_have_destHigh = false;
johnb 55:610aa4a2ed3b 252 m_have_destLow = false;
johnb 56:7fe74b03e6b1 253 m_have_encryptionEnabled = false;
johnb 56:7fe74b03e6b1 254 m_keySet = false;
johnb 56:7fe74b03e6b1 255
johnb 55:610aa4a2ed3b 256 m_writeCount = 0;
johnb 55:610aa4a2ed3b 257 m_applyCount = 0;
johnb 55:610aa4a2ed3b 258 m_resetCount = 0;
johnb 55:610aa4a2ed3b 259 m_sampleCount = 0;
johnb 55:610aa4a2ed3b 260 m_restoreCount = 0;
johnb 55:610aa4a2ed3b 261
johnb 55:610aa4a2ed3b 262 /* We DO NOT reset m_have_snLow and m_have_snHigh here as
johnb 55:610aa4a2ed3b 263 these are reset only in the custructor - we assume that if
johnb 55:610aa4a2ed3b 264 we've received them then they can't change
johnb 55:610aa4a2ed3b 265 TODO: Could be wrong - what about if we're re-using remote XBee? */
johnb 55:610aa4a2ed3b 266
johnb 52:0950b05d5270 267 for( i = 0;
johnb 51:a7d0d2ef9261 268 i < XBEE_API_DIO_CHANNEL_COUNT;
johnb 51:a7d0d2ef9261 269 i++ )
johnb 51:a7d0d2ef9261 270 {
johnb 51:a7d0d2ef9261 271 m_have_d[ i ] = false;
johnb 52:0950b05d5270 272 m_ioDigitalUpdatedTime[ i ] = 0;
johnb 52:0950b05d5270 273 }
johnb 52:0950b05d5270 274 for( i = 0;
johnb 52:0950b05d5270 275 i < XBEE_API_ADC_CHANNEL_COUNT;
johnb 52:0950b05d5270 276 i++ )
johnb 52:0950b05d5270 277 {
johnb 52:0950b05d5270 278 m_ioAnalogueUpdatedTime[ i ] = 0;
johnb 51:a7d0d2ef9261 279 }
johnb 8:1b48b619d7f6 280 }
johnb 8:1b48b619d7f6 281
johnb 55:610aa4a2ed3b 282
johnb 55:610aa4a2ed3b 283 XBeeApiCmdAt::XBeeApiCmdAt( XBeeDevice* const p_device ) : XBeeApiFrameDecoder( p_device ) ,
johnb 55:610aa4a2ed3b 284 m_have_snLow ( false ),
johnb 55:610aa4a2ed3b 285 m_have_snHigh ( false )
johnb 55:610aa4a2ed3b 286 {
johnb 55:610aa4a2ed3b 287 resetCachedData();
johnb 55:610aa4a2ed3b 288 }
johnb 55:610aa4a2ed3b 289
johnb 51:a7d0d2ef9261 290 #define RESPONSE_OK( _data ) (_data[ statusPosn ] == 0)
johnb 51:a7d0d2ef9261 291
johnb 51:a7d0d2ef9261 292 #define PROCESS_SET_RESPONSE( _type, _var ) \
johnb 51:a7d0d2ef9261 293 case CMD_RESPONSE_SET_ ## _type: \
johnb 51:a7d0d2ef9261 294 if( RESPONSE_OK( p_data )) \
johnb 51:a7d0d2ef9261 295 { \
johnb 51:a7d0d2ef9261 296 m_ ## _var = m_ ## _var ## Pend; \
johnb 51:a7d0d2ef9261 297 m_have_ ## _var = true; \
johnb 51:a7d0d2ef9261 298 } \
johnb 51:a7d0d2ef9261 299 else \
johnb 51:a7d0d2ef9261 300 { \
johnb 51:a7d0d2ef9261 301 /* TODO */ \
johnb 51:a7d0d2ef9261 302 } \
johnb 51:a7d0d2ef9261 303 ret_val = true; \
johnb 51:a7d0d2ef9261 304 break;
johnb 51:a7d0d2ef9261 305
johnb 51:a7d0d2ef9261 306 #define PROCESS_SET_GET_RESPONSE_GENERIC( _type, _var, _src, _t, _sfx ) \
johnb 32:af4e495afd62 307 case CMD_RESPONSE_SET_ ## _type: \
johnb 32:af4e495afd62 308 case CMD_RESPONSE_GET_ ## _type: \
johnb 51:a7d0d2ef9261 309 if( RESPONSE_OK( p_data )) \
johnb 32:af4e495afd62 310 { \
johnb 50:f76b7e7959a2 311 if( CMD_RESPONSE_GET_ ## _type == p_data[ XBEE_CMD_POSN_FRAME_ID ] ) \
johnb 32:af4e495afd62 312 { \
johnb 51:a7d0d2ef9261 313 m_ ##_var ##_sfx = (_t) (_src); \
johnb 32:af4e495afd62 314 } \
johnb 32:af4e495afd62 315 else \
johnb 32:af4e495afd62 316 { \
johnb 51:a7d0d2ef9261 317 m_ ##_var ##_sfx = m_ ## _var ## Pend ## _sfx; \
johnb 32:af4e495afd62 318 } \
johnb 51:a7d0d2ef9261 319 m_have_ ##_var ##_sfx = true; \
johnb 32:af4e495afd62 320 } \
johnb 32:af4e495afd62 321 else \
johnb 32:af4e495afd62 322 { \
johnb 32:af4e495afd62 323 /* TODO */ \
johnb 32:af4e495afd62 324 } \
johnb 32:af4e495afd62 325 ret_val = true; \
johnb 32:af4e495afd62 326 break;
johnb 32:af4e495afd62 327
johnb 32:af4e495afd62 328 #define PROCESS_GET_RESPONSE_GENERIC( _type, _var, _src ) \
johnb 32:af4e495afd62 329 case CMD_RESPONSE_GET_ ## _type: \
johnb 51:a7d0d2ef9261 330 if( RESPONSE_OK( p_data )) \
johnb 32:af4e495afd62 331 { \
johnb 32:af4e495afd62 332 m_ ##_var = _src; \
johnb 32:af4e495afd62 333 m_have_ ## _var = true; \
johnb 32:af4e495afd62 334 } \
johnb 32:af4e495afd62 335 else \
johnb 32:af4e495afd62 336 { \
johnb 32:af4e495afd62 337 /* TODO */ \
johnb 32:af4e495afd62 338 } \
johnb 32:af4e495afd62 339 ret_val = true; \
johnb 32:af4e495afd62 340 break;
johnb 32:af4e495afd62 341
johnb 51:a7d0d2ef9261 342 #define PROCESS_SET_GET_RESPONSE_8BIT_WITHCAST( _type, _var, _t, _sfx ) PROCESS_SET_GET_RESPONSE_GENERIC( _type, _var, p_data[ dataPosn ], _t, _sfx )
johnb 51:a7d0d2ef9261 343 #define PROCESS_SET_GET_RESPONSE_8BIT( _type, _var ) PROCESS_SET_GET_RESPONSE_GENERIC( _type, _var, p_data[ dataPosn ], uint8_t, )
johnb 51:a7d0d2ef9261 344 #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 51:a7d0d2ef9261 345 #define PROCESS_SET_GET_RESPONSE_32BIT( _type, _var ) PROCESS_SET_GET_RESPONSE_GENERIC( _type, _var, ((uint32_t)p_data[ dataPosn ] << 24) |\
johnb 51:a7d0d2ef9261 346 ((uint32_t)p_data[ dataPosn + 1 ] << 16) |\
johnb 51:a7d0d2ef9261 347 ((uint32_t)p_data[ dataPosn + 2 ] << 8) |\
johnb 51:a7d0d2ef9261 348 ((uint32_t)p_data[ dataPosn + 3 ]), uint32_t, )
johnb 50:f76b7e7959a2 349
johnb 50:f76b7e7959a2 350 #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 351 #define PROCESS_GET_RESPONSE_32BIT( _type, _var ) PROCESS_GET_RESPONSE_GENERIC( _type, _var, ((uint32_t)p_data[ dataPosn ] << 24) |\
johnb 50:f76b7e7959a2 352 ((uint32_t)p_data[ dataPosn + 1 ] << 16) |\
johnb 50:f76b7e7959a2 353 ((uint32_t)p_data[ dataPosn + 2 ] << 8) |\
johnb 50:f76b7e7959a2 354 ((uint32_t)p_data[ dataPosn + 3 ]))
johnb 50:f76b7e7959a2 355
johnb 50:f76b7e7959a2 356 size_t XBeeApiCmdAt::getResponseStatusPos( void ) const
johnb 50:f76b7e7959a2 357 {
johnb 50:f76b7e7959a2 358 return XBEE_CMD_POSN_STATUS;
johnb 50:f76b7e7959a2 359 }
johnb 32:af4e495afd62 360
johnb 50:f76b7e7959a2 361 bool XBeeApiCmdAt::processResponseFrame( const uint8_t* const p_data, size_t p_len )
johnb 50:f76b7e7959a2 362 {
johnb 50:f76b7e7959a2 363 bool ret_val = false;
johnb 50:f76b7e7959a2 364 size_t statusPosn = getResponseStatusPos();
johnb 50:f76b7e7959a2 365 size_t dataPosn = statusPosn + 1;
johnb 50:f76b7e7959a2 366
johnb 50:f76b7e7959a2 367 switch( p_data[ XBEE_CMD_POSN_FRAME_ID ] )
johnb 50:f76b7e7959a2 368 {
johnb 56:7fe74b03e6b1 369 case CMD_RESPONSE_SET_KY:
johnb 56:7fe74b03e6b1 370 if( RESPONSE_OK( p_data ))
johnb 56:7fe74b03e6b1 371 {
johnb 56:7fe74b03e6b1 372 m_keySet = true;
johnb 56:7fe74b03e6b1 373 }
johnb 56:7fe74b03e6b1 374 ret_val = true;
johnb 56:7fe74b03e6b1 375 break;
johnb 51:a7d0d2ef9261 376 case CMD_RESPONSE_SET_WR:
johnb 51:a7d0d2ef9261 377 if( RESPONSE_OK( p_data ))
johnb 51:a7d0d2ef9261 378 {
johnb 51:a7d0d2ef9261 379 m_writeCount++;
johnb 51:a7d0d2ef9261 380 }
johnb 51:a7d0d2ef9261 381 ret_val = true;
johnb 51:a7d0d2ef9261 382 break;
johnb 51:a7d0d2ef9261 383 case CMD_RESPONSE_SET_AC:
johnb 51:a7d0d2ef9261 384 if( RESPONSE_OK( p_data ))
johnb 51:a7d0d2ef9261 385 {
johnb 51:a7d0d2ef9261 386 m_applyCount++;
johnb 51:a7d0d2ef9261 387 }
johnb 51:a7d0d2ef9261 388 ret_val = true;
johnb 51:a7d0d2ef9261 389 break;
johnb 51:a7d0d2ef9261 390 case CMD_RESPONSE_SET_FR:
johnb 51:a7d0d2ef9261 391 if( RESPONSE_OK( p_data ))
johnb 51:a7d0d2ef9261 392 {
johnb 51:a7d0d2ef9261 393 m_resetCount++;
johnb 51:a7d0d2ef9261 394 }
johnb 51:a7d0d2ef9261 395 ret_val = true;
johnb 51:a7d0d2ef9261 396 break;
johnb 51:a7d0d2ef9261 397 case CMD_RESPONSE_SET_IS:
johnb 51:a7d0d2ef9261 398 if( RESPONSE_OK( p_data ))
johnb 51:a7d0d2ef9261 399 {
johnb 51:a7d0d2ef9261 400 m_sampleCount++;
johnb 51:a7d0d2ef9261 401 }
johnb 51:a7d0d2ef9261 402 ret_val = true;
johnb 51:a7d0d2ef9261 403 break;
johnb 55:610aa4a2ed3b 404 case CMD_RESPONSE_SET_RE:
johnb 55:610aa4a2ed3b 405 if( RESPONSE_OK( p_data ))
johnb 55:610aa4a2ed3b 406 {
johnb 55:610aa4a2ed3b 407 /* If all settings have been reset, clear out any cached
johnb 55:610aa4a2ed3b 408 data members in this class */
johnb 55:610aa4a2ed3b 409 resetCachedData();
johnb 55:610aa4a2ed3b 410 m_restoreCount++;
johnb 55:610aa4a2ed3b 411 }
johnb 55:610aa4a2ed3b 412 ret_val = true;
johnb 55:610aa4a2ed3b 413 break;
johnb 50:f76b7e7959a2 414 PROCESS_GET_RESPONSE_16BIT( HV, hwVer )
johnb 50:f76b7e7959a2 415 PROCESS_GET_RESPONSE_16BIT( VR, fwVer )
johnb 50:f76b7e7959a2 416
johnb 50:f76b7e7959a2 417 PROCESS_SET_GET_RESPONSE_8BIT( CH, chan )
johnb 50:f76b7e7959a2 418 PROCESS_SET_GET_RESPONSE_8BIT( CE, CE )
johnb 50:f76b7e7959a2 419 PROCESS_SET_GET_RESPONSE_16BIT( PID, PANId )
johnb 50:f76b7e7959a2 420 PROCESS_SET_GET_RESPONSE_8BIT( EDA, EDA )
johnb 50:f76b7e7959a2 421 PROCESS_SET_GET_RESPONSE_8BIT( RR, retries )
johnb 50:f76b7e7959a2 422 PROCESS_SET_GET_RESPONSE_16BIT( MY, sourceAddress )
johnb 50:f76b7e7959a2 423 PROCESS_GET_RESPONSE_32BIT( SH, snHigh )
johnb 50:f76b7e7959a2 424 PROCESS_GET_RESPONSE_32BIT( SL, snLow )
johnb 51:a7d0d2ef9261 425 PROCESS_SET_GET_RESPONSE_32BIT( DH, destHigh )
johnb 51:a7d0d2ef9261 426 PROCESS_SET_GET_RESPONSE_32BIT( DL, destLow )
johnb 50:f76b7e7959a2 427 PROCESS_SET_GET_RESPONSE_8BIT( RN, randomDelaySlots )
johnb 56:7fe74b03e6b1 428 PROCESS_SET_GET_RESPONSE_8BIT_WITHCAST( EE, encryptionEnabled, bool, )
johnb 51:a7d0d2ef9261 429 PROCESS_SET_GET_RESPONSE_8BIT_WITHCAST( MM, macMode, XBeeApiMACMode_e, )
johnb 50:f76b7e7959a2 430 /* TODO: Add D0, D1, D2 response handling */
johnb 51:a7d0d2ef9261 431 PROCESS_SET_GET_RESPONSE_8BIT_WITHCAST( D0, d, XBeeApiDioConfig_e, [0] )
johnb 51:a7d0d2ef9261 432 PROCESS_SET_GET_RESPONSE_8BIT( IC, dioChangeDetectMask )
johnb 51:a7d0d2ef9261 433 PROCESS_SET_RESPONSE( IO, dioLevels )
johnb 51:a7d0d2ef9261 434 PROCESS_SET_GET_RESPONSE_16BIT( IR, sampleRate )
johnb 50:f76b7e7959a2 435 }
johnb 32:af4e495afd62 436
johnb 50:f76b7e7959a2 437 return ret_val;
johnb 50:f76b7e7959a2 438 }
johnb 32:af4e495afd62 439
johnb 52:0950b05d5270 440 #define DIO_CHANNEL_MASK (0x01FFU)
johnb 52:0950b05d5270 441 #define ADC_CHANNEL_MASK (0x7E00U)
johnb 52:0950b05d5270 442
johnb 52:0950b05d5270 443 bool XBeeApiCmdAt::processIOFrame( const uint8_t* const p_data, size_t p_len, const size_t p_start )
johnb 52:0950b05d5270 444 {
johnb 52:0950b05d5270 445 #if 0
johnb 52:0950b05d5270 446 /* This is the number of sample sets that are contained in the packet, set using the IT AT command */
johnb 52:0950b05d5270 447 uint8_t sampleCount = p_data[ p_start ];
johnb 52:0950b05d5270 448 #endif
johnb 52:0950b05d5270 449
johnb 53:7b65422d7a32 450 const uint16_t channelMask = (((uint16_t)p_data[ p_start + 1 ]) << 8) |
johnb 53:7b65422d7a32 451 ((uint16_t)p_data[ p_start + 2 ]);
johnb 52:0950b05d5270 452 const uint8_t* dataPtr = &( p_data[ p_start + 3 ] );
johnb 52:0950b05d5270 453 const uint16_t dioMask = channelMask & DIO_CHANNEL_MASK;
johnb 52:0950b05d5270 454 uint16_t adcMask = (channelMask & ADC_CHANNEL_MASK) >> 9U;
johnb 52:0950b05d5270 455 uint8_t adc = 0;
johnb 52:0950b05d5270 456
johnb 52:0950b05d5270 457 time_t seconds = time( NULL );
johnb 52:0950b05d5270 458
johnb 52:0950b05d5270 459 if( dioMask )
johnb 52:0950b05d5270 460 {
johnb 52:0950b05d5270 461 uint16_t dioData = (((uint16_t)dataPtr[ 0 ]) << 8U) |
johnb 52:0950b05d5270 462 (uint16_t)dataPtr[ 1 ];
johnb 52:0950b05d5270 463 dataPtr += 2;
johnb 52:0950b05d5270 464
johnb 52:0950b05d5270 465 for( unsigned i = 0;
johnb 52:0950b05d5270 466 i < XBEE_API_DIO_CHANNEL_COUNT;
johnb 52:0950b05d5270 467 i++ )
johnb 52:0950b05d5270 468 {
johnb 52:0950b05d5270 469 if(( dioMask >> i ) & 0x01 )
johnb 52:0950b05d5270 470 {
johnb 52:0950b05d5270 471 m_ioDigitalState[i] = ( dioData >> i ) & 0x01;
johnb 52:0950b05d5270 472 m_ioDigitalUpdatedTime[i] = seconds;
johnb 52:0950b05d5270 473 }
johnb 52:0950b05d5270 474 }
johnb 52:0950b05d5270 475 }
johnb 52:0950b05d5270 476
johnb 52:0950b05d5270 477 while( adcMask )
johnb 52:0950b05d5270 478 {
johnb 52:0950b05d5270 479 if( adcMask & 0x01 )
johnb 52:0950b05d5270 480 {
johnb 52:0950b05d5270 481 uint16_t adcData = (((uint16_t)dataPtr[ 0 ]) << 8U) |
johnb 52:0950b05d5270 482 (uint16_t)dataPtr[ 1 ];
johnb 52:0950b05d5270 483 dataPtr += 2;
johnb 52:0950b05d5270 484
johnb 52:0950b05d5270 485 m_ioAnalogueVal[adc] = adcData;
johnb 52:0950b05d5270 486 m_ioAnalogueUpdatedTime[adc] = seconds;
johnb 52:0950b05d5270 487 }
johnb 52:0950b05d5270 488 adcMask = adcMask >> 1U;
johnb 52:0950b05d5270 489 adc++;
johnb 52:0950b05d5270 490 }
johnb 52:0950b05d5270 491
johnb 52:0950b05d5270 492 return true;
johnb 52:0950b05d5270 493 }
johnb 52:0950b05d5270 494
johnb 52:0950b05d5270 495 #define XBEE_IO_PACKET_ADDRESS (XBEE_CMD_POSN_ID_SPECIFIC_DATA)
johnb 52:0950b05d5270 496 #define XBEE_IO_PACKET_64BIT_DATA_START (XBEE_IO_PACKET_ADDRESS + sizeof( uint64_t) + 1U + 1U)
johnb 52:0950b05d5270 497 #define XBEE_IO_PACKET_16BIT_DATA_START (XBEE_IO_PACKET_ADDRESS + sizeof( uint16_t) + 1U + 1U)
johnb 52:0950b05d5270 498
johnb 8:1b48b619d7f6 499 bool XBeeApiCmdAt::decodeCallback( const uint8_t* const p_data, size_t p_len )
johnb 8:1b48b619d7f6 500 {
johnb 8:1b48b619d7f6 501 bool ret_val = false;
johnb 13:302e7c1ea0b3 502
johnb 50:f76b7e7959a2 503 if( XBEE_CMD_AT_RESPONSE == p_data[ XBEE_CMD_POSN_API_ID ] )
johnb 50:f76b7e7959a2 504 {
johnb 50:f76b7e7959a2 505 ret_val = processResponseFrame( p_data, p_len );
johnb 52:0950b05d5270 506 }
johnb 52:0950b05d5270 507 else if( XBEE_CMD_RX_16B_IO == p_data[ XBEE_CMD_POSN_API_ID ] )
johnb 52:0950b05d5270 508 {
johnb 52:0950b05d5270 509 uint16_t src16BitAddr = (((uint16_t)p_data[ XBEE_IO_PACKET_ADDRESS ]) << 8U) |
johnb 52:0950b05d5270 510 p_data[ XBEE_IO_PACKET_ADDRESS + 1 ];
johnb 52:0950b05d5270 511 if( m_have_sourceAddress &&
johnb 52:0950b05d5270 512 ( src16BitAddr == m_sourceAddress ))
johnb 52:0950b05d5270 513 {
johnb 52:0950b05d5270 514 ret_val = processIOFrame( p_data, p_len, XBEE_IO_PACKET_16BIT_DATA_START );
johnb 52:0950b05d5270 515 }
johnb 8:1b48b619d7f6 516 }
johnb 52:0950b05d5270 517 else if( XBEE_CMD_RX_64B_IO == p_data[ XBEE_CMD_POSN_API_ID ] )
johnb 52:0950b05d5270 518 {
johnb 52:0950b05d5270 519 uint32_t srcAddrHigh = (((uint64_t)p_data[ XBEE_IO_PACKET_ADDRESS ]) << 24U) |
johnb 52:0950b05d5270 520 (((uint64_t)p_data[ XBEE_IO_PACKET_ADDRESS + 1 ]) << 16U) |
johnb 52:0950b05d5270 521 (((uint64_t)p_data[ XBEE_IO_PACKET_ADDRESS + 2 ]) << 8U) |
johnb 52:0950b05d5270 522 (((uint64_t)p_data[ XBEE_IO_PACKET_ADDRESS + 3 ]));
johnb 52:0950b05d5270 523 uint32_t srcAddrLow = (((uint64_t)p_data[ XBEE_IO_PACKET_ADDRESS + 4 ]) << 24U) |
johnb 52:0950b05d5270 524 (((uint64_t)p_data[ XBEE_IO_PACKET_ADDRESS + 5 ]) << 16U) |
johnb 52:0950b05d5270 525 (((uint64_t)p_data[ XBEE_IO_PACKET_ADDRESS + 6 ]) << 8U) |
johnb 52:0950b05d5270 526 ((uint64_t)p_data[ XBEE_IO_PACKET_ADDRESS + 7 ]);
johnb 52:0950b05d5270 527 if( m_have_snLow &&
johnb 52:0950b05d5270 528 m_have_snHigh &&
johnb 52:0950b05d5270 529 ( srcAddrHigh == m_snHigh ) &&
johnb 52:0950b05d5270 530 ( srcAddrLow == m_snLow ))
johnb 52:0950b05d5270 531 {
johnb 52:0950b05d5270 532 ret_val = processIOFrame( p_data, p_len, XBEE_IO_PACKET_64BIT_DATA_START );
johnb 52:0950b05d5270 533 }
johnb 52:0950b05d5270 534 }
johnb 52:0950b05d5270 535 else
johnb 52:0950b05d5270 536 {
johnb 52:0950b05d5270 537 }
johnb 52:0950b05d5270 538
johnb 8:1b48b619d7f6 539 return ret_val;
johnb 8:1b48b619d7f6 540 }
johnb 8:1b48b619d7f6 541
johnb 8:1b48b619d7f6 542 bool XBeeApiCmdAt::setChannel( uint8_t const p_chan )
johnb 8:1b48b619d7f6 543 {
johnb 29:c6d037cceb02 544 bool ret_val = false;
johnb 29:c6d037cceb02 545
johnb 29:c6d037cceb02 546 if((( m_device->getXBeeModel() == XBeeDevice::XBEEDEVICE_S1 ) &&
johnb 29:c6d037cceb02 547 ( p_chan >= XBEE_CHAN_MIN ) &&
johnb 29:c6d037cceb02 548 ( p_chan <= XBEE_CHAN_MAX )) ||
johnb 29:c6d037cceb02 549 (( m_device->getXBeeModel() == XBeeDevice::XBEEDEVICE_S1_PRO ) &&
johnb 29:c6d037cceb02 550 ( p_chan >= XBEE_PRO_CHAN_MIN ) &&
johnb 29:c6d037cceb02 551 ( p_chan <= XBEE_PRO_CHAN_MAX )))
johnb 29:c6d037cceb02 552 {
johnb 29:c6d037cceb02 553 m_chanPend = p_chan;
johnb 50:f76b7e7959a2 554 SendCmd_uint8_t( cmd_ch_set_fid, cmd_ch_set, p_chan );
johnb 29:c6d037cceb02 555 ret_val = true;
johnb 29:c6d037cceb02 556 }
johnb 29:c6d037cceb02 557 return ret_val;
johnb 8:1b48b619d7f6 558 }
johnb 8:1b48b619d7f6 559
johnb 31:c144106e55b5 560 #define MAKE_REQUEST( _name, _mnemonic, _cmd ) \
johnb 31:c144106e55b5 561 bool XBeeApiCmdAt::request ## _name( void ) \
johnb 31:c144106e55b5 562 {\
johnb 50:f76b7e7959a2 563 m_have_ ## _mnemonic = false; \
johnb 56:7fe74b03e6b1 564 SendCmd( _cmd ## _get_fid, _cmd, NULL, 0 ); \
johnb 31:c144106e55b5 565 return true;\
johnb 8:1b48b619d7f6 566 }
johnb 8:1b48b619d7f6 567
johnb 51:a7d0d2ef9261 568 MAKE_REQUEST( HardwareVersion, hwVer, cmd_hv )
johnb 51:a7d0d2ef9261 569 MAKE_REQUEST( FirmwareVersion, fwVer, cmd_vr )
johnb 51:a7d0d2ef9261 570 MAKE_REQUEST( Channel, chan, cmd_ch )
johnb 51:a7d0d2ef9261 571 MAKE_REQUEST( PanId, PANId, cmd_pid )
johnb 51:a7d0d2ef9261 572 MAKE_REQUEST( CoordinatorEnabled, CE, cmd_ce )
johnb 51:a7d0d2ef9261 573 MAKE_REQUEST( EndDeviceAssociationEnabled, EDA, cmd_eda )
johnb 51:a7d0d2ef9261 574 MAKE_REQUEST( SourceAddress, sourceAddress, cmd_my )
johnb 51:a7d0d2ef9261 575 MAKE_REQUEST( Retries, retries, cmd_rr )
johnb 51:a7d0d2ef9261 576 MAKE_REQUEST( RandomDelaySlots, randomDelaySlots, cmd_rn )
johnb 51:a7d0d2ef9261 577 MAKE_REQUEST( MacMode, macMode, cmd_mm )
johnb 51:a7d0d2ef9261 578 MAKE_REQUEST( SerialNumberHigh, snHigh, cmd_sh )
johnb 51:a7d0d2ef9261 579 MAKE_REQUEST( SerialNumberLow, snLow, cmd_sl )
johnb 51:a7d0d2ef9261 580 MAKE_REQUEST( DioChangeDetectMask, dioChangeDetectMask, cmd_ic )
johnb 51:a7d0d2ef9261 581 MAKE_REQUEST( SampleRate, sampleRate, cmd_ir )
johnb 51:a7d0d2ef9261 582 MAKE_REQUEST( DestinationAddressHigh, destHigh, cmd_dh )
johnb 51:a7d0d2ef9261 583 MAKE_REQUEST( DestinationAddressLow, destLow, cmd_dl )
johnb 56:7fe74b03e6b1 584 MAKE_REQUEST( EncryptionEnabled, encryptionEnabled, cmd_ee )
johnb 51:a7d0d2ef9261 585
johnb 51:a7d0d2ef9261 586 bool XBeeApiCmdAt::requestWriteSettings( void )
johnb 51:a7d0d2ef9261 587 {
johnb 56:7fe74b03e6b1 588 SendCmd( cmd_wr_set_fid, cmd_wr, NULL, 0 );
johnb 51:a7d0d2ef9261 589 return true;
johnb 51:a7d0d2ef9261 590 }
johnb 51:a7d0d2ef9261 591
johnb 51:a7d0d2ef9261 592 bool XBeeApiCmdAt::requestApplyChanges( void )
johnb 51:a7d0d2ef9261 593 {
johnb 56:7fe74b03e6b1 594 SendCmd( cmd_ac_set_fid, cmd_ac, NULL, 0 );
johnb 51:a7d0d2ef9261 595 return true;
johnb 51:a7d0d2ef9261 596 }
johnb 51:a7d0d2ef9261 597
johnb 51:a7d0d2ef9261 598 bool XBeeApiCmdAt::requestReset( void )
johnb 51:a7d0d2ef9261 599 {
johnb 56:7fe74b03e6b1 600 SendCmd( cmd_fr_set_fid, cmd_fr, NULL, 0 );
johnb 51:a7d0d2ef9261 601 return true;
johnb 51:a7d0d2ef9261 602 }
johnb 51:a7d0d2ef9261 603
johnb 51:a7d0d2ef9261 604 bool XBeeApiCmdAt::requestForceSample( void )
johnb 51:a7d0d2ef9261 605 {
johnb 56:7fe74b03e6b1 606 SendCmd( cmd_is_set_fid, cmd_is, NULL, 0 );
johnb 51:a7d0d2ef9261 607 return true;
johnb 51:a7d0d2ef9261 608 }
johnb 32:af4e495afd62 609
johnb 55:610aa4a2ed3b 610 bool XBeeApiCmdAt::requestRestoreDefaults( void )
johnb 55:610aa4a2ed3b 611 {
johnb 56:7fe74b03e6b1 612 SendCmd( cmd_re_set_fid, cmd_re, NULL, 0 );
johnb 55:610aa4a2ed3b 613 return true;
johnb 55:610aa4a2ed3b 614 }
johnb 55:610aa4a2ed3b 615
johnb 32:af4e495afd62 616 bool XBeeApiCmdAt::requestSerialNumber( void )
johnb 32:af4e495afd62 617 {
johnb 50:f76b7e7959a2 618 requestSerialNumberHigh();
johnb 50:f76b7e7959a2 619 requestSerialNumberLow();
johnb 32:af4e495afd62 620 return true;
johnb 32:af4e495afd62 621 }
johnb 8:1b48b619d7f6 622
johnb 51:a7d0d2ef9261 623 bool XBeeApiCmdAt::requestDestinationAddress( void )
johnb 51:a7d0d2ef9261 624 {
johnb 51:a7d0d2ef9261 625 requestDestinationAddressHigh();
johnb 51:a7d0d2ef9261 626 requestDestinationAddressLow();
johnb 51:a7d0d2ef9261 627 return true;
johnb 51:a7d0d2ef9261 628 }
johnb 51:a7d0d2ef9261 629
johnb 50:f76b7e7959a2 630 bool XBeeApiCmdAt::requestDioConfig( const uint8_t p_chanNo )
johnb 50:f76b7e7959a2 631 {
johnb 50:f76b7e7959a2 632 bool ret_val = false;
johnb 50:f76b7e7959a2 633 if( p_chanNo < XBEE_API_DIO_CHANNEL_COUNT )
johnb 50:f76b7e7959a2 634 {
johnb 50:f76b7e7959a2 635 m_have_d[ p_chanNo ] = false;
johnb 56:7fe74b03e6b1 636 SendCmd( cmd_d_get_fid[ p_chanNo ], cmd_d[ p_chanNo ], NULL, 0 );
johnb 50:f76b7e7959a2 637 ret_val = true;
johnb 50:f76b7e7959a2 638 }
johnb 50:f76b7e7959a2 639 return ret_val;
johnb 50:f76b7e7959a2 640 }
johnb 50:f76b7e7959a2 641
johnb 52:0950b05d5270 642 time_t XBeeApiCmdAt::getDigitalState( const uint8_t p_chanNo, bool& p_state )
johnb 52:0950b05d5270 643 {
johnb 52:0950b05d5270 644 time_t ret_val = 0;
johnb 52:0950b05d5270 645 if( p_chanNo < XBEE_API_DIO_CHANNEL_COUNT )
johnb 52:0950b05d5270 646 {
johnb 52:0950b05d5270 647 p_state = m_ioDigitalState[ p_chanNo ];
johnb 52:0950b05d5270 648 ret_val = m_ioDigitalUpdatedTime[ p_chanNo ];
johnb 52:0950b05d5270 649 }
johnb 52:0950b05d5270 650 return ret_val;
johnb 52:0950b05d5270 651 }
johnb 52:0950b05d5270 652
johnb 52:0950b05d5270 653 time_t XBeeApiCmdAt::getAnalogueValue( const uint8_t p_chanNo, uint16_t& p_val )
johnb 52:0950b05d5270 654 {
johnb 52:0950b05d5270 655 time_t ret_val = 0;
johnb 52:0950b05d5270 656 if( p_chanNo < XBEE_API_ADC_CHANNEL_COUNT )
johnb 52:0950b05d5270 657 {
johnb 52:0950b05d5270 658 p_val = m_ioAnalogueVal[ p_chanNo ];
johnb 52:0950b05d5270 659 ret_val = m_ioAnalogueUpdatedTime[ p_chanNo ];
johnb 52:0950b05d5270 660 }
johnb 52:0950b05d5270 661 return ret_val;
johnb 52:0950b05d5270 662 }
johnb 50:f76b7e7959a2 663
johnb 31:c144106e55b5 664 #define MAKE_GET(_name, _mnemonic, _type ) \
johnb 31:c144106e55b5 665 bool XBeeApiCmdAt::get ## _name( _type* const p_param ) \
johnb 31:c144106e55b5 666 {\
johnb 31:c144106e55b5 667 if( m_have_ ## _mnemonic ) {\
johnb 31:c144106e55b5 668 *p_param = m_ ## _mnemonic;\
johnb 31:c144106e55b5 669 } \
johnb 31:c144106e55b5 670 return m_have_ ## _mnemonic; \
johnb 13:302e7c1ea0b3 671 }
johnb 13:302e7c1ea0b3 672
johnb 51:a7d0d2ef9261 673 MAKE_GET( FirmwareVersion, fwVer, uint16_t )
johnb 51:a7d0d2ef9261 674 MAKE_GET( HardwareVersion, hwVer, uint16_t )
johnb 51:a7d0d2ef9261 675 MAKE_GET( Channel, chan, uint8_t )
johnb 51:a7d0d2ef9261 676 MAKE_GET( CoordinatorEnabled, CE, bool )
johnb 51:a7d0d2ef9261 677 MAKE_GET( EndDeviceAssociationEnabled, EDA, bool )
johnb 51:a7d0d2ef9261 678 MAKE_GET( PanId, PANId, panId_t )
johnb 51:a7d0d2ef9261 679 MAKE_GET( SourceAddress, sourceAddress, uint16_t )
johnb 51:a7d0d2ef9261 680 MAKE_GET( Retries, retries, uint8_t )
johnb 51:a7d0d2ef9261 681 MAKE_GET( RandomDelaySlots, randomDelaySlots, uint8_t )
johnb 51:a7d0d2ef9261 682 MAKE_GET( MacMode, macMode, XBeeApiMACMode_e )
johnb 51:a7d0d2ef9261 683 MAKE_GET( DioChangeDetectMask, dioChangeDetectMask, uint8_t )
johnb 51:a7d0d2ef9261 684 MAKE_GET( DioLevels, dioLevels, uint8_t )
johnb 51:a7d0d2ef9261 685 MAKE_GET( SampleRate, sampleRate, uint16_t )
johnb 51:a7d0d2ef9261 686 MAKE_GET( DestinationAddressHigh, destHigh, uint32_t )
johnb 51:a7d0d2ef9261 687 MAKE_GET( DestinationAddressLow, destLow, uint32_t )
johnb 56:7fe74b03e6b1 688 MAKE_GET( EncryptionEnabled, encryptionEnabled, bool )
johnb 32:af4e495afd62 689
johnb 32:af4e495afd62 690 bool XBeeApiCmdAt::getSerialNumber( uint64_t* const p_sn )
johnb 32:af4e495afd62 691 {
johnb 32:af4e495afd62 692 /* Need both halves to have the complete serial number */
johnb 32:af4e495afd62 693 bool have_sn = m_have_snLow && m_have_snHigh;
johnb 32:af4e495afd62 694 if( have_sn )
johnb 32:af4e495afd62 695 {
johnb 32:af4e495afd62 696 *p_sn = m_snHigh;
johnb 32:af4e495afd62 697 *p_sn = *p_sn << 32U;
johnb 32:af4e495afd62 698 *p_sn |= m_snLow;
johnb 32:af4e495afd62 699 }
johnb 32:af4e495afd62 700 return( have_sn );
johnb 32:af4e495afd62 701 }
johnb 25:db6874b7ac4b 702
johnb 51:a7d0d2ef9261 703 bool XBeeApiCmdAt::getDestinationAddress( uint64_t* const p_addr )
johnb 51:a7d0d2ef9261 704 {
johnb 51:a7d0d2ef9261 705 bool have_da = m_have_destLow && m_have_destHigh;
johnb 51:a7d0d2ef9261 706 if( have_da )
johnb 51:a7d0d2ef9261 707 {
johnb 51:a7d0d2ef9261 708 *p_addr = m_destHigh;
johnb 51:a7d0d2ef9261 709 *p_addr = *p_addr << 32U;
johnb 51:a7d0d2ef9261 710 *p_addr |= m_destLow;
johnb 51:a7d0d2ef9261 711 }
johnb 51:a7d0d2ef9261 712 return( have_da );
johnb 51:a7d0d2ef9261 713
johnb 51:a7d0d2ef9261 714 }
johnb 51:a7d0d2ef9261 715
johnb 50:f76b7e7959a2 716 bool XBeeApiCmdAt::getDioConfig( const uint8_t p_chanNo, XBeeApiDioConfig_e* const p_conf )
johnb 50:f76b7e7959a2 717 {
johnb 50:f76b7e7959a2 718 bool ret_val = false;
johnb 50:f76b7e7959a2 719 if( p_chanNo < XBEE_API_DIO_CHANNEL_COUNT )
johnb 50:f76b7e7959a2 720 {
johnb 50:f76b7e7959a2 721 if( m_have_d[ p_chanNo ] )
johnb 50:f76b7e7959a2 722 {
johnb 50:f76b7e7959a2 723 *p_conf = m_d[ p_chanNo ];
johnb 50:f76b7e7959a2 724 ret_val = true;
johnb 50:f76b7e7959a2 725 }
johnb 50:f76b7e7959a2 726 }
johnb 50:f76b7e7959a2 727 return ret_val;
johnb 50:f76b7e7959a2 728 }
johnb 50:f76b7e7959a2 729
johnb 56:7fe74b03e6b1 730 bool XBeeApiCmdAt::getEncryptionKeySet( void )
johnb 56:7fe74b03e6b1 731 {
johnb 56:7fe74b03e6b1 732 return m_keySet;
johnb 56:7fe74b03e6b1 733 }
johnb 56:7fe74b03e6b1 734
johnb 50:f76b7e7959a2 735 #define MAKE_SET( _name, _mnemonic, _cmd, _type, _transmit_type ) \
johnb 31:c144106e55b5 736 bool XBeeApiCmdAt::set ## _name( const _type p_param ) \
johnb 31:c144106e55b5 737 {\
johnb 31:c144106e55b5 738 m_have_ ## _mnemonic = false;\
johnb 31:c144106e55b5 739 m_## _mnemonic ## Pend = p_param;\
johnb 50:f76b7e7959a2 740 SendCmd_ ## _transmit_type ( _cmd ## _fid, _cmd, p_param ); \
johnb 31:c144106e55b5 741 return true;\
johnb 13:302e7c1ea0b3 742 }
johnb 13:302e7c1ea0b3 743
johnb 51:a7d0d2ef9261 744 MAKE_SET( CoordinatorEnabled, CE, cmd_ce_set, bool, uint8_t )
johnb 51:a7d0d2ef9261 745 MAKE_SET( EndDeviceAssociationEnabled, EDA, cmd_eda_set, bool, uint8_t )
johnb 51:a7d0d2ef9261 746 MAKE_SET( PanId, PANId, cmd_pid_set, uint16_t, uint16_t )
johnb 51:a7d0d2ef9261 747 MAKE_SET( SourceAddress, sourceAddress, cmd_my_set, uint16_t, uint16_t )
johnb 51:a7d0d2ef9261 748 MAKE_SET( Retries, retries, cmd_rr_set, uint8_t, uint16_t )
johnb 51:a7d0d2ef9261 749 MAKE_SET( RandomDelaySlots, randomDelaySlots, cmd_rn_set, uint8_t, uint16_t )
johnb 51:a7d0d2ef9261 750 MAKE_SET( MacMode, macMode, cmd_mm_set, XBeeApiMACMode_e, uint8_t )
johnb 51:a7d0d2ef9261 751 MAKE_SET( DioChangeDetectMask, dioChangeDetectMask, cmd_ic_set, uint8_t, uint8_t )
johnb 51:a7d0d2ef9261 752 MAKE_SET( DioLevels, dioLevels, cmd_io_set, uint8_t, uint8_t )
johnb 51:a7d0d2ef9261 753 MAKE_SET( SampleRate, sampleRate, cmd_ir_set, uint16_t, uint16_t )
johnb 51:a7d0d2ef9261 754 MAKE_SET( DestinationAddressHigh, destHigh, cmd_dh_set, uint32_t, uint32_t )
johnb 51:a7d0d2ef9261 755 MAKE_SET( DestinationAddressLow, destLow, cmd_dl_set, uint32_t, uint32_t )
johnb 56:7fe74b03e6b1 756 MAKE_SET( EncryptionEnabled, encryptionEnabled, cmd_ee_set, bool, uint8_t )
johnb 50:f76b7e7959a2 757
johnb 56:7fe74b03e6b1 758 #define XBEE_ENCRYPTION_KEY_LEN 16U
johnb 56:7fe74b03e6b1 759
johnb 56:7fe74b03e6b1 760 bool XBeeApiCmdAt::setEncryptionKey( const uint8_t* p_key )
johnb 56:7fe74b03e6b1 761 {
johnb 56:7fe74b03e6b1 762 m_keySet = false;
johnb 56:7fe74b03e6b1 763 SendCmd( cmd_ky_set_fid, cmd_ky_set, p_key, XBEE_ENCRYPTION_KEY_LEN );
johnb 56:7fe74b03e6b1 764
johnb 56:7fe74b03e6b1 765 return true;
johnb 56:7fe74b03e6b1 766 }
johnb 50:f76b7e7959a2 767
johnb 50:f76b7e7959a2 768 bool XBeeApiCmdAt::setDioConfig( const uint8_t p_chanNo, const XBeeApiDioConfig_e p_conf )
johnb 50:f76b7e7959a2 769 {
johnb 50:f76b7e7959a2 770 bool ret_val = false;
johnb 50:f76b7e7959a2 771 if( p_chanNo < XBEE_API_DIO_CHANNEL_COUNT )
johnb 50:f76b7e7959a2 772 {
johnb 51:a7d0d2ef9261 773 /* TODO: Add check that p_conf is valid for this channel */
johnb 50:f76b7e7959a2 774 m_have_d[ p_chanNo ] = false;
johnb 50:f76b7e7959a2 775 m_dPend[ p_chanNo ] = p_conf;
johnb 50:f76b7e7959a2 776 SendCmd_uint8_t( cmd_d_get_fid[ p_chanNo ], cmd_d[ p_chanNo ], p_conf );
johnb 50:f76b7e7959a2 777 }
johnb 50:f76b7e7959a2 778 return ret_val;
johnb 50:f76b7e7959a2 779 }
johnb 50:f76b7e7959a2 780
johnb 51:a7d0d2ef9261 781 bool XBeeApiCmdAt::setDestinationAddress( const uint64_t p_addr )
johnb 51:a7d0d2ef9261 782 {
johnb 51:a7d0d2ef9261 783 m_have_destHigh = m_have_destLow = false;
johnb 51:a7d0d2ef9261 784
johnb 51:a7d0d2ef9261 785 setDestinationAddressHigh( p_addr >> 32U );
johnb 51:a7d0d2ef9261 786 setDestinationAddressLow( p_addr );
johnb 51:a7d0d2ef9261 787
johnb 51:a7d0d2ef9261 788 return true;
johnb 51:a7d0d2ef9261 789 }
johnb 51:a7d0d2ef9261 790
johnb 50:f76b7e7959a2 791 void XBeeApiCmdAt::SendCmd_uint8_t( const uint8_t p_frameId,
johnb 50:f76b7e7959a2 792 const uint8_t* const p_data,
johnb 50:f76b7e7959a2 793 const uint8_t& p_val )
johnb 50:f76b7e7959a2 794 {
johnb 56:7fe74b03e6b1 795 SendCmd( p_frameId, p_data, &p_val, sizeof( uint8_t ));
johnb 50:f76b7e7959a2 796 }
johnb 50:f76b7e7959a2 797
johnb 50:f76b7e7959a2 798 void XBeeApiCmdAt::SendCmd_uint16_t( const uint8_t p_frameId,
johnb 50:f76b7e7959a2 799 const uint8_t* const p_data,
johnb 50:f76b7e7959a2 800 const uint16_t& p_val )
johnb 50:f76b7e7959a2 801 {
johnb 56:7fe74b03e6b1 802 uint8_t buffer[ sizeof( uint16_t )];
johnb 56:7fe74b03e6b1 803
johnb 56:7fe74b03e6b1 804 buffer[0] = (uint8_t)((p_val >> 8U) & 0xFF);
johnb 56:7fe74b03e6b1 805 buffer[1] = (uint8_t)((p_val >> 0U) & 0xFF);
johnb 56:7fe74b03e6b1 806
johnb 56:7fe74b03e6b1 807 SendCmd( p_frameId, p_data, buffer, sizeof( uint16_t ));
johnb 50:f76b7e7959a2 808 }
johnb 13:302e7c1ea0b3 809
johnb 51:a7d0d2ef9261 810 void XBeeApiCmdAt::SendCmd_uint32_t( const uint8_t p_frameId,
johnb 51:a7d0d2ef9261 811 const uint8_t* const p_data,
johnb 51:a7d0d2ef9261 812 const uint32_t& p_val )
johnb 8:1b48b619d7f6 813 {
johnb 56:7fe74b03e6b1 814 uint8_t buffer[ sizeof( uint32_t )];
johnb 56:7fe74b03e6b1 815
johnb 56:7fe74b03e6b1 816 buffer[0] = (uint8_t)((p_val >> 24U) & 0xFF);
johnb 56:7fe74b03e6b1 817 buffer[1] = (uint8_t)((p_val >> 16U) & 0xFF);
johnb 56:7fe74b03e6b1 818 buffer[2] = (uint8_t)((p_val >> 8U) & 0xFF);
johnb 56:7fe74b03e6b1 819 buffer[3] = (uint8_t)((p_val >> 0U) & 0xFF);
johnb 56:7fe74b03e6b1 820
johnb 56:7fe74b03e6b1 821 SendCmd( p_frameId, p_data, buffer, sizeof( uint32_t ));
johnb 50:f76b7e7959a2 822 }
johnb 31:c144106e55b5 823
johnb 56:7fe74b03e6b1 824 void XBeeApiCmdAt::SendCmd( const uint8_t p_frameId,
johnb 56:7fe74b03e6b1 825 const uint8_t* const p_data,
johnb 56:7fe74b03e6b1 826 const uint8_t* const p_val,
johnb 56:7fe74b03e6b1 827 const uint8_t p_len )
johnb 8:1b48b619d7f6 828 {
johnb 56:7fe74b03e6b1 829 XBeeApiCmdAtFrame req( p_frameId, p_data, p_val, p_len );
johnb 56:7fe74b03e6b1 830 m_device->SendFrame( &req );
johnb 56:7fe74b03e6b1 831 }
johnb 56:7fe74b03e6b1 832
johnb 56:7fe74b03e6b1 833 XBeeApiCmdAtFrame::XBeeApiCmdAtFrame( const uint8_t p_frameId,
johnb 56:7fe74b03e6b1 834 const uint8_t* const p_data,
johnb 56:7fe74b03e6b1 835 const uint8_t* const p_val,
johnb 56:7fe74b03e6b1 836 const uint8_t p_len ) : XBeeApiFrame( )
johnb 56:7fe74b03e6b1 837 {
johnb 25:db6874b7ac4b 838
johnb 13:302e7c1ea0b3 839 m_apiId = XBEE_CMD_AT_CMD;
johnb 25:db6874b7ac4b 840
johnb 50:f76b7e7959a2 841 m_buffer[0] = p_frameId;
johnb 50:f76b7e7959a2 842 m_buffer[1] = p_data[0];
johnb 50:f76b7e7959a2 843 m_buffer[2] = p_data[1];
johnb 36:cc7e8d1e35dd 844
johnb 56:7fe74b03e6b1 845 m_data = m_buffer;
johnb 56:7fe74b03e6b1 846 m_dataLen = XBEE_API_CMD_SET_HEADER_LEN;
johnb 56:7fe74b03e6b1 847
johnb 56:7fe74b03e6b1 848 if(( p_val != NULL ) &&
johnb 56:7fe74b03e6b1 849 ( p_len <= XBEE_CMD_MAX_PARAM_LENGTH ))
johnb 56:7fe74b03e6b1 850 {
johnb 56:7fe74b03e6b1 851 size_t s = 0;
johnb 56:7fe74b03e6b1 852 uint8_t* dest = &( m_buffer[ XBEE_API_CMD_SET_HEADER_LEN ] );
johnb 56:7fe74b03e6b1 853 const uint8_t* src = p_val;
johnb 56:7fe74b03e6b1 854
johnb 56:7fe74b03e6b1 855 for( s = 0;
johnb 56:7fe74b03e6b1 856 s < p_len;
johnb 56:7fe74b03e6b1 857 s++, dest++, src++ ) {
johnb 56:7fe74b03e6b1 858 *dest = *src;
johnb 56:7fe74b03e6b1 859 }
johnb 56:7fe74b03e6b1 860 m_dataLen += p_len;
johnb 25:db6874b7ac4b 861 }
johnb 56:7fe74b03e6b1 862
johnb 56:7fe74b03e6b1 863 #if 0
johnb 56:7fe74b03e6b1 864 /* Debugging code */
johnb 56:7fe74b03e6b1 865 extern Serial pc;
johnb 56:7fe74b03e6b1 866 size_t x = 0;
johnb 56:7fe74b03e6b1 867 pc.printf("\r\n[%02X][%02X][%02X]",(m_dataLen>>8U)&0xFF,m_dataLen&0xFF,XBEE_CMD_AT_CMD);
johnb 56:7fe74b03e6b1 868 for( x = 0; x < m_dataLen; x++ )
johnb 56:7fe74b03e6b1 869 {
johnb 56:7fe74b03e6b1 870 if( x < 3 )
johnb 56:7fe74b03e6b1 871 {
johnb 56:7fe74b03e6b1 872 pc.printf("%c",m_data[x]);
johnb 56:7fe74b03e6b1 873 }
johnb 56:7fe74b03e6b1 874 pc.printf("[%02X]",m_data[x]);
johnb 56:7fe74b03e6b1 875 }
johnb 56:7fe74b03e6b1 876 pc.printf("\r\n");
johnb 56:7fe74b03e6b1 877 #endif
johnb 50:f76b7e7959a2 878 }
johnb 13:302e7c1ea0b3 879
johnb 56:7fe74b03e6b1 880 XBeeApiCmdAtFrame::~XBeeApiCmdAtFrame()
johnb 13:302e7c1ea0b3 881 {
johnb 25:db6874b7ac4b 882 }