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