XBee API mode library

Committer:
yamaguch
Date:
Thu Jul 26 10:33:11 2012 +0000
Revision:
0:0232a97b3883
Child:
3:8453df14bd30
[mbed] converted /XBeeExamples/XBee

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yamaguch 0:0232a97b3883 1 /*
yamaguch 0:0232a97b3883 2 Copyright (c) 2011, Senio Networks, Inc.
yamaguch 0:0232a97b3883 3
yamaguch 0:0232a97b3883 4 Permission is hereby granted, free of charge, to any person obtaining a copy
yamaguch 0:0232a97b3883 5 of this software and associated documentation files (the "Software"), to deal
yamaguch 0:0232a97b3883 6 in the Software without restriction, including without limitation the rights
yamaguch 0:0232a97b3883 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
yamaguch 0:0232a97b3883 8 copies of the Software, and to permit persons to whom the Software is
yamaguch 0:0232a97b3883 9 furnished to do so, subject to the following conditions:
yamaguch 0:0232a97b3883 10
yamaguch 0:0232a97b3883 11 The above copyright notice and this permission notice shall be included in
yamaguch 0:0232a97b3883 12 all copies or substantial portions of the Software.
yamaguch 0:0232a97b3883 13
yamaguch 0:0232a97b3883 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
yamaguch 0:0232a97b3883 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
yamaguch 0:0232a97b3883 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
yamaguch 0:0232a97b3883 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
yamaguch 0:0232a97b3883 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
yamaguch 0:0232a97b3883 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
yamaguch 0:0232a97b3883 20 THE SOFTWARE.
yamaguch 0:0232a97b3883 21 */
yamaguch 0:0232a97b3883 22
yamaguch 0:0232a97b3883 23 #ifndef XBEE_H
yamaguch 0:0232a97b3883 24 #define XBEE_H
yamaguch 0:0232a97b3883 25
yamaguch 0:0232a97b3883 26 #include "mbed.h"
yamaguch 0:0232a97b3883 27 #include "XBeeDataTypes.h"
yamaguch 0:0232a97b3883 28
yamaguch 0:0232a97b3883 29 #define min(x, y) ((x) < (y) ? (x) : (y))
yamaguch 0:0232a97b3883 30 #define INDEX(n) ((n) % BUFSIZE)
yamaguch 0:0232a97b3883 31 #define SIZE(b, i) (b[i] << 8 | b[INDEX(i + 1)])
yamaguch 0:0232a97b3883 32
yamaguch 0:0232a97b3883 33 const int BUFSIZE = 512;
yamaguch 0:0232a97b3883 34 const char ESCAPE = 0x7D;
yamaguch 0:0232a97b3883 35 const char PREAMBLE = 0x7E;
yamaguch 0:0232a97b3883 36
yamaguch 0:0232a97b3883 37 /**
yamaguch 0:0232a97b3883 38 * class for XBee module API mode interface
yamaguch 0:0232a97b3883 39 */
yamaguch 0:0232a97b3883 40 class XBee : public Serial {
yamaguch 0:0232a97b3883 41 public:
yamaguch 0:0232a97b3883 42
yamaguch 0:0232a97b3883 43 /**
yamaguch 0:0232a97b3883 44 * Frame type declaration for XBee API frames
yamaguch 0:0232a97b3883 45 */
yamaguch 0:0232a97b3883 46 enum FrameType {
yamaguch 0:0232a97b3883 47 /**
yamaguch 0:0232a97b3883 48 * Empty data
yamaguch 0:0232a97b3883 49 */
yamaguch 0:0232a97b3883 50 None = 0,
yamaguch 0:0232a97b3883 51
yamaguch 0:0232a97b3883 52 /**
yamaguch 0:0232a97b3883 53 * AT Command Response API frame
yamaguch 0:0232a97b3883 54 */
yamaguch 0:0232a97b3883 55 ATCommandResponse,
yamaguch 0:0232a97b3883 56
yamaguch 0:0232a97b3883 57 /**
yamaguch 0:0232a97b3883 58 * Modem Status API frame
yamaguch 0:0232a97b3883 59 */
yamaguch 0:0232a97b3883 60 ModemStatus,
yamaguch 0:0232a97b3883 61
yamaguch 0:0232a97b3883 62 /**
yamaguch 0:0232a97b3883 63 * ZigBee Transmit Status API frame
yamaguch 0:0232a97b3883 64 */
yamaguch 0:0232a97b3883 65 ZigBeeTransmitStatus,
yamaguch 0:0232a97b3883 66
yamaguch 0:0232a97b3883 67 /**
yamaguch 0:0232a97b3883 68 * ZigBee Receive Packet API frame
yamaguch 0:0232a97b3883 69 */
yamaguch 0:0232a97b3883 70 ZigBeeReceivePacket,
yamaguch 0:0232a97b3883 71
yamaguch 0:0232a97b3883 72 /**
yamaguch 0:0232a97b3883 73 * ZigBee Explicit Rx Indicator API frame
yamaguch 0:0232a97b3883 74 */
yamaguch 0:0232a97b3883 75 ZigBeeExplicitRxIndicator,
yamaguch 0:0232a97b3883 76
yamaguch 0:0232a97b3883 77 /**
yamaguch 0:0232a97b3883 78 * ZigBee I/O Data Sample Rx Indicator API frame
yamaguch 0:0232a97b3883 79 */
yamaguch 0:0232a97b3883 80 ZigBeeIODataSampleRxIndicator,
yamaguch 0:0232a97b3883 81
yamaguch 0:0232a97b3883 82 /**
yamaguch 0:0232a97b3883 83 * XBee Sensor Read Indicator API frame
yamaguch 0:0232a97b3883 84 */
yamaguch 0:0232a97b3883 85 XBeeSensorReadIndicator,
yamaguch 0:0232a97b3883 86
yamaguch 0:0232a97b3883 87 /**
yamaguch 0:0232a97b3883 88 * Node Identification Indicator API frame
yamaguch 0:0232a97b3883 89 */
yamaguch 0:0232a97b3883 90 NodeIdentificationIndicator,
yamaguch 0:0232a97b3883 91
yamaguch 0:0232a97b3883 92 /**
yamaguch 0:0232a97b3883 93 * Remote Command Response API frame
yamaguch 0:0232a97b3883 94 */
yamaguch 0:0232a97b3883 95 RemoteCommandResponse,
yamaguch 0:0232a97b3883 96
yamaguch 0:0232a97b3883 97 /**
yamaguch 0:0232a97b3883 98 * Unknown API frame
yamaguch 0:0232a97b3883 99 */
yamaguch 0:0232a97b3883 100 Other
yamaguch 0:0232a97b3883 101 };
yamaguch 0:0232a97b3883 102
yamaguch 0:0232a97b3883 103 /**
yamaguch 0:0232a97b3883 104 * Value type declarations for retrieving frame data contents
yamaguch 0:0232a97b3883 105 */
yamaguch 0:0232a97b3883 106 enum ValueType {
yamaguch 0:0232a97b3883 107 /**
yamaguch 0:0232a97b3883 108 * Frame ID
yamaguch 0:0232a97b3883 109 */
yamaguch 0:0232a97b3883 110 FrameID,
yamaguch 0:0232a97b3883 111
yamaguch 0:0232a97b3883 112 /**
yamaguch 0:0232a97b3883 113 *AT command name
yamaguch 0:0232a97b3883 114 */
yamaguch 0:0232a97b3883 115 ATCommand,
yamaguch 0:0232a97b3883 116
yamaguch 0:0232a97b3883 117 /**
yamaguch 0:0232a97b3883 118 * Status
yamaguch 0:0232a97b3883 119 */
yamaguch 0:0232a97b3883 120 Status,
yamaguch 0:0232a97b3883 121
yamaguch 0:0232a97b3883 122 /**
yamaguch 0:0232a97b3883 123 * Command data
yamaguch 0:0232a97b3883 124 */
yamaguch 0:0232a97b3883 125 CommandData,
yamaguch 0:0232a97b3883 126
yamaguch 0:0232a97b3883 127 /**
yamaguch 0:0232a97b3883 128 * 16 bit address
yamaguch 0:0232a97b3883 129 */
yamaguch 0:0232a97b3883 130 Address16,
yamaguch 0:0232a97b3883 131
yamaguch 0:0232a97b3883 132 /**
yamaguch 0:0232a97b3883 133 * 64 bit address
yamaguch 0:0232a97b3883 134 */
yamaguch 0:0232a97b3883 135 Address64,
yamaguch 0:0232a97b3883 136
yamaguch 0:0232a97b3883 137 /**
yamaguch 0:0232a97b3883 138 * Retry count
yamaguch 0:0232a97b3883 139 */
yamaguch 0:0232a97b3883 140 RetryCount,
yamaguch 0:0232a97b3883 141
yamaguch 0:0232a97b3883 142 /**
yamaguch 0:0232a97b3883 143 * Delivery status
yamaguch 0:0232a97b3883 144 */
yamaguch 0:0232a97b3883 145 DeliveryStatus,
yamaguch 0:0232a97b3883 146
yamaguch 0:0232a97b3883 147 /**
yamaguch 0:0232a97b3883 148 * Discovery status
yamaguch 0:0232a97b3883 149 */
yamaguch 0:0232a97b3883 150 DiscoveryStatus,
yamaguch 0:0232a97b3883 151
yamaguch 0:0232a97b3883 152 /**
yamaguch 0:0232a97b3883 153 * Receive option
yamaguch 0:0232a97b3883 154 */
yamaguch 0:0232a97b3883 155 ReceiveOptions,
yamaguch 0:0232a97b3883 156
yamaguch 0:0232a97b3883 157 /**
yamaguch 0:0232a97b3883 158 * Received data
yamaguch 0:0232a97b3883 159 */
yamaguch 0:0232a97b3883 160 ReceivedData,
yamaguch 0:0232a97b3883 161
yamaguch 0:0232a97b3883 162 /**
yamaguch 0:0232a97b3883 163 * Raw data
yamaguch 0:0232a97b3883 164 */
yamaguch 0:0232a97b3883 165 RawData
yamaguch 0:0232a97b3883 166 };
yamaguch 0:0232a97b3883 167
yamaguch 0:0232a97b3883 168
yamaguch 0:0232a97b3883 169 /**
yamaguch 0:0232a97b3883 170 * creates an XBee interface object.
yamaguch 0:0232a97b3883 171 *
yamaguch 0:0232a97b3883 172 * @param ser Serial object through which XBee module is connected to mbed
yamaguch 0:0232a97b3883 173 * @param apiMode API mode either 1 or 2 (use escape; default)
yamaguch 0:0232a97b3883 174 * @param debug display debugging (I/O state) information through LEDs
yamaguch 0:0232a97b3883 175 */
yamaguch 0:0232a97b3883 176 XBee(Serial& ser, int apiMode = 2, bool debug = false);
yamaguch 0:0232a97b3883 177
yamaguch 0:0232a97b3883 178
yamaguch 0:0232a97b3883 179 /**
yamaguch 0:0232a97b3883 180 * creates an XBee interface object.
yamaguch 0:0232a97b3883 181 *
yamaguch 0:0232a97b3883 182 * @param tx TX pin connected to XBee
yamaguch 0:0232a97b3883 183 * @param rx RX pin connected to XBee
yamaguch 0:0232a97b3883 184 * @param apiMode API mode either 1 or 2 (use escape; default)
yamaguch 0:0232a97b3883 185 * @param debug display debugging (I/O state) information through LEDs
yamaguch 0:0232a97b3883 186 */
yamaguch 0:0232a97b3883 187 XBee(PinName tx, PinName rx, int apiMode = 2, bool debug = false);
yamaguch 0:0232a97b3883 188
yamaguch 0:0232a97b3883 189 /**
yamaguch 0:0232a97b3883 190 * creates an XBee interface object.
yamaguch 0:0232a97b3883 191 *
yamaguch 0:0232a97b3883 192 * @param ser Serial object through which XBee module is connected to mbed
yamaguch 0:0232a97b3883 193 * @param mon alternate Serial object for monitoring (use serial ports other than USBTX/USBRX)
yamaguch 0:0232a97b3883 194 * @param apiMode API mode either 1 or 2 (use escape; default)
yamaguch 0:0232a97b3883 195 * @param debug display debugging (I/O state) information through LEDs
yamaguch 0:0232a97b3883 196 */
yamaguch 0:0232a97b3883 197 XBee(Serial& ser, Serial& mon, int apiMode = 2, bool debug = false);
yamaguch 0:0232a97b3883 198
yamaguch 0:0232a97b3883 199 /**
yamaguch 0:0232a97b3883 200 * creates an XBee interface object.
yamaguch 0:0232a97b3883 201 *
yamaguch 0:0232a97b3883 202 * @param tx TX pin connected to XBee
yamaguch 0:0232a97b3883 203 * @param rx RX pin connected to XBee
yamaguch 0:0232a97b3883 204 * @param mon alternate Serial object for monitoring (use serial ports other than USBTX/USBRX)
yamaguch 0:0232a97b3883 205 * @param apiMode API mode either 1 or 2 (use escape; default)
yamaguch 0:0232a97b3883 206 * @param debug display debugging (I/O state) information through LEDs
yamaguch 0:0232a97b3883 207 */
yamaguch 0:0232a97b3883 208 XBee(PinName tx, PinName rx, Serial& mon, int apiMode = 2, bool debug = false);
yamaguch 0:0232a97b3883 209
yamaguch 0:0232a97b3883 210 /**
yamaguch 0:0232a97b3883 211 * initializes XBee module.
yamaguch 0:0232a97b3883 212 *
yamaguch 0:0232a97b3883 213 * issues VR command to test XBee modem connection
yamaguch 0:0232a97b3883 214 *
yamaguch 0:0232a97b3883 215 * @returns true if initialization succeeded, false otherwise
yamaguch 0:0232a97b3883 216 */
yamaguch 0:0232a97b3883 217 bool init(float timeout = 15.0);
yamaguch 0:0232a97b3883 218
yamaguch 0:0232a97b3883 219 /**
yamaguch 0:0232a97b3883 220 * sets destination addresses.
yamaguch 0:0232a97b3883 221 *
yamaguch 0:0232a97b3883 222 * @param address64 XBeeAddress64 type address
yamaguch 0:0232a97b3883 223 * @param address16 XBeeAddress16 type address (optional)
yamaguch 0:0232a97b3883 224 */
yamaguch 0:0232a97b3883 225 void setDestination(XBeeAddress64 address64, XBeeAddress16 address16 = 0xFFFE);
yamaguch 0:0232a97b3883 226
yamaguch 0:0232a97b3883 227 /**
yamaguch 0:0232a97b3883 228 * sets destination addresses.
yamaguch 0:0232a97b3883 229 *
yamaguch 0:0232a97b3883 230 * @param address64 64-bit destination address in uint64_t
yamaguch 0:0232a97b3883 231 * @param address16 16-bit destination address in uint16_t
yamaguch 0:0232a97b3883 232 */
yamaguch 0:0232a97b3883 233 void setDestination(uint64_t address64, uint16_t address16 = 0xFFFE);
yamaguch 0:0232a97b3883 234
yamaguch 0:0232a97b3883 235 /**
yamaguch 0:0232a97b3883 236 * sets destination addresses.
yamaguch 0:0232a97b3883 237 *
yamaguch 0:0232a97b3883 238 * @param address64 64-bit destination address in bytes (big endian)
yamaguch 0:0232a97b3883 239 * @param address16 16-bit destination address in bytes
yamaguch 0:0232a97b3883 240 */
yamaguch 0:0232a97b3883 241 void setDestination(char address64[], char address16[]);
yamaguch 0:0232a97b3883 242
yamaguch 0:0232a97b3883 243 /**
yamaguch 0:0232a97b3883 244 * sends an AT command.
yamaguch 0:0232a97b3883 245 *
yamaguch 0:0232a97b3883 246 * @param command AT command char string
yamaguch 0:0232a97b3883 247 * @param param parameter to the AT command
yamaguch 0:0232a97b3883 248 */
yamaguch 0:0232a97b3883 249 void sendCommand(const char *command, int8_t param, bool queue = false);
yamaguch 0:0232a97b3883 250 void sendCommand(const char *command, int16_t param, bool queue = false);
yamaguch 0:0232a97b3883 251 void sendCommand(const char *command, int32_t param, bool queue = false);
yamaguch 0:0232a97b3883 252 void sendCommand(const char *command, int64_t param, bool queue = false);
yamaguch 0:0232a97b3883 253 void sendCommand(const char *command, uint8_t param, bool queue = false);
yamaguch 0:0232a97b3883 254 void sendCommand(const char *command, uint16_t param, bool queue = false);
yamaguch 0:0232a97b3883 255 void sendCommand(const char *command, uint32_t param, bool queue = false);
yamaguch 0:0232a97b3883 256 void sendCommand(const char *command, uint64_t param, bool queue = false);
yamaguch 0:0232a97b3883 257 void sendCommand(const char *command, const char *param, bool queue = false);
yamaguch 0:0232a97b3883 258
yamaguch 0:0232a97b3883 259 /**
yamaguch 0:0232a97b3883 260 * sends an AT command.
yamaguch 0:0232a97b3883 261 *
yamaguch 0:0232a97b3883 262 * @param command AT command char string
yamaguch 0:0232a97b3883 263 * @param param parameter to the AT command (pointer to byte array)
yamaguch 0:0232a97b3883 264 * @param param_length parameter length in bytes
yamaguch 0:0232a97b3883 265 * @param queue true if command paramter is to be queued
yamaguch 0:0232a97b3883 266 */
yamaguch 0:0232a97b3883 267 void sendCommand(const char *command, const uint8_t *param = 0, int param_length = 0, bool queue = false);
yamaguch 0:0232a97b3883 268
yamaguch 0:0232a97b3883 269 /**
yamaguch 0:0232a97b3883 270 * sends a remote AT command.
yamaguch 0:0232a97b3883 271 *
yamaguch 0:0232a97b3883 272 * sends an AT command to the XBee(s) at the destination address
yamaguch 0:0232a97b3883 273 *
yamaguch 0:0232a97b3883 274 * @param command AT command char string
yamaguch 0:0232a97b3883 275 * @param param parameter to the AT command (pointer to byte array)
yamaguch 0:0232a97b3883 276 * @param param_length parameter length in bytes
yamaguch 0:0232a97b3883 277 * @param options remote command options
yamaguch 0:0232a97b3883 278 */
yamaguch 0:0232a97b3883 279 void sendRemoteCommand(const char *command, int8_t param);
yamaguch 0:0232a97b3883 280 void sendRemoteCommand(const char *command, int16_t param);
yamaguch 0:0232a97b3883 281 void sendRemoteCommand(const char *command, int32_t param);
yamaguch 0:0232a97b3883 282 void sendRemoteCommand(const char *command, int64_t param);
yamaguch 0:0232a97b3883 283 void sendRemoteCommand(const char *command, uint8_t param);
yamaguch 0:0232a97b3883 284 void sendRemoteCommand(const char *command, uint16_t param);
yamaguch 0:0232a97b3883 285 void sendRemoteCommand(const char *command, uint32_t param);
yamaguch 0:0232a97b3883 286 void sendRemoteCommand(const char *command, uint64_t param);
yamaguch 0:0232a97b3883 287 void sendRemoteCommand(const char *command, const char *param);
yamaguch 0:0232a97b3883 288
yamaguch 0:0232a97b3883 289 /**
yamaguch 0:0232a97b3883 290 * sends a remote AT command.
yamaguch 0:0232a97b3883 291 *
yamaguch 0:0232a97b3883 292 * sends an AT command to the XBee(s) at the destination address
yamaguch 0:0232a97b3883 293 *
yamaguch 0:0232a97b3883 294 * @param command AT command char string
yamaguch 0:0232a97b3883 295 * @param param parameter to the AT command (pointer to byte array)
yamaguch 0:0232a97b3883 296 * @param param_length parameter length in bytes
yamaguch 0:0232a97b3883 297 * @param options remote command options
yamaguch 0:0232a97b3883 298 */
yamaguch 0:0232a97b3883 299 void sendRemoteCommand(const char *command, const uint8_t *param = 0, int param_length = 0, char options = 0x02);
yamaguch 0:0232a97b3883 300
yamaguch 0:0232a97b3883 301 /**
yamaguch 0:0232a97b3883 302 * executes an AT command and gets the result.
yamaguch 0:0232a97b3883 303 *
yamaguch 0:0232a97b3883 304 * @param command AT command char string
yamaguch 0:0232a97b3883 305 * @param param parameter to the AT command
yamaguch 0:0232a97b3883 306 *
yamaguch 0:0232a97b3883 307 * @returns pointer to the command result, if the result is a number (char, short, long, int64_t),
yamaguch 0:0232a97b3883 308 * the address to the number will be returned; otherwise the address to the byte array
yamaguch 0:0232a97b3883 309 * containing the command response will be returned.
yamaguch 0:0232a97b3883 310 */
yamaguch 0:0232a97b3883 311 void *executeCommand(const char *command, int8_t param);
yamaguch 0:0232a97b3883 312 void *executeCommand(const char *command, int16_t param);
yamaguch 0:0232a97b3883 313 void *executeCommand(const char *command, int32_t param);
yamaguch 0:0232a97b3883 314 void *executeCommand(const char *command, int64_t param);
yamaguch 0:0232a97b3883 315 void *executeCommand(const char *command, uint8_t param);
yamaguch 0:0232a97b3883 316 void *executeCommand(const char *command, uint16_t param);
yamaguch 0:0232a97b3883 317 void *executeCommand(const char *command, uint32_t param);
yamaguch 0:0232a97b3883 318 void *executeCommand(const char *command, uint64_t param);
yamaguch 0:0232a97b3883 319 void *executeCommand(const char *command, const char *param);
yamaguch 0:0232a97b3883 320
yamaguch 0:0232a97b3883 321 /**
yamaguch 0:0232a97b3883 322 * executes an AT command and gets the result.
yamaguch 0:0232a97b3883 323 *
yamaguch 0:0232a97b3883 324 * @param command AT command char string
yamaguch 0:0232a97b3883 325 * @param param parameter to the AT command (pointer to byte array)
yamaguch 0:0232a97b3883 326 * @param param_length parameter length in bytes
yamaguch 0:0232a97b3883 327 *
yamaguch 0:0232a97b3883 328 * @returns pointer to the command result, if the result is a number (char, short, long, long long),
yamaguch 0:0232a97b3883 329 * the address to the number will be returned; otherwise the address to the byte array
yamaguch 0:0232a97b3883 330 * containing the command response will be returned.
yamaguch 0:0232a97b3883 331 */
yamaguch 0:0232a97b3883 332 void *executeCommand(const char *command, const uint8_t *param = 0, int laram_length = 0);
yamaguch 0:0232a97b3883 333
yamaguch 0:0232a97b3883 334 /**
yamaguch 0:0232a97b3883 335 * sends data to the XBee(s) at the destination address.
yamaguch 0:0232a97b3883 336 *
yamaguch 0:0232a97b3883 337 * @param data address to the data (byte array)
yamaguch 0:0232a97b3883 338 * @param length data length in bytes
yamaguch 0:0232a97b3883 339 * @param confirm if true, checks the transmission status frame and returns the result
yamaguch 0:0232a97b3883 340 */
yamaguch 0:0232a97b3883 341 bool send(const char *data, int length, bool confirm);
yamaguch 0:0232a97b3883 342
yamaguch 0:0232a97b3883 343 /**
yamaguch 0:0232a97b3883 344 * sends data and confirm the transmit status.
yamaguch 0:0232a97b3883 345 *
yamaguch 0:0232a97b3883 346 * @param data address to the data (byte array)
yamaguch 0:0232a97b3883 347 * @param length data length in bytes
yamaguch 0:0232a97b3883 348 *
yamaguch 0:0232a97b3883 349 * @returns true if sent successfully, false otherwise (either timeout or send error occurred)
yamaguch 0:0232a97b3883 350 */
yamaguch 0:0232a97b3883 351 bool sendConfirm(const char *data, int length);
yamaguch 0:0232a97b3883 352
yamaguch 0:0232a97b3883 353 /**
yamaguch 0:0232a97b3883 354 * sends data to the destination using printf format.
yamaguch 0:0232a97b3883 355 *
yamaguch 0:0232a97b3883 356 * @param format printf format string, followed by corresponding arguments
yamaguch 0:0232a97b3883 357 *
yamaguch 0:0232a97b3883 358 * @returns the number of charancters sent, or negative if error occurred
yamaguch 0:0232a97b3883 359 */
yamaguch 0:0232a97b3883 360 int printf(const char *format, ...);
yamaguch 0:0232a97b3883 361
yamaguch 0:0232a97b3883 362 /**
yamaguch 0:0232a97b3883 363 * receives data frame from the XBee module.
yamaguch 0:0232a97b3883 364 *
yamaguch 0:0232a97b3883 365 * @param timeout seconds bofer time out
yamaguch 0:0232a97b3883 366 *
yamaguch 0:0232a97b3883 367 * @returns FrameType of the received frame data
yamaguch 0:0232a97b3883 368 */
yamaguch 0:0232a97b3883 369 FrameType receive(float timeout = 3.0);
yamaguch 0:0232a97b3883 370
yamaguch 0:0232a97b3883 371 /**
yamaguch 0:0232a97b3883 372 * scan received data
yamaguch 0:0232a97b3883 373 *
yamaguch 0:0232a97b3883 374 * @param data XBeeDataType data to be scanned
yamaguch 0:0232a97b3883 375 *
yamaguch 0:0232a97b3883 376 * @param true if scan succeeded, false otherwise
yamaguch 0:0232a97b3883 377 */
yamaguch 0:0232a97b3883 378 bool scan(XBeeFrameID& id) { return scan(XBee::FrameID, id.raw_address(), 1); }
yamaguch 0:0232a97b3883 379 bool scan(XBeeRetryCount& count) { return scan(XBee::RetryCount, count.raw_address(), 1); }
yamaguch 0:0232a97b3883 380 bool scan(XBeeStatus& status) { return scan(XBee::Status, status.raw_address(), 1); }
yamaguch 0:0232a97b3883 381 bool scan(XBeeDeliveryStatus& status) { return scan(XBee::DeliveryStatus, status.raw_address(), 1); }
yamaguch 0:0232a97b3883 382 bool scan(XBeeDiscoveryStatus& status) { return scan(XBee::DiscoveryStatus, status.raw_address(), 1); }
yamaguch 0:0232a97b3883 383 bool scan(XBeeReceiveOptions& options) { return scan(XBee::ReceiveOptions, options.raw_address(), 1); }
yamaguch 0:0232a97b3883 384 bool scan(XBeeAddress64& address64) { return scan(XBee::Address64, address64.raw_address(), 8); }
yamaguch 0:0232a97b3883 385 bool scan(XBeeAddress16& address16) { return scan(XBee::Address16, address16.raw_address(), 2); }
yamaguch 0:0232a97b3883 386 bool scan(XBeeATCommand& command) { return scan(XBee::ATCommand, command.raw_address(), 3); }
yamaguch 0:0232a97b3883 387 bool scan(XBeeCommandData& data) { return scan(XBee::CommandData, data.raw_address(), data.capacity, &data.size); }
yamaguch 0:0232a97b3883 388 bool scan(XBeeReceivedData& data) { return scan(XBee::ReceivedData, data.raw_address(), data.capacity, &data.size); }
yamaguch 0:0232a97b3883 389 bool scan(XBeeRawData& data) { return scan(XBee::RawData, data.raw_address(), data.capacity, &data.size); }
yamaguch 0:0232a97b3883 390
yamaguch 0:0232a97b3883 391 /**
yamaguch 0:0232a97b3883 392 * scan received data according to the specified format.
yamaguch 0:0232a97b3883 393 *
yamaguch 0:0232a97b3883 394 * @param type ValueType of the data to be scanned
yamaguch 0:0232a97b3883 395 * @param value pointer to the byte array to store the scanned value
yamaguch 0:0232a97b3883 396 * @param maxlength max size of the value in bytes
yamaguch 0:0232a97b3883 397 * @param length pointer to an int to receive the actual data length
yamaguch 0:0232a97b3883 398 *
yamaguch 0:0232a97b3883 399 * @param true if scan succeeded, false otherwise
yamaguch 0:0232a97b3883 400 */
yamaguch 0:0232a97b3883 401 bool scan(ValueType type, char *value, int maxlength = 1, int *length = 0);
yamaguch 0:0232a97b3883 402
yamaguch 0:0232a97b3883 403 /**
yamaguch 0:0232a97b3883 404 * gets the XBee firmware version.
yamaguch 0:0232a97b3883 405 *
yamaguch 0:0232a97b3883 406 * @returns XBee firmwre version in int (unsigned short value)
yamaguch 0:0232a97b3883 407 */
yamaguch 0:0232a97b3883 408 int getFirmwareVersion();
yamaguch 0:0232a97b3883 409
yamaguch 0:0232a97b3883 410 /**
yamaguch 0:0232a97b3883 411 * gets the current frame ID.
yamaguch 0:0232a97b3883 412 *
yamaguch 0:0232a97b3883 413 * @returns frame ID number being used in the next send request
yamaguch 0:0232a97b3883 414 */
yamaguch 0:0232a97b3883 415 char getFrameID();
yamaguch 0:0232a97b3883 416
yamaguch 0:0232a97b3883 417 /**
yamaguch 0:0232a97b3883 418 * sets to run in debug mode.
yamaguch 0:0232a97b3883 419 *
yamaguch 0:0232a97b3883 420 * @param debug true to display debugging information
yamaguch 0:0232a97b3883 421 */
yamaguch 0:0232a97b3883 422 void setDebug(bool debug);
yamaguch 0:0232a97b3883 423
yamaguch 0:0232a97b3883 424 /**
yamaguch 0:0232a97b3883 425 * displays received data in dump format.
yamaguch 0:0232a97b3883 426 */
yamaguch 0:0232a97b3883 427 void dump();
yamaguch 0:0232a97b3883 428
yamaguch 0:0232a97b3883 429 /**
yamaguch 0:0232a97b3883 430 * displays the internal data fields and receive buffer in dump format.
yamaguch 0:0232a97b3883 431 */
yamaguch 0:0232a97b3883 432 void dumpAll();
yamaguch 0:0232a97b3883 433
yamaguch 0:0232a97b3883 434 /**
yamaguch 0:0232a97b3883 435 * operator overloading for testing XBee modem connection status.
yamaguch 0:0232a97b3883 436 *
yamaguch 0:0232a97b3883 437 * @returns false if XBee modem connection has an error
yamaguch 0:0232a97b3883 438 */
yamaguch 0:0232a97b3883 439 operator bool();
yamaguch 0:0232a97b3883 440
yamaguch 0:0232a97b3883 441 private:
yamaguch 0:0232a97b3883 442 Serial mon;
yamaguch 0:0232a97b3883 443 BusOut leds;
yamaguch 0:0232a97b3883 444 int apiMode;
yamaguch 0:0232a97b3883 445 volatile enum {UNKNOWN, LENGTH1, LENGTH2, DATA, SUMCHECK} state;
yamaguch 0:0232a97b3883 446 volatile int cur, in, out, received, free;
yamaguch 0:0232a97b3883 447 char frame_id;
yamaguch 0:0232a97b3883 448 char destination64[8];
yamaguch 0:0232a97b3883 449 char destination16[2];
yamaguch 0:0232a97b3883 450 char buf[BUFSIZE];
yamaguch 0:0232a97b3883 451 bool debug;
yamaguch 0:0232a97b3883 452
yamaguch 0:0232a97b3883 453 void send(char c);
yamaguch 0:0232a97b3883 454 void send2(char c);
yamaguch 0:0232a97b3883 455 void sendFrame(const char *frame, int length);
yamaguch 0:0232a97b3883 456 int createTxRequest(char frame_id, const char *data, int data_length, char *buf, int buf_size);
yamaguch 0:0232a97b3883 457 int createAtRequest(char frame_id, const char *command, const uint8_t *param, int param_length, bool queue, char *buf, int buf_size);
yamaguch 0:0232a97b3883 458 int createRemoteAtRequest(char frame_id, const char *command, const uint8_t *param, int param_length, char options, char *buf, int buf_size);
yamaguch 0:0232a97b3883 459 int seekFor(FrameType type, float timeout);
yamaguch 0:0232a97b3883 460 FrameType getFrameType(char c);
yamaguch 0:0232a97b3883 461 bool scan(int i, ValueType type, char *value, int maxlength = 1, int *length = 0);
yamaguch 0:0232a97b3883 462 void flush();
yamaguch 0:0232a97b3883 463 void rxInterruptHandler();
yamaguch 0:0232a97b3883 464 void rxInterruptHandler2();
yamaguch 0:0232a97b3883 465
yamaguch 0:0232a97b3883 466 void dump(const char *data, int length);
yamaguch 0:0232a97b3883 467 void dumpIOSample(const char *data, int length);
yamaguch 0:0232a97b3883 468 void copy(char *toBuf, int fromIndex, int length);
yamaguch 0:0232a97b3883 469 };
yamaguch 0:0232a97b3883 470
yamaguch 0:0232a97b3883 471 #endif