XBee API mode library

Committer:
yamaguch
Date:
Wed Jan 23 04:00:51 2013 +0000
Revision:
5:b82970ef7fb0
Parent:
3:8453df14bd30
Child:
6:d15800bfa15d
added NodeIdentifierIndicator

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 5:b82970ef7fb0 136
yamaguch 5:b82970ef7fb0 137 /**
yamaguch 5:b82970ef7fb0 138 * 16 bit remote address
yamaguch 5:b82970ef7fb0 139 */
yamaguch 5:b82970ef7fb0 140 RemoteAddress16,
yamaguch 5:b82970ef7fb0 141
yamaguch 5:b82970ef7fb0 142 /**
yamaguch 5:b82970ef7fb0 143 * 64 bit remote address
yamaguch 5:b82970ef7fb0 144 */
yamaguch 5:b82970ef7fb0 145 RemoteAddress64,
yamaguch 5:b82970ef7fb0 146
yamaguch 5:b82970ef7fb0 147 /**
yamaguch 5:b82970ef7fb0 148 * 16 bit parent address
yamaguch 5:b82970ef7fb0 149 */
yamaguch 5:b82970ef7fb0 150 ParentAddress16,
yamaguch 0:0232a97b3883 151
yamaguch 0:0232a97b3883 152 /**
yamaguch 0:0232a97b3883 153 * Retry count
yamaguch 0:0232a97b3883 154 */
yamaguch 0:0232a97b3883 155 RetryCount,
yamaguch 0:0232a97b3883 156
yamaguch 0:0232a97b3883 157 /**
yamaguch 0:0232a97b3883 158 * Delivery status
yamaguch 0:0232a97b3883 159 */
yamaguch 0:0232a97b3883 160 DeliveryStatus,
yamaguch 0:0232a97b3883 161
yamaguch 0:0232a97b3883 162 /**
yamaguch 0:0232a97b3883 163 * Discovery status
yamaguch 0:0232a97b3883 164 */
yamaguch 0:0232a97b3883 165 DiscoveryStatus,
yamaguch 0:0232a97b3883 166
yamaguch 0:0232a97b3883 167 /**
yamaguch 0:0232a97b3883 168 * Receive option
yamaguch 0:0232a97b3883 169 */
yamaguch 0:0232a97b3883 170 ReceiveOptions,
yamaguch 0:0232a97b3883 171
yamaguch 0:0232a97b3883 172 /**
yamaguch 0:0232a97b3883 173 * Received data
yamaguch 0:0232a97b3883 174 */
yamaguch 0:0232a97b3883 175 ReceivedData,
yamaguch 0:0232a97b3883 176
yamaguch 0:0232a97b3883 177 /**
yamaguch 5:b82970ef7fb0 178 * Node Identifier String
yamaguch 5:b82970ef7fb0 179 */
yamaguch 5:b82970ef7fb0 180 NIString,
yamaguch 5:b82970ef7fb0 181
yamaguch 5:b82970ef7fb0 182 /**
yamaguch 5:b82970ef7fb0 183 * Device Type
yamaguch 5:b82970ef7fb0 184 */
yamaguch 5:b82970ef7fb0 185 DeviceType,
yamaguch 5:b82970ef7fb0 186
yamaguch 5:b82970ef7fb0 187 /**
yamaguch 5:b82970ef7fb0 188 * Source Event
yamaguch 5:b82970ef7fb0 189 */
yamaguch 5:b82970ef7fb0 190 SourceEvent,
yamaguch 5:b82970ef7fb0 191
yamaguch 5:b82970ef7fb0 192 /**
yamaguch 0:0232a97b3883 193 * Raw data
yamaguch 0:0232a97b3883 194 */
yamaguch 0:0232a97b3883 195 RawData
yamaguch 0:0232a97b3883 196 };
yamaguch 0:0232a97b3883 197
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 ser Serial object through which XBee module is connected to mbed
yamaguch 0:0232a97b3883 203 * @param apiMode API mode either 1 or 2 (use escape; default)
yamaguch 0:0232a97b3883 204 * @param debug display debugging (I/O state) information through LEDs
yamaguch 0:0232a97b3883 205 */
yamaguch 0:0232a97b3883 206 XBee(Serial& ser, int apiMode = 2, bool debug = false);
yamaguch 0:0232a97b3883 207
yamaguch 0:0232a97b3883 208
yamaguch 0:0232a97b3883 209 /**
yamaguch 0:0232a97b3883 210 * creates an XBee interface object.
yamaguch 0:0232a97b3883 211 *
yamaguch 0:0232a97b3883 212 * @param tx TX pin connected to XBee
yamaguch 0:0232a97b3883 213 * @param rx RX pin connected to XBee
yamaguch 0:0232a97b3883 214 * @param apiMode API mode either 1 or 2 (use escape; default)
yamaguch 0:0232a97b3883 215 * @param debug display debugging (I/O state) information through LEDs
yamaguch 0:0232a97b3883 216 */
yamaguch 0:0232a97b3883 217 XBee(PinName tx, PinName rx, int apiMode = 2, bool debug = false);
yamaguch 0:0232a97b3883 218
yamaguch 0:0232a97b3883 219 /**
yamaguch 0:0232a97b3883 220 * creates an XBee interface object.
yamaguch 0:0232a97b3883 221 *
yamaguch 0:0232a97b3883 222 * @param ser Serial object through which XBee module is connected to mbed
yamaguch 0:0232a97b3883 223 * @param mon alternate Serial object for monitoring (use serial ports other than USBTX/USBRX)
yamaguch 0:0232a97b3883 224 * @param apiMode API mode either 1 or 2 (use escape; default)
yamaguch 0:0232a97b3883 225 * @param debug display debugging (I/O state) information through LEDs
yamaguch 0:0232a97b3883 226 */
yamaguch 0:0232a97b3883 227 XBee(Serial& ser, Serial& mon, int apiMode = 2, bool debug = false);
yamaguch 0:0232a97b3883 228
yamaguch 0:0232a97b3883 229 /**
yamaguch 0:0232a97b3883 230 * creates an XBee interface object.
yamaguch 0:0232a97b3883 231 *
yamaguch 0:0232a97b3883 232 * @param tx TX pin connected to XBee
yamaguch 0:0232a97b3883 233 * @param rx RX pin connected to XBee
yamaguch 0:0232a97b3883 234 * @param mon alternate Serial object for monitoring (use serial ports other than USBTX/USBRX)
yamaguch 0:0232a97b3883 235 * @param apiMode API mode either 1 or 2 (use escape; default)
yamaguch 0:0232a97b3883 236 * @param debug display debugging (I/O state) information through LEDs
yamaguch 0:0232a97b3883 237 */
yamaguch 0:0232a97b3883 238 XBee(PinName tx, PinName rx, Serial& mon, int apiMode = 2, bool debug = false);
yamaguch 0:0232a97b3883 239
yamaguch 0:0232a97b3883 240 /**
yamaguch 0:0232a97b3883 241 * initializes XBee module.
yamaguch 0:0232a97b3883 242 *
yamaguch 0:0232a97b3883 243 * issues VR command to test XBee modem connection
yamaguch 0:0232a97b3883 244 *
yamaguch 0:0232a97b3883 245 * @returns true if initialization succeeded, false otherwise
yamaguch 0:0232a97b3883 246 */
yamaguch 0:0232a97b3883 247 bool init(float timeout = 15.0);
yamaguch 0:0232a97b3883 248
yamaguch 0:0232a97b3883 249 /**
yamaguch 0:0232a97b3883 250 * sets destination addresses.
yamaguch 0:0232a97b3883 251 *
yamaguch 0:0232a97b3883 252 * @param address64 XBeeAddress64 type address
yamaguch 0:0232a97b3883 253 * @param address16 XBeeAddress16 type address (optional)
yamaguch 0:0232a97b3883 254 */
yamaguch 0:0232a97b3883 255 void setDestination(XBeeAddress64 address64, XBeeAddress16 address16 = 0xFFFE);
yamaguch 0:0232a97b3883 256
yamaguch 0:0232a97b3883 257 /**
yamaguch 0:0232a97b3883 258 * sets destination addresses.
yamaguch 0:0232a97b3883 259 *
yamaguch 0:0232a97b3883 260 * @param address64 64-bit destination address in uint64_t
yamaguch 0:0232a97b3883 261 * @param address16 16-bit destination address in uint16_t
yamaguch 0:0232a97b3883 262 */
yamaguch 0:0232a97b3883 263 void setDestination(uint64_t address64, uint16_t address16 = 0xFFFE);
yamaguch 0:0232a97b3883 264
yamaguch 0:0232a97b3883 265 /**
yamaguch 0:0232a97b3883 266 * sets destination addresses.
yamaguch 0:0232a97b3883 267 *
yamaguch 0:0232a97b3883 268 * @param address64 64-bit destination address in bytes (big endian)
yamaguch 0:0232a97b3883 269 * @param address16 16-bit destination address in bytes
yamaguch 0:0232a97b3883 270 */
yamaguch 0:0232a97b3883 271 void setDestination(char address64[], char address16[]);
yamaguch 0:0232a97b3883 272
yamaguch 0:0232a97b3883 273 /**
yamaguch 0:0232a97b3883 274 * sends an AT command.
yamaguch 0:0232a97b3883 275 *
yamaguch 0:0232a97b3883 276 * @param command AT command char string
yamaguch 0:0232a97b3883 277 * @param param parameter to the AT command
yamaguch 0:0232a97b3883 278 */
yamaguch 0:0232a97b3883 279 void sendCommand(const char *command, int8_t param, bool queue = false);
yamaguch 0:0232a97b3883 280 void sendCommand(const char *command, int16_t param, bool queue = false);
yamaguch 0:0232a97b3883 281 void sendCommand(const char *command, int32_t param, bool queue = false);
yamaguch 0:0232a97b3883 282 void sendCommand(const char *command, int64_t param, bool queue = false);
yamaguch 0:0232a97b3883 283 void sendCommand(const char *command, uint8_t param, bool queue = false);
yamaguch 0:0232a97b3883 284 void sendCommand(const char *command, uint16_t param, bool queue = false);
yamaguch 0:0232a97b3883 285 void sendCommand(const char *command, uint32_t param, bool queue = false);
yamaguch 0:0232a97b3883 286 void sendCommand(const char *command, uint64_t param, bool queue = false);
yamaguch 0:0232a97b3883 287 void sendCommand(const char *command, const char *param, bool queue = false);
yamaguch 0:0232a97b3883 288
yamaguch 0:0232a97b3883 289 /**
yamaguch 0:0232a97b3883 290 * sends an AT command.
yamaguch 0:0232a97b3883 291 *
yamaguch 0:0232a97b3883 292 * @param command AT command char string
yamaguch 0:0232a97b3883 293 * @param param parameter to the AT command (pointer to byte array)
yamaguch 0:0232a97b3883 294 * @param param_length parameter length in bytes
yamaguch 0:0232a97b3883 295 * @param queue true if command paramter is to be queued
yamaguch 0:0232a97b3883 296 */
yamaguch 0:0232a97b3883 297 void sendCommand(const char *command, const uint8_t *param = 0, int param_length = 0, bool queue = false);
yamaguch 0:0232a97b3883 298
yamaguch 0:0232a97b3883 299 /**
yamaguch 0:0232a97b3883 300 * sends a remote AT command.
yamaguch 0:0232a97b3883 301 *
yamaguch 0:0232a97b3883 302 * sends an AT command to the XBee(s) at the destination address
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 (pointer to byte array)
yamaguch 0:0232a97b3883 306 * @param param_length parameter length in bytes
yamaguch 0:0232a97b3883 307 * @param options remote command options
yamaguch 0:0232a97b3883 308 */
yamaguch 0:0232a97b3883 309 void sendRemoteCommand(const char *command, int8_t param);
yamaguch 0:0232a97b3883 310 void sendRemoteCommand(const char *command, int16_t param);
yamaguch 0:0232a97b3883 311 void sendRemoteCommand(const char *command, int32_t param);
yamaguch 0:0232a97b3883 312 void sendRemoteCommand(const char *command, int64_t param);
yamaguch 0:0232a97b3883 313 void sendRemoteCommand(const char *command, uint8_t param);
yamaguch 0:0232a97b3883 314 void sendRemoteCommand(const char *command, uint16_t param);
yamaguch 0:0232a97b3883 315 void sendRemoteCommand(const char *command, uint32_t param);
yamaguch 0:0232a97b3883 316 void sendRemoteCommand(const char *command, uint64_t param);
yamaguch 0:0232a97b3883 317 void sendRemoteCommand(const char *command, const char *param);
yamaguch 0:0232a97b3883 318
yamaguch 0:0232a97b3883 319 /**
yamaguch 0:0232a97b3883 320 * sends a remote AT command.
yamaguch 0:0232a97b3883 321 *
yamaguch 0:0232a97b3883 322 * sends an AT command to the XBee(s) at the destination address
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 * @param options remote command options
yamaguch 0:0232a97b3883 328 */
yamaguch 0:0232a97b3883 329 void sendRemoteCommand(const char *command, const uint8_t *param = 0, int param_length = 0, char options = 0x02);
yamaguch 0:0232a97b3883 330
yamaguch 0:0232a97b3883 331 /**
yamaguch 0:0232a97b3883 332 * executes an AT command and gets the result.
yamaguch 0:0232a97b3883 333 *
yamaguch 0:0232a97b3883 334 * @param command AT command char string
yamaguch 0:0232a97b3883 335 * @param param parameter to the AT command
yamaguch 0:0232a97b3883 336 *
yamaguch 0:0232a97b3883 337 * @returns pointer to the command result, if the result is a number (char, short, long, int64_t),
yamaguch 0:0232a97b3883 338 * the address to the number will be returned; otherwise the address to the byte array
yamaguch 0:0232a97b3883 339 * containing the command response will be returned.
yamaguch 0:0232a97b3883 340 */
yamaguch 0:0232a97b3883 341 void *executeCommand(const char *command, int8_t param);
yamaguch 0:0232a97b3883 342 void *executeCommand(const char *command, int16_t param);
yamaguch 0:0232a97b3883 343 void *executeCommand(const char *command, int32_t param);
yamaguch 0:0232a97b3883 344 void *executeCommand(const char *command, int64_t param);
yamaguch 0:0232a97b3883 345 void *executeCommand(const char *command, uint8_t param);
yamaguch 0:0232a97b3883 346 void *executeCommand(const char *command, uint16_t param);
yamaguch 0:0232a97b3883 347 void *executeCommand(const char *command, uint32_t param);
yamaguch 0:0232a97b3883 348 void *executeCommand(const char *command, uint64_t param);
yamaguch 0:0232a97b3883 349 void *executeCommand(const char *command, const char *param);
yamaguch 0:0232a97b3883 350
yamaguch 0:0232a97b3883 351 /**
yamaguch 0:0232a97b3883 352 * executes an AT command and gets the result.
yamaguch 0:0232a97b3883 353 *
yamaguch 0:0232a97b3883 354 * @param command AT command char string
yamaguch 0:0232a97b3883 355 * @param param parameter to the AT command (pointer to byte array)
yamaguch 0:0232a97b3883 356 * @param param_length parameter length in bytes
yamaguch 0:0232a97b3883 357 *
yamaguch 0:0232a97b3883 358 * @returns pointer to the command result, if the result is a number (char, short, long, long long),
yamaguch 0:0232a97b3883 359 * the address to the number will be returned; otherwise the address to the byte array
yamaguch 0:0232a97b3883 360 * containing the command response will be returned.
yamaguch 0:0232a97b3883 361 */
yamaguch 0:0232a97b3883 362 void *executeCommand(const char *command, const uint8_t *param = 0, int laram_length = 0);
yamaguch 0:0232a97b3883 363
yamaguch 0:0232a97b3883 364 /**
yamaguch 0:0232a97b3883 365 * sends data to the XBee(s) at the destination address.
yamaguch 0:0232a97b3883 366 *
yamaguch 0:0232a97b3883 367 * @param data address to the data (byte array)
yamaguch 0:0232a97b3883 368 * @param length data length in bytes
yamaguch 0:0232a97b3883 369 * @param confirm if true, checks the transmission status frame and returns the result
yamaguch 0:0232a97b3883 370 */
yamaguch 0:0232a97b3883 371 bool send(const char *data, int length, bool confirm);
yamaguch 0:0232a97b3883 372
yamaguch 0:0232a97b3883 373 /**
yamaguch 0:0232a97b3883 374 * sends data and confirm the transmit status.
yamaguch 0:0232a97b3883 375 *
yamaguch 0:0232a97b3883 376 * @param data address to the data (byte array)
yamaguch 0:0232a97b3883 377 * @param length data length in bytes
yamaguch 0:0232a97b3883 378 *
yamaguch 0:0232a97b3883 379 * @returns true if sent successfully, false otherwise (either timeout or send error occurred)
yamaguch 0:0232a97b3883 380 */
yamaguch 0:0232a97b3883 381 bool sendConfirm(const char *data, int length);
yamaguch 0:0232a97b3883 382
yamaguch 0:0232a97b3883 383 /**
yamaguch 0:0232a97b3883 384 * sends data to the destination using printf format.
yamaguch 0:0232a97b3883 385 *
yamaguch 0:0232a97b3883 386 * @param format printf format string, followed by corresponding arguments
yamaguch 0:0232a97b3883 387 *
yamaguch 0:0232a97b3883 388 * @returns the number of charancters sent, or negative if error occurred
yamaguch 0:0232a97b3883 389 */
yamaguch 0:0232a97b3883 390 int printf(const char *format, ...);
yamaguch 0:0232a97b3883 391
yamaguch 0:0232a97b3883 392 /**
yamaguch 0:0232a97b3883 393 * receives data frame from the XBee module.
yamaguch 0:0232a97b3883 394 *
yamaguch 0:0232a97b3883 395 * @param timeout seconds bofer time out
yamaguch 0:0232a97b3883 396 *
yamaguch 0:0232a97b3883 397 * @returns FrameType of the received frame data
yamaguch 0:0232a97b3883 398 */
yamaguch 0:0232a97b3883 399 FrameType receive(float timeout = 3.0);
yamaguch 0:0232a97b3883 400
yamaguch 0:0232a97b3883 401 /**
yamaguch 0:0232a97b3883 402 * scan received data
yamaguch 0:0232a97b3883 403 *
yamaguch 0:0232a97b3883 404 * @param data XBeeDataType data to be scanned
yamaguch 0:0232a97b3883 405 *
yamaguch 0:0232a97b3883 406 * @param true if scan succeeded, false otherwise
yamaguch 0:0232a97b3883 407 */
yamaguch 0:0232a97b3883 408 bool scan(XBeeFrameID& id) { return scan(XBee::FrameID, id.raw_address(), 1); }
yamaguch 0:0232a97b3883 409 bool scan(XBeeRetryCount& count) { return scan(XBee::RetryCount, count.raw_address(), 1); }
yamaguch 0:0232a97b3883 410 bool scan(XBeeStatus& status) { return scan(XBee::Status, status.raw_address(), 1); }
yamaguch 0:0232a97b3883 411 bool scan(XBeeDeliveryStatus& status) { return scan(XBee::DeliveryStatus, status.raw_address(), 1); }
yamaguch 0:0232a97b3883 412 bool scan(XBeeDiscoveryStatus& status) { return scan(XBee::DiscoveryStatus, status.raw_address(), 1); }
yamaguch 0:0232a97b3883 413 bool scan(XBeeReceiveOptions& options) { return scan(XBee::ReceiveOptions, options.raw_address(), 1); }
yamaguch 5:b82970ef7fb0 414 bool scan(XBeeDeviceType& device) { return scan(XBee::DeviceType, device.raw_address(), 1); }
yamaguch 5:b82970ef7fb0 415 bool scan(XBeeSourceEvent& event) { return scan(XBee::SourceEvent, event.raw_address(), 1); }
yamaguch 0:0232a97b3883 416 bool scan(XBeeAddress64& address64) { return scan(XBee::Address64, address64.raw_address(), 8); }
yamaguch 0:0232a97b3883 417 bool scan(XBeeAddress16& address16) { return scan(XBee::Address16, address16.raw_address(), 2); }
yamaguch 0:0232a97b3883 418 bool scan(XBeeATCommand& command) { return scan(XBee::ATCommand, command.raw_address(), 3); }
yamaguch 0:0232a97b3883 419 bool scan(XBeeCommandData& data) { return scan(XBee::CommandData, data.raw_address(), data.capacity, &data.size); }
yamaguch 0:0232a97b3883 420 bool scan(XBeeReceivedData& data) { return scan(XBee::ReceivedData, data.raw_address(), data.capacity, &data.size); }
yamaguch 0:0232a97b3883 421 bool scan(XBeeRawData& data) { return scan(XBee::RawData, data.raw_address(), data.capacity, &data.size); }
yamaguch 0:0232a97b3883 422
yamaguch 0:0232a97b3883 423 /**
yamaguch 0:0232a97b3883 424 * scan received data according to the specified format.
yamaguch 0:0232a97b3883 425 *
yamaguch 0:0232a97b3883 426 * @param type ValueType of the data to be scanned
yamaguch 0:0232a97b3883 427 * @param value pointer to the byte array to store the scanned value
yamaguch 0:0232a97b3883 428 * @param maxlength max size of the value in bytes
yamaguch 0:0232a97b3883 429 * @param length pointer to an int to receive the actual data length
yamaguch 0:0232a97b3883 430 *
yamaguch 0:0232a97b3883 431 * @param true if scan succeeded, false otherwise
yamaguch 0:0232a97b3883 432 */
yamaguch 0:0232a97b3883 433 bool scan(ValueType type, char *value, int maxlength = 1, int *length = 0);
yamaguch 0:0232a97b3883 434
yamaguch 0:0232a97b3883 435 /**
yamaguch 0:0232a97b3883 436 * gets the XBee firmware version.
yamaguch 0:0232a97b3883 437 *
yamaguch 0:0232a97b3883 438 * @returns XBee firmwre version in int (unsigned short value)
yamaguch 0:0232a97b3883 439 */
yamaguch 0:0232a97b3883 440 int getFirmwareVersion();
yamaguch 0:0232a97b3883 441
yamaguch 0:0232a97b3883 442 /**
yamaguch 0:0232a97b3883 443 * gets the current frame ID.
yamaguch 0:0232a97b3883 444 *
yamaguch 0:0232a97b3883 445 * @returns frame ID number being used in the next send request
yamaguch 0:0232a97b3883 446 */
yamaguch 0:0232a97b3883 447 char getFrameID();
yamaguch 0:0232a97b3883 448
yamaguch 0:0232a97b3883 449 /**
yamaguch 0:0232a97b3883 450 * sets to run in debug mode.
yamaguch 0:0232a97b3883 451 *
yamaguch 0:0232a97b3883 452 * @param debug true to display debugging information
yamaguch 0:0232a97b3883 453 */
yamaguch 0:0232a97b3883 454 void setDebug(bool debug);
yamaguch 0:0232a97b3883 455
yamaguch 0:0232a97b3883 456 /**
yamaguch 0:0232a97b3883 457 * displays received data in dump format.
yamaguch 0:0232a97b3883 458 */
yamaguch 0:0232a97b3883 459 void dump();
yamaguch 0:0232a97b3883 460
yamaguch 0:0232a97b3883 461 /**
yamaguch 0:0232a97b3883 462 * displays the internal data fields and receive buffer in dump format.
yamaguch 0:0232a97b3883 463 */
yamaguch 0:0232a97b3883 464 void dumpAll();
yamaguch 0:0232a97b3883 465
yamaguch 0:0232a97b3883 466 /**
yamaguch 0:0232a97b3883 467 * operator overloading for testing XBee modem connection status.
yamaguch 0:0232a97b3883 468 *
yamaguch 0:0232a97b3883 469 * @returns false if XBee modem connection has an error
yamaguch 0:0232a97b3883 470 */
yamaguch 0:0232a97b3883 471 operator bool();
yamaguch 0:0232a97b3883 472
yamaguch 0:0232a97b3883 473 private:
yamaguch 0:0232a97b3883 474 Serial mon;
yamaguch 0:0232a97b3883 475 BusOut leds;
yamaguch 0:0232a97b3883 476 int apiMode;
yamaguch 0:0232a97b3883 477 volatile enum {UNKNOWN, LENGTH1, LENGTH2, DATA, SUMCHECK} state;
yamaguch 0:0232a97b3883 478 volatile int cur, in, out, received, free;
yamaguch 0:0232a97b3883 479 char frame_id;
yamaguch 0:0232a97b3883 480 char destination64[8];
yamaguch 0:0232a97b3883 481 char destination16[2];
yamaguch 0:0232a97b3883 482 char buf[BUFSIZE];
yamaguch 0:0232a97b3883 483 bool debug;
yamaguch 0:0232a97b3883 484
yamaguch 0:0232a97b3883 485 void send(char c);
yamaguch 0:0232a97b3883 486 void send2(char c);
yamaguch 0:0232a97b3883 487 void sendFrame(const char *frame, int length);
yamaguch 0:0232a97b3883 488 int createTxRequest(char frame_id, const char *data, int data_length, char *buf, int buf_size);
yamaguch 0:0232a97b3883 489 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 490 int createRemoteAtRequest(char frame_id, const char *command, const uint8_t *param, int param_length, char options, char *buf, int buf_size);
yamaguch 3:8453df14bd30 491 int seekFor(FrameType type, char id, float timeout);
yamaguch 0:0232a97b3883 492 FrameType getFrameType(char c);
yamaguch 0:0232a97b3883 493 bool scan(int i, ValueType type, char *value, int maxlength = 1, int *length = 0);
yamaguch 0:0232a97b3883 494 void flush();
yamaguch 0:0232a97b3883 495 void rxInterruptHandler();
yamaguch 0:0232a97b3883 496 void rxInterruptHandler2();
yamaguch 0:0232a97b3883 497
yamaguch 0:0232a97b3883 498 void dump(const char *data, int length);
yamaguch 0:0232a97b3883 499 void dumpIOSample(const char *data, int length);
yamaguch 0:0232a97b3883 500 void copy(char *toBuf, int fromIndex, int length);
yamaguch 0:0232a97b3883 501 };
yamaguch 0:0232a97b3883 502
yamaguch 0:0232a97b3883 503 #endif