XBee API mode library
XBee.h@16:cdfcb63b2c4b, 2013-03-20 (annotated)
- Committer:
- yamaguch
- Date:
- Wed Mar 20 00:28:27 2013 +0000
- Revision:
- 16:cdfcb63b2c4b
- Parent:
- 15:10224db0fc2b
- Child:
- 17:2f728fd13bc0
non rtos version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yamaguch | 0:0232a97b3883 | 1 | /* |
yamaguch | 8:776b8dc51932 | 2 | Copyright (c) 2013, 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 | 16:cdfcb63b2c4b | 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 | 6:d15800bfa15d | 178 | * Node Identification 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 | * creates an XBee interface object. |
yamaguch | 0:0232a97b3883 | 200 | * |
yamaguch | 0:0232a97b3883 | 201 | * @param ser Serial object through which XBee module is connected to mbed |
yamaguch | 0:0232a97b3883 | 202 | * @param apiMode API mode either 1 or 2 (use escape; default) |
yamaguch | 0:0232a97b3883 | 203 | * @param debug display debugging (I/O state) information through LEDs |
yamaguch | 0:0232a97b3883 | 204 | */ |
yamaguch | 16:cdfcb63b2c4b | 205 | XBee(Serial& ser, int apiMode = 2); |
yamaguch | 0:0232a97b3883 | 206 | |
yamaguch | 0:0232a97b3883 | 207 | /** |
yamaguch | 0:0232a97b3883 | 208 | * creates an XBee interface object. |
yamaguch | 0:0232a97b3883 | 209 | * |
yamaguch | 0:0232a97b3883 | 210 | * @param tx TX pin connected to XBee |
yamaguch | 0:0232a97b3883 | 211 | * @param rx RX pin connected to XBee |
yamaguch | 0:0232a97b3883 | 212 | * @param apiMode API mode either 1 or 2 (use escape; default) |
yamaguch | 0:0232a97b3883 | 213 | * @param debug display debugging (I/O state) information through LEDs |
yamaguch | 0:0232a97b3883 | 214 | */ |
yamaguch | 16:cdfcb63b2c4b | 215 | XBee(PinName tx, PinName rx, int apiMode = 2); |
yamaguch | 0:0232a97b3883 | 216 | |
yamaguch | 0:0232a97b3883 | 217 | /** |
yamaguch | 0:0232a97b3883 | 218 | * creates an XBee interface object. |
yamaguch | 0:0232a97b3883 | 219 | * |
yamaguch | 0:0232a97b3883 | 220 | * @param ser Serial object through which XBee module is connected to mbed |
yamaguch | 0:0232a97b3883 | 221 | * @param mon alternate Serial object for monitoring (use serial ports other than USBTX/USBRX) |
yamaguch | 0:0232a97b3883 | 222 | * @param apiMode API mode either 1 or 2 (use escape; default) |
yamaguch | 0:0232a97b3883 | 223 | * @param debug display debugging (I/O state) information through LEDs |
yamaguch | 0:0232a97b3883 | 224 | */ |
yamaguch | 16:cdfcb63b2c4b | 225 | XBee(Serial& ser, Serial& mon, int apiMode = 2); |
yamaguch | 0:0232a97b3883 | 226 | |
yamaguch | 0:0232a97b3883 | 227 | /** |
yamaguch | 0:0232a97b3883 | 228 | * creates an XBee interface object. |
yamaguch | 0:0232a97b3883 | 229 | * |
yamaguch | 0:0232a97b3883 | 230 | * @param tx TX pin connected to XBee |
yamaguch | 0:0232a97b3883 | 231 | * @param rx RX pin connected to XBee |
yamaguch | 0:0232a97b3883 | 232 | * @param mon alternate Serial object for monitoring (use serial ports other than USBTX/USBRX) |
yamaguch | 0:0232a97b3883 | 233 | * @param apiMode API mode either 1 or 2 (use escape; default) |
yamaguch | 0:0232a97b3883 | 234 | * @param debug display debugging (I/O state) information through LEDs |
yamaguch | 0:0232a97b3883 | 235 | */ |
yamaguch | 16:cdfcb63b2c4b | 236 | XBee(PinName tx, PinName rx, Serial& mon, int apiMode = 2); |
yamaguch | 0:0232a97b3883 | 237 | |
yamaguch | 0:0232a97b3883 | 238 | /** |
yamaguch | 0:0232a97b3883 | 239 | * initializes XBee module. |
yamaguch | 0:0232a97b3883 | 240 | * |
yamaguch | 0:0232a97b3883 | 241 | * issues VR command to test XBee modem connection |
yamaguch | 0:0232a97b3883 | 242 | * |
yamaguch | 0:0232a97b3883 | 243 | * @returns true if initialization succeeded, false otherwise |
yamaguch | 0:0232a97b3883 | 244 | */ |
yamaguch | 0:0232a97b3883 | 245 | bool init(float timeout = 15.0); |
yamaguch | 0:0232a97b3883 | 246 | |
yamaguch | 0:0232a97b3883 | 247 | /** |
yamaguch | 0:0232a97b3883 | 248 | * sets destination addresses. |
yamaguch | 0:0232a97b3883 | 249 | * |
yamaguch | 0:0232a97b3883 | 250 | * @param address64 XBeeAddress64 type address |
yamaguch | 0:0232a97b3883 | 251 | * @param address16 XBeeAddress16 type address (optional) |
yamaguch | 0:0232a97b3883 | 252 | */ |
yamaguch | 0:0232a97b3883 | 253 | void setDestination(XBeeAddress64 address64, XBeeAddress16 address16 = 0xFFFE); |
yamaguch | 0:0232a97b3883 | 254 | |
yamaguch | 0:0232a97b3883 | 255 | /** |
yamaguch | 0:0232a97b3883 | 256 | * sets destination addresses. |
yamaguch | 0:0232a97b3883 | 257 | * |
yamaguch | 0:0232a97b3883 | 258 | * @param address64 64-bit destination address in uint64_t |
yamaguch | 0:0232a97b3883 | 259 | * @param address16 16-bit destination address in uint16_t |
yamaguch | 0:0232a97b3883 | 260 | */ |
yamaguch | 0:0232a97b3883 | 261 | void setDestination(uint64_t address64, uint16_t address16 = 0xFFFE); |
yamaguch | 0:0232a97b3883 | 262 | |
yamaguch | 0:0232a97b3883 | 263 | /** |
yamaguch | 0:0232a97b3883 | 264 | * sets destination addresses. |
yamaguch | 0:0232a97b3883 | 265 | * |
yamaguch | 0:0232a97b3883 | 266 | * @param address64 64-bit destination address in bytes (big endian) |
yamaguch | 0:0232a97b3883 | 267 | * @param address16 16-bit destination address in bytes |
yamaguch | 0:0232a97b3883 | 268 | */ |
yamaguch | 0:0232a97b3883 | 269 | void setDestination(char address64[], char address16[]); |
yamaguch | 0:0232a97b3883 | 270 | |
yamaguch | 0:0232a97b3883 | 271 | /** |
yamaguch | 0:0232a97b3883 | 272 | * sends an AT command. |
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 |
yamaguch | 0:0232a97b3883 | 276 | */ |
yamaguch | 0:0232a97b3883 | 277 | void sendCommand(const char *command, int8_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 278 | void sendCommand(const char *command, int16_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 279 | void sendCommand(const char *command, int32_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 280 | void sendCommand(const char *command, int64_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 281 | void sendCommand(const char *command, uint8_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 282 | void sendCommand(const char *command, uint16_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 283 | void sendCommand(const char *command, uint32_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 284 | void sendCommand(const char *command, uint64_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 285 | void sendCommand(const char *command, const char *param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 286 | |
yamaguch | 0:0232a97b3883 | 287 | /** |
yamaguch | 0:0232a97b3883 | 288 | * sends an AT command. |
yamaguch | 0:0232a97b3883 | 289 | * |
yamaguch | 0:0232a97b3883 | 290 | * @param command AT command char string |
yamaguch | 0:0232a97b3883 | 291 | * @param param parameter to the AT command (pointer to byte array) |
yamaguch | 0:0232a97b3883 | 292 | * @param param_length parameter length in bytes |
yamaguch | 0:0232a97b3883 | 293 | * @param queue true if command paramter is to be queued |
yamaguch | 0:0232a97b3883 | 294 | */ |
yamaguch | 0:0232a97b3883 | 295 | void sendCommand(const char *command, const uint8_t *param = 0, int param_length = 0, bool queue = false); |
yamaguch | 0:0232a97b3883 | 296 | |
yamaguch | 0:0232a97b3883 | 297 | /** |
yamaguch | 0:0232a97b3883 | 298 | * sends a remote AT command. |
yamaguch | 0:0232a97b3883 | 299 | * |
yamaguch | 0:0232a97b3883 | 300 | * sends an AT command to the XBee(s) at the destination address |
yamaguch | 0:0232a97b3883 | 301 | * |
yamaguch | 0:0232a97b3883 | 302 | * @param command AT command char string |
yamaguch | 0:0232a97b3883 | 303 | * @param param parameter to the AT command (pointer to byte array) |
yamaguch | 0:0232a97b3883 | 304 | * @param param_length parameter length in bytes |
yamaguch | 0:0232a97b3883 | 305 | * @param options remote command options |
yamaguch | 0:0232a97b3883 | 306 | */ |
yamaguch | 0:0232a97b3883 | 307 | void sendRemoteCommand(const char *command, int8_t param); |
yamaguch | 0:0232a97b3883 | 308 | void sendRemoteCommand(const char *command, int16_t param); |
yamaguch | 0:0232a97b3883 | 309 | void sendRemoteCommand(const char *command, int32_t param); |
yamaguch | 0:0232a97b3883 | 310 | void sendRemoteCommand(const char *command, int64_t param); |
yamaguch | 0:0232a97b3883 | 311 | void sendRemoteCommand(const char *command, uint8_t param); |
yamaguch | 0:0232a97b3883 | 312 | void sendRemoteCommand(const char *command, uint16_t param); |
yamaguch | 0:0232a97b3883 | 313 | void sendRemoteCommand(const char *command, uint32_t param); |
yamaguch | 0:0232a97b3883 | 314 | void sendRemoteCommand(const char *command, uint64_t param); |
yamaguch | 0:0232a97b3883 | 315 | void sendRemoteCommand(const char *command, const char *param); |
yamaguch | 0:0232a97b3883 | 316 | |
yamaguch | 0:0232a97b3883 | 317 | /** |
yamaguch | 0:0232a97b3883 | 318 | * sends a remote AT command. |
yamaguch | 0:0232a97b3883 | 319 | * |
yamaguch | 0:0232a97b3883 | 320 | * sends an AT command to the XBee(s) at the destination address |
yamaguch | 0:0232a97b3883 | 321 | * |
yamaguch | 0:0232a97b3883 | 322 | * @param command AT command char string |
yamaguch | 0:0232a97b3883 | 323 | * @param param parameter to the AT command (pointer to byte array) |
yamaguch | 0:0232a97b3883 | 324 | * @param param_length parameter length in bytes |
yamaguch | 0:0232a97b3883 | 325 | * @param options remote command options |
yamaguch | 0:0232a97b3883 | 326 | */ |
yamaguch | 0:0232a97b3883 | 327 | void sendRemoteCommand(const char *command, const uint8_t *param = 0, int param_length = 0, char options = 0x02); |
yamaguch | 0:0232a97b3883 | 328 | |
yamaguch | 0:0232a97b3883 | 329 | /** |
yamaguch | 0:0232a97b3883 | 330 | * executes an AT command and gets the result. |
yamaguch | 0:0232a97b3883 | 331 | * |
yamaguch | 0:0232a97b3883 | 332 | * @param command AT command char string |
yamaguch | 0:0232a97b3883 | 333 | * @param param parameter to the AT command |
yamaguch | 0:0232a97b3883 | 334 | * |
yamaguch | 0:0232a97b3883 | 335 | * @returns pointer to the command result, if the result is a number (char, short, long, int64_t), |
yamaguch | 0:0232a97b3883 | 336 | * the address to the number will be returned; otherwise the address to the byte array |
yamaguch | 0:0232a97b3883 | 337 | * containing the command response will be returned. |
yamaguch | 0:0232a97b3883 | 338 | */ |
yamaguch | 0:0232a97b3883 | 339 | void *executeCommand(const char *command, int8_t param); |
yamaguch | 0:0232a97b3883 | 340 | void *executeCommand(const char *command, int16_t param); |
yamaguch | 0:0232a97b3883 | 341 | void *executeCommand(const char *command, int32_t param); |
yamaguch | 0:0232a97b3883 | 342 | void *executeCommand(const char *command, int64_t param); |
yamaguch | 0:0232a97b3883 | 343 | void *executeCommand(const char *command, uint8_t param); |
yamaguch | 0:0232a97b3883 | 344 | void *executeCommand(const char *command, uint16_t param); |
yamaguch | 0:0232a97b3883 | 345 | void *executeCommand(const char *command, uint32_t param); |
yamaguch | 0:0232a97b3883 | 346 | void *executeCommand(const char *command, uint64_t param); |
yamaguch | 0:0232a97b3883 | 347 | void *executeCommand(const char *command, const char *param); |
yamaguch | 0:0232a97b3883 | 348 | |
yamaguch | 0:0232a97b3883 | 349 | /** |
yamaguch | 0:0232a97b3883 | 350 | * executes an AT command and gets the result. |
yamaguch | 0:0232a97b3883 | 351 | * |
yamaguch | 0:0232a97b3883 | 352 | * @param command AT command char string |
yamaguch | 0:0232a97b3883 | 353 | * @param param parameter to the AT command (pointer to byte array) |
yamaguch | 0:0232a97b3883 | 354 | * @param param_length parameter length in bytes |
yamaguch | 0:0232a97b3883 | 355 | * |
yamaguch | 0:0232a97b3883 | 356 | * @returns pointer to the command result, if the result is a number (char, short, long, long long), |
yamaguch | 0:0232a97b3883 | 357 | * the address to the number will be returned; otherwise the address to the byte array |
yamaguch | 0:0232a97b3883 | 358 | * containing the command response will be returned. |
yamaguch | 0:0232a97b3883 | 359 | */ |
yamaguch | 0:0232a97b3883 | 360 | void *executeCommand(const char *command, const uint8_t *param = 0, int laram_length = 0); |
yamaguch | 0:0232a97b3883 | 361 | |
yamaguch | 0:0232a97b3883 | 362 | /** |
yamaguch | 0:0232a97b3883 | 363 | * sends data to the XBee(s) at the destination address. |
yamaguch | 0:0232a97b3883 | 364 | * |
yamaguch | 0:0232a97b3883 | 365 | * @param data address to the data (byte array) |
yamaguch | 0:0232a97b3883 | 366 | * @param length data length in bytes |
yamaguch | 0:0232a97b3883 | 367 | */ |
yamaguch | 10:3da24a020e67 | 368 | bool send(const char *data, int length); |
yamaguch | 13:5f102be205f8 | 369 | |
yamaguch | 0:0232a97b3883 | 370 | /** |
yamaguch | 10:3da24a020e67 | 371 | * sets send confirmation timeout |
yamaguch | 0:0232a97b3883 | 372 | * |
yamaguch | 10:3da24a020e67 | 373 | * @param sendConfirmation maximum waiting time for receiving transmit status |
yamaguch | 0:0232a97b3883 | 374 | * |
yamaguch | 0:0232a97b3883 | 375 | */ |
yamaguch | 10:3da24a020e67 | 376 | void setSendConfirmation(float sendConfirmation); |
yamaguch | 0:0232a97b3883 | 377 | |
yamaguch | 0:0232a97b3883 | 378 | /** |
yamaguch | 0:0232a97b3883 | 379 | * sends data to the destination using printf format. |
yamaguch | 0:0232a97b3883 | 380 | * |
yamaguch | 0:0232a97b3883 | 381 | * @param format printf format string, followed by corresponding arguments |
yamaguch | 0:0232a97b3883 | 382 | * |
yamaguch | 0:0232a97b3883 | 383 | * @returns the number of charancters sent, or negative if error occurred |
yamaguch | 0:0232a97b3883 | 384 | */ |
yamaguch | 0:0232a97b3883 | 385 | int printf(const char *format, ...); |
yamaguch | 0:0232a97b3883 | 386 | |
yamaguch | 0:0232a97b3883 | 387 | /** |
yamaguch | 0:0232a97b3883 | 388 | * receives data frame from the XBee module. |
yamaguch | 0:0232a97b3883 | 389 | * |
yamaguch | 0:0232a97b3883 | 390 | * @param timeout seconds bofer time out |
yamaguch | 0:0232a97b3883 | 391 | * |
yamaguch | 0:0232a97b3883 | 392 | * @returns FrameType of the received frame data |
yamaguch | 0:0232a97b3883 | 393 | */ |
yamaguch | 0:0232a97b3883 | 394 | FrameType receive(float timeout = 3.0); |
yamaguch | 0:0232a97b3883 | 395 | |
yamaguch | 0:0232a97b3883 | 396 | /** |
yamaguch | 0:0232a97b3883 | 397 | * scan received data |
yamaguch | 0:0232a97b3883 | 398 | * |
yamaguch | 0:0232a97b3883 | 399 | * @param data XBeeDataType data to be scanned |
yamaguch | 0:0232a97b3883 | 400 | * |
yamaguch | 0:0232a97b3883 | 401 | * @param true if scan succeeded, false otherwise |
yamaguch | 0:0232a97b3883 | 402 | */ |
yamaguch | 0:0232a97b3883 | 403 | bool scan(XBeeFrameID& id) { return scan(XBee::FrameID, id.raw_address(), 1); } |
yamaguch | 0:0232a97b3883 | 404 | bool scan(XBeeRetryCount& count) { return scan(XBee::RetryCount, count.raw_address(), 1); } |
yamaguch | 0:0232a97b3883 | 405 | bool scan(XBeeStatus& status) { return scan(XBee::Status, status.raw_address(), 1); } |
yamaguch | 0:0232a97b3883 | 406 | bool scan(XBeeDeliveryStatus& status) { return scan(XBee::DeliveryStatus, status.raw_address(), 1); } |
yamaguch | 0:0232a97b3883 | 407 | bool scan(XBeeDiscoveryStatus& status) { return scan(XBee::DiscoveryStatus, status.raw_address(), 1); } |
yamaguch | 0:0232a97b3883 | 408 | bool scan(XBeeReceiveOptions& options) { return scan(XBee::ReceiveOptions, options.raw_address(), 1); } |
yamaguch | 5:b82970ef7fb0 | 409 | bool scan(XBeeDeviceType& device) { return scan(XBee::DeviceType, device.raw_address(), 1); } |
yamaguch | 5:b82970ef7fb0 | 410 | bool scan(XBeeSourceEvent& event) { return scan(XBee::SourceEvent, event.raw_address(), 1); } |
yamaguch | 0:0232a97b3883 | 411 | bool scan(XBeeAddress64& address64) { return scan(XBee::Address64, address64.raw_address(), 8); } |
yamaguch | 0:0232a97b3883 | 412 | bool scan(XBeeAddress16& address16) { return scan(XBee::Address16, address16.raw_address(), 2); } |
yamaguch | 0:0232a97b3883 | 413 | bool scan(XBeeATCommand& command) { return scan(XBee::ATCommand, command.raw_address(), 3); } |
yamaguch | 0:0232a97b3883 | 414 | bool scan(XBeeCommandData& data) { return scan(XBee::CommandData, data.raw_address(), data.capacity, &data.size); } |
yamaguch | 0:0232a97b3883 | 415 | bool scan(XBeeReceivedData& data) { return scan(XBee::ReceivedData, data.raw_address(), data.capacity, &data.size); } |
yamaguch | 7:19f03567ec4e | 416 | bool scan(XBeeNodeIdentifier& ni) { return scan(XBee::NIString, ni.raw_address(), ni.capacity, &ni.size); } |
yamaguch | 0:0232a97b3883 | 417 | bool scan(XBeeRawData& data) { return scan(XBee::RawData, data.raw_address(), data.capacity, &data.size); } |
yamaguch | 0:0232a97b3883 | 418 | |
yamaguch | 0:0232a97b3883 | 419 | /** |
yamaguch | 0:0232a97b3883 | 420 | * scan received data according to the specified format. |
yamaguch | 0:0232a97b3883 | 421 | * |
yamaguch | 0:0232a97b3883 | 422 | * @param type ValueType of the data to be scanned |
yamaguch | 0:0232a97b3883 | 423 | * @param value pointer to the byte array to store the scanned value |
yamaguch | 0:0232a97b3883 | 424 | * @param maxlength max size of the value in bytes |
yamaguch | 0:0232a97b3883 | 425 | * @param length pointer to an int to receive the actual data length |
yamaguch | 0:0232a97b3883 | 426 | * |
yamaguch | 0:0232a97b3883 | 427 | * @param true if scan succeeded, false otherwise |
yamaguch | 0:0232a97b3883 | 428 | */ |
yamaguch | 0:0232a97b3883 | 429 | bool scan(ValueType type, char *value, int maxlength = 1, int *length = 0); |
yamaguch | 0:0232a97b3883 | 430 | |
yamaguch | 0:0232a97b3883 | 431 | /** |
yamaguch | 0:0232a97b3883 | 432 | * gets the XBee firmware version. |
yamaguch | 0:0232a97b3883 | 433 | * |
yamaguch | 0:0232a97b3883 | 434 | * @returns XBee firmwre version in int (unsigned short value) |
yamaguch | 0:0232a97b3883 | 435 | */ |
yamaguch | 0:0232a97b3883 | 436 | int getFirmwareVersion(); |
yamaguch | 0:0232a97b3883 | 437 | |
yamaguch | 0:0232a97b3883 | 438 | /** |
yamaguch | 0:0232a97b3883 | 439 | * gets the current frame ID. |
yamaguch | 0:0232a97b3883 | 440 | * |
yamaguch | 0:0232a97b3883 | 441 | * @returns frame ID number being used in the next send request |
yamaguch | 0:0232a97b3883 | 442 | */ |
yamaguch | 0:0232a97b3883 | 443 | char getFrameID(); |
yamaguch | 0:0232a97b3883 | 444 | |
yamaguch | 0:0232a97b3883 | 445 | /** |
yamaguch | 0:0232a97b3883 | 446 | * sets to run in debug mode. |
yamaguch | 0:0232a97b3883 | 447 | * |
yamaguch | 0:0232a97b3883 | 448 | * @param debug true to display debugging information |
yamaguch | 0:0232a97b3883 | 449 | */ |
yamaguch | 0:0232a97b3883 | 450 | void setDebug(bool debug); |
yamaguch | 0:0232a97b3883 | 451 | |
yamaguch | 0:0232a97b3883 | 452 | /** |
yamaguch | 0:0232a97b3883 | 453 | * displays received data in dump format. |
yamaguch | 0:0232a97b3883 | 454 | */ |
yamaguch | 0:0232a97b3883 | 455 | void dump(); |
yamaguch | 0:0232a97b3883 | 456 | |
yamaguch | 0:0232a97b3883 | 457 | /** |
yamaguch | 0:0232a97b3883 | 458 | * displays the internal data fields and receive buffer in dump format. |
yamaguch | 0:0232a97b3883 | 459 | */ |
yamaguch | 0:0232a97b3883 | 460 | void dumpAll(); |
yamaguch | 0:0232a97b3883 | 461 | |
yamaguch | 0:0232a97b3883 | 462 | /** |
yamaguch | 0:0232a97b3883 | 463 | * operator overloading for testing XBee modem connection status. |
yamaguch | 0:0232a97b3883 | 464 | * |
yamaguch | 0:0232a97b3883 | 465 | * @returns false if XBee modem connection has an error |
yamaguch | 0:0232a97b3883 | 466 | */ |
yamaguch | 0:0232a97b3883 | 467 | operator bool(); |
yamaguch | 0:0232a97b3883 | 468 | |
yamaguch | 0:0232a97b3883 | 469 | private: |
yamaguch | 0:0232a97b3883 | 470 | Serial mon; |
yamaguch | 0:0232a97b3883 | 471 | int apiMode; |
yamaguch | 0:0232a97b3883 | 472 | volatile int cur, in, out, received, free; |
yamaguch | 0:0232a97b3883 | 473 | char frame_id; |
yamaguch | 10:3da24a020e67 | 474 | float sendConfirmation; |
yamaguch | 0:0232a97b3883 | 475 | char destination64[8]; |
yamaguch | 0:0232a97b3883 | 476 | char destination16[2]; |
yamaguch | 0:0232a97b3883 | 477 | char buf[BUFSIZE]; |
yamaguch | 0:0232a97b3883 | 478 | bool debug; |
yamaguch | 16:cdfcb63b2c4b | 479 | |
yamaguch | 0:0232a97b3883 | 480 | void send(char c); |
yamaguch | 0:0232a97b3883 | 481 | void send2(char c); |
yamaguch | 0:0232a97b3883 | 482 | void sendFrame(const char *frame, int length); |
yamaguch | 0:0232a97b3883 | 483 | int createTxRequest(char frame_id, const char *data, int data_length, char *buf, int buf_size); |
yamaguch | 0:0232a97b3883 | 484 | 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 | 485 | int createRemoteAtRequest(char frame_id, const char *command, const uint8_t *param, int param_length, char options, char *buf, int buf_size); |
yamaguch | 10:3da24a020e67 | 486 | bool send(const char *data, int length, float timeout); |
yamaguch | 3:8453df14bd30 | 487 | int seekFor(FrameType type, char id, float timeout); |
yamaguch | 0:0232a97b3883 | 488 | FrameType getFrameType(char c); |
yamaguch | 0:0232a97b3883 | 489 | bool scan(int i, ValueType type, char *value, int maxlength = 1, int *length = 0); |
yamaguch | 0:0232a97b3883 | 490 | void flush(); |
yamaguch | 8:776b8dc51932 | 491 | void rxISR(); |
yamaguch | 0:0232a97b3883 | 492 | void dump(const char *data, int length); |
yamaguch | 0:0232a97b3883 | 493 | void dumpIOSample(const char *data, int length); |
yamaguch | 0:0232a97b3883 | 494 | void copy(char *toBuf, int fromIndex, int length); |
yamaguch | 0:0232a97b3883 | 495 | }; |
yamaguch | 0:0232a97b3883 | 496 | |
yamaguch | 0:0232a97b3883 | 497 | #endif |