2015/05/16
Dependents: Aigamozu_Robot_ver3_1 Aigamozu_Robot_ver3_2 Aigamozu_Robot_ver3_3 Aigamozu_Robot_ver3_4 ... more
Fork of XBee by
XBee.h@8:a1bf1c09f7ab, 2015-05-16 (annotated)
- Committer:
- s1200058
- Date:
- Sat May 16 14:06:50 2015 +0000
- Revision:
- 8:a1bf1c09f7ab
- Parent:
- 6:6f84e2840408
2015/05/16
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
okini3939 | 1:e3b2027e685c | 1 | /** |
okini3939 | 1:e3b2027e685c | 2 | * XBee-mbed library |
okini3939 | 1:e3b2027e685c | 3 | * Modified for mbed, 2011 Suga. |
okini3939 | 1:e3b2027e685c | 4 | * |
okini3939 | 1:e3b2027e685c | 5 | * |
okini3939 | 1:e3b2027e685c | 6 | * Copyright (c) 2009 Andrew Rapp. All rights reserved. |
okini3939 | 1:e3b2027e685c | 7 | * |
okini3939 | 1:e3b2027e685c | 8 | * This file is part of XBee-Arduino. |
okini3939 | 1:e3b2027e685c | 9 | * |
okini3939 | 1:e3b2027e685c | 10 | * XBee-Arduino is free software: you can redistribute it and/or modify |
okini3939 | 1:e3b2027e685c | 11 | * it under the terms of the GNU General Public License as published by |
okini3939 | 1:e3b2027e685c | 12 | * the Free Software Foundation, either version 3 of the License, or |
okini3939 | 1:e3b2027e685c | 13 | * (at your option) any later version. |
okini3939 | 1:e3b2027e685c | 14 | * |
okini3939 | 1:e3b2027e685c | 15 | * XBee-Arduino is distributed in the hope that it will be useful, |
okini3939 | 1:e3b2027e685c | 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
okini3939 | 1:e3b2027e685c | 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
okini3939 | 1:e3b2027e685c | 18 | * GNU General Public License for more details. |
okini3939 | 1:e3b2027e685c | 19 | * |
okini3939 | 1:e3b2027e685c | 20 | * You should have received a copy of the GNU General Public License |
okini3939 | 1:e3b2027e685c | 21 | * along with XBee-Arduino. If not, see <http://www.gnu.org/licenses/>. |
okini3939 | 1:e3b2027e685c | 22 | */ |
okini3939 | 1:e3b2027e685c | 23 | |
okini3939 | 3:8573b122fa84 | 24 | /** @file |
okini3939 | 3:8573b122fa84 | 25 | * @brief XBee library for mbed |
okini3939 | 3:8573b122fa84 | 26 | */ |
okini3939 | 3:8573b122fa84 | 27 | |
okini3939 | 6:6f84e2840408 | 28 | #include "XBee_conf.h" |
okini3939 | 6:6f84e2840408 | 29 | |
okini3939 | 1:e3b2027e685c | 30 | #ifndef XBee_h |
okini3939 | 1:e3b2027e685c | 31 | #define XBee_h |
okini3939 | 1:e3b2027e685c | 32 | |
okini3939 | 1:e3b2027e685c | 33 | #include "mbed.h" |
okini3939 | 1:e3b2027e685c | 34 | #include <inttypes.h> |
s1200058 | 8:a1bf1c09f7ab | 35 | #include <iostream> |
okini3939 | 1:e3b2027e685c | 36 | |
okini3939 | 1:e3b2027e685c | 37 | #define SERIES_1 |
okini3939 | 1:e3b2027e685c | 38 | #define SERIES_2 |
okini3939 | 4:f6d73acc1f75 | 39 | #define WIFI |
okini3939 | 1:e3b2027e685c | 40 | |
okini3939 | 1:e3b2027e685c | 41 | // set to ATAP value of XBee. AP=2 is recommended |
okini3939 | 1:e3b2027e685c | 42 | #define ATAP 2 |
okini3939 | 1:e3b2027e685c | 43 | |
okini3939 | 1:e3b2027e685c | 44 | #define START_BYTE 0x7e |
okini3939 | 1:e3b2027e685c | 45 | #define ESCAPE 0x7d |
okini3939 | 1:e3b2027e685c | 46 | #define XON 0x11 |
okini3939 | 1:e3b2027e685c | 47 | #define XOFF 0x13 |
okini3939 | 1:e3b2027e685c | 48 | |
okini3939 | 1:e3b2027e685c | 49 | // This value determines the size of the byte array for receiving RX packets |
okini3939 | 1:e3b2027e685c | 50 | // Most users won't be dealing with packets this large so you can adjust this |
okini3939 | 1:e3b2027e685c | 51 | // value to reduce memory consumption. But, remember that |
okini3939 | 1:e3b2027e685c | 52 | // if a RX packet exceeds this size, it cannot be parsed! |
okini3939 | 1:e3b2027e685c | 53 | |
okini3939 | 1:e3b2027e685c | 54 | // This value is determined by the largest packet size (100 byte payload + 64-bit address + option byte and rssi byte) of a series 1 radio |
okini3939 | 4:f6d73acc1f75 | 55 | //#define MAX_FRAME_DATA_SIZE 110 |
okini3939 | 4:f6d73acc1f75 | 56 | #define MAX_FRAME_DATA_SIZE 1520 |
okini3939 | 4:f6d73acc1f75 | 57 | #define MAX_RXBUF_SIZE 32 |
okini3939 | 1:e3b2027e685c | 58 | |
okini3939 | 1:e3b2027e685c | 59 | #define BROADCAST_ADDRESS 0xffff |
okini3939 | 1:e3b2027e685c | 60 | #define ZB_BROADCAST_ADDRESS 0xfffe |
okini3939 | 1:e3b2027e685c | 61 | |
okini3939 | 1:e3b2027e685c | 62 | // the non-variable length of the frame data (not including frame id or api id or variable data size (e.g. payload, at command set value) |
okini3939 | 1:e3b2027e685c | 63 | #define ZB_TX_API_LENGTH 12 |
okini3939 | 1:e3b2027e685c | 64 | #define TX_16_API_LENGTH 3 |
okini3939 | 1:e3b2027e685c | 65 | #define TX_64_API_LENGTH 9 |
okini3939 | 1:e3b2027e685c | 66 | #define AT_COMMAND_API_LENGTH 2 |
okini3939 | 1:e3b2027e685c | 67 | #define REMOTE_AT_COMMAND_API_LENGTH 13 |
okini3939 | 1:e3b2027e685c | 68 | // start/length(2)/api/frameid/checksum bytes |
okini3939 | 1:e3b2027e685c | 69 | #define PACKET_OVERHEAD_LENGTH 6 |
okini3939 | 1:e3b2027e685c | 70 | // api is always the third byte in packet |
okini3939 | 1:e3b2027e685c | 71 | #define API_ID_INDEX 3 |
okini3939 | 1:e3b2027e685c | 72 | |
okini3939 | 1:e3b2027e685c | 73 | // frame position of rssi byte |
okini3939 | 1:e3b2027e685c | 74 | #define RX_16_RSSI_OFFSET 2 |
okini3939 | 1:e3b2027e685c | 75 | #define RX_64_RSSI_OFFSET 8 |
okini3939 | 1:e3b2027e685c | 76 | |
okini3939 | 1:e3b2027e685c | 77 | #define DEFAULT_FRAME_ID 1 |
okini3939 | 1:e3b2027e685c | 78 | #define NO_RESPONSE_FRAME_ID 0 |
okini3939 | 1:e3b2027e685c | 79 | |
okini3939 | 1:e3b2027e685c | 80 | // TODO put in tx16 class |
okini3939 | 1:e3b2027e685c | 81 | #define ACK_OPTION 0 |
okini3939 | 1:e3b2027e685c | 82 | #define DISABLE_ACK_OPTION 1 |
okini3939 | 1:e3b2027e685c | 83 | #define BROADCAST_OPTION 4 |
okini3939 | 1:e3b2027e685c | 84 | |
okini3939 | 1:e3b2027e685c | 85 | // RX options |
okini3939 | 1:e3b2027e685c | 86 | #define ZB_PACKET_ACKNOWLEDGED 0x01 |
okini3939 | 1:e3b2027e685c | 87 | #define ZB_BROADCAST_PACKET 0x02 |
okini3939 | 1:e3b2027e685c | 88 | |
okini3939 | 1:e3b2027e685c | 89 | // not everything is implemented! |
okini3939 | 1:e3b2027e685c | 90 | /** |
okini3939 | 1:e3b2027e685c | 91 | * Api Id constants |
okini3939 | 1:e3b2027e685c | 92 | */ |
okini3939 | 1:e3b2027e685c | 93 | #define TX_64_REQUEST 0x0 |
okini3939 | 1:e3b2027e685c | 94 | #define TX_16_REQUEST 0x1 |
okini3939 | 1:e3b2027e685c | 95 | #define AT_COMMAND_REQUEST 0x08 |
okini3939 | 1:e3b2027e685c | 96 | #define AT_COMMAND_QUEUE_REQUEST 0x09 |
okini3939 | 1:e3b2027e685c | 97 | #define REMOTE_AT_REQUEST 0x17 |
okini3939 | 1:e3b2027e685c | 98 | #define ZB_TX_REQUEST 0x10 |
okini3939 | 1:e3b2027e685c | 99 | #define ZB_EXPLICIT_TX_REQUEST 0x11 |
okini3939 | 1:e3b2027e685c | 100 | #define RX_64_RESPONSE 0x80 |
okini3939 | 1:e3b2027e685c | 101 | #define RX_16_RESPONSE 0x81 |
okini3939 | 1:e3b2027e685c | 102 | #define RX_64_IO_RESPONSE 0x82 |
okini3939 | 1:e3b2027e685c | 103 | #define RX_16_IO_RESPONSE 0x83 |
okini3939 | 1:e3b2027e685c | 104 | #define AT_RESPONSE 0x88 |
okini3939 | 1:e3b2027e685c | 105 | #define TX_STATUS_RESPONSE 0x89 |
okini3939 | 1:e3b2027e685c | 106 | #define MODEM_STATUS_RESPONSE 0x8a |
okini3939 | 1:e3b2027e685c | 107 | #define ZB_RX_RESPONSE 0x90 |
okini3939 | 1:e3b2027e685c | 108 | #define ZB_EXPLICIT_RX_RESPONSE 0x91 |
okini3939 | 1:e3b2027e685c | 109 | #define ZB_TX_STATUS_RESPONSE 0x8b |
okini3939 | 1:e3b2027e685c | 110 | #define ZB_IO_SAMPLE_RESPONSE 0x92 |
okini3939 | 1:e3b2027e685c | 111 | #define ZB_IO_NODE_IDENTIFIER_RESPONSE 0x95 |
okini3939 | 1:e3b2027e685c | 112 | #define AT_COMMAND_RESPONSE 0x88 |
okini3939 | 1:e3b2027e685c | 113 | #define REMOTE_AT_COMMAND_RESPONSE 0x97 |
okini3939 | 1:e3b2027e685c | 114 | |
okini3939 | 1:e3b2027e685c | 115 | |
okini3939 | 1:e3b2027e685c | 116 | /** |
okini3939 | 1:e3b2027e685c | 117 | * TX STATUS constants |
okini3939 | 1:e3b2027e685c | 118 | */ |
okini3939 | 1:e3b2027e685c | 119 | #define SUCCESS 0x0 |
okini3939 | 1:e3b2027e685c | 120 | #define CCA_FAILURE 0x2 |
okini3939 | 1:e3b2027e685c | 121 | #define INVALID_DESTINATION_ENDPOINT_SUCCESS 0x15 |
okini3939 | 1:e3b2027e685c | 122 | #define NETWORK_ACK_FAILURE 0x21 |
okini3939 | 1:e3b2027e685c | 123 | #define NOT_JOINED_TO_NETWORK 0x22 |
okini3939 | 1:e3b2027e685c | 124 | #define SELF_ADDRESSED 0x23 |
okini3939 | 1:e3b2027e685c | 125 | #define ADDRESS_NOT_FOUND 0x24 |
okini3939 | 1:e3b2027e685c | 126 | #define ROUTE_NOT_FOUND 0x25 |
okini3939 | 1:e3b2027e685c | 127 | #define PAYLOAD_TOO_LARGE 0x74 |
okini3939 | 1:e3b2027e685c | 128 | |
okini3939 | 1:e3b2027e685c | 129 | // modem status |
okini3939 | 1:e3b2027e685c | 130 | #define HARDWARE_RESET 0 |
okini3939 | 1:e3b2027e685c | 131 | #define WATCHDOG_TIMER_RESET 1 |
okini3939 | 1:e3b2027e685c | 132 | #define ASSOCIATED 2 |
okini3939 | 1:e3b2027e685c | 133 | #define DISASSOCIATED 3 |
okini3939 | 1:e3b2027e685c | 134 | #define SYNCHRONIZATION_LOST 4 |
okini3939 | 1:e3b2027e685c | 135 | #define COORDINATOR_REALIGNMENT 5 |
okini3939 | 1:e3b2027e685c | 136 | #define COORDINATOR_STARTED 6 |
okini3939 | 1:e3b2027e685c | 137 | |
okini3939 | 1:e3b2027e685c | 138 | #define ZB_BROADCAST_RADIUS_MAX_HOPS 0 |
okini3939 | 1:e3b2027e685c | 139 | |
okini3939 | 1:e3b2027e685c | 140 | #define ZB_TX_UNICAST 0 |
okini3939 | 1:e3b2027e685c | 141 | #define ZB_TX_BROADCAST 8 |
okini3939 | 1:e3b2027e685c | 142 | |
okini3939 | 1:e3b2027e685c | 143 | #define AT_OK 0 |
okini3939 | 1:e3b2027e685c | 144 | #define AT_ERROR 1 |
okini3939 | 1:e3b2027e685c | 145 | #define AT_INVALID_COMMAND 2 |
okini3939 | 1:e3b2027e685c | 146 | #define AT_INVALID_PARAMETER 3 |
okini3939 | 1:e3b2027e685c | 147 | #define AT_NO_RESPONSE 4 |
okini3939 | 1:e3b2027e685c | 148 | |
okini3939 | 1:e3b2027e685c | 149 | #define NO_ERROR 0 |
okini3939 | 1:e3b2027e685c | 150 | #define CHECKSUM_FAILURE 1 |
okini3939 | 1:e3b2027e685c | 151 | #define PACKET_EXCEEDS_BYTE_ARRAY_LENGTH 2 |
okini3939 | 1:e3b2027e685c | 152 | #define UNEXPECTED_START_BYTE 3 |
okini3939 | 1:e3b2027e685c | 153 | |
okini3939 | 1:e3b2027e685c | 154 | /** |
okini3939 | 1:e3b2027e685c | 155 | * The super class of all XBee responses (RX packets) |
okini3939 | 1:e3b2027e685c | 156 | * Users should never attempt to create an instance of this class; instead |
okini3939 | 1:e3b2027e685c | 157 | * create an instance of a subclass |
okini3939 | 1:e3b2027e685c | 158 | * It is recommend to reuse subclasses to conserve memory |
okini3939 | 1:e3b2027e685c | 159 | */ |
okini3939 | 1:e3b2027e685c | 160 | class XBeeResponse { |
okini3939 | 1:e3b2027e685c | 161 | public: |
okini3939 | 1:e3b2027e685c | 162 | //static const int MODEM_STATUS = 0x8a; |
okini3939 | 1:e3b2027e685c | 163 | /** |
okini3939 | 1:e3b2027e685c | 164 | * Default constructor |
okini3939 | 1:e3b2027e685c | 165 | */ |
okini3939 | 1:e3b2027e685c | 166 | XBeeResponse(); |
okini3939 | 1:e3b2027e685c | 167 | /** |
okini3939 | 1:e3b2027e685c | 168 | * Returns Api Id of the response |
okini3939 | 1:e3b2027e685c | 169 | */ |
okini3939 | 1:e3b2027e685c | 170 | uint8_t getApiId(); |
okini3939 | 1:e3b2027e685c | 171 | void setApiId(uint8_t apiId); |
okini3939 | 1:e3b2027e685c | 172 | /** |
okini3939 | 1:e3b2027e685c | 173 | * Returns the MSB length of the packet |
okini3939 | 1:e3b2027e685c | 174 | */ |
okini3939 | 1:e3b2027e685c | 175 | uint8_t getMsbLength(); |
okini3939 | 1:e3b2027e685c | 176 | void setMsbLength(uint8_t msbLength); |
okini3939 | 1:e3b2027e685c | 177 | /** |
okini3939 | 1:e3b2027e685c | 178 | * Returns the LSB length of the packet |
okini3939 | 1:e3b2027e685c | 179 | */ |
okini3939 | 1:e3b2027e685c | 180 | uint8_t getLsbLength(); |
okini3939 | 1:e3b2027e685c | 181 | void setLsbLength(uint8_t lsbLength); |
okini3939 | 1:e3b2027e685c | 182 | /** |
okini3939 | 1:e3b2027e685c | 183 | * Returns the packet checksum |
okini3939 | 1:e3b2027e685c | 184 | */ |
okini3939 | 1:e3b2027e685c | 185 | uint8_t getChecksum(); |
okini3939 | 1:e3b2027e685c | 186 | void setChecksum(uint8_t checksum); |
okini3939 | 1:e3b2027e685c | 187 | /** |
okini3939 | 1:e3b2027e685c | 188 | * Returns the length of the frame data: all bytes after the api id, and prior to the checksum |
okini3939 | 1:e3b2027e685c | 189 | * Note up to release 0.1.2, this was incorrectly including the checksum in the length. |
okini3939 | 1:e3b2027e685c | 190 | */ |
okini3939 | 4:f6d73acc1f75 | 191 | uint16_t getFrameDataLength(); |
okini3939 | 1:e3b2027e685c | 192 | void setFrameData(uint8_t* frameDataPtr); |
okini3939 | 1:e3b2027e685c | 193 | /** |
okini3939 | 1:e3b2027e685c | 194 | * Returns the buffer that contains the response. |
okini3939 | 1:e3b2027e685c | 195 | * Starts with byte that follows API ID and includes all bytes prior to the checksum |
okini3939 | 1:e3b2027e685c | 196 | * Length is specified by getFrameDataLength() |
okini3939 | 1:e3b2027e685c | 197 | * Note: Unlike Digi's definition of the frame data, this does not start with the API ID.. |
okini3939 | 1:e3b2027e685c | 198 | * The reason for this is all responses include an API ID, whereas my frame data |
okini3939 | 1:e3b2027e685c | 199 | * includes only the API specific data. |
okini3939 | 1:e3b2027e685c | 200 | */ |
okini3939 | 1:e3b2027e685c | 201 | uint8_t* getFrameData(); |
okini3939 | 1:e3b2027e685c | 202 | |
okini3939 | 4:f6d73acc1f75 | 203 | void setFrameLength(uint16_t frameLength); |
okini3939 | 1:e3b2027e685c | 204 | // to support future 65535 byte packets I guess |
okini3939 | 1:e3b2027e685c | 205 | /** |
okini3939 | 1:e3b2027e685c | 206 | * Returns the length of the packet |
okini3939 | 1:e3b2027e685c | 207 | */ |
okini3939 | 1:e3b2027e685c | 208 | uint16_t getPacketLength(); |
okini3939 | 1:e3b2027e685c | 209 | /** |
okini3939 | 1:e3b2027e685c | 210 | * Resets the response to default values |
okini3939 | 1:e3b2027e685c | 211 | */ |
okini3939 | 1:e3b2027e685c | 212 | void reset(); |
okini3939 | 1:e3b2027e685c | 213 | /** |
okini3939 | 1:e3b2027e685c | 214 | * Initializes the response |
okini3939 | 1:e3b2027e685c | 215 | */ |
okini3939 | 1:e3b2027e685c | 216 | void init(); |
okini3939 | 1:e3b2027e685c | 217 | #ifdef SERIES_2 |
okini3939 | 1:e3b2027e685c | 218 | /** |
okini3939 | 1:e3b2027e685c | 219 | * Call with instance of ZBTxStatusResponse class only if getApiId() == ZB_TX_STATUS_RESPONSE |
okini3939 | 1:e3b2027e685c | 220 | * to populate response |
okini3939 | 1:e3b2027e685c | 221 | */ |
okini3939 | 1:e3b2027e685c | 222 | void getZBTxStatusResponse(XBeeResponse &response); |
okini3939 | 1:e3b2027e685c | 223 | /** |
okini3939 | 1:e3b2027e685c | 224 | * Call with instance of ZBRxResponse class only if getApiId() == ZB_RX_RESPONSE |
okini3939 | 1:e3b2027e685c | 225 | * to populate response |
okini3939 | 1:e3b2027e685c | 226 | */ |
okini3939 | 1:e3b2027e685c | 227 | void getZBRxResponse(XBeeResponse &response); |
okini3939 | 1:e3b2027e685c | 228 | /** |
okini3939 | 1:e3b2027e685c | 229 | * Call with instance of ZBRxIoSampleResponse class only if getApiId() == ZB_IO_SAMPLE_RESPONSE |
okini3939 | 1:e3b2027e685c | 230 | * to populate response |
okini3939 | 1:e3b2027e685c | 231 | */ |
okini3939 | 1:e3b2027e685c | 232 | void getZBRxIoSampleResponse(XBeeResponse &response); |
okini3939 | 1:e3b2027e685c | 233 | #endif |
okini3939 | 1:e3b2027e685c | 234 | #ifdef SERIES_1 |
okini3939 | 1:e3b2027e685c | 235 | /** |
okini3939 | 1:e3b2027e685c | 236 | * Call with instance of TxStatusResponse only if getApiId() == TX_STATUS_RESPONSE |
okini3939 | 1:e3b2027e685c | 237 | */ |
okini3939 | 1:e3b2027e685c | 238 | void getTxStatusResponse(XBeeResponse &response); |
okini3939 | 1:e3b2027e685c | 239 | /** |
okini3939 | 1:e3b2027e685c | 240 | * Call with instance of Rx16Response only if getApiId() == RX_16_RESPONSE |
okini3939 | 1:e3b2027e685c | 241 | */ |
okini3939 | 1:e3b2027e685c | 242 | void getRx16Response(XBeeResponse &response); |
okini3939 | 1:e3b2027e685c | 243 | /** |
okini3939 | 1:e3b2027e685c | 244 | * Call with instance of Rx64Response only if getApiId() == RX_64_RESPONSE |
okini3939 | 1:e3b2027e685c | 245 | */ |
okini3939 | 1:e3b2027e685c | 246 | void getRx64Response(XBeeResponse &response); |
okini3939 | 1:e3b2027e685c | 247 | /** |
okini3939 | 1:e3b2027e685c | 248 | * Call with instance of Rx16IoSampleResponse only if getApiId() == RX_16_IO_RESPONSE |
okini3939 | 1:e3b2027e685c | 249 | */ |
okini3939 | 1:e3b2027e685c | 250 | void getRx16IoSampleResponse(XBeeResponse &response); |
okini3939 | 1:e3b2027e685c | 251 | /** |
okini3939 | 1:e3b2027e685c | 252 | * Call with instance of Rx64IoSampleResponse only if getApiId() == RX_64_IO_RESPONSE |
okini3939 | 1:e3b2027e685c | 253 | */ |
okini3939 | 1:e3b2027e685c | 254 | void getRx64IoSampleResponse(XBeeResponse &response); |
okini3939 | 1:e3b2027e685c | 255 | #endif |
okini3939 | 1:e3b2027e685c | 256 | /** |
okini3939 | 1:e3b2027e685c | 257 | * Call with instance of AtCommandResponse only if getApiId() == AT_COMMAND_RESPONSE |
okini3939 | 1:e3b2027e685c | 258 | */ |
okini3939 | 1:e3b2027e685c | 259 | void getAtCommandResponse(XBeeResponse &responses); |
okini3939 | 1:e3b2027e685c | 260 | /** |
okini3939 | 1:e3b2027e685c | 261 | * Call with instance of RemoteAtCommandResponse only if getApiId() == REMOTE_AT_COMMAND_RESPONSE |
okini3939 | 1:e3b2027e685c | 262 | */ |
okini3939 | 1:e3b2027e685c | 263 | void getRemoteAtCommandResponse(XBeeResponse &response); |
okini3939 | 1:e3b2027e685c | 264 | /** |
okini3939 | 1:e3b2027e685c | 265 | * Call with instance of ModemStatusResponse only if getApiId() == MODEM_STATUS_RESPONSE |
okini3939 | 1:e3b2027e685c | 266 | */ |
okini3939 | 1:e3b2027e685c | 267 | void getModemStatusResponse(XBeeResponse &response); |
okini3939 | 1:e3b2027e685c | 268 | /** |
okini3939 | 1:e3b2027e685c | 269 | * Returns true if the response has been successfully parsed and is complete and ready for use |
okini3939 | 1:e3b2027e685c | 270 | */ |
okini3939 | 1:e3b2027e685c | 271 | bool isAvailable(); |
okini3939 | 1:e3b2027e685c | 272 | void setAvailable(bool complete); |
okini3939 | 1:e3b2027e685c | 273 | /** |
okini3939 | 1:e3b2027e685c | 274 | * Returns true if the response contains errors |
okini3939 | 1:e3b2027e685c | 275 | */ |
okini3939 | 1:e3b2027e685c | 276 | bool isError(); |
okini3939 | 1:e3b2027e685c | 277 | /** |
okini3939 | 1:e3b2027e685c | 278 | * Returns an error code, or zero, if successful. |
okini3939 | 1:e3b2027e685c | 279 | * Error codes include: CHECKSUM_FAILURE, PACKET_EXCEEDS_BYTE_ARRAY_LENGTH, UNEXPECTED_START_BYTE |
okini3939 | 1:e3b2027e685c | 280 | */ |
okini3939 | 1:e3b2027e685c | 281 | uint8_t getErrorCode(); |
okini3939 | 1:e3b2027e685c | 282 | void setErrorCode(uint8_t errorCode); |
okini3939 | 1:e3b2027e685c | 283 | protected: |
okini3939 | 1:e3b2027e685c | 284 | // pointer to frameData |
okini3939 | 1:e3b2027e685c | 285 | uint8_t* _frameDataPtr; |
okini3939 | 1:e3b2027e685c | 286 | private: |
okini3939 | 1:e3b2027e685c | 287 | void setCommon(XBeeResponse &target); |
okini3939 | 1:e3b2027e685c | 288 | uint8_t _apiId; |
okini3939 | 1:e3b2027e685c | 289 | uint8_t _msbLength; |
okini3939 | 1:e3b2027e685c | 290 | uint8_t _lsbLength; |
okini3939 | 1:e3b2027e685c | 291 | uint8_t _checksum; |
okini3939 | 4:f6d73acc1f75 | 292 | uint16_t _frameLength; |
okini3939 | 1:e3b2027e685c | 293 | bool _complete; |
okini3939 | 1:e3b2027e685c | 294 | uint8_t _errorCode; |
okini3939 | 1:e3b2027e685c | 295 | }; |
okini3939 | 1:e3b2027e685c | 296 | |
okini3939 | 1:e3b2027e685c | 297 | class XBeeAddress { |
okini3939 | 1:e3b2027e685c | 298 | public: |
okini3939 | 1:e3b2027e685c | 299 | XBeeAddress(); |
okini3939 | 1:e3b2027e685c | 300 | }; |
okini3939 | 1:e3b2027e685c | 301 | |
okini3939 | 1:e3b2027e685c | 302 | /** |
okini3939 | 1:e3b2027e685c | 303 | * Represents a 64-bit XBee Address |
okini3939 | 1:e3b2027e685c | 304 | */ |
okini3939 | 1:e3b2027e685c | 305 | class XBeeAddress64 : public XBeeAddress { |
okini3939 | 1:e3b2027e685c | 306 | public: |
okini3939 | 1:e3b2027e685c | 307 | XBeeAddress64(uint32_t msb, uint32_t lsb); |
okini3939 | 1:e3b2027e685c | 308 | XBeeAddress64(); |
okini3939 | 1:e3b2027e685c | 309 | uint32_t getMsb(); |
okini3939 | 1:e3b2027e685c | 310 | uint32_t getLsb(); |
okini3939 | 1:e3b2027e685c | 311 | void setMsb(uint32_t msb); |
okini3939 | 1:e3b2027e685c | 312 | void setLsb(uint32_t lsb); |
okini3939 | 1:e3b2027e685c | 313 | private: |
okini3939 | 1:e3b2027e685c | 314 | uint32_t _msb; |
okini3939 | 1:e3b2027e685c | 315 | uint32_t _lsb; |
okini3939 | 1:e3b2027e685c | 316 | }; |
okini3939 | 1:e3b2027e685c | 317 | |
okini3939 | 1:e3b2027e685c | 318 | //class XBeeAddress16 : public XBeeAddress { |
okini3939 | 1:e3b2027e685c | 319 | //public: |
okini3939 | 1:e3b2027e685c | 320 | // XBeeAddress16(uint16_t addr); |
okini3939 | 1:e3b2027e685c | 321 | // XBeeAddress16(); |
okini3939 | 1:e3b2027e685c | 322 | // uint16_t getAddress(); |
okini3939 | 1:e3b2027e685c | 323 | // void setAddress(uint16_t addr); |
okini3939 | 1:e3b2027e685c | 324 | //private: |
okini3939 | 1:e3b2027e685c | 325 | // uint16_t _addr; |
okini3939 | 1:e3b2027e685c | 326 | //}; |
okini3939 | 1:e3b2027e685c | 327 | |
okini3939 | 1:e3b2027e685c | 328 | /** |
okini3939 | 1:e3b2027e685c | 329 | * This class is extended by all Responses that include a frame id |
okini3939 | 1:e3b2027e685c | 330 | */ |
okini3939 | 1:e3b2027e685c | 331 | class FrameIdResponse : public XBeeResponse { |
okini3939 | 1:e3b2027e685c | 332 | public: |
okini3939 | 1:e3b2027e685c | 333 | FrameIdResponse(); |
okini3939 | 1:e3b2027e685c | 334 | uint8_t getFrameId(); |
okini3939 | 1:e3b2027e685c | 335 | private: |
okini3939 | 1:e3b2027e685c | 336 | uint8_t _frameId; |
okini3939 | 1:e3b2027e685c | 337 | }; |
okini3939 | 1:e3b2027e685c | 338 | |
okini3939 | 1:e3b2027e685c | 339 | /** |
okini3939 | 1:e3b2027e685c | 340 | * Common functionality for both Series 1 and 2 data RX data packets |
okini3939 | 1:e3b2027e685c | 341 | */ |
okini3939 | 1:e3b2027e685c | 342 | class RxDataResponse : public XBeeResponse { |
okini3939 | 1:e3b2027e685c | 343 | public: |
okini3939 | 1:e3b2027e685c | 344 | RxDataResponse(); |
okini3939 | 1:e3b2027e685c | 345 | /** |
okini3939 | 1:e3b2027e685c | 346 | * Returns the specified index of the payload. The index may be 0 to getDataLength() - 1 |
okini3939 | 1:e3b2027e685c | 347 | * This method is deprecated; use uint8_t* getData() |
okini3939 | 1:e3b2027e685c | 348 | */ |
okini3939 | 1:e3b2027e685c | 349 | uint8_t getData(int index); |
okini3939 | 1:e3b2027e685c | 350 | /** |
okini3939 | 1:e3b2027e685c | 351 | * Returns the payload array. This may be accessed from index 0 to getDataLength() - 1 |
okini3939 | 1:e3b2027e685c | 352 | */ |
okini3939 | 1:e3b2027e685c | 353 | uint8_t* getData(); |
okini3939 | 1:e3b2027e685c | 354 | /** |
okini3939 | 1:e3b2027e685c | 355 | * Returns the length of the payload |
okini3939 | 1:e3b2027e685c | 356 | */ |
okini3939 | 4:f6d73acc1f75 | 357 | virtual uint16_t getDataLength() = 0; |
okini3939 | 1:e3b2027e685c | 358 | /** |
okini3939 | 1:e3b2027e685c | 359 | * Returns the position in the frame data where the data begins |
okini3939 | 1:e3b2027e685c | 360 | */ |
okini3939 | 1:e3b2027e685c | 361 | virtual uint8_t getDataOffset() = 0; |
okini3939 | 1:e3b2027e685c | 362 | }; |
okini3939 | 1:e3b2027e685c | 363 | |
okini3939 | 1:e3b2027e685c | 364 | // getResponse to return the proper subclass: |
okini3939 | 1:e3b2027e685c | 365 | // we maintain a pointer to each type of response, when a response is parsed, it is allocated only if NULL |
okini3939 | 1:e3b2027e685c | 366 | // can we allocate an object in a function? |
okini3939 | 1:e3b2027e685c | 367 | |
okini3939 | 1:e3b2027e685c | 368 | #ifdef SERIES_2 |
okini3939 | 1:e3b2027e685c | 369 | /** |
okini3939 | 1:e3b2027e685c | 370 | * Represents a Series 2 TX status packet |
okini3939 | 1:e3b2027e685c | 371 | */ |
okini3939 | 1:e3b2027e685c | 372 | class ZBTxStatusResponse : public FrameIdResponse { |
okini3939 | 1:e3b2027e685c | 373 | public: |
okini3939 | 1:e3b2027e685c | 374 | ZBTxStatusResponse(); |
okini3939 | 1:e3b2027e685c | 375 | uint16_t getRemoteAddress(); |
okini3939 | 1:e3b2027e685c | 376 | uint8_t getTxRetryCount(); |
okini3939 | 1:e3b2027e685c | 377 | uint8_t getDeliveryStatus(); |
okini3939 | 1:e3b2027e685c | 378 | uint8_t getDiscoveryStatus(); |
okini3939 | 1:e3b2027e685c | 379 | bool isSuccess(); |
okini3939 | 1:e3b2027e685c | 380 | }; |
okini3939 | 1:e3b2027e685c | 381 | |
okini3939 | 1:e3b2027e685c | 382 | /** |
okini3939 | 1:e3b2027e685c | 383 | * Represents a Series 2 RX packet |
okini3939 | 1:e3b2027e685c | 384 | */ |
okini3939 | 1:e3b2027e685c | 385 | class ZBRxResponse : public RxDataResponse { |
okini3939 | 1:e3b2027e685c | 386 | public: |
okini3939 | 1:e3b2027e685c | 387 | ZBRxResponse(); |
okini3939 | 1:e3b2027e685c | 388 | XBeeAddress64& getRemoteAddress64(); |
okini3939 | 1:e3b2027e685c | 389 | uint16_t getRemoteAddress16(); |
okini3939 | 1:e3b2027e685c | 390 | uint8_t getOption(); |
okini3939 | 4:f6d73acc1f75 | 391 | virtual uint16_t getDataLength(); |
okini3939 | 1:e3b2027e685c | 392 | // frame position where data starts |
okini3939 | 1:e3b2027e685c | 393 | virtual uint8_t getDataOffset(); |
okini3939 | 1:e3b2027e685c | 394 | private: |
okini3939 | 1:e3b2027e685c | 395 | XBeeAddress64 _remoteAddress64; |
okini3939 | 1:e3b2027e685c | 396 | }; |
okini3939 | 1:e3b2027e685c | 397 | |
okini3939 | 1:e3b2027e685c | 398 | /** |
okini3939 | 1:e3b2027e685c | 399 | * Represents a Series 2 RX I/O Sample packet |
okini3939 | 1:e3b2027e685c | 400 | */ |
okini3939 | 1:e3b2027e685c | 401 | class ZBRxIoSampleResponse : public ZBRxResponse { |
okini3939 | 1:e3b2027e685c | 402 | public: |
okini3939 | 1:e3b2027e685c | 403 | ZBRxIoSampleResponse(); |
okini3939 | 1:e3b2027e685c | 404 | bool containsAnalog(); |
okini3939 | 1:e3b2027e685c | 405 | bool containsDigital(); |
okini3939 | 1:e3b2027e685c | 406 | /** |
okini3939 | 1:e3b2027e685c | 407 | * Returns true if the pin is enabled |
okini3939 | 1:e3b2027e685c | 408 | */ |
okini3939 | 1:e3b2027e685c | 409 | bool isAnalogEnabled(uint8_t pin); |
okini3939 | 1:e3b2027e685c | 410 | /** |
okini3939 | 1:e3b2027e685c | 411 | * Returns true if the pin is enabled |
okini3939 | 1:e3b2027e685c | 412 | */ |
okini3939 | 1:e3b2027e685c | 413 | bool isDigitalEnabled(uint8_t pin); |
okini3939 | 1:e3b2027e685c | 414 | /** |
okini3939 | 1:e3b2027e685c | 415 | * Returns the 10-bit analog reading of the specified pin. |
okini3939 | 1:e3b2027e685c | 416 | * Valid pins include ADC:xxx. |
okini3939 | 1:e3b2027e685c | 417 | */ |
okini3939 | 1:e3b2027e685c | 418 | uint16_t getAnalog(uint8_t pin); |
okini3939 | 1:e3b2027e685c | 419 | /** |
okini3939 | 1:e3b2027e685c | 420 | * Returns true if the specified pin is high/on. |
okini3939 | 1:e3b2027e685c | 421 | * Valid pins include DIO:xxx. |
okini3939 | 1:e3b2027e685c | 422 | */ |
okini3939 | 1:e3b2027e685c | 423 | bool isDigitalOn(uint8_t pin); |
okini3939 | 1:e3b2027e685c | 424 | uint8_t getDigitalMaskMsb(); |
okini3939 | 1:e3b2027e685c | 425 | uint8_t getDigitalMaskLsb(); |
okini3939 | 1:e3b2027e685c | 426 | uint8_t getAnalogMask(); |
okini3939 | 1:e3b2027e685c | 427 | }; |
okini3939 | 1:e3b2027e685c | 428 | |
okini3939 | 1:e3b2027e685c | 429 | #endif |
okini3939 | 1:e3b2027e685c | 430 | |
okini3939 | 1:e3b2027e685c | 431 | #ifdef SERIES_1 |
okini3939 | 1:e3b2027e685c | 432 | /** |
okini3939 | 1:e3b2027e685c | 433 | * Represents a Series 1 TX Status packet |
okini3939 | 1:e3b2027e685c | 434 | */ |
okini3939 | 1:e3b2027e685c | 435 | class TxStatusResponse : public FrameIdResponse { |
okini3939 | 1:e3b2027e685c | 436 | public: |
okini3939 | 1:e3b2027e685c | 437 | TxStatusResponse(); |
okini3939 | 1:e3b2027e685c | 438 | uint8_t getStatus(); |
okini3939 | 1:e3b2027e685c | 439 | bool isSuccess(); |
okini3939 | 1:e3b2027e685c | 440 | }; |
okini3939 | 1:e3b2027e685c | 441 | |
okini3939 | 1:e3b2027e685c | 442 | /** |
okini3939 | 1:e3b2027e685c | 443 | * Represents a Series 1 RX packet |
okini3939 | 1:e3b2027e685c | 444 | */ |
okini3939 | 1:e3b2027e685c | 445 | class RxResponse : public RxDataResponse { |
okini3939 | 1:e3b2027e685c | 446 | public: |
okini3939 | 1:e3b2027e685c | 447 | RxResponse(); |
okini3939 | 1:e3b2027e685c | 448 | // remember rssi is negative but this is unsigned byte so it's up to you to convert |
okini3939 | 1:e3b2027e685c | 449 | uint8_t getRssi(); |
okini3939 | 1:e3b2027e685c | 450 | uint8_t getOption(); |
okini3939 | 1:e3b2027e685c | 451 | bool isAddressBroadcast(); |
okini3939 | 1:e3b2027e685c | 452 | bool isPanBroadcast(); |
okini3939 | 4:f6d73acc1f75 | 453 | virtual uint16_t getDataLength(); |
okini3939 | 1:e3b2027e685c | 454 | virtual uint8_t getDataOffset(); |
okini3939 | 1:e3b2027e685c | 455 | virtual uint8_t getRssiOffset() = 0; |
okini3939 | 1:e3b2027e685c | 456 | }; |
okini3939 | 1:e3b2027e685c | 457 | |
okini3939 | 1:e3b2027e685c | 458 | /** |
okini3939 | 1:e3b2027e685c | 459 | * Represents a Series 1 16-bit address RX packet |
okini3939 | 1:e3b2027e685c | 460 | */ |
okini3939 | 1:e3b2027e685c | 461 | class Rx16Response : public RxResponse { |
okini3939 | 1:e3b2027e685c | 462 | public: |
okini3939 | 1:e3b2027e685c | 463 | Rx16Response(); |
okini3939 | 1:e3b2027e685c | 464 | virtual uint8_t getRssiOffset(); |
okini3939 | 1:e3b2027e685c | 465 | uint16_t getRemoteAddress16(); |
okini3939 | 1:e3b2027e685c | 466 | protected: |
okini3939 | 1:e3b2027e685c | 467 | uint16_t _remoteAddress; |
okini3939 | 1:e3b2027e685c | 468 | }; |
okini3939 | 1:e3b2027e685c | 469 | |
okini3939 | 1:e3b2027e685c | 470 | /** |
okini3939 | 1:e3b2027e685c | 471 | * Represents a Series 1 64-bit address RX packet |
okini3939 | 1:e3b2027e685c | 472 | */ |
okini3939 | 1:e3b2027e685c | 473 | class Rx64Response : public RxResponse { |
okini3939 | 1:e3b2027e685c | 474 | public: |
okini3939 | 1:e3b2027e685c | 475 | Rx64Response(); |
okini3939 | 1:e3b2027e685c | 476 | virtual uint8_t getRssiOffset(); |
okini3939 | 1:e3b2027e685c | 477 | XBeeAddress64& getRemoteAddress64(); |
okini3939 | 1:e3b2027e685c | 478 | private: |
okini3939 | 1:e3b2027e685c | 479 | XBeeAddress64 _remoteAddress; |
okini3939 | 1:e3b2027e685c | 480 | }; |
okini3939 | 1:e3b2027e685c | 481 | |
okini3939 | 1:e3b2027e685c | 482 | /** |
okini3939 | 1:e3b2027e685c | 483 | * Represents a Series 1 RX I/O Sample packet |
okini3939 | 1:e3b2027e685c | 484 | */ |
okini3939 | 1:e3b2027e685c | 485 | class RxIoSampleBaseResponse : public RxResponse { |
okini3939 | 1:e3b2027e685c | 486 | public: |
okini3939 | 1:e3b2027e685c | 487 | RxIoSampleBaseResponse(); |
okini3939 | 1:e3b2027e685c | 488 | /** |
okini3939 | 1:e3b2027e685c | 489 | * Returns the number of samples in this packet |
okini3939 | 1:e3b2027e685c | 490 | */ |
okini3939 | 1:e3b2027e685c | 491 | uint8_t getSampleSize(); |
okini3939 | 1:e3b2027e685c | 492 | bool containsAnalog(); |
okini3939 | 1:e3b2027e685c | 493 | bool containsDigital(); |
okini3939 | 1:e3b2027e685c | 494 | /** |
okini3939 | 1:e3b2027e685c | 495 | * Returns true if the specified analog pin is enabled |
okini3939 | 1:e3b2027e685c | 496 | */ |
okini3939 | 1:e3b2027e685c | 497 | bool isAnalogEnabled(uint8_t pin); |
okini3939 | 1:e3b2027e685c | 498 | /** |
okini3939 | 1:e3b2027e685c | 499 | * Returns true if the specified digital pin is enabled |
okini3939 | 1:e3b2027e685c | 500 | */ |
okini3939 | 1:e3b2027e685c | 501 | bool isDigitalEnabled(uint8_t pin); |
okini3939 | 1:e3b2027e685c | 502 | /** |
okini3939 | 1:e3b2027e685c | 503 | * Returns the 10-bit analog reading of the specified pin. |
okini3939 | 1:e3b2027e685c | 504 | * Valid pins include ADC:0-5. Sample index starts at 0 |
okini3939 | 1:e3b2027e685c | 505 | */ |
okini3939 | 1:e3b2027e685c | 506 | uint16_t getAnalog(uint8_t pin, uint8_t sample); |
okini3939 | 1:e3b2027e685c | 507 | /** |
okini3939 | 1:e3b2027e685c | 508 | * Returns true if the specified pin is high/on. |
okini3939 | 1:e3b2027e685c | 509 | * Valid pins include DIO:0-8. Sample index starts at 0 |
okini3939 | 1:e3b2027e685c | 510 | */ |
okini3939 | 1:e3b2027e685c | 511 | bool isDigitalOn(uint8_t pin, uint8_t sample); |
okini3939 | 1:e3b2027e685c | 512 | uint8_t getSampleOffset(); |
okini3939 | 1:e3b2027e685c | 513 | private: |
okini3939 | 1:e3b2027e685c | 514 | }; |
okini3939 | 1:e3b2027e685c | 515 | |
okini3939 | 1:e3b2027e685c | 516 | class Rx16IoSampleResponse : public RxIoSampleBaseResponse { |
okini3939 | 1:e3b2027e685c | 517 | public: |
okini3939 | 1:e3b2027e685c | 518 | Rx16IoSampleResponse(); |
okini3939 | 1:e3b2027e685c | 519 | uint16_t getRemoteAddress16(); |
okini3939 | 1:e3b2027e685c | 520 | virtual uint8_t getRssiOffset(); |
okini3939 | 1:e3b2027e685c | 521 | |
okini3939 | 1:e3b2027e685c | 522 | }; |
okini3939 | 1:e3b2027e685c | 523 | |
okini3939 | 1:e3b2027e685c | 524 | class Rx64IoSampleResponse : public RxIoSampleBaseResponse { |
okini3939 | 1:e3b2027e685c | 525 | public: |
okini3939 | 1:e3b2027e685c | 526 | Rx64IoSampleResponse(); |
okini3939 | 1:e3b2027e685c | 527 | XBeeAddress64& getRemoteAddress64(); |
okini3939 | 1:e3b2027e685c | 528 | virtual uint8_t getRssiOffset(); |
okini3939 | 1:e3b2027e685c | 529 | private: |
okini3939 | 1:e3b2027e685c | 530 | XBeeAddress64 _remoteAddress; |
okini3939 | 1:e3b2027e685c | 531 | }; |
okini3939 | 1:e3b2027e685c | 532 | |
okini3939 | 1:e3b2027e685c | 533 | #endif |
okini3939 | 1:e3b2027e685c | 534 | |
okini3939 | 1:e3b2027e685c | 535 | /** |
okini3939 | 1:e3b2027e685c | 536 | * Represents a Modem Status RX packet |
okini3939 | 1:e3b2027e685c | 537 | */ |
okini3939 | 1:e3b2027e685c | 538 | class ModemStatusResponse : public XBeeResponse { |
okini3939 | 1:e3b2027e685c | 539 | public: |
okini3939 | 1:e3b2027e685c | 540 | ModemStatusResponse(); |
okini3939 | 1:e3b2027e685c | 541 | uint8_t getStatus(); |
okini3939 | 1:e3b2027e685c | 542 | }; |
okini3939 | 1:e3b2027e685c | 543 | |
okini3939 | 1:e3b2027e685c | 544 | /** |
okini3939 | 1:e3b2027e685c | 545 | * Represents an AT Command RX packet |
okini3939 | 1:e3b2027e685c | 546 | */ |
okini3939 | 1:e3b2027e685c | 547 | class AtCommandResponse : public FrameIdResponse { |
okini3939 | 1:e3b2027e685c | 548 | public: |
okini3939 | 1:e3b2027e685c | 549 | AtCommandResponse(); |
okini3939 | 1:e3b2027e685c | 550 | /** |
okini3939 | 1:e3b2027e685c | 551 | * Returns an array containing the two character command |
okini3939 | 1:e3b2027e685c | 552 | */ |
okini3939 | 1:e3b2027e685c | 553 | uint8_t* getCommand(); |
okini3939 | 1:e3b2027e685c | 554 | /** |
okini3939 | 1:e3b2027e685c | 555 | * Returns the command status code. |
okini3939 | 1:e3b2027e685c | 556 | * Zero represents a successful command |
okini3939 | 1:e3b2027e685c | 557 | */ |
okini3939 | 1:e3b2027e685c | 558 | uint8_t getStatus(); |
okini3939 | 1:e3b2027e685c | 559 | /** |
okini3939 | 1:e3b2027e685c | 560 | * Returns an array containing the command value. |
okini3939 | 1:e3b2027e685c | 561 | * This is only applicable to query commands. |
okini3939 | 1:e3b2027e685c | 562 | */ |
okini3939 | 1:e3b2027e685c | 563 | uint8_t* getValue(); |
okini3939 | 1:e3b2027e685c | 564 | /** |
okini3939 | 1:e3b2027e685c | 565 | * Returns the length of the command value array. |
okini3939 | 1:e3b2027e685c | 566 | */ |
okini3939 | 4:f6d73acc1f75 | 567 | uint16_t getValueLength(); |
okini3939 | 1:e3b2027e685c | 568 | /** |
okini3939 | 1:e3b2027e685c | 569 | * Returns true if status equals AT_OK |
okini3939 | 1:e3b2027e685c | 570 | */ |
okini3939 | 1:e3b2027e685c | 571 | bool isOk(); |
okini3939 | 1:e3b2027e685c | 572 | }; |
okini3939 | 1:e3b2027e685c | 573 | |
okini3939 | 1:e3b2027e685c | 574 | /** |
okini3939 | 1:e3b2027e685c | 575 | * Represents a Remote AT Command RX packet |
okini3939 | 1:e3b2027e685c | 576 | */ |
okini3939 | 1:e3b2027e685c | 577 | class RemoteAtCommandResponse : public AtCommandResponse { |
okini3939 | 1:e3b2027e685c | 578 | public: |
okini3939 | 1:e3b2027e685c | 579 | RemoteAtCommandResponse(); |
okini3939 | 1:e3b2027e685c | 580 | /** |
okini3939 | 1:e3b2027e685c | 581 | * Returns an array containing the two character command |
okini3939 | 1:e3b2027e685c | 582 | */ |
okini3939 | 1:e3b2027e685c | 583 | uint8_t* getCommand(); |
okini3939 | 1:e3b2027e685c | 584 | /** |
okini3939 | 1:e3b2027e685c | 585 | * Returns the command status code. |
okini3939 | 1:e3b2027e685c | 586 | * Zero represents a successful command |
okini3939 | 1:e3b2027e685c | 587 | */ |
okini3939 | 1:e3b2027e685c | 588 | uint8_t getStatus(); |
okini3939 | 1:e3b2027e685c | 589 | /** |
okini3939 | 1:e3b2027e685c | 590 | * Returns an array containing the command value. |
okini3939 | 1:e3b2027e685c | 591 | * This is only applicable to query commands. |
okini3939 | 1:e3b2027e685c | 592 | */ |
okini3939 | 1:e3b2027e685c | 593 | uint8_t* getValue(); |
okini3939 | 1:e3b2027e685c | 594 | /** |
okini3939 | 1:e3b2027e685c | 595 | * Returns the length of the command value array. |
okini3939 | 1:e3b2027e685c | 596 | */ |
okini3939 | 4:f6d73acc1f75 | 597 | uint16_t getValueLength(); |
okini3939 | 1:e3b2027e685c | 598 | /** |
okini3939 | 1:e3b2027e685c | 599 | * Returns the 16-bit address of the remote radio |
okini3939 | 1:e3b2027e685c | 600 | */ |
okini3939 | 1:e3b2027e685c | 601 | uint16_t getRemoteAddress16(); |
okini3939 | 1:e3b2027e685c | 602 | /** |
okini3939 | 1:e3b2027e685c | 603 | * Returns the 64-bit address of the remote radio |
okini3939 | 1:e3b2027e685c | 604 | */ |
okini3939 | 1:e3b2027e685c | 605 | XBeeAddress64& getRemoteAddress64(); |
okini3939 | 1:e3b2027e685c | 606 | /** |
okini3939 | 1:e3b2027e685c | 607 | * Returns true if command was successful |
okini3939 | 1:e3b2027e685c | 608 | */ |
okini3939 | 1:e3b2027e685c | 609 | bool isOk(); |
okini3939 | 1:e3b2027e685c | 610 | private: |
okini3939 | 1:e3b2027e685c | 611 | XBeeAddress64 _remoteAddress64; |
okini3939 | 1:e3b2027e685c | 612 | }; |
okini3939 | 1:e3b2027e685c | 613 | |
okini3939 | 1:e3b2027e685c | 614 | |
okini3939 | 1:e3b2027e685c | 615 | /** |
okini3939 | 1:e3b2027e685c | 616 | * Super class of all XBee requests (TX packets) |
okini3939 | 1:e3b2027e685c | 617 | * Users should never create an instance of this class; instead use an subclass of this class |
okini3939 | 1:e3b2027e685c | 618 | * It is recommended to reuse Subclasses of the class to conserve memory |
okini3939 | 1:e3b2027e685c | 619 | * <p/> |
okini3939 | 1:e3b2027e685c | 620 | * This class allocates a buffer to |
okini3939 | 1:e3b2027e685c | 621 | */ |
okini3939 | 1:e3b2027e685c | 622 | class XBeeRequest { |
okini3939 | 1:e3b2027e685c | 623 | public: |
okini3939 | 1:e3b2027e685c | 624 | /** |
okini3939 | 1:e3b2027e685c | 625 | * Constructor |
okini3939 | 1:e3b2027e685c | 626 | * TODO make protected |
okini3939 | 1:e3b2027e685c | 627 | */ |
okini3939 | 1:e3b2027e685c | 628 | XBeeRequest(uint8_t apiId, uint8_t frameId); |
okini3939 | 1:e3b2027e685c | 629 | /** |
okini3939 | 1:e3b2027e685c | 630 | * Sets the frame id. Must be between 1 and 255 inclusive to get a TX status response. |
okini3939 | 1:e3b2027e685c | 631 | */ |
okini3939 | 1:e3b2027e685c | 632 | void setFrameId(uint8_t frameId); |
okini3939 | 1:e3b2027e685c | 633 | /** |
okini3939 | 1:e3b2027e685c | 634 | * Returns the frame id |
okini3939 | 1:e3b2027e685c | 635 | */ |
okini3939 | 1:e3b2027e685c | 636 | uint8_t getFrameId(); |
okini3939 | 1:e3b2027e685c | 637 | /** |
okini3939 | 1:e3b2027e685c | 638 | * Returns the API id |
okini3939 | 1:e3b2027e685c | 639 | */ |
okini3939 | 1:e3b2027e685c | 640 | uint8_t getApiId(); |
okini3939 | 1:e3b2027e685c | 641 | // setting = 0 makes this a pure virtual function, meaning the subclass must implement, like abstract in java |
okini3939 | 1:e3b2027e685c | 642 | /** |
okini3939 | 1:e3b2027e685c | 643 | * Starting after the frame id (pos = 0) and up to but not including the checksum |
okini3939 | 1:e3b2027e685c | 644 | * Note: Unlike Digi's definition of the frame data, this does not start with the API ID. |
okini3939 | 1:e3b2027e685c | 645 | * The reason for this is the API ID and Frame ID are common to all requests, whereas my definition of |
okini3939 | 1:e3b2027e685c | 646 | * frame data is only the API specific data. |
okini3939 | 1:e3b2027e685c | 647 | */ |
okini3939 | 4:f6d73acc1f75 | 648 | virtual uint8_t getFrameData(uint16_t pos) = 0; |
okini3939 | 1:e3b2027e685c | 649 | /** |
okini3939 | 1:e3b2027e685c | 650 | * Returns the size of the api frame (not including frame id or api id or checksum). |
okini3939 | 1:e3b2027e685c | 651 | */ |
okini3939 | 4:f6d73acc1f75 | 652 | virtual uint16_t getFrameDataLength() = 0; |
okini3939 | 1:e3b2027e685c | 653 | //void reset(); |
okini3939 | 1:e3b2027e685c | 654 | protected: |
okini3939 | 1:e3b2027e685c | 655 | void setApiId(uint8_t apiId); |
okini3939 | 1:e3b2027e685c | 656 | private: |
okini3939 | 1:e3b2027e685c | 657 | uint8_t _apiId; |
okini3939 | 1:e3b2027e685c | 658 | uint8_t _frameId; |
okini3939 | 1:e3b2027e685c | 659 | }; |
okini3939 | 1:e3b2027e685c | 660 | |
okini3939 | 1:e3b2027e685c | 661 | // TODO add reset/clear method since responses are often reused |
okini3939 | 1:e3b2027e685c | 662 | /** |
okini3939 | 1:e3b2027e685c | 663 | * Primary interface for communicating with an XBee Radio. |
okini3939 | 1:e3b2027e685c | 664 | * This class provides methods for sending and receiving packets with an XBee radio via the serial port. |
okini3939 | 1:e3b2027e685c | 665 | * The XBee radio must be configured in API (packet) mode (AP=2) |
okini3939 | 1:e3b2027e685c | 666 | * in order to use this software. |
okini3939 | 1:e3b2027e685c | 667 | * <p/> |
okini3939 | 1:e3b2027e685c | 668 | * Since this code is designed to run on a microcontroller, with only one thread, you are responsible for reading the |
okini3939 | 1:e3b2027e685c | 669 | * data off the serial buffer in a timely manner. This involves a call to a variant of readPacket(...). |
okini3939 | 1:e3b2027e685c | 670 | * If your serial port is receiving data faster than you are reading, you can expect to lose packets. |
okini3939 | 1:e3b2027e685c | 671 | * Arduino only has a 128 byte serial buffer so it can easily overflow if two or more packets arrive |
okini3939 | 1:e3b2027e685c | 672 | * without a call to readPacket(...) |
okini3939 | 1:e3b2027e685c | 673 | * <p/> |
okini3939 | 1:e3b2027e685c | 674 | * In order to conserve resources, this class only supports storing one response packet in memory at a time. |
okini3939 | 1:e3b2027e685c | 675 | * This means that you must fully consume the packet prior to calling readPacket(...), because calling |
okini3939 | 1:e3b2027e685c | 676 | * readPacket(...) overwrites the previous response. |
okini3939 | 1:e3b2027e685c | 677 | * <p/> |
okini3939 | 1:e3b2027e685c | 678 | * This class creates an array of size MAX_FRAME_DATA_SIZE for storing the response packet. You may want |
okini3939 | 1:e3b2027e685c | 679 | * to adjust this value to conserve memory. |
okini3939 | 1:e3b2027e685c | 680 | * |
okini3939 | 1:e3b2027e685c | 681 | * \author Andrew Rapp |
okini3939 | 1:e3b2027e685c | 682 | */ |
okini3939 | 1:e3b2027e685c | 683 | class XBee { |
okini3939 | 1:e3b2027e685c | 684 | public: |
okini3939 | 1:e3b2027e685c | 685 | XBee(PinName p_tx, PinName p_rx); |
okini3939 | 4:f6d73acc1f75 | 686 | XBee(PinName p_tx, PinName p_rx, PinName p_cts, PinName p_rts); |
okini3939 | 1:e3b2027e685c | 687 | // for eclipse dev only |
okini3939 | 1:e3b2027e685c | 688 | // void setSerial(HardwareSerial serial); |
okini3939 | 1:e3b2027e685c | 689 | /** |
okini3939 | 1:e3b2027e685c | 690 | * Reads all available serial bytes until a packet is parsed, an error occurs, or the buffer is empty. |
okini3939 | 1:e3b2027e685c | 691 | * You may call <i>xbee</i>.getResponse().isAvailable() after calling this method to determine if |
okini3939 | 1:e3b2027e685c | 692 | * a packet is ready, or <i>xbee</i>.getResponse().isError() to determine if |
okini3939 | 1:e3b2027e685c | 693 | * a error occurred. |
okini3939 | 1:e3b2027e685c | 694 | * <p/> |
okini3939 | 1:e3b2027e685c | 695 | * This method should always return quickly since it does not wait for serial data to arrive. |
okini3939 | 1:e3b2027e685c | 696 | * You will want to use this method if you are doing other timely stuff in your loop, where |
okini3939 | 1:e3b2027e685c | 697 | * a delay would cause problems. |
okini3939 | 1:e3b2027e685c | 698 | * NOTE: calling this method resets the current response, so make sure you first consume the |
okini3939 | 1:e3b2027e685c | 699 | * current response |
okini3939 | 1:e3b2027e685c | 700 | */ |
okini3939 | 1:e3b2027e685c | 701 | void readPacket(); |
okini3939 | 1:e3b2027e685c | 702 | /** |
okini3939 | 1:e3b2027e685c | 703 | * Waits a maximum of <i>timeout</i> milliseconds for a response packet before timing out; returns true if packet is read. |
okini3939 | 1:e3b2027e685c | 704 | * Returns false if timeout or error occurs. |
okini3939 | 1:e3b2027e685c | 705 | */ |
okini3939 | 1:e3b2027e685c | 706 | bool readPacket(int timeout); |
okini3939 | 1:e3b2027e685c | 707 | /** |
okini3939 | 1:e3b2027e685c | 708 | * Reads until a packet is received or an error occurs. |
okini3939 | 1:e3b2027e685c | 709 | * Caution: use this carefully since if you don't get a response, your Arduino code will hang on this |
okini3939 | 1:e3b2027e685c | 710 | * call forever!! often it's better to use a timeout: readPacket(int) |
okini3939 | 1:e3b2027e685c | 711 | */ |
okini3939 | 1:e3b2027e685c | 712 | void readPacketUntilAvailable(); |
okini3939 | 1:e3b2027e685c | 713 | /** |
okini3939 | 1:e3b2027e685c | 714 | * Starts the serial connection at the supplied baud rate |
okini3939 | 1:e3b2027e685c | 715 | */ |
okini3939 | 1:e3b2027e685c | 716 | void begin(long baud); |
okini3939 | 1:e3b2027e685c | 717 | void getResponse(XBeeResponse &response); |
okini3939 | 1:e3b2027e685c | 718 | /** |
okini3939 | 1:e3b2027e685c | 719 | * Returns a reference to the current response |
okini3939 | 1:e3b2027e685c | 720 | * Note: once readPacket is called again this response will be overwritten! |
okini3939 | 1:e3b2027e685c | 721 | */ |
okini3939 | 1:e3b2027e685c | 722 | XBeeResponse& getResponse(); |
okini3939 | 1:e3b2027e685c | 723 | /** |
okini3939 | 1:e3b2027e685c | 724 | * Sends a XBeeRequest (TX packet) out the serial port |
okini3939 | 1:e3b2027e685c | 725 | */ |
okini3939 | 1:e3b2027e685c | 726 | void send(XBeeRequest &request); |
okini3939 | 1:e3b2027e685c | 727 | //uint8_t sendAndWaitForResponse(XBeeRequest &request, int timeout); |
okini3939 | 1:e3b2027e685c | 728 | /** |
okini3939 | 1:e3b2027e685c | 729 | * Returns a sequential frame id between 1 and 255 |
okini3939 | 1:e3b2027e685c | 730 | */ |
okini3939 | 1:e3b2027e685c | 731 | uint8_t getNextFrameId(); |
okini3939 | 4:f6d73acc1f75 | 732 | |
okini3939 | 4:f6d73acc1f75 | 733 | void isr_recv (); |
okini3939 | 4:f6d73acc1f75 | 734 | int getbuf (); |
okini3939 | 4:f6d73acc1f75 | 735 | int bufreadable (); |
okini3939 | 1:e3b2027e685c | 736 | private: |
okini3939 | 1:e3b2027e685c | 737 | void sendByte(uint8_t b, bool escape); |
okini3939 | 1:e3b2027e685c | 738 | void resetResponse(); |
okini3939 | 1:e3b2027e685c | 739 | XBeeResponse _response; |
okini3939 | 1:e3b2027e685c | 740 | bool _escape; |
okini3939 | 1:e3b2027e685c | 741 | // current packet position for response. just a state variable for packet parsing and has no relevance for the response otherwise |
okini3939 | 4:f6d73acc1f75 | 742 | uint16_t _pos, _epos; |
okini3939 | 1:e3b2027e685c | 743 | // last byte read |
okini3939 | 1:e3b2027e685c | 744 | uint8_t b; |
okini3939 | 4:f6d73acc1f75 | 745 | uint16_t _checksumTotal; |
okini3939 | 1:e3b2027e685c | 746 | uint8_t _nextFrameId; |
okini3939 | 1:e3b2027e685c | 747 | // buffer for incoming RX packets. holds only the api specific frame data, starting after the api id byte and prior to checksum |
okini3939 | 1:e3b2027e685c | 748 | uint8_t _responseFrameData[MAX_FRAME_DATA_SIZE]; |
okini3939 | 1:e3b2027e685c | 749 | Serial _xbee; |
okini3939 | 4:f6d73acc1f75 | 750 | char _rxbuf[MAX_RXBUF_SIZE]; |
okini3939 | 4:f6d73acc1f75 | 751 | int _rxaddr_w, _rxaddr_r; |
okini3939 | 4:f6d73acc1f75 | 752 | bool _rts; |
okini3939 | 1:e3b2027e685c | 753 | }; |
okini3939 | 1:e3b2027e685c | 754 | |
okini3939 | 1:e3b2027e685c | 755 | /** |
okini3939 | 1:e3b2027e685c | 756 | * All TX packets that support payloads extend this class |
okini3939 | 1:e3b2027e685c | 757 | */ |
okini3939 | 1:e3b2027e685c | 758 | class PayloadRequest : public XBeeRequest { |
okini3939 | 1:e3b2027e685c | 759 | public: |
okini3939 | 4:f6d73acc1f75 | 760 | PayloadRequest(uint8_t apiId, uint8_t frameId, uint8_t *payload, uint16_t payloadLength); |
okini3939 | 1:e3b2027e685c | 761 | /** |
okini3939 | 1:e3b2027e685c | 762 | * Returns the payload of the packet, if not null |
okini3939 | 1:e3b2027e685c | 763 | */ |
okini3939 | 1:e3b2027e685c | 764 | uint8_t* getPayload(); |
okini3939 | 1:e3b2027e685c | 765 | /** |
okini3939 | 1:e3b2027e685c | 766 | * Sets the payload array |
okini3939 | 1:e3b2027e685c | 767 | */ |
okini3939 | 1:e3b2027e685c | 768 | void setPayload(uint8_t* payloadPtr); |
okini3939 | 1:e3b2027e685c | 769 | /** |
okini3939 | 1:e3b2027e685c | 770 | * Returns the length of the payload array, as specified by the user. |
okini3939 | 1:e3b2027e685c | 771 | */ |
okini3939 | 4:f6d73acc1f75 | 772 | uint16_t getPayloadLength(); |
okini3939 | 1:e3b2027e685c | 773 | /** |
okini3939 | 1:e3b2027e685c | 774 | * Sets the length of the payload to include in the request. For example if the payload array |
okini3939 | 1:e3b2027e685c | 775 | * is 50 bytes and you only want the first 10 to be included in the packet, set the length to 10. |
okini3939 | 1:e3b2027e685c | 776 | * Length must be <= to the array length. |
okini3939 | 1:e3b2027e685c | 777 | */ |
okini3939 | 4:f6d73acc1f75 | 778 | void setPayloadLength(uint16_t payloadLength); |
okini3939 | 1:e3b2027e685c | 779 | private: |
okini3939 | 1:e3b2027e685c | 780 | uint8_t* _payloadPtr; |
okini3939 | 4:f6d73acc1f75 | 781 | uint16_t _payloadLength; |
okini3939 | 1:e3b2027e685c | 782 | }; |
okini3939 | 1:e3b2027e685c | 783 | |
okini3939 | 1:e3b2027e685c | 784 | #ifdef SERIES_1 |
okini3939 | 1:e3b2027e685c | 785 | |
okini3939 | 1:e3b2027e685c | 786 | /** |
okini3939 | 1:e3b2027e685c | 787 | * Represents a Series 1 TX packet that corresponds to Api Id: TX_16_REQUEST |
okini3939 | 1:e3b2027e685c | 788 | * <p/> |
okini3939 | 1:e3b2027e685c | 789 | * Be careful not to send a data array larger than the max packet size of your radio. |
okini3939 | 1:e3b2027e685c | 790 | * This class does not perform any validation of packet size and there will be no indication |
okini3939 | 1:e3b2027e685c | 791 | * if the packet is too large, other than you will not get a TX Status response. |
okini3939 | 1:e3b2027e685c | 792 | * The datasheet says 100 bytes is the maximum, although that could change in future firmware. |
okini3939 | 1:e3b2027e685c | 793 | */ |
okini3939 | 1:e3b2027e685c | 794 | class Tx16Request : public PayloadRequest { |
okini3939 | 1:e3b2027e685c | 795 | public: |
okini3939 | 4:f6d73acc1f75 | 796 | Tx16Request(uint16_t addr16, uint8_t option, uint8_t *payload, uint16_t payloadLength, uint8_t frameId); |
okini3939 | 1:e3b2027e685c | 797 | /** |
okini3939 | 1:e3b2027e685c | 798 | * Creates a Unicast Tx16Request with the ACK option and DEFAULT_FRAME_ID |
okini3939 | 1:e3b2027e685c | 799 | */ |
okini3939 | 4:f6d73acc1f75 | 800 | Tx16Request(uint16_t addr16, uint8_t *payload, uint16_t payloadLength); |
okini3939 | 1:e3b2027e685c | 801 | /** |
okini3939 | 1:e3b2027e685c | 802 | * Creates a default instance of this class. At a minimum you must specify |
okini3939 | 1:e3b2027e685c | 803 | * a payload, payload length and a destination address before sending this request. |
okini3939 | 1:e3b2027e685c | 804 | */ |
okini3939 | 1:e3b2027e685c | 805 | Tx16Request(); |
okini3939 | 1:e3b2027e685c | 806 | uint16_t getAddress16(); |
okini3939 | 1:e3b2027e685c | 807 | void setAddress16(uint16_t addr16); |
okini3939 | 1:e3b2027e685c | 808 | uint8_t getOption(); |
okini3939 | 1:e3b2027e685c | 809 | void setOption(uint8_t option); |
okini3939 | 4:f6d73acc1f75 | 810 | virtual uint8_t getFrameData(uint16_t pos); |
okini3939 | 4:f6d73acc1f75 | 811 | virtual uint16_t getFrameDataLength(); |
okini3939 | 1:e3b2027e685c | 812 | protected: |
okini3939 | 1:e3b2027e685c | 813 | private: |
okini3939 | 1:e3b2027e685c | 814 | uint16_t _addr16; |
okini3939 | 1:e3b2027e685c | 815 | uint8_t _option; |
okini3939 | 1:e3b2027e685c | 816 | }; |
okini3939 | 1:e3b2027e685c | 817 | |
okini3939 | 1:e3b2027e685c | 818 | /** |
okini3939 | 1:e3b2027e685c | 819 | * Represents a Series 1 TX packet that corresponds to Api Id: TX_64_REQUEST |
okini3939 | 1:e3b2027e685c | 820 | * |
okini3939 | 1:e3b2027e685c | 821 | * Be careful not to send a data array larger than the max packet size of your radio. |
okini3939 | 1:e3b2027e685c | 822 | * This class does not perform any validation of packet size and there will be no indication |
okini3939 | 1:e3b2027e685c | 823 | * if the packet is too large, other than you will not get a TX Status response. |
okini3939 | 1:e3b2027e685c | 824 | * The datasheet says 100 bytes is the maximum, although that could change in future firmware. |
okini3939 | 1:e3b2027e685c | 825 | */ |
okini3939 | 1:e3b2027e685c | 826 | class Tx64Request : public PayloadRequest { |
okini3939 | 1:e3b2027e685c | 827 | public: |
okini3939 | 4:f6d73acc1f75 | 828 | Tx64Request(XBeeAddress64 &addr64, uint8_t option, uint8_t *payload, uint16_t payloadLength, uint8_t frameId); |
okini3939 | 1:e3b2027e685c | 829 | /** |
okini3939 | 1:e3b2027e685c | 830 | * Creates a unicast Tx64Request with the ACK option and DEFAULT_FRAME_ID |
okini3939 | 1:e3b2027e685c | 831 | */ |
okini3939 | 4:f6d73acc1f75 | 832 | Tx64Request(XBeeAddress64 &addr64, uint8_t *payload, uint16_t payloadLength); |
okini3939 | 1:e3b2027e685c | 833 | /** |
okini3939 | 1:e3b2027e685c | 834 | * Creates a default instance of this class. At a minimum you must specify |
okini3939 | 1:e3b2027e685c | 835 | * a payload, payload length and a destination address before sending this request. |
okini3939 | 1:e3b2027e685c | 836 | */ |
okini3939 | 1:e3b2027e685c | 837 | Tx64Request(); |
okini3939 | 1:e3b2027e685c | 838 | XBeeAddress64& getAddress64(); |
okini3939 | 1:e3b2027e685c | 839 | void setAddress64(XBeeAddress64& addr64); |
okini3939 | 1:e3b2027e685c | 840 | // TODO move option to superclass |
okini3939 | 1:e3b2027e685c | 841 | uint8_t getOption(); |
okini3939 | 1:e3b2027e685c | 842 | void setOption(uint8_t option); |
okini3939 | 4:f6d73acc1f75 | 843 | virtual uint8_t getFrameData(uint16_t pos); |
okini3939 | 4:f6d73acc1f75 | 844 | virtual uint16_t getFrameDataLength(); |
okini3939 | 1:e3b2027e685c | 845 | private: |
okini3939 | 1:e3b2027e685c | 846 | XBeeAddress64 _addr64; |
okini3939 | 1:e3b2027e685c | 847 | uint8_t _option; |
okini3939 | 1:e3b2027e685c | 848 | }; |
okini3939 | 1:e3b2027e685c | 849 | |
okini3939 | 1:e3b2027e685c | 850 | #endif |
okini3939 | 1:e3b2027e685c | 851 | |
okini3939 | 1:e3b2027e685c | 852 | |
okini3939 | 1:e3b2027e685c | 853 | #ifdef SERIES_2 |
okini3939 | 1:e3b2027e685c | 854 | |
okini3939 | 1:e3b2027e685c | 855 | /** |
okini3939 | 1:e3b2027e685c | 856 | * Represents a Series 2 TX packet that corresponds to Api Id: ZB_TX_REQUEST |
okini3939 | 1:e3b2027e685c | 857 | * |
okini3939 | 1:e3b2027e685c | 858 | * Be careful not to send a data array larger than the max packet size of your radio. |
okini3939 | 1:e3b2027e685c | 859 | * This class does not perform any validation of packet size and there will be no indication |
okini3939 | 1:e3b2027e685c | 860 | * if the packet is too large, other than you will not get a TX Status response. |
okini3939 | 1:e3b2027e685c | 861 | * The datasheet says 72 bytes is the maximum for ZNet firmware and ZB Pro firmware provides |
okini3939 | 1:e3b2027e685c | 862 | * the ATNP command to get the max supported payload size. This command is useful since the |
okini3939 | 1:e3b2027e685c | 863 | * maximum payload size varies according to certain settings, such as encryption. |
okini3939 | 1:e3b2027e685c | 864 | * ZB Pro firmware provides a PAYLOAD_TOO_LARGE that is returned if payload size |
okini3939 | 1:e3b2027e685c | 865 | * exceeds the maximum. |
okini3939 | 1:e3b2027e685c | 866 | */ |
okini3939 | 1:e3b2027e685c | 867 | class ZBTxRequest : public PayloadRequest { |
okini3939 | 1:e3b2027e685c | 868 | public: |
okini3939 | 1:e3b2027e685c | 869 | /** |
okini3939 | 1:e3b2027e685c | 870 | * Creates a unicast ZBTxRequest with the ACK option and DEFAULT_FRAME_ID |
okini3939 | 1:e3b2027e685c | 871 | */ |
okini3939 | 4:f6d73acc1f75 | 872 | ZBTxRequest(XBeeAddress64 &addr64, uint8_t *payload, uint16_t payloadLength); |
okini3939 | 4:f6d73acc1f75 | 873 | ZBTxRequest(XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *payload, uint16_t payloadLength, uint8_t frameId); |
okini3939 | 1:e3b2027e685c | 874 | /** |
okini3939 | 1:e3b2027e685c | 875 | * Creates a default instance of this class. At a minimum you must specify |
okini3939 | 1:e3b2027e685c | 876 | * a payload, payload length and a destination address before sending this request. |
okini3939 | 1:e3b2027e685c | 877 | */ |
okini3939 | 1:e3b2027e685c | 878 | ZBTxRequest(); |
okini3939 | 1:e3b2027e685c | 879 | XBeeAddress64& getAddress64(); |
okini3939 | 1:e3b2027e685c | 880 | uint16_t getAddress16(); |
okini3939 | 1:e3b2027e685c | 881 | uint8_t getBroadcastRadius(); |
okini3939 | 1:e3b2027e685c | 882 | uint8_t getOption(); |
okini3939 | 1:e3b2027e685c | 883 | void setAddress64(XBeeAddress64& addr64); |
okini3939 | 1:e3b2027e685c | 884 | void setAddress16(uint16_t addr16); |
okini3939 | 1:e3b2027e685c | 885 | void setBroadcastRadius(uint8_t broadcastRadius); |
okini3939 | 1:e3b2027e685c | 886 | void setOption(uint8_t option); |
okini3939 | 1:e3b2027e685c | 887 | protected: |
okini3939 | 1:e3b2027e685c | 888 | // declare virtual functions |
okini3939 | 4:f6d73acc1f75 | 889 | virtual uint8_t getFrameData(uint16_t pos); |
okini3939 | 4:f6d73acc1f75 | 890 | virtual uint16_t getFrameDataLength(); |
okini3939 | 1:e3b2027e685c | 891 | private: |
okini3939 | 1:e3b2027e685c | 892 | XBeeAddress64 _addr64; |
okini3939 | 1:e3b2027e685c | 893 | uint16_t _addr16; |
okini3939 | 1:e3b2027e685c | 894 | uint8_t _broadcastRadius; |
okini3939 | 1:e3b2027e685c | 895 | uint8_t _option; |
okini3939 | 1:e3b2027e685c | 896 | }; |
okini3939 | 1:e3b2027e685c | 897 | |
okini3939 | 1:e3b2027e685c | 898 | #endif |
okini3939 | 1:e3b2027e685c | 899 | |
okini3939 | 1:e3b2027e685c | 900 | /** |
okini3939 | 1:e3b2027e685c | 901 | * Represents an AT Command TX packet |
okini3939 | 1:e3b2027e685c | 902 | * The command is used to configure the serially connected XBee radio |
okini3939 | 1:e3b2027e685c | 903 | */ |
okini3939 | 1:e3b2027e685c | 904 | class AtCommandRequest : public XBeeRequest { |
okini3939 | 1:e3b2027e685c | 905 | public: |
okini3939 | 1:e3b2027e685c | 906 | AtCommandRequest(); |
okini3939 | 1:e3b2027e685c | 907 | AtCommandRequest(uint8_t *command); |
okini3939 | 1:e3b2027e685c | 908 | AtCommandRequest(uint8_t *command, uint8_t *commandValue, uint8_t commandValueLength); |
okini3939 | 4:f6d73acc1f75 | 909 | virtual uint8_t getFrameData(uint16_t pos); |
okini3939 | 4:f6d73acc1f75 | 910 | virtual uint16_t getFrameDataLength(); |
okini3939 | 1:e3b2027e685c | 911 | uint8_t* getCommand(); |
okini3939 | 1:e3b2027e685c | 912 | void setCommand(uint8_t* command); |
okini3939 | 1:e3b2027e685c | 913 | uint8_t* getCommandValue(); |
okini3939 | 1:e3b2027e685c | 914 | void setCommandValue(uint8_t* command); |
okini3939 | 1:e3b2027e685c | 915 | uint8_t getCommandValueLength(); |
okini3939 | 1:e3b2027e685c | 916 | void setCommandValueLength(uint8_t length); |
okini3939 | 1:e3b2027e685c | 917 | /** |
okini3939 | 1:e3b2027e685c | 918 | * Clears the optional commandValue and commandValueLength so that a query may be sent |
okini3939 | 1:e3b2027e685c | 919 | */ |
okini3939 | 1:e3b2027e685c | 920 | void clearCommandValue(); |
okini3939 | 1:e3b2027e685c | 921 | //void reset(); |
okini3939 | 1:e3b2027e685c | 922 | private: |
okini3939 | 1:e3b2027e685c | 923 | uint8_t *_command; |
okini3939 | 1:e3b2027e685c | 924 | uint8_t *_commandValue; |
okini3939 | 1:e3b2027e685c | 925 | uint8_t _commandValueLength; |
okini3939 | 1:e3b2027e685c | 926 | }; |
okini3939 | 1:e3b2027e685c | 927 | |
okini3939 | 1:e3b2027e685c | 928 | /** |
okini3939 | 1:e3b2027e685c | 929 | * Represents an Remote AT Command TX packet |
okini3939 | 1:e3b2027e685c | 930 | * The command is used to configure a remote XBee radio |
okini3939 | 1:e3b2027e685c | 931 | */ |
okini3939 | 1:e3b2027e685c | 932 | class RemoteAtCommandRequest : public AtCommandRequest { |
okini3939 | 1:e3b2027e685c | 933 | public: |
okini3939 | 1:e3b2027e685c | 934 | RemoteAtCommandRequest(); |
okini3939 | 1:e3b2027e685c | 935 | /** |
okini3939 | 1:e3b2027e685c | 936 | * Creates a RemoteAtCommandRequest with 16-bit address to set a command. |
okini3939 | 1:e3b2027e685c | 937 | * 64-bit address defaults to broadcast and applyChanges is true. |
okini3939 | 1:e3b2027e685c | 938 | */ |
okini3939 | 1:e3b2027e685c | 939 | RemoteAtCommandRequest(uint16_t remoteAddress16, uint8_t *command, uint8_t *commandValue, uint8_t commandValueLength); |
okini3939 | 1:e3b2027e685c | 940 | /** |
okini3939 | 1:e3b2027e685c | 941 | * Creates a RemoteAtCommandRequest with 16-bit address to query a command. |
okini3939 | 1:e3b2027e685c | 942 | * 64-bit address defaults to broadcast and applyChanges is true. |
okini3939 | 1:e3b2027e685c | 943 | */ |
okini3939 | 1:e3b2027e685c | 944 | RemoteAtCommandRequest(uint16_t remoteAddress16, uint8_t *command); |
okini3939 | 1:e3b2027e685c | 945 | /** |
okini3939 | 1:e3b2027e685c | 946 | * Creates a RemoteAtCommandRequest with 64-bit address to set a command. |
okini3939 | 1:e3b2027e685c | 947 | * 16-bit address defaults to broadcast and applyChanges is true. |
okini3939 | 1:e3b2027e685c | 948 | */ |
okini3939 | 1:e3b2027e685c | 949 | RemoteAtCommandRequest(XBeeAddress64 &remoteAddress64, uint8_t *command, uint8_t *commandValue, uint8_t commandValueLength); |
okini3939 | 1:e3b2027e685c | 950 | /** |
okini3939 | 1:e3b2027e685c | 951 | * Creates a RemoteAtCommandRequest with 16-bit address to query a command. |
okini3939 | 1:e3b2027e685c | 952 | * 16-bit address defaults to broadcast and applyChanges is true. |
okini3939 | 1:e3b2027e685c | 953 | */ |
okini3939 | 1:e3b2027e685c | 954 | RemoteAtCommandRequest(XBeeAddress64 &remoteAddress64, uint8_t *command); |
okini3939 | 1:e3b2027e685c | 955 | uint16_t getRemoteAddress16(); |
okini3939 | 1:e3b2027e685c | 956 | void setRemoteAddress16(uint16_t remoteAddress16); |
okini3939 | 1:e3b2027e685c | 957 | XBeeAddress64& getRemoteAddress64(); |
okini3939 | 1:e3b2027e685c | 958 | void setRemoteAddress64(XBeeAddress64 &remoteAddress64); |
okini3939 | 1:e3b2027e685c | 959 | bool getApplyChanges(); |
okini3939 | 1:e3b2027e685c | 960 | void setApplyChanges(bool applyChanges); |
okini3939 | 4:f6d73acc1f75 | 961 | virtual uint8_t getFrameData(uint16_t pos); |
okini3939 | 4:f6d73acc1f75 | 962 | virtual uint16_t getFrameDataLength(); |
okini3939 | 1:e3b2027e685c | 963 | static XBeeAddress64 broadcastAddress64; |
okini3939 | 1:e3b2027e685c | 964 | // static uint16_t broadcast16Address; |
okini3939 | 1:e3b2027e685c | 965 | private: |
okini3939 | 1:e3b2027e685c | 966 | XBeeAddress64 _remoteAddress64; |
okini3939 | 1:e3b2027e685c | 967 | uint16_t _remoteAddress16; |
okini3939 | 1:e3b2027e685c | 968 | bool _applyChanges; |
okini3939 | 1:e3b2027e685c | 969 | }; |
okini3939 | 1:e3b2027e685c | 970 | |
okini3939 | 1:e3b2027e685c | 971 | |
okini3939 | 1:e3b2027e685c | 972 | |
okini3939 | 1:e3b2027e685c | 973 | #endif //XBee_h |