XBee API mode library
XBee.h@8:776b8dc51932, 2013-01-29 (annotated)
- Committer:
- yamaguch
- Date:
- Tue Jan 29 13:46:41 2013 +0000
- Revision:
- 8:776b8dc51932
- Parent:
- 7:19f03567ec4e
- Child:
- 10:3da24a020e67
rtos support
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 | 8:776b8dc51932 | 26 | #define XBEE_RTOS |
yamaguch | 8:776b8dc51932 | 27 | |
yamaguch | 8:776b8dc51932 | 28 | #ifdef XBEE_RTOS |
yamaguch | 8:776b8dc51932 | 29 | #include "rtos.h" |
yamaguch | 8:776b8dc51932 | 30 | #include "ThreadBase.h" |
yamaguch | 8:776b8dc51932 | 31 | #include "RingBuffer.h" |
yamaguch | 8:776b8dc51932 | 32 | #endif |
yamaguch | 0:0232a97b3883 | 33 | #include "mbed.h" |
yamaguch | 0:0232a97b3883 | 34 | #include "XBeeDataTypes.h" |
yamaguch | 0:0232a97b3883 | 35 | |
yamaguch | 0:0232a97b3883 | 36 | #define min(x, y) ((x) < (y) ? (x) : (y)) |
yamaguch | 0:0232a97b3883 | 37 | #define INDEX(n) ((n) % BUFSIZE) |
yamaguch | 0:0232a97b3883 | 38 | #define SIZE(b, i) (b[i] << 8 | b[INDEX(i + 1)]) |
yamaguch | 0:0232a97b3883 | 39 | |
yamaguch | 0:0232a97b3883 | 40 | const int BUFSIZE = 512; |
yamaguch | 0:0232a97b3883 | 41 | const char ESCAPE = 0x7D; |
yamaguch | 0:0232a97b3883 | 42 | const char PREAMBLE = 0x7E; |
yamaguch | 0:0232a97b3883 | 43 | |
yamaguch | 0:0232a97b3883 | 44 | /** |
yamaguch | 0:0232a97b3883 | 45 | * class for XBee module API mode interface |
yamaguch | 0:0232a97b3883 | 46 | */ |
yamaguch | 8:776b8dc51932 | 47 | #ifndef XBEE_RTOS |
yamaguch | 0:0232a97b3883 | 48 | class XBee : public Serial { |
yamaguch | 8:776b8dc51932 | 49 | #else |
yamaguch | 8:776b8dc51932 | 50 | class XBee : public Serial, ThreadBase { |
yamaguch | 8:776b8dc51932 | 51 | #endif |
yamaguch | 0:0232a97b3883 | 52 | public: |
yamaguch | 0:0232a97b3883 | 53 | |
yamaguch | 0:0232a97b3883 | 54 | /** |
yamaguch | 0:0232a97b3883 | 55 | * Frame type declaration for XBee API frames |
yamaguch | 0:0232a97b3883 | 56 | */ |
yamaguch | 0:0232a97b3883 | 57 | enum FrameType { |
yamaguch | 0:0232a97b3883 | 58 | /** |
yamaguch | 0:0232a97b3883 | 59 | * Empty data |
yamaguch | 0:0232a97b3883 | 60 | */ |
yamaguch | 0:0232a97b3883 | 61 | None = 0, |
yamaguch | 0:0232a97b3883 | 62 | |
yamaguch | 0:0232a97b3883 | 63 | /** |
yamaguch | 0:0232a97b3883 | 64 | * AT Command Response API frame |
yamaguch | 0:0232a97b3883 | 65 | */ |
yamaguch | 0:0232a97b3883 | 66 | ATCommandResponse, |
yamaguch | 0:0232a97b3883 | 67 | |
yamaguch | 0:0232a97b3883 | 68 | /** |
yamaguch | 0:0232a97b3883 | 69 | * Modem Status API frame |
yamaguch | 0:0232a97b3883 | 70 | */ |
yamaguch | 0:0232a97b3883 | 71 | ModemStatus, |
yamaguch | 0:0232a97b3883 | 72 | |
yamaguch | 0:0232a97b3883 | 73 | /** |
yamaguch | 0:0232a97b3883 | 74 | * ZigBee Transmit Status API frame |
yamaguch | 0:0232a97b3883 | 75 | */ |
yamaguch | 0:0232a97b3883 | 76 | ZigBeeTransmitStatus, |
yamaguch | 0:0232a97b3883 | 77 | |
yamaguch | 0:0232a97b3883 | 78 | /** |
yamaguch | 0:0232a97b3883 | 79 | * ZigBee Receive Packet API frame |
yamaguch | 0:0232a97b3883 | 80 | */ |
yamaguch | 0:0232a97b3883 | 81 | ZigBeeReceivePacket, |
yamaguch | 0:0232a97b3883 | 82 | |
yamaguch | 0:0232a97b3883 | 83 | /** |
yamaguch | 0:0232a97b3883 | 84 | * ZigBee Explicit Rx Indicator API frame |
yamaguch | 0:0232a97b3883 | 85 | */ |
yamaguch | 0:0232a97b3883 | 86 | ZigBeeExplicitRxIndicator, |
yamaguch | 0:0232a97b3883 | 87 | |
yamaguch | 0:0232a97b3883 | 88 | /** |
yamaguch | 0:0232a97b3883 | 89 | * ZigBee I/O Data Sample Rx Indicator API frame |
yamaguch | 0:0232a97b3883 | 90 | */ |
yamaguch | 0:0232a97b3883 | 91 | ZigBeeIODataSampleRxIndicator, |
yamaguch | 0:0232a97b3883 | 92 | |
yamaguch | 0:0232a97b3883 | 93 | /** |
yamaguch | 0:0232a97b3883 | 94 | * XBee Sensor Read Indicator API frame |
yamaguch | 0:0232a97b3883 | 95 | */ |
yamaguch | 0:0232a97b3883 | 96 | XBeeSensorReadIndicator, |
yamaguch | 0:0232a97b3883 | 97 | |
yamaguch | 0:0232a97b3883 | 98 | /** |
yamaguch | 0:0232a97b3883 | 99 | * Node Identification Indicator API frame |
yamaguch | 0:0232a97b3883 | 100 | */ |
yamaguch | 0:0232a97b3883 | 101 | NodeIdentificationIndicator, |
yamaguch | 0:0232a97b3883 | 102 | |
yamaguch | 0:0232a97b3883 | 103 | /** |
yamaguch | 0:0232a97b3883 | 104 | * Remote Command Response API frame |
yamaguch | 0:0232a97b3883 | 105 | */ |
yamaguch | 0:0232a97b3883 | 106 | RemoteCommandResponse, |
yamaguch | 0:0232a97b3883 | 107 | |
yamaguch | 0:0232a97b3883 | 108 | /** |
yamaguch | 0:0232a97b3883 | 109 | * Unknown API frame |
yamaguch | 0:0232a97b3883 | 110 | */ |
yamaguch | 0:0232a97b3883 | 111 | Other |
yamaguch | 0:0232a97b3883 | 112 | }; |
yamaguch | 0:0232a97b3883 | 113 | |
yamaguch | 0:0232a97b3883 | 114 | /** |
yamaguch | 0:0232a97b3883 | 115 | * Value type declarations for retrieving frame data contents |
yamaguch | 0:0232a97b3883 | 116 | */ |
yamaguch | 0:0232a97b3883 | 117 | enum ValueType { |
yamaguch | 0:0232a97b3883 | 118 | /** |
yamaguch | 0:0232a97b3883 | 119 | * Frame ID |
yamaguch | 0:0232a97b3883 | 120 | */ |
yamaguch | 0:0232a97b3883 | 121 | FrameID, |
yamaguch | 0:0232a97b3883 | 122 | |
yamaguch | 0:0232a97b3883 | 123 | /** |
yamaguch | 0:0232a97b3883 | 124 | *AT command name |
yamaguch | 0:0232a97b3883 | 125 | */ |
yamaguch | 0:0232a97b3883 | 126 | ATCommand, |
yamaguch | 0:0232a97b3883 | 127 | |
yamaguch | 0:0232a97b3883 | 128 | /** |
yamaguch | 0:0232a97b3883 | 129 | * Status |
yamaguch | 0:0232a97b3883 | 130 | */ |
yamaguch | 0:0232a97b3883 | 131 | Status, |
yamaguch | 0:0232a97b3883 | 132 | |
yamaguch | 0:0232a97b3883 | 133 | /** |
yamaguch | 0:0232a97b3883 | 134 | * Command data |
yamaguch | 0:0232a97b3883 | 135 | */ |
yamaguch | 0:0232a97b3883 | 136 | CommandData, |
yamaguch | 0:0232a97b3883 | 137 | |
yamaguch | 0:0232a97b3883 | 138 | /** |
yamaguch | 0:0232a97b3883 | 139 | * 16 bit address |
yamaguch | 0:0232a97b3883 | 140 | */ |
yamaguch | 0:0232a97b3883 | 141 | Address16, |
yamaguch | 0:0232a97b3883 | 142 | |
yamaguch | 0:0232a97b3883 | 143 | /** |
yamaguch | 0:0232a97b3883 | 144 | * 64 bit address |
yamaguch | 0:0232a97b3883 | 145 | */ |
yamaguch | 0:0232a97b3883 | 146 | Address64, |
yamaguch | 5:b82970ef7fb0 | 147 | |
yamaguch | 5:b82970ef7fb0 | 148 | /** |
yamaguch | 5:b82970ef7fb0 | 149 | * 16 bit remote address |
yamaguch | 5:b82970ef7fb0 | 150 | */ |
yamaguch | 5:b82970ef7fb0 | 151 | RemoteAddress16, |
yamaguch | 5:b82970ef7fb0 | 152 | |
yamaguch | 5:b82970ef7fb0 | 153 | /** |
yamaguch | 5:b82970ef7fb0 | 154 | * 64 bit remote address |
yamaguch | 5:b82970ef7fb0 | 155 | */ |
yamaguch | 5:b82970ef7fb0 | 156 | RemoteAddress64, |
yamaguch | 5:b82970ef7fb0 | 157 | |
yamaguch | 5:b82970ef7fb0 | 158 | /** |
yamaguch | 5:b82970ef7fb0 | 159 | * 16 bit parent address |
yamaguch | 5:b82970ef7fb0 | 160 | */ |
yamaguch | 5:b82970ef7fb0 | 161 | ParentAddress16, |
yamaguch | 0:0232a97b3883 | 162 | |
yamaguch | 0:0232a97b3883 | 163 | /** |
yamaguch | 0:0232a97b3883 | 164 | * Retry count |
yamaguch | 0:0232a97b3883 | 165 | */ |
yamaguch | 0:0232a97b3883 | 166 | RetryCount, |
yamaguch | 0:0232a97b3883 | 167 | |
yamaguch | 0:0232a97b3883 | 168 | /** |
yamaguch | 0:0232a97b3883 | 169 | * Delivery status |
yamaguch | 0:0232a97b3883 | 170 | */ |
yamaguch | 0:0232a97b3883 | 171 | DeliveryStatus, |
yamaguch | 0:0232a97b3883 | 172 | |
yamaguch | 0:0232a97b3883 | 173 | /** |
yamaguch | 0:0232a97b3883 | 174 | * Discovery status |
yamaguch | 0:0232a97b3883 | 175 | */ |
yamaguch | 0:0232a97b3883 | 176 | DiscoveryStatus, |
yamaguch | 0:0232a97b3883 | 177 | |
yamaguch | 0:0232a97b3883 | 178 | /** |
yamaguch | 0:0232a97b3883 | 179 | * Receive option |
yamaguch | 0:0232a97b3883 | 180 | */ |
yamaguch | 0:0232a97b3883 | 181 | ReceiveOptions, |
yamaguch | 0:0232a97b3883 | 182 | |
yamaguch | 0:0232a97b3883 | 183 | /** |
yamaguch | 0:0232a97b3883 | 184 | * Received data |
yamaguch | 0:0232a97b3883 | 185 | */ |
yamaguch | 0:0232a97b3883 | 186 | ReceivedData, |
yamaguch | 0:0232a97b3883 | 187 | |
yamaguch | 0:0232a97b3883 | 188 | /** |
yamaguch | 6:d15800bfa15d | 189 | * Node Identification String |
yamaguch | 5:b82970ef7fb0 | 190 | */ |
yamaguch | 5:b82970ef7fb0 | 191 | NIString, |
yamaguch | 5:b82970ef7fb0 | 192 | |
yamaguch | 5:b82970ef7fb0 | 193 | /** |
yamaguch | 5:b82970ef7fb0 | 194 | * Device Type |
yamaguch | 5:b82970ef7fb0 | 195 | */ |
yamaguch | 5:b82970ef7fb0 | 196 | DeviceType, |
yamaguch | 5:b82970ef7fb0 | 197 | |
yamaguch | 5:b82970ef7fb0 | 198 | /** |
yamaguch | 5:b82970ef7fb0 | 199 | * Source Event |
yamaguch | 5:b82970ef7fb0 | 200 | */ |
yamaguch | 5:b82970ef7fb0 | 201 | SourceEvent, |
yamaguch | 5:b82970ef7fb0 | 202 | |
yamaguch | 5:b82970ef7fb0 | 203 | /** |
yamaguch | 0:0232a97b3883 | 204 | * Raw data |
yamaguch | 0:0232a97b3883 | 205 | */ |
yamaguch | 0:0232a97b3883 | 206 | RawData |
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 ser Serial object through which XBee module is connected to mbed |
yamaguch | 0:0232a97b3883 | 213 | * @param apiMode API mode either 1 or 2 (use escape; default) |
yamaguch | 0:0232a97b3883 | 214 | * @param debug display debugging (I/O state) information through LEDs |
yamaguch | 0:0232a97b3883 | 215 | */ |
yamaguch | 8:776b8dc51932 | 216 | XBee(Serial& ser, int apiMode = 2, bool debug = true); |
yamaguch | 0:0232a97b3883 | 217 | |
yamaguch | 0:0232a97b3883 | 218 | /** |
yamaguch | 0:0232a97b3883 | 219 | * creates an XBee interface object. |
yamaguch | 0:0232a97b3883 | 220 | * |
yamaguch | 0:0232a97b3883 | 221 | * @param tx TX pin connected to XBee |
yamaguch | 0:0232a97b3883 | 222 | * @param rx RX pin connected to XBee |
yamaguch | 0:0232a97b3883 | 223 | * @param apiMode API mode either 1 or 2 (use escape; default) |
yamaguch | 0:0232a97b3883 | 224 | * @param debug display debugging (I/O state) information through LEDs |
yamaguch | 0:0232a97b3883 | 225 | */ |
yamaguch | 8:776b8dc51932 | 226 | XBee(PinName tx, PinName rx, int apiMode = 2, bool debug = true); |
yamaguch | 0:0232a97b3883 | 227 | |
yamaguch | 0:0232a97b3883 | 228 | /** |
yamaguch | 0:0232a97b3883 | 229 | * creates an XBee interface object. |
yamaguch | 0:0232a97b3883 | 230 | * |
yamaguch | 0:0232a97b3883 | 231 | * @param ser Serial object through which XBee module is connected to mbed |
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 | 8:776b8dc51932 | 236 | XBee(Serial& ser, Serial& mon, int apiMode = 2, bool debug = true); |
yamaguch | 0:0232a97b3883 | 237 | |
yamaguch | 0:0232a97b3883 | 238 | /** |
yamaguch | 0:0232a97b3883 | 239 | * creates an XBee interface object. |
yamaguch | 0:0232a97b3883 | 240 | * |
yamaguch | 0:0232a97b3883 | 241 | * @param tx TX pin connected to XBee |
yamaguch | 0:0232a97b3883 | 242 | * @param rx RX pin connected to XBee |
yamaguch | 0:0232a97b3883 | 243 | * @param mon alternate Serial object for monitoring (use serial ports other than USBTX/USBRX) |
yamaguch | 0:0232a97b3883 | 244 | * @param apiMode API mode either 1 or 2 (use escape; default) |
yamaguch | 0:0232a97b3883 | 245 | * @param debug display debugging (I/O state) information through LEDs |
yamaguch | 0:0232a97b3883 | 246 | */ |
yamaguch | 8:776b8dc51932 | 247 | XBee(PinName tx, PinName rx, Serial& mon, int apiMode = 2, bool debug = true); |
yamaguch | 0:0232a97b3883 | 248 | |
yamaguch | 0:0232a97b3883 | 249 | /** |
yamaguch | 0:0232a97b3883 | 250 | * initializes XBee module. |
yamaguch | 0:0232a97b3883 | 251 | * |
yamaguch | 0:0232a97b3883 | 252 | * issues VR command to test XBee modem connection |
yamaguch | 0:0232a97b3883 | 253 | * |
yamaguch | 0:0232a97b3883 | 254 | * @returns true if initialization succeeded, false otherwise |
yamaguch | 0:0232a97b3883 | 255 | */ |
yamaguch | 0:0232a97b3883 | 256 | bool init(float timeout = 15.0); |
yamaguch | 0:0232a97b3883 | 257 | |
yamaguch | 0:0232a97b3883 | 258 | /** |
yamaguch | 0:0232a97b3883 | 259 | * sets destination addresses. |
yamaguch | 0:0232a97b3883 | 260 | * |
yamaguch | 0:0232a97b3883 | 261 | * @param address64 XBeeAddress64 type address |
yamaguch | 0:0232a97b3883 | 262 | * @param address16 XBeeAddress16 type address (optional) |
yamaguch | 0:0232a97b3883 | 263 | */ |
yamaguch | 0:0232a97b3883 | 264 | void setDestination(XBeeAddress64 address64, XBeeAddress16 address16 = 0xFFFE); |
yamaguch | 0:0232a97b3883 | 265 | |
yamaguch | 0:0232a97b3883 | 266 | /** |
yamaguch | 0:0232a97b3883 | 267 | * sets destination addresses. |
yamaguch | 0:0232a97b3883 | 268 | * |
yamaguch | 0:0232a97b3883 | 269 | * @param address64 64-bit destination address in uint64_t |
yamaguch | 0:0232a97b3883 | 270 | * @param address16 16-bit destination address in uint16_t |
yamaguch | 0:0232a97b3883 | 271 | */ |
yamaguch | 0:0232a97b3883 | 272 | void setDestination(uint64_t address64, uint16_t address16 = 0xFFFE); |
yamaguch | 0:0232a97b3883 | 273 | |
yamaguch | 0:0232a97b3883 | 274 | /** |
yamaguch | 0:0232a97b3883 | 275 | * sets destination addresses. |
yamaguch | 0:0232a97b3883 | 276 | * |
yamaguch | 0:0232a97b3883 | 277 | * @param address64 64-bit destination address in bytes (big endian) |
yamaguch | 0:0232a97b3883 | 278 | * @param address16 16-bit destination address in bytes |
yamaguch | 0:0232a97b3883 | 279 | */ |
yamaguch | 0:0232a97b3883 | 280 | void setDestination(char address64[], char address16[]); |
yamaguch | 0:0232a97b3883 | 281 | |
yamaguch | 0:0232a97b3883 | 282 | /** |
yamaguch | 0:0232a97b3883 | 283 | * sends an AT command. |
yamaguch | 0:0232a97b3883 | 284 | * |
yamaguch | 0:0232a97b3883 | 285 | * @param command AT command char string |
yamaguch | 0:0232a97b3883 | 286 | * @param param parameter to the AT command |
yamaguch | 0:0232a97b3883 | 287 | */ |
yamaguch | 0:0232a97b3883 | 288 | void sendCommand(const char *command, int8_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 289 | void sendCommand(const char *command, int16_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 290 | void sendCommand(const char *command, int32_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 291 | void sendCommand(const char *command, int64_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 292 | void sendCommand(const char *command, uint8_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 293 | void sendCommand(const char *command, uint16_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 294 | void sendCommand(const char *command, uint32_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 295 | void sendCommand(const char *command, uint64_t param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 296 | void sendCommand(const char *command, const char *param, bool queue = false); |
yamaguch | 0:0232a97b3883 | 297 | |
yamaguch | 0:0232a97b3883 | 298 | /** |
yamaguch | 0:0232a97b3883 | 299 | * sends an AT command. |
yamaguch | 0:0232a97b3883 | 300 | * |
yamaguch | 0:0232a97b3883 | 301 | * @param command AT command char string |
yamaguch | 0:0232a97b3883 | 302 | * @param param parameter to the AT command (pointer to byte array) |
yamaguch | 0:0232a97b3883 | 303 | * @param param_length parameter length in bytes |
yamaguch | 0:0232a97b3883 | 304 | * @param queue true if command paramter is to be queued |
yamaguch | 0:0232a97b3883 | 305 | */ |
yamaguch | 0:0232a97b3883 | 306 | void sendCommand(const char *command, const uint8_t *param = 0, int param_length = 0, bool queue = false); |
yamaguch | 0:0232a97b3883 | 307 | |
yamaguch | 0:0232a97b3883 | 308 | /** |
yamaguch | 0:0232a97b3883 | 309 | * sends a remote AT command. |
yamaguch | 0:0232a97b3883 | 310 | * |
yamaguch | 0:0232a97b3883 | 311 | * sends an AT command to the XBee(s) at the destination address |
yamaguch | 0:0232a97b3883 | 312 | * |
yamaguch | 0:0232a97b3883 | 313 | * @param command AT command char string |
yamaguch | 0:0232a97b3883 | 314 | * @param param parameter to the AT command (pointer to byte array) |
yamaguch | 0:0232a97b3883 | 315 | * @param param_length parameter length in bytes |
yamaguch | 0:0232a97b3883 | 316 | * @param options remote command options |
yamaguch | 0:0232a97b3883 | 317 | */ |
yamaguch | 0:0232a97b3883 | 318 | void sendRemoteCommand(const char *command, int8_t param); |
yamaguch | 0:0232a97b3883 | 319 | void sendRemoteCommand(const char *command, int16_t param); |
yamaguch | 0:0232a97b3883 | 320 | void sendRemoteCommand(const char *command, int32_t param); |
yamaguch | 0:0232a97b3883 | 321 | void sendRemoteCommand(const char *command, int64_t param); |
yamaguch | 0:0232a97b3883 | 322 | void sendRemoteCommand(const char *command, uint8_t param); |
yamaguch | 0:0232a97b3883 | 323 | void sendRemoteCommand(const char *command, uint16_t param); |
yamaguch | 0:0232a97b3883 | 324 | void sendRemoteCommand(const char *command, uint32_t param); |
yamaguch | 0:0232a97b3883 | 325 | void sendRemoteCommand(const char *command, uint64_t param); |
yamaguch | 0:0232a97b3883 | 326 | void sendRemoteCommand(const char *command, const char *param); |
yamaguch | 0:0232a97b3883 | 327 | |
yamaguch | 0:0232a97b3883 | 328 | /** |
yamaguch | 0:0232a97b3883 | 329 | * sends a remote AT command. |
yamaguch | 0:0232a97b3883 | 330 | * |
yamaguch | 0:0232a97b3883 | 331 | * sends an AT command to the XBee(s) at the destination address |
yamaguch | 0:0232a97b3883 | 332 | * |
yamaguch | 0:0232a97b3883 | 333 | * @param command AT command char string |
yamaguch | 0:0232a97b3883 | 334 | * @param param parameter to the AT command (pointer to byte array) |
yamaguch | 0:0232a97b3883 | 335 | * @param param_length parameter length in bytes |
yamaguch | 0:0232a97b3883 | 336 | * @param options remote command options |
yamaguch | 0:0232a97b3883 | 337 | */ |
yamaguch | 0:0232a97b3883 | 338 | void sendRemoteCommand(const char *command, const uint8_t *param = 0, int param_length = 0, char options = 0x02); |
yamaguch | 0:0232a97b3883 | 339 | |
yamaguch | 0:0232a97b3883 | 340 | /** |
yamaguch | 0:0232a97b3883 | 341 | * executes an AT command and gets the result. |
yamaguch | 0:0232a97b3883 | 342 | * |
yamaguch | 0:0232a97b3883 | 343 | * @param command AT command char string |
yamaguch | 0:0232a97b3883 | 344 | * @param param parameter to the AT command |
yamaguch | 0:0232a97b3883 | 345 | * |
yamaguch | 0:0232a97b3883 | 346 | * @returns pointer to the command result, if the result is a number (char, short, long, int64_t), |
yamaguch | 0:0232a97b3883 | 347 | * the address to the number will be returned; otherwise the address to the byte array |
yamaguch | 0:0232a97b3883 | 348 | * containing the command response will be returned. |
yamaguch | 0:0232a97b3883 | 349 | */ |
yamaguch | 0:0232a97b3883 | 350 | void *executeCommand(const char *command, int8_t param); |
yamaguch | 0:0232a97b3883 | 351 | void *executeCommand(const char *command, int16_t param); |
yamaguch | 0:0232a97b3883 | 352 | void *executeCommand(const char *command, int32_t param); |
yamaguch | 0:0232a97b3883 | 353 | void *executeCommand(const char *command, int64_t param); |
yamaguch | 0:0232a97b3883 | 354 | void *executeCommand(const char *command, uint8_t param); |
yamaguch | 0:0232a97b3883 | 355 | void *executeCommand(const char *command, uint16_t param); |
yamaguch | 0:0232a97b3883 | 356 | void *executeCommand(const char *command, uint32_t param); |
yamaguch | 0:0232a97b3883 | 357 | void *executeCommand(const char *command, uint64_t param); |
yamaguch | 0:0232a97b3883 | 358 | void *executeCommand(const char *command, const char *param); |
yamaguch | 0:0232a97b3883 | 359 | |
yamaguch | 0:0232a97b3883 | 360 | /** |
yamaguch | 0:0232a97b3883 | 361 | * executes an AT command and gets the result. |
yamaguch | 0:0232a97b3883 | 362 | * |
yamaguch | 0:0232a97b3883 | 363 | * @param command AT command char string |
yamaguch | 0:0232a97b3883 | 364 | * @param param parameter to the AT command (pointer to byte array) |
yamaguch | 0:0232a97b3883 | 365 | * @param param_length parameter length in bytes |
yamaguch | 0:0232a97b3883 | 366 | * |
yamaguch | 0:0232a97b3883 | 367 | * @returns pointer to the command result, if the result is a number (char, short, long, long long), |
yamaguch | 0:0232a97b3883 | 368 | * the address to the number will be returned; otherwise the address to the byte array |
yamaguch | 0:0232a97b3883 | 369 | * containing the command response will be returned. |
yamaguch | 0:0232a97b3883 | 370 | */ |
yamaguch | 0:0232a97b3883 | 371 | void *executeCommand(const char *command, const uint8_t *param = 0, int laram_length = 0); |
yamaguch | 0:0232a97b3883 | 372 | |
yamaguch | 0:0232a97b3883 | 373 | /** |
yamaguch | 0:0232a97b3883 | 374 | * sends data to the XBee(s) at the destination address. |
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 | * @param confirm if true, checks the transmission status frame and returns the result |
yamaguch | 0:0232a97b3883 | 379 | */ |
yamaguch | 0:0232a97b3883 | 380 | bool send(const char *data, int length, bool confirm); |
yamaguch | 0:0232a97b3883 | 381 | |
yamaguch | 0:0232a97b3883 | 382 | /** |
yamaguch | 0:0232a97b3883 | 383 | * sends data and confirm the transmit status. |
yamaguch | 0:0232a97b3883 | 384 | * |
yamaguch | 0:0232a97b3883 | 385 | * @param data address to the data (byte array) |
yamaguch | 0:0232a97b3883 | 386 | * @param length data length in bytes |
yamaguch | 0:0232a97b3883 | 387 | * |
yamaguch | 0:0232a97b3883 | 388 | * @returns true if sent successfully, false otherwise (either timeout or send error occurred) |
yamaguch | 0:0232a97b3883 | 389 | */ |
yamaguch | 0:0232a97b3883 | 390 | bool sendConfirm(const char *data, int length); |
yamaguch | 0:0232a97b3883 | 391 | |
yamaguch | 0:0232a97b3883 | 392 | /** |
yamaguch | 0:0232a97b3883 | 393 | * sends data to the destination using printf format. |
yamaguch | 0:0232a97b3883 | 394 | * |
yamaguch | 0:0232a97b3883 | 395 | * @param format printf format string, followed by corresponding arguments |
yamaguch | 0:0232a97b3883 | 396 | * |
yamaguch | 0:0232a97b3883 | 397 | * @returns the number of charancters sent, or negative if error occurred |
yamaguch | 0:0232a97b3883 | 398 | */ |
yamaguch | 0:0232a97b3883 | 399 | int printf(const char *format, ...); |
yamaguch | 0:0232a97b3883 | 400 | |
yamaguch | 0:0232a97b3883 | 401 | /** |
yamaguch | 0:0232a97b3883 | 402 | * receives data frame from the XBee module. |
yamaguch | 0:0232a97b3883 | 403 | * |
yamaguch | 0:0232a97b3883 | 404 | * @param timeout seconds bofer time out |
yamaguch | 0:0232a97b3883 | 405 | * |
yamaguch | 0:0232a97b3883 | 406 | * @returns FrameType of the received frame data |
yamaguch | 0:0232a97b3883 | 407 | */ |
yamaguch | 0:0232a97b3883 | 408 | FrameType receive(float timeout = 3.0); |
yamaguch | 0:0232a97b3883 | 409 | |
yamaguch | 0:0232a97b3883 | 410 | /** |
yamaguch | 0:0232a97b3883 | 411 | * scan received data |
yamaguch | 0:0232a97b3883 | 412 | * |
yamaguch | 0:0232a97b3883 | 413 | * @param data XBeeDataType data to be scanned |
yamaguch | 0:0232a97b3883 | 414 | * |
yamaguch | 0:0232a97b3883 | 415 | * @param true if scan succeeded, false otherwise |
yamaguch | 0:0232a97b3883 | 416 | */ |
yamaguch | 0:0232a97b3883 | 417 | bool scan(XBeeFrameID& id) { return scan(XBee::FrameID, id.raw_address(), 1); } |
yamaguch | 0:0232a97b3883 | 418 | bool scan(XBeeRetryCount& count) { return scan(XBee::RetryCount, count.raw_address(), 1); } |
yamaguch | 0:0232a97b3883 | 419 | bool scan(XBeeStatus& status) { return scan(XBee::Status, status.raw_address(), 1); } |
yamaguch | 0:0232a97b3883 | 420 | bool scan(XBeeDeliveryStatus& status) { return scan(XBee::DeliveryStatus, status.raw_address(), 1); } |
yamaguch | 0:0232a97b3883 | 421 | bool scan(XBeeDiscoveryStatus& status) { return scan(XBee::DiscoveryStatus, status.raw_address(), 1); } |
yamaguch | 0:0232a97b3883 | 422 | bool scan(XBeeReceiveOptions& options) { return scan(XBee::ReceiveOptions, options.raw_address(), 1); } |
yamaguch | 5:b82970ef7fb0 | 423 | bool scan(XBeeDeviceType& device) { return scan(XBee::DeviceType, device.raw_address(), 1); } |
yamaguch | 5:b82970ef7fb0 | 424 | bool scan(XBeeSourceEvent& event) { return scan(XBee::SourceEvent, event.raw_address(), 1); } |
yamaguch | 0:0232a97b3883 | 425 | bool scan(XBeeAddress64& address64) { return scan(XBee::Address64, address64.raw_address(), 8); } |
yamaguch | 0:0232a97b3883 | 426 | bool scan(XBeeAddress16& address16) { return scan(XBee::Address16, address16.raw_address(), 2); } |
yamaguch | 0:0232a97b3883 | 427 | bool scan(XBeeATCommand& command) { return scan(XBee::ATCommand, command.raw_address(), 3); } |
yamaguch | 0:0232a97b3883 | 428 | bool scan(XBeeCommandData& data) { return scan(XBee::CommandData, data.raw_address(), data.capacity, &data.size); } |
yamaguch | 0:0232a97b3883 | 429 | bool scan(XBeeReceivedData& data) { return scan(XBee::ReceivedData, data.raw_address(), data.capacity, &data.size); } |
yamaguch | 7:19f03567ec4e | 430 | bool scan(XBeeNodeIdentifier& ni) { return scan(XBee::NIString, ni.raw_address(), ni.capacity, &ni.size); } |
yamaguch | 0:0232a97b3883 | 431 | bool scan(XBeeRawData& data) { return scan(XBee::RawData, data.raw_address(), data.capacity, &data.size); } |
yamaguch | 0:0232a97b3883 | 432 | |
yamaguch | 0:0232a97b3883 | 433 | /** |
yamaguch | 0:0232a97b3883 | 434 | * scan received data according to the specified format. |
yamaguch | 0:0232a97b3883 | 435 | * |
yamaguch | 0:0232a97b3883 | 436 | * @param type ValueType of the data to be scanned |
yamaguch | 0:0232a97b3883 | 437 | * @param value pointer to the byte array to store the scanned value |
yamaguch | 0:0232a97b3883 | 438 | * @param maxlength max size of the value in bytes |
yamaguch | 0:0232a97b3883 | 439 | * @param length pointer to an int to receive the actual data length |
yamaguch | 0:0232a97b3883 | 440 | * |
yamaguch | 0:0232a97b3883 | 441 | * @param true if scan succeeded, false otherwise |
yamaguch | 0:0232a97b3883 | 442 | */ |
yamaguch | 0:0232a97b3883 | 443 | bool scan(ValueType type, char *value, int maxlength = 1, int *length = 0); |
yamaguch | 0:0232a97b3883 | 444 | |
yamaguch | 0:0232a97b3883 | 445 | /** |
yamaguch | 0:0232a97b3883 | 446 | * gets the XBee firmware version. |
yamaguch | 0:0232a97b3883 | 447 | * |
yamaguch | 0:0232a97b3883 | 448 | * @returns XBee firmwre version in int (unsigned short value) |
yamaguch | 0:0232a97b3883 | 449 | */ |
yamaguch | 0:0232a97b3883 | 450 | int getFirmwareVersion(); |
yamaguch | 0:0232a97b3883 | 451 | |
yamaguch | 0:0232a97b3883 | 452 | /** |
yamaguch | 0:0232a97b3883 | 453 | * gets the current frame ID. |
yamaguch | 0:0232a97b3883 | 454 | * |
yamaguch | 0:0232a97b3883 | 455 | * @returns frame ID number being used in the next send request |
yamaguch | 0:0232a97b3883 | 456 | */ |
yamaguch | 0:0232a97b3883 | 457 | char getFrameID(); |
yamaguch | 0:0232a97b3883 | 458 | |
yamaguch | 0:0232a97b3883 | 459 | /** |
yamaguch | 0:0232a97b3883 | 460 | * sets to run in debug mode. |
yamaguch | 0:0232a97b3883 | 461 | * |
yamaguch | 0:0232a97b3883 | 462 | * @param debug true to display debugging information |
yamaguch | 0:0232a97b3883 | 463 | */ |
yamaguch | 0:0232a97b3883 | 464 | void setDebug(bool debug); |
yamaguch | 0:0232a97b3883 | 465 | |
yamaguch | 0:0232a97b3883 | 466 | /** |
yamaguch | 0:0232a97b3883 | 467 | * displays received data in dump format. |
yamaguch | 0:0232a97b3883 | 468 | */ |
yamaguch | 0:0232a97b3883 | 469 | void dump(); |
yamaguch | 0:0232a97b3883 | 470 | |
yamaguch | 0:0232a97b3883 | 471 | /** |
yamaguch | 0:0232a97b3883 | 472 | * displays the internal data fields and receive buffer in dump format. |
yamaguch | 0:0232a97b3883 | 473 | */ |
yamaguch | 0:0232a97b3883 | 474 | void dumpAll(); |
yamaguch | 0:0232a97b3883 | 475 | |
yamaguch | 0:0232a97b3883 | 476 | /** |
yamaguch | 0:0232a97b3883 | 477 | * operator overloading for testing XBee modem connection status. |
yamaguch | 0:0232a97b3883 | 478 | * |
yamaguch | 0:0232a97b3883 | 479 | * @returns false if XBee modem connection has an error |
yamaguch | 0:0232a97b3883 | 480 | */ |
yamaguch | 0:0232a97b3883 | 481 | operator bool(); |
yamaguch | 0:0232a97b3883 | 482 | |
yamaguch | 0:0232a97b3883 | 483 | private: |
yamaguch | 0:0232a97b3883 | 484 | Serial mon; |
yamaguch | 0:0232a97b3883 | 485 | BusOut leds; |
yamaguch | 0:0232a97b3883 | 486 | int apiMode; |
yamaguch | 0:0232a97b3883 | 487 | volatile enum {UNKNOWN, LENGTH1, LENGTH2, DATA, SUMCHECK} state; |
yamaguch | 0:0232a97b3883 | 488 | volatile int cur, in, out, received, free; |
yamaguch | 0:0232a97b3883 | 489 | char frame_id; |
yamaguch | 0:0232a97b3883 | 490 | char destination64[8]; |
yamaguch | 0:0232a97b3883 | 491 | char destination16[2]; |
yamaguch | 0:0232a97b3883 | 492 | char buf[BUFSIZE]; |
yamaguch | 8:776b8dc51932 | 493 | RingBuffer<char, 32> rxBuf; |
yamaguch | 0:0232a97b3883 | 494 | bool debug; |
yamaguch | 8:776b8dc51932 | 495 | #ifdef XBEE_RTOS |
yamaguch | 8:776b8dc51932 | 496 | Mutex mutex; |
yamaguch | 8:776b8dc51932 | 497 | #endif |
yamaguch | 0:0232a97b3883 | 498 | void send(char c); |
yamaguch | 0:0232a97b3883 | 499 | void send2(char c); |
yamaguch | 0:0232a97b3883 | 500 | void sendFrame(const char *frame, int length); |
yamaguch | 0:0232a97b3883 | 501 | int createTxRequest(char frame_id, const char *data, int data_length, char *buf, int buf_size); |
yamaguch | 0:0232a97b3883 | 502 | 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 | 503 | 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 | 504 | int seekFor(FrameType type, char id, float timeout); |
yamaguch | 0:0232a97b3883 | 505 | FrameType getFrameType(char c); |
yamaguch | 0:0232a97b3883 | 506 | bool scan(int i, ValueType type, char *value, int maxlength = 1, int *length = 0); |
yamaguch | 0:0232a97b3883 | 507 | void flush(); |
yamaguch | 8:776b8dc51932 | 508 | #ifndef XBEE_RTOS |
yamaguch | 0:0232a97b3883 | 509 | void rxInterruptHandler(); |
yamaguch | 8:776b8dc51932 | 510 | #else |
yamaguch | 8:776b8dc51932 | 511 | void rxISR(); |
yamaguch | 8:776b8dc51932 | 512 | virtual void run(); |
yamaguch | 8:776b8dc51932 | 513 | #endif |
yamaguch | 0:0232a97b3883 | 514 | void dump(const char *data, int length); |
yamaguch | 0:0232a97b3883 | 515 | void dumpIOSample(const char *data, int length); |
yamaguch | 0:0232a97b3883 | 516 | void copy(char *toBuf, int fromIndex, int length); |
yamaguch | 0:0232a97b3883 | 517 | }; |
yamaguch | 0:0232a97b3883 | 518 | |
yamaguch | 0:0232a97b3883 | 519 | #endif |